next up previous contents index
Next: Trajectory frames Up: Trace on the pick Previous: Making a sphere appear

Drawing a line from the eye to the picked atom

 

This last example of a trace on the picked atom draws a line from the picked atom to the user's eye. It is a good example of how to use matrices in VMD. The limitation to the following procedure is that it doesn't understand perspective viewing, so to make it work, use the orthographic mode.

This was used to find the direction to pull a ligand from its bound position out of the protein. The molecule was rotated until the user could look straight down to the ligand. The user then picked an atom on the ligand, causing a line (actually, a cylinder) to be drawn from the atom past the eye location, and the start and end points of the cylinder were printed for later use.

proc eye_line {} {
  global vmd_pick_atom vmd_pick_mol
  set sel [atomselect $vmd_pick_mol "index $vmd_pick_atom"]

  # coordinates of the atom
  set coords [lindex [$sel get {x y z}] 0]

  # position in world space
  set mat [lindex [molinfo $vmd_pick_mol get view_matrix] 0]
  set world [vectrans $mat $coords]

  # since this is orthographic, just get the projection on z
  lassign $world x y
  # get a coordinate behind the eye
  set world2 "$x $y 5"

  # convert back to molecule space
  # (need an inverse, which is only available with the 
  #  measure command)
  set inv [measure inverse $mat]
  set coords2 [vectrans $inv $world2]

  # and draw the line
  draw cylinder $coords $coords2 radius 0.3

  puts "Start: $coords"
  puts "End: $coords2"
}



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