Python Integration

General information about Python can be found on the home page and in the documentation. Information about integrating PyMOL with Python can be found below.

Design Philosophy

The basic idea behind PyMOL was to leverage Python for what it does well, while avoiding it for the things it does poorly. Generally this means using Python for command & control while leaving the heavy-lifting to C. In addition, there emerged a need to run PyMOL as pure C program without Python (CMol) to support integrated usage from Java (JyMOL), as well as ActiveX.

As of PyMOL 1.0, the application known as PyMOL relies heavily on the combination of C and Python.

Python is used:

  • to evaluate user-provided expressions (e.g. label, alter, iterate).
  • to drive the Tcl/Tk/Tkinter-based user interface.
  • to manage the OpenGL pop-up menus.
  • to round-trip certain complex tasks (via the command-line FIFO).
  • to parse command-line input.
  • to obtain and use platform-independent threads and mutexes.
  • to handle exceptions.
  • to pre-process atom selections.
  • to expose PyMOL’s capabilities to end-user or 3rd-party Python programs.
  • to perform certain I/O tasks, such as download via URLs.

C is used:

  • to peform most number-crunching tasks (e.g. geometry creation).
  • to hold the “model” (i.e. the underlying molecular data).
  • to exploit parallel processing capabilities of multicore hardware.
  • to interact with OpenGL and GLUT (or Objective C/Cocoa in MacPyMOL).
  • to access the underlying libraries (png, freetype, etc.)
  • to efficiently pack and unpack Python data structures.

One important consequence and limitation of this approach is that the Python object model is barely used from within PyMOL. In other words, there is no Python “object” which corresponds to an actual atom or molecule from within PyMOL.

However, PyMOL can in some instances provide you with a pure Python copy of certain parts of the model (e.g. see cmd.get_model and cmd.load_model), and commands like iterate, alter, and label provide the ability to access and manipulate the C model using Python expressions and data structures.

 
devel/python.txt
 
Copyright © Schrödinger, LLC. All Rights Reserved.