Skip to content

Commit d776d86

Browse files
committed
Add Multiplot menu entry for Colvars
This is a first example, letting users swap the axes of a pairwise plot More entries can be added to other plot types
1 parent c7893a6 commit d776d86

File tree

1 file changed

+62
-36
lines changed

1 file changed

+62
-36
lines changed

vmd/cv_dashboard/cv_dashboard_plots.tcl

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ proc ::cv_dashboard::plot { { type timeline } } {
8585
set plothandle [multiplot -title {Colvars trajectory [click on markers, keyb arrows (+ Shift/Ctrl) to navigate]} \
8686
-xlabel $xname -ylabel $yname -nostats -marker circle -fill white -radius 4 -callback ::cv_dashboard::marker_clicked]
8787
$plothandle add $y($xname) $y($yname)
88+
89+
# Add custom Colvars menu item to Multiplot window
90+
set plot_ns [$plothandle namespace]
91+
set menubar "[set ${plot_ns}::w].menubar"
92+
menubutton $menubar.colvars -text "Colvars" -underline 0 -menu $menubar.colvars.menu
93+
menu $menubar.colvars.menu -tearoff 0
94+
$menubar.colvars.menu add command -label "Swap axes" -command ::cv_dashboard::pairwise_swap_axes
95+
# Add item to existing menu bar
96+
set col [lindex [grid size $menubar] 0]
97+
grid $menubar.colvars -row 0 -column $col -sticky nsw
98+
grid columnconfigure $menubar $col -weight 2
99+
88100
} elseif { $type == "histogram"} {
89101
set xname [lindex $name_list 0]
90102
# Save list of values for navigating
@@ -112,7 +124,6 @@ proc ::cv_dashboard::plot { { type timeline } } {
112124
-xlabel $xname -ylabel "N" -nostats -xmin $xmin -xmax $xmax \
113125
-ymin 0.0 -x $centers -y $frequencies -nolines -plot]
114126

115-
set ns [namespace qualifiers $plothandle]
116127
# force bars to start at zero
117128
set ymin 0.0
118129

@@ -251,13 +262,13 @@ proc ::cv_dashboard::plot_bias_energy { } {
251262
# Callback for click inside plot window, at coords x y
252263
proc ::cv_dashboard::plot_clicked { x y } {
253264

254-
set ns [$::cv_dashboard::plothandle namespace]
255-
set xplotmin [set ${ns}::xplotmin]
256-
set xplotmax [set ${ns}::xplotmax]
257-
set yplotmin [set ${ns}::yplotmin]
258-
set yplotmax [set ${ns}::yplotmax]
259-
set scalex [set ${ns}::scalex]
260-
set xmin [set ${ns}::xmin]
265+
set plot_ns [$::cv_dashboard::plothandle namespace]
266+
set xplotmin [set ${plot_ns}::xplotmin]
267+
set xplotmax [set ${plot_ns}::xplotmax]
268+
set yplotmin [set ${plot_ns}::yplotmin]
269+
set yplotmax [set ${plot_ns}::yplotmax]
270+
set scalex [set ${plot_ns}::scalex]
271+
set xmin [set ${plot_ns}::xmin]
261272

262273
# note: ymax < ymin because of pixel coordinate convention
263274
if { [expr {($x < $xplotmin) || ($x > $xplotmax) || ($y > $yplotmin) || ($y < $yplotmax)}] } {
@@ -330,9 +341,9 @@ proc ::cv_dashboard::chg_frame { shift { order "traj" } } {
330341
proc ::cv_dashboard::zoom { factor } {
331342
variable ::cv_dashboard::plothandle
332343

333-
set ns [namespace qualifiers $plothandle]
334-
set xmin [set ${ns}::xmin]
335-
set xmax [set ${ns}::xmax]
344+
set plot_ns [$plothandle namespace]
345+
set xmin [set ${plot_ns}::xmin]
346+
set xmax [set ${plot_ns}::xmax]
336347

337348
set f $::cv_dashboard::current_frame
338349
# rescale current half-width
@@ -357,9 +368,9 @@ proc ::cv_dashboard::zoom { factor } {
357368
proc ::cv_dashboard::fit_vertically {} {
358369
variable ::cv_dashboard::plothandle
359370

360-
set ns [namespace qualifiers $plothandle]
361-
set xmin [set ${ns}::xmin]
362-
set xmax [set ${ns}::xmax]
371+
set plot_ns [$plothandle namespace]
372+
set xmin [set ${plot_ns}::xmin]
373+
set xmax [set ${plot_ns}::xmax]
363374
set ydata [$plothandle ydata]
364375
set ymin [lindex [lindex $ydata 0] $xmin]
365376
set ymax $ymin
@@ -399,11 +410,11 @@ proc ::cv_dashboard::display_marker { f } {
399410
# we tinker a little with Multiplot's internals to get access to its Tk canvas
400411
# necessary because Multiplot does not expose an interface to draw & delete
401412
# objects without redrawing the whole plot - which takes too long for this
402-
set ns [namespace qualifiers $plothandle]
413+
set plot_ns [$plothandle namespace]
403414
if { $::cv_dashboard::plottype == "timeline" } {
404415

405-
set xmin [set ${ns}::xmin]
406-
set xmax [set ${ns}::xmax]
416+
set xmin [set ${plot_ns}::xmin]
417+
set xmax [set ${plot_ns}::xmax]
407418
# Move plot boundaries if necessary
408419
if { $f < $xmin } {
409420
set xmax [expr { $xmax + $f - $xmin }]
@@ -416,49 +427,49 @@ proc ::cv_dashboard::display_marker { f } {
416427
$plothandle configure -xmin $xmin -xmax $xmax -plot
417428
}
418429

419-
set y1 [set ${ns}::yplotmin]
420-
set y2 [set ${ns}::yplotmax]
421-
set xplotmin [set ${ns}::xplotmin]
422-
set scalex [set ${ns}::scalex]
430+
set y1 [set ${plot_ns}::yplotmin]
431+
set y2 [set ${plot_ns}::yplotmax]
432+
set xplotmin [set ${plot_ns}::xplotmin]
433+
set scalex [set ${plot_ns}::scalex]
423434
set x [expr $xplotmin+($scalex*($f-$xmin))]
424435

425-
set canv "[set ${ns}::w].f.cf"
436+
set canv "[set ${plot_ns}::w].f.cf"
426437
$canv delete frame_marker
427438
$canv create line $x $y1 $x $y2 -fill $timeline_color -tags frame_marker
428439
} elseif { $::cv_dashboard::plottype == "2cv" } {
429440
set x [lindex [ lindex [$plothandle xdata] 0] $f]
430441
set y [lindex [ lindex [$plothandle ydata] 0] $f]
431442

432-
set xmin [set ${ns}::xmin]
433-
set ymin [set ${ns}::ymin]
443+
set xmin [set ${plot_ns}::xmin]
444+
set ymin [set ${plot_ns}::ymin]
434445

435446
set radius 5
436-
set xplotmin [set ${ns}::xplotmin]
437-
set scalex [set ${ns}::scalex]
447+
set xplotmin [set ${plot_ns}::xplotmin]
448+
set scalex [set ${plot_ns}::scalex]
438449
set x1 [expr {$xplotmin+$scalex*($x-$xmin) - $radius}]
439450
set x2 [expr {$xplotmin+$scalex*($x-$xmin) + $radius}]
440451

441-
set yplotmin [set ${ns}::yplotmin]
442-
set scaley [set ${ns}::scaley]
452+
set yplotmin [set ${plot_ns}::yplotmin]
453+
set scaley [set ${plot_ns}::scaley]
443454
set y1 [expr {$yplotmin+$scaley*($y-$ymin) - $radius}]
444455
set y2 [expr {$yplotmin+$scaley*($y-$ymin) + $radius}]
445456

446-
set canv "[set ${ns}::w].f.cf"
457+
set canv "[set ${plot_ns}::w].f.cf"
447458
$canv delete frame_marker
448459
$canv create oval $x1 $y1 $x2 $y2 -outline white -fill $2cv_color -tags frame_marker
449460
} elseif { $::cv_dashboard::plottype == "histogram" } {
450-
set xmin [set ${ns}::xmin]
451-
set xmax [set ${ns}::xmax]
461+
set xmin [set ${plot_ns}::xmin]
462+
set xmax [set ${plot_ns}::xmax]
452463

453-
set y1 [set ${ns}::yplotmin]
454-
set y2 [set ${ns}::yplotmax]
464+
set y1 [set ${plot_ns}::yplotmin]
465+
set y2 [set ${plot_ns}::yplotmax]
455466
set v [lindex $cv_dashboard::histogram_time_series $f]
456467

457-
set xplotmin [set ${ns}::xplotmin]
458-
set scalex [set ${ns}::scalex]
468+
set xplotmin [set ${plot_ns}::xplotmin]
469+
set scalex [set ${plot_ns}::scalex]
459470
set x [expr $xplotmin+($scalex*($v-$xmin))]
460471

461-
set canv "[set ${ns}::w].f.cf"
472+
set canv "[set ${plot_ns}::w].f.cf"
462473
$canv delete frame_marker
463474
$canv create line $x $y1 $x $y2 -fill $histogram_color -tags frame_marker
464475
}
@@ -519,3 +530,18 @@ proc ::cv_dashboard::simplify x {
519530
set x [expr round($x / $factor) * $factor]
520531
return $x
521532
}
533+
534+
535+
proc ::cv_dashboard::pairwise_swap_axes {} {
536+
537+
variable ::cv_dashboard::plothandle
538+
set plot_ns [$plothandle namespace]
539+
540+
set x [$plothandle xdata]
541+
set y [$plothandle ydata]
542+
set xlabel [set ${plot_ns}::xlabeltext]
543+
set ylabel [set ${plot_ns}::ylabeltext]
544+
545+
$plothandle clear
546+
$plothandle add $y $x -xlabel $ylabel -ylabel $xlabel -plot
547+
}

0 commit comments

Comments
 (0)