next up previous contents index
Next: Animation Up: Tutorials and Examples Previous: Adding a label   Contents   Index


Interface to picking

When an atom is picked with the mouse, the Tcl variable vmd_pick_mol gets set to the moleule id of the picked molecule, and vmd_pick_atom contains the atom index. The Tcl command trace can be used to call a function when those values change.

As an example of what can be done with this, the following statements will put a sphere around each atom when it has been picked with the mouse. To turn it off, execute
trace vdelete vmd_pick_atom w sphere_pick.

proc sphere_pick {name element op} {
     # get the atom and molecule picked
     global vmd_pick_atom vmd_pick_mol
     # get the coordinates
     set sel [atomselect $vmd_pick_mol "index $vmd_pick_atom"]
     lassign [$sel get {x y z}] coords
     draw sphere $coords radius 1.0
}
trace variable vmd_pick_atom w sphere_pick



vmd@ks.uiuc.edu