From: Andrew Dalke (dalke_at_bioreason.com)
Date: Mon Aug 24 1998 - 15:01:05 CDT

Keith Refson <Keith.Refson_at_earth.ox.ac.uk> asked:
> I have a related question, which I can't quite see how to answer
> from this posting. I am trying to animate the results of a an
> ab-initio MD calculation where the bonding changes during the run.
> It looks like VMD keeps the original bond information for every
> frame in the sequence. This is not appropriate for my application:
> what I would really like is to be able to tell VMD to recalculate
> the bonds for each frame in the sequence separately.

For that you need two things, the bond information and someway to
update the bond lists at every timestep of the animation. The essay
covered how to do the first part. The second one is done with a trace
on the Tcl variable "vmd_frame".

  Jeff Ulrich wrote an article about this a little over a year ago. I
looked at the vmd-l archive on the web page but it doesn't appear to
be working. I've forward that article to Keith, and we'll see about
fixing the web accessibility.

  The gist is that when the timestep frame of a molecule (with id
of "$molid") changes, the Tcl variable "vmd_frame($molid)" is set.
Suppose somehow you've read all the bond information into the 2D Tcl
array "bond_data($molid,$frame)". (Two dimensional so you can have
different bondings for different different molecules but the same
timestep frame.) Then you can write a trace callback function like:

proc update_bond_info {name molid op} {
   global bond_data
   ## get the new frame number
   # Tcl doesn't yet have it, but VMD does ...
   set frame [molinfo $index get frame]
   if [info exists bond_data($molid,$frame)] {
     set sel [atomselect $molid all]
     $sel set bondlist $bond_data($molid,$frame)
     return
   }
   # if you get to this point you have no bond information. You can
   # let it go or attempt to determine it dynamically (eg, check if
   # filename+frame number exists and read it from a file or recompute
   # the bonds with some function of your own devising). Remember to
   # cache the results into "bond_data" so you can easily recall the data.
}

An example of this, indeed, my first use of this feature, is at:
  http://www.ks.uiuc.edu/Research/vmd/script_library/scripts/sscache/

It computes the secondary structure throughout the trajectory so on
playback you can see how the structure changes as the conformation
changes. It only compute the structures as needed and caches the
results for later use, hence the name "sscache".

So, combining those two features (modifying the bond lists and
checking the frame) you should be able to get what you want.

                                                Andrew Dalke
                                                dalke_at_bioreason.com