# this will only work for one molecule #VMD --- start of VMD description block #Name: # Bridging waters #Synopsis: # Example of how to display a selection that changes over an animation #Version: # 1.0 #Uses VMD version: # 1.1 #Ease of use: # 4 #Procedures: #
  • start_bridging molid -- start the trace on the vmd_frame for molid #
  • stop_bridging -- top the current trace #
  • calc_bridging -- check the cache, create a selection if needed #
  • num_bridging -- example of how to get data from the cache #Description: # When the frame changes, a cache is checked to see if a selection has been # computed for it. If not, one is made and added to the cache. The Tcl # variable "bridging" is set to the atomselection, and element 0 of the # graphics list is changed to "@bridging". This forces that element to # be redrawn using the new selection. #Warning: # This will only work for one selection on one molecule #Example: #
    # mol load psf er-ere.psf pdb er-ere.pdb
    # # start the bridge calculations
    # start_bridging
    # # however, one frame has already been read, so do its calculations
    # # by hand
    # calc_bridging
    # # read the rest of the frames (the selections are automatically computed)
    # animate read dcd dyn100frames.DCD
    # 
    #Files: # active_selection.vmd #See also: # # SSCache #Author: # Andrew Dalke <dalke@ks.uiuc.edu> #\VMD --- end of block # start the trace proc start_bridging {{molid top}} { global vmd_frame bridging_molecule if {![string compare $molid top]} { set molid [molinfo top] } trace variable vmd_frame($molid) w calc_bridging set bridging_molecule $molid } # stop the trace proc stop_bridging {} { global bridging_molecule vmd_frame trace vdelete vmd_frame($bridging_molecule) w calc_bridging } # do the actual calculation proc calc_bridging {args} { global bridging_waters bridging_molecule bridging # get the current frame number set frame [molinfo $bridging_molecule get frame] # has the selection already been made? if {! [info exists bridging_waters($frame)]} { puts "Calculating frame $frame for $bridging_molecule" set bridging_waters($frame) [atomselect $bridging_molecule \ {x < 10} frame $frame] } # set things up for the graphics form to use the precomputed selection set bridging $bridging_waters($frame) # do this since otherwise the selection is deleted when the proc ends $bridging global # update the 0th element of the graphics molecule # Note: if the display wasn't turned off, there would be an extra # update of the animation ... very bad. Or maybe there is a bug # in VMD here? display update off mol modselect 0 $bridging_molecule {@bridging} display update on } # a simple example of how to use the precomputed results # This prints the number of atoms in the given selection for # each frame proc num_bridging {} { global bridging_waters set nums [lsort -integer [array names bridging_waters]] foreach num $nums { set num_atoms [$bridging_waters($num) num] puts "Frame $num has $num_atoms atoms" } }