Scripting FAQs

From PyMOLWiki
Revision as of 20:38, 19 September 2008 by Inchoate (talk | contribs)
Jump to navigation Jump to search

Script within a Structure

Q: Is there a way to embed a script within a PDB structure?

A: Yes, there are two ways

delete all
cmd.read_pdbstr("""HETATM 1985  O00 MOH   132      18.797   6.477 -12.112 0.00  0.00           O\
HETATM 1988  H03 MOH   132      18.437   7.229 -11.665  0.00  0.00    H\
HETATM 1989  C04 MOH   132      17.737   5.662 -12.563  0.00  0.00    C\
HETATM 1990  H05 MOH   132      18.129   4.785 -13.080  0.00  0.00    H\
HETATM 1991  H06 MOH   132      17.096   6.211 -13.253  0.00  0.00    H\
HETATM 1992  H07 MOH   132      17.130   5.322 -11.722  0.00  0.00    H""","mymolecule")
show sticks

Don't forget the backslashes there -- it's one long command. Example

  • Or, as Warren noted, you can do with with a "p1m" file, which is like a "pml" file, but data can be included as well. Also note that p1m files are intended for web publishing, so embedded Python is disallowed. In p1m files, there is an "embed" command that enables this for PDB, MOL, MOL2, SDF, and XPLOR data. It works like this:
embed tag, format
****REPLACE THIS LINE WITH YOUR DATA FILE****
embed end
load_embedded tag

where tag is some identifier of your choice.

Scripting and Command Line Options

PyMol will allow you to use command line options in a script. That means, the following

pymol -qrc script.py arg1 arg2

will work if you add a double-hyphen before the first argument in order to signal Pymol to stop interpreting arguments:

pymol -qrc script.py -- arg1 arg2

Then your script can get these arguments as follows:

from sys import argv
my_argv =3D argv[argv.index("--"):]
print my_argv[1], my_argv[2]