Contents Previous

Callback Objects and PyOpenGL

This is mainly a developer's function, so most users can skip this section. You will need some Python knowledge to understand the example.


Athough all OpenGL rendering in PyMOL is perfomed at the C level, PyOpenGL provides an alternative binding of the OpenGL API from Python. Unfortunately, it is impossible for PyMOL to produces ray-traced images of objects rendered using PyOpenGL. Nevertheless, PyOpenGL can be used within PyMOL via Callback objects for pure OpenGL-based rendering pursposes. If you need your graphics to ray-tracable, then you should use Compiled Graphics Objects (see previous section).

Callback objects are trivial Python objects which have a "__call__" method for rendering and a "get_extent" method which tells PyMOL where in space the object is located. Once a callback object has been loaded into PyMOL, Python will automatically call this object when needed to update the screen.

PyMOL includes a copy of PyOpenGL under the pymol module hierarchy (pymol.opengl), but usage of this copy is of course optional. You can instead bind to the latest version without problems, provided that you install it yourself into the Python library that PyMOL is using by default.

NOTE: The current Window's version of PyMOL does not include Numeric, which makes heavy usage of PyOpenGL from within PyMOL impractical under Windows at present.


The following Python program shows how you can use a Callback object within PyMOL to perform rendering using OpenGL. For more examples, see the directory "$PYMOL_PATH/examples/devel".

from import *
from pymol.callback import Callback
from pymol import cmd
class myCallback(Callback):
   def __call__(self):
   def get_extent(self):
      return [[0.0,0.0,0.0],[1.0,2.0,3.0]]


Callback objects are loaded into PyMOL using the "load_callback" function.


NOTE: This manual is a PyMOL Incentive Product with a One-Year Evaluation Period. You, your school, or your employer must purchase a PyMOL License & Maintenance Subscription to cover usage beyond the first year. We trust you to support the PyMOL project via the "honor" system, so please do your part! See Usage Terms for more information.
Copyright © 2004 DeLano Scientific LLC. All Rights Reserved.

Contents Previous