Run Python Statements from PyMol

This section provides a tutorial on how to Run Python Statements from PyMol.

PyMol allows you to run Python statements automatically, if you have Python installed on your system.

If you just want to run a single Python statement, just enter the statement as is at the "PyMOL>" prompt or in a command script: For example:

PyMOL> print 1 + 2
3

If you want to run a statement block, then you need to add a backslash ('\') at the end of each statement except the last statement. For example:

PyMOL>for a in range(1,6): \
PyMOL>   b = 6 - a \
PyMOL>   print(a, b)
1 5
2 4
3 3
4 2
5 1

Note that you can not use PyMol commands inside a Python statement block. For example, if you try to turn the camera in a loop, you will get an error.

PyMOL>for a in range(1, 36): \
PyMOL>   turn y, 10
  File "toplevel", line 2
    turn y, 10
         ^
SyntaxError: invalid syntax

Python variables are not allowed in PyMol commands either:

PyMOL>angle = 45
PyMOL>turn y, angle
Traceback (most recent call last):
  File "/Applications/PyMOL.app/.../viewing.py", line 1411, in turn
    r = _cmd.turn(_self._COb,str(axis),float(angle))
ValueError: could not convert string to float: 'angle'

As you can see, integrating Python statements into PyMol command scripts is not that useful.

Table of Contents

 About This Book

 Introduction of Molecules

 Molecule Names and Identifications

 Molecule Mass and Weight

 Protein and Amino Acid

 Nucleobase, Nucleoside, Nucleotide, DNA and RNA

 Gene and Chromosome

 Protein Kinase (PK)

 DNA Sequencing

 Gene Mutation

 SDF (Structure Data File)

 PyMol Installation

 PyMol GUI and CLI

 PyMol Selections

 PyMol Editing Functions

 PyMol Measurement Functions

 PyMol Movie Functions

PyMol Python Integration

Run Python Statements from PyMol

 PyMol Python API

 Launch PyMol from Python Interpreter

 PyMol Python API Only Functions

 PyMol Object Functions

 ChEMBL Database - European Molecular Biology Laboratory

 PubChem Database - National Library of Medicine

 PDB (Protein Data Bank)

 INSDC (International Nucleotide Sequence Database Collaboration)

 HGNC (HUGO Gene Nomenclature Committee)

 Relocated Tutorials

 Resources and Tools

 Molecule Related Terminologies

 References

 Full Version in PDF/EPUB