next up previous contents index
Next: Trace on the pick Up: Advanced Script Writing Previous: save/load VMD state information

Currently picked molecule/atom

 

Every time an atom is picked, the Tcl variables vmd_pick_mol and   vmd_pick_atom   are set to the molecule id and atom index of the picked atom. This is useful for scripts that need to act on used defined atom.

For example, the following procedure takes the picked atom and finds the molecular weight of residue it is on.

 

proc mol_weight {} {
      # use the picked atom's index and molecule id
      global vmd_pick_atom vmd_pick_mol
      set sel [atomselect $vmd_pick_mol "same residue as index $vmd_pick_atom"]
      set mass 0
      foreach m [$sel get mass] {
            set mass [expr $mass + $m]
      }
      # get residue name and id
      set atom [atomselect $vmd_pick_mol "index $vmd_pick_atom"]
      lassign [$atom get {resname resid}] resname resid
      # print the result
      puts "Mass of $resname $resid = $mass"
}
Once an atom has been picked, run the command mol_weight to get output like:
Mass of ALA 7 : 67.047



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