Hi Warren,
i have just updated the stpng() function that generates stereo figures. the
function can be called with
contrib.stpng('filename.ext')
it supports a wide range of image formats, which are chosen by the extension
of the image file (ie. .png .tif .ps .pdf .gif .jpg etc...).
contrib.stpng() requires the Python Image Library (PIL) to merge the left and
right images, but the last part of the code can be commented out on systems
that dont have PIL installed. in that case left and right images are still
generated 'filename_left.png, filename_right.png', but not merged.
the function has been tested with the binary version of pymol_0.78 rh7.2 and
python2.1 on a Linux system (SuSE7.3) .
The function is installed by replacing pymol/modules/pymol/contrib.py with
the attached file and please ensure that PIL (ie.
/usr/lib/python/site-packages/PIL) is included in your python path.
cheers
peter
:) ___________________________________________
Peter Haebel
Institute for Molecular Biology and Biophysics
ETH Hoenggerberg, HPK H 11
CH-8037 Zurich
Phone: +41 1 63-33960 Fax: +41 1 633-1246
Email: [email protected]
# Contributed functionality which is either
# untested or considered unsupported by
# DeLano Scientific
import os
import pymol
import cmd
# contrib.stpng('filename.ext') generates stereo figure of current view
#
# The image format is determined by the extension of the image filename.
# Supported formats: .png .jpg .tif .pdf .gif .ps etc...
#
# NOTE: Requires the Python Image Library. If PIL is not installed
# remove the second part of the code (see below!) and merge the
# left and right images in an external program.
#
# Tested on SuSE linux 7.3, Python 2.1, PIL
# Contributed by P. Haebel
def stpng(filename="stereo.png"):
filename=str(filename)
leftfile="%s_left.png"%filename
rightfile="%s_right.png"%filename
# render left image and save as 'filename_left.png'
print "Rendering %s"%leftfile
cmd.turn("y","3")
cmd.ray()
cmd.png(leftfile)
# render right image and save as 'filename_right.png'
print "Rendering %s"%rightfile
cmd.turn("y","-6")
cmd.ray()
cmd.png(rightfile)
# reset original view
cmd.turn("y","3")
############################################################
# Requires Python PIL
# remove following lines if you dont have PIL installed
# Import Pyhton Image Library
import Image
# Open left and right images and determine the image size
leftim=Image.open(leftfile)
rightim=Image.open(rightfile)
size=leftim.size
# Set size of new stereo figure and define location of left and right
# stereo images in the new figure
sizex=size[0]
sizey=size[1]
stsizex=2*sizex
stsizey=sizey
stsize=(stsizex,stsizey)
leftbox=(0,0,sizex,sizey)
rightbox=(sizex,0,stsizex,stsizey)
# Create new 'empty' stereo image
stereoim=Image.new("RGB",stsize)
# Paste left and right images into new stereo image
stereoim.paste(leftim,leftbox)
stereoim.paste(rightim,rightbox)
# Save stereo image - file format is automatically derived from the
# extension of the filename (i.e. png,jpg,tif,pdf)
stereoim.save(filename)
print "Saved stereo image:%s"%filename
# Remove temporary left and right image files
os.remove(leftfile)
os.remove(rightfile)
# end of section to remove
##############################################################