Stereo ray: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
Line 77: Line 77:


[[Category:Script_Library|Stereo Ray]]
[[Category:Script_Library|Stereo Ray]]
[[Category:UI_Scripts]]

Revision as of 07:25, 30 April 2009

Left Image
Right Image
Combined Images


Manually

To get a stereo diagram you need two images. The left image is rotated +3 degrees and the right image is rotated -3 degrees.

To obtain the left image, type:

ray angle=+3
png left-image.png

Likewise, to obtain the right image, type:

ray angle=-3
png right-image.png

You still use any other ray based modifications, such as:

ray 1600,1200,angle=+3
png big-left-image.png

Script

A user on the PyMol list wrote a very nice little stereo ray tracing script. Just copy this to a text file. Then, in PyMol run

run dirName/scriptName.pym

where dirName is where you put it, and scriptName is what you named the file then run one something like the example lines given:

EXAMPLE
   stereo_ray output, 1000, 600
   stereo_ray secondImage.png

This will create to images, one with an L and one with an R suffix. Just paste the two images next to each other (in some image editing program) and you're done.

from pymol import cmd

def stereo_ray(output='', width='', height=''):
   '''
DESCRIPTION
   "stereo_ray" ray-traces the current scene twice (separated by 
   a six-degree rotation around the y axis)
   and saves a pair of images that can be combined in any image
   manipulation software to form a stereoimage.
   The first argument, the output file name, is mandatory.
   The second and third arguments, the size of the image, are not.
   If the width is given, the height will be calculated.

USAGE
   stereo_ray filename [, width [, height]]

EXAMPLE
   stereo_ray output, 1000, 600
   stereo_ray secondImage.png
   '''

   if output == '':
      print 'no output filename defined\n'
      print 'try: \'stereo_ray filename\''
      return -1
      # abort if no output file name given

   if width == '':
      width,height = cmd.get_session()['main'][0:2]
      # get dimensions from viewer if not given

   elif height == '':
      oldWidth,oldHeight = cmd.get_session()['main'][0:2]
      height = int(width)*oldHeight/oldWidth
      # calculate height from proportions of viewer if
      # only width is given

   cmd.ray(width, height, angle=-3)
   cmd.png(output+"_r")
   cmd.ray(width, height, angle=3)
   cmd.png(output+"_l")

cmd.extend('stereo_ray',stereo_ray)