Structural Bioinformatics

Lesson 4 of 13 · 11 min

PyMOL: Loading and the Selection Language

PyMOL is fully scriptable: every action in the GUI maps to a command you can type at the PyMOL prompt or batch into a .pml script run with pymol -cq. The real power for structural analysis comes from its selection language, an algebra over atom properties that lets you name and reuse arbitrary subsets of a structure. This lesson covers getting coordinates in with fetch and load, then composing selections for pockets, interfaces, and specific residues.

Loading Structures

bash
# interactive session with the OpenGL GUI
pymol

# headless: run a .pml script quietly, no GUI, then exit
pymol -cq analysis.pml

# quiet startup that stays open for interactive follow-up
pymol -q analysis.pml
text
# download straight from the PDB (async=0 blocks until the file is loaded)
fetch 1hsg, async=0

# or read a local coordinate file and name the object explicitly
load /data/structures/1hsg.pdb, hiv_pr

# set a clean starting representation
hide everything
show cartoon
 ExecutiveLoad-Detail: Detected mmCIF
 ObjectMolecule: Read secondary structure assignments.
 ObjectMolecule: Read crystal symmetry information.
 CmdLoad: "./1hsg.cif" loaded as "1hsg".

Selections are built from property selectors combined with the boolean operators and, or, and not. The core atomic selectors are resi for residue numbers or ranges, resn for residue names, chain for chain identifiers, name for atom names, elem for chemical elements, and hetatm for records outside the standard polymer. Three expanders complete the toolkit: byres promotes any partial hit to its whole residue, s1 within X of s2 keeps atoms of s1 lying within X angstroms of s2, and s1 around X selects atoms near s1 while excluding s1 itself.

text
# the bound inhibitor indinavir (ligand code MK1)
select lig, resn MK1

# catalytic aspartate (Asp25) contributed by both monomers
select cat_asp, resn ASP and resi 25

# backbone alpha carbons of chain A only
select ca_A, chain A and name CA

# crystallographic waters (the solvent keyword targets HOH)
select waters, solvent
 Selector: selection "lig" defined with 45 atoms.
 Selector: selection "cat_asp" defined with 16 atoms.
 Selector: selection "ca_A" defined with 99 atoms.
 Selector: selection "waters" defined with 127 atoms.

Proximity and Reuse

text
# whole residues lining the binding pocket (within 5 A of the ligand)
select pocket, byres (polymer within 5 of lig)

# the contact shell around the ligand, ligand atoms excluded
select shell, lig around 4.5

# the protease dimer interface: chain A residues close to chain B
select interface, byres (chain A within 4 of chain B)

# polar pocket atoms to target for later distance measurements
select pocket_polar, pocket and (elem N+O)
python
from pymol import cmd

# async_ has a trailing underscore because async is a Python keyword
cmd.fetch("1hsg", async_=0)
cmd.select("pocket", "byres (polymer within 5 of resn MK1)")
print(cmd.count_atoms("pocket"))

# named selections persist, so reuse them to style and measure
cmd.show("sticks", "pocket")
cmd.get_area("pocket")

Try it yourself: Fetch the trypsin-benzamidine complex with fetch 3ptb, async=0. Build lig as resn BEN, a pocket as byres (polymer within 4 of lig), and a shell as lig around 4, then run count_atoms on each. To feel how within and around differ, compare count_atoms('all within 4 of lig') against count_atoms('lig around 4'): the within form counts the benzamidine atoms themselves because every atom lies within 4 A of itself, while around drops them. Finally refine with pocket and elem N to isolate the nitrogen atoms you would measure hydrogen bonds from.