Skip to content

Commit 50415bf

Browse files
committed
Dash: Add graphical control to save traj file
1 parent d8b5a7f commit 50415bf

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

vmd/cv_dashboard/cv_dashboard.tcl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
# Usage (after installing):
55
# package require cv_dashboard
66
# cv_dashboard
7+
# or select the Extensions/Analysis menu item
78

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

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

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

956958

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

959962
proc create_traj_colvar { molid cv } {
960963

@@ -1010,3 +1013,20 @@ proc create_traj_colvar { molid cv } {
10101013
"
10111014
cv config $configString
10121015
}
1016+
1017+
# Save trajectory of currently defined colvars to a file in the colvars.traj format
1018+
1019+
proc ::cv_dashboard::save_traj_file { fileName } {
1020+
1021+
puts "Writing colvars trajectory to file $fileName"
1022+
set o [open $fileName w]
1023+
puts -nonewline $o [cv printframelabels]
1024+
1025+
set nf [molinfo top get numframes]
1026+
for {set f 0} {$f< $nf} {incr f} {
1027+
cv frame $f
1028+
cv update
1029+
puts -nonewline $o [cv printframe]
1030+
}
1031+
close $o
1032+
}

vmd/cv_dashboard/cv_dashboard_main.tcl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ proc ::cv_dashboard::createWindow {} {
3333
-row $gridrow -column 0 -pady 2 -padx 2 -sticky nsew
3434
grid [ttk::button $w.save -text "Save" -command ::cv_dashboard::save -padding "2 0 2 0"] \
3535
-row $gridrow -column 1 -pady 2 -padx 2 -sticky nsew
36-
grid [ttk::button $w.reset -text "Reset" -command ::cv_dashboard::reset -padding "2 0 2 0"] \
36+
grid [ttk::button $w.reset -text "Reset" -command ::cv_dashboard::reset -padding "2 0 2 0"] \
3737
-row $gridrow -column 2 -pady 2 -padx 2 -sticky nsew
3838

39+
incr gridrow
40+
grid [ttk::button $w.save_traj -text "Save traj file" -command ::cv_dashboard::save_traj_dialog -padding "2 0 2 0"] \
41+
-row $gridrow -column 0 -pady 2 -padx 2 -sticky nsew
42+
3943
# Table of colvars
4044
ttk::treeview $w.cvtable -selectmode extended -show {headings tree} -height 8
4145
$w.cvtable configure -column val
@@ -516,7 +520,7 @@ https://colvars.github.io
516520
In [vmdinfo versionmsg]
517521
Running Tcl/Tk [info patchlevel]
518522
519-
Jérôme Hénin (jerome.henin@ibpc.fr), Giacomo Fiorin (giacomo.fiorin@nih.gov) and the Colvars developers.
523+
Jérôme Hénin (jerome.henin@cnrs.fr), Giacomo Fiorin (giacomo.fiorin@nih.gov) and the Colvars developers.
520524
521525
#Please cite the following references for features currently in use:
522526
@@ -1488,3 +1492,13 @@ proc ::cv_dashboard::createRotationMenu { row } {
14881492

14891493
grid remove $menu.show_rotation $menu.hide_rotation
14901494
}
1495+
1496+
# Open file dialog to choose file name, then save colvars trajectory
1497+
1498+
proc ::cv_dashboard::save_traj_dialog {} {
1499+
set file [tk_getSaveFile -title "Colvars trajectory file to be written" \
1500+
-filetypes {{"Colvars traj" .colvars.traj} {"All files" *}}]
1501+
if {[llength $file] > 0 } {
1502+
::cv_dashboard::save_traj_file $file
1503+
}
1504+
}

0 commit comments

Comments
 (0)