diff --git a/vmd/cv_dashboard/cv_dashboard.tcl b/vmd/cv_dashboard/cv_dashboard.tcl index 281ceccdf..748b44156 100644 --- a/vmd/cv_dashboard/cv_dashboard.tcl +++ b/vmd/cv_dashboard/cv_dashboard.tcl @@ -4,6 +4,7 @@ # 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 @@ -11,8 +12,9 @@ # - 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) @@ -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 } { @@ -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 +} diff --git a/vmd/cv_dashboard/cv_dashboard_main.tcl b/vmd/cv_dashboard/cv_dashboard_main.tcl index b1dd7a3e3..d7791d49d 100644 --- a/vmd/cv_dashboard/cv_dashboard_main.tcl +++ b/vmd/cv_dashboard/cv_dashboard_main.tcl @@ -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 @@ -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 (giacomo.fiorin@nih.gov) and the Colvars developers. +Jérôme Hénin (jerome.henin@cnrs.fr), Giacomo Fiorin (giacomo.fiorin@nih.gov) and the Colvars developers. #Please cite the following references for features currently in use: @@ -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 + } +}