Skip to content

Commit

Permalink
Dash: Add graphical control to save traj file
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenin committed Nov 21, 2024
1 parent 1e7b54d commit edcb47d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
26 changes: 23 additions & 3 deletions vmd/cv_dashboard/cv_dashboard.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
# Usage (after installing):
# package require cv_dashboard
# cv_dashboard
# or select the Extensions/Analysis menu item

# Design principles:
# - take advantage of colvars/VMD binding for maximum user interaction
# - hide the colvars config text from user, instead expose colvar, names and values
# - do not try to parse the colvars config (let the Colvars Module do it)
# to avoid coming up with an incompatible parser

# This plugin only acts on the "top" molecule
# which is most consistent for trajectory animation (determined by the frame number of mol)
# Source file layout:
# - this file contains utility functions and data structure, without GUI
# - other files contain GUI elements

# TODO Multiplot:
# - properly calculate position of cursor in plot when not all the plot is visible (resized window)
Expand Down Expand Up @@ -954,7 +956,8 @@ Read the standard output (terminal) for details."
}


# Create a scripted colvar that returns values from a precomputed trajectory
# Create a scripted colvar that returns values from a precomputed trajectory
# (internal utility function for load_cv_traj, hence not in the main namespace)

proc create_traj_colvar { molid cv } {

Expand Down Expand Up @@ -1010,3 +1013,20 @@ proc create_traj_colvar { molid cv } {
"
cv config $configString
}

# Save trajectory of currently defined colvars to a file in the colvars.traj format

proc ::cv_dashboard::save_traj_file { fileName } {

puts "Writing colvars trajectory to file $fileName"
set o [open $fileName w]
puts -nonewline $o [cv printframelabels]

set nf [molinfo top get numframes]
for {set f 0} {$f< $nf} {incr f} {
cv frame $f
cv update
puts -nonewline $o [cv printframe]
}
close $o
}
18 changes: 16 additions & 2 deletions vmd/cv_dashboard/cv_dashboard_main.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ proc ::cv_dashboard::createWindow {} {
-row $gridrow -column 0 -pady 2 -padx 2 -sticky nsew
grid [ttk::button $w.save -text "Save" -command ::cv_dashboard::save -padding "2 0 2 0"] \
-row $gridrow -column 1 -pady 2 -padx 2 -sticky nsew
grid [ttk::button $w.reset -text "Reset" -command ::cv_dashboard::reset -padding "2 0 2 0"] \
grid [ttk::button $w.reset -text "Reset" -command ::cv_dashboard::reset -padding "2 0 2 0"] \
-row $gridrow -column 2 -pady 2 -padx 2 -sticky nsew

incr gridrow
grid [ttk::button $w.save_traj -text "Save traj file" -command ::cv_dashboard::save_traj_dialog -padding "2 0 2 0"] \
-row $gridrow -column 0 -pady 2 -padx 2 -sticky nsew

# Table of colvars
ttk::treeview $w.cvtable -selectmode extended -show {headings tree} -height 8
$w.cvtable configure -column val
Expand Down Expand Up @@ -516,7 +520,7 @@ https://colvars.github.io
In [vmdinfo versionmsg]
Running Tcl/Tk [info patchlevel]
Jérôme Hénin (jerome.henin@ibpc.fr), Giacomo Fiorin ([email protected]) and the Colvars developers.
Jérôme Hénin (jerome.henin@cnrs.fr), Giacomo Fiorin ([email protected]) and the Colvars developers.
#Please cite the following references for features currently in use:
Expand Down Expand Up @@ -1488,3 +1492,13 @@ proc ::cv_dashboard::createRotationMenu { row } {

grid remove $menu.show_rotation $menu.hide_rotation
}

# Open file dialog to choose file name, then save colvars trajectory

proc ::cv_dashboard::save_traj_dialog {} {
set file [tk_getSaveFile -title "Colvars trajectory file to be written" \
-filetypes {{"Colvars traj" .colvars.traj} {"All files" *}}]
if {[llength $file] > 0 } {
::cv_dashboard::save_traj_file $file
}
}

0 comments on commit edcb47d

Please sign in to comment.