Recent site activity

Random Hacks‎ > ‎

Irregular VMD Representation Update

Whenever looking at animations in VMD that have a selection string using "within" or a function of atom positions, then one needs to update the selection, or else VMD will show the atoms that would satisfy the selection condition at the frame it was defined only. There is an option to automatically "Update Selection [in] Every Frame" in the GUI, but that can lead to distractions, because at the boundary where atoms are moving in and out of the selection, any animation will look very busy and may needlessly call attention to it. Better would be to have this update of the selection happen only every N steps and even better would be, if this N would have some degree of randomness to it. The following little Tcl script realizes just that.

proc do_toggle_selupdate {args} {
    global updmol updrep lastup stepup randup
    #puts "do_toggle_selupdate: $args : dipmol $dipmol  diprep $diprep  lastup $lastup  stepup $stepup"

    set frame [molinfo $updmol get frame]
    if {[expr {abs($frame - $lastup)}] < [expr {$stepup + int(rand()*$randup)}]} {
       mol selupdate $updrep $updmol 0
    } else {
       mol selupdate $updrep $updmol 1
       set lastup $frame
    }
}

This subroutine needs some (global) defaults and settings, so they can be passed to the callback function.

# global variables
set updmol 0           ; # molecule we want the irregular update for
set updrep 0           ; # representation id we need to toggle
set stepup  50         ; # update only about every 50+x steps
set lastup -$stepup    ; # last frame the rep was updated for
set randup  $stepup    ; # add some randomness to the update
global upd_mol upd_rep lastup stepup randup

Final step is to add the function to the list of callbacks for the VMD animation loop for this molecule.

# hook up the callback function
trace add variable vmd_frame($updmol) write do_toggle_selupdate

Comments