Skip to content

Selections

PDB files, and standard mmCIF atom-site loops, carry atom and residue metadata. Use that metadata to create subsets:

chain_a = mol.select(chain="A")
carbons = mol.select(element="C")
waters = mol.select(resname="HOH")
region = mol.select(resid=(10, 20))

resid is kept as the integer residue number for compatibility. For real PDB/mmCIF files with insertion codes, use icode or ResidueId selectors:

mol.icodes                              # per-atom insertion codes
mol.residue_ids                         # per-atom ResidueId objects
mol.select(resid=100, icode="A")        # residue 100A
mol.select(residue_id=ms.ResidueId("A", 100, "B"))

mol.residue_groups() yields objects with a .residue_id field, but they still unpack as (atom_indices, resname, resid, chain) for older code.

Protein helpers:

backbone = mol.backbone()
ca = mol.alpha_carbons()

Numpy-style masks and index arrays also work:

first_ten = mol[list(range(10))]

Selections return new Molecule objects.

The command-line viewer accepts the same basic fields for quick inspection:

molscope examples/data/1fqy.pdb --select "chain=A and atom_name=CA"
molscope examples/data/1fqy.pdb --select chain=A --select atom_name=CA