Molecule Tutorials - Herong's Tutorial Examples - v1.26, by Herong Yang
PyMol Python API
This section provides a tutorial on how to use PyMol Python API to invoke PyMol commands from Python scripts.
PyMol also provides a Python API that allows you to access all PyMol functionalities from a Python script.
All PyMol commands are wrapped as Python functions in the pymol.com class packaged in the "pymol" module. You call those functions to perform any molecule visualization tasks.
For example, the following Python script will rotate the viewing camera 360 degrees in 1 second in a loop:
# Rotate-Camera.py import pymol import time for i in range(1, 21): print("Moving...") pymol.cmd.turn('y', 18) time.sleep(0.05)
One way to execute this script is to use the "run" command at the PyMOL command prompt:
PyMOL>run Rotate-Camera.py
If you try the above command, you probably expect the molecule structure view will be rotated a full circle in 20 steps in 1 second time period. However, PyMol will actually freeze the viewer for 1 second and display the structure once at the end.
I think the "run" command is actually executing the entire Python script in the background without updating the structure image in the viewer during the execution.
When you use the "run python-script-file" command at the PyMOL command prompt, you are using the PyMOL interpreter to execute the Python script, which calls back PyMol API functions.
See the next tutorial on how to use Python interpreter to execute Python scripts that calls PyMol API functions.
You can also read PyMol Python API reference on line at pymol.org/dokuwiki/doku.php?id=api.
Table of Contents
Molecule Names and Identifications
Nucleobase, Nucleoside, Nucleotide, DNA and RNA
Run Python Statements from PyMol
Launch PyMol from Python Interpreter
PyMol Python API Only Functions
ChEMBL Database - European Molecular Biology Laboratory
PubChem Database - National Library of Medicine
INSDC (International Nucleotide Sequence Database Collaboration)
HGNC (HUGO Gene Nomenclature Committee)