next up previous contents index
Next: RMSD and best-fit alignments Up: Trajectory frames Previous: Viewing selections which change

Simulation frames

      When a new simulation timestep arrives, the Tcl variable vmd_timestep(molecule) is set to the value of the new frame. You guessed it - this can be used along with the trace command.

One simple case prints the temperature of the new timestep.

proc timestep_temp_trace {name id op} {
      set temp [molinfo $id get temperature]
      puts "Temp. of molecule $id is $temp"
}

trace variable vmd_timestep w timestep_temp_trace

Of course, why do textually what you can do graphically? The following makes a plot of the last ten temperatures. For simplicity, only one plot is allowed.

  The begin_temp_plot sets up the temperature plot variables and calls the trace. The trace calls timestep_temp_trace which adds the new temperature to the storage list and then calls the graphics routine. (A list was used here because, while slower than an array, the lvarpop was handy.) There is nothing new or unusual about the plotting procedure (draw_temps_plot) or the routine to finish the real-time plotting (end_temp_plot).

proc begin_temp_plot {molid} {
   # make sure the molecule exists
   molinfo $molid get frame

   global temps temps_mol temps_trace_mol vmd_timestep
   # create a new graphics molecule
   mol load graphics "Temp.of_$molid"
   set temps_mol [molinfo top]
   set temps [ldup 10 0]
   # the molecule to watch
   set temps_trace_mol $molid
   # start the trace
   trace variable vmd_timestep($molid) w timestep_temp_trace
}

proc end_temp_plot {} {
   global temps_trace_mol
   # remove the trace
   trace vdelete vmd_timestep($temps_trace_mol) w timestep_temp_trace
}

proc draw_temps_plot {} {
   global temps temps_mol
   graphics $temps_mol delete all
   graphics $temps_mol color red
   set tmp $temps
   set pt0 [lvarpop tmp]
   set x0 0
   set x1 10
   foreach pt1 $tmp {
      graphics $temps_mol line "$x0 $pt0 0" "$x1 $pt1 0"
        set x0 $x1
        incr x1 10
        set pt0 $pt1
   }
   graphics $temps_mol color green
   graphics $temps_mol line {0 0 0} {100 0 0}
   graphics $temps_mol line {0 0 0} {0 500 0}
}

proc timestep_temp_trace {args} {
   global temps temps_mol temps_trace_mol
   # delete old and add newest value to temps
   lvarpop temps
   set new_t [molinfo $temps_trace_mol get temp]
   set temps "$temps $new_t"
   draw_temps_plot
}

Needless to say, many more options can be added to this for plotting different variables, autoscaling, adding text, etc.

By the way, though it has not yet been tested out, we envision that a trace on the vmd_timestep variable could be used to modify the user forces as the simulation progresses. This makes the linear force controls emulate a harmonic well, or let you apply the forces along a path. You could even make two atoms come towards each other, or draw apply the forces to the atoms on a selection such that the center of mass of the selection is the important term. If you want to try it out, good luck!



Justin Gullingsrud
Tue Apr 6 09:22:39 CDT 1999