PyMOL Selections: A Complete Guide with Examples

PyMOL Selections: A Complete Guide with Examples

Selections are the foundation of everything in PyMOL. Every command — coloring, showing, hiding, measuring, labeling — targets a selection. Master the selection syntax and every other PyMOL task becomes straightforward.

Anatomy of a selection command

Every PyMOL selection has the same structure: a command, an optional name for the selection, and a selection expression that describes which atoms to include.

select binding_site , chain A and resi 100-150
Command select — creates a named selection. Other commands like color, show, hide use the same expression syntax.
Selection name An optional label for this set of atoms. Named selections appear in the object list and can be reused.
Selection expression The logic that identifies which atoms to include. Built from keywords and boolean operators.

The selection expression is the part that varies. It can be as simple as chain A or as complex as byres ((chain A and resi 200-300) within 5 of chain B). Everything else is just combinations of the keywords and operators covered in this guide.

Core selection keywords

chain
chain A
Selects all atoms in the specified chain identifier
resi
resi 100-150
Residue number or range. Use + for non-contiguous: resi 100+150+273
resn
resn LYS
Residue name (3-letter code). resn LIG for ligands, resn HOH for water
name
name CA
Atom name within a residue. name CA = alpha carbons, name N+CA+C+O = backbone
elem
elem C
Element symbol. elem N = all nitrogens, elem S = all sulfurs
b
b > 70
B-factor value. In AlphaFold structures, this holds pLDDT. Supports >, <, =, !=
ss
ss h
Secondary structure: h=helix, s=sheet, l=loop (or "" for unassigned)
hetatm
hetatm
All heteroatoms — ligands, waters, ions, cofactors. Opposite of polymer
polymer
polymer
All polymer atoms (protein + nucleic acid). Excludes water and ligands
all
all
Every atom in every loaded object. Equivalent to *

Selecting by chain

Chain selections are the most common starting point for any multi-chain structure. Chain identifiers are case-sensitive — chain A and chain a are different.

PyMOL command line
# Single chain
select receptor, chain A

# Multiple chains (use or)
select both_chains, chain A or chain B

# Everything except a specific chain
select not_water_chain, not chain W

# Chain + residue range combined
select domain, chain A and resi 50-200

# Color directly without creating a named selection
color slate, chain A
color salmon, chain B

Selecting by residue

Residue selections target specific positions in the sequence. resi takes residue numbers; resn takes three-letter residue names.

PyMOL command line
# Contiguous range
select loop, resi 100-120

# Non-contiguous list (use +)
select active_site, resi 175+248+249+273

# By residue name (3-letter code)
select all_lys, resn LYS
select charged, resn LYS+ARG+ASP+GLU

# Waters
select waters, resn HOH
hide everything, resn HOH     # common: remove waters from view

# Combine residue number and name for precision
select key_arg, resn ARG and resi 273 and chain A
resi vs resn
resi selects by residue number (position in the sequence). resn selects by residue name (amino acid type). resi 100 picks the 100th residue regardless of what it is. resn LYS picks every lysine regardless of where it is. Combine them when you need one specific residue at one specific position.

Selecting by atom type and element

Atom-level selections are useful for showing specific parts of residues — the backbone only, just the side chains, or specific functional groups in a ligand.

PyMOL command line
# Backbone atoms only
select backbone, name N+CA+C+O

# Alpha carbons only (lightest representation of structure)
select ca_only, name CA

# Side chains only (exclude backbone)
select sidechains, not name N+CA+C+O and polymer

# Heteroatoms (non-hydrogen atoms in ligands)
select ligand_heavy, hetatm and not resn HOH

# By element
select all_sulfurs, elem S
select metals, elem ZN+MG+CA+FE+MN

# B-factor threshold (pLDDT in AlphaFold)
select confident, b > 70
select disordered, b < 50

Distance-based selections

Distance selections are among PyMOL's most powerful features. They let you select atoms based on their spatial proximity to other atoms — essential for binding site analysis, interface identification, and contact mapping.

PyMOL command line
# All atoms within 5 Å of the ligand
select near_lig, ligand around 5

# Complete residues with any atom within 5 Å of ligand
select binding_site, byres (ligand around 5)

# Interface residues: chain A atoms within 4 Å of chain B
select iface_A, chain A and (byres chain B around 4)
select iface_B, chain B and (byres chain A around 4)

# within syntax (equivalent to around, preferred in some contexts)
select close, protein within 5 of ligand

# Expand an existing selection by a radius
select expanded, byres (active_site expand 3)
around vs within vs byres
around N and within N of select individual atoms within N ångströms. byres (...) expands the result to include complete residues if any atom from that residue is within range. For binding site analysis, always use byres — showing partial residues in a binding site figure looks wrong and makes measuring interactions harder.

Boolean operators — and, or, not

and
Intersection — atoms that match both conditions. Narrows the selection. chain A and resi 100 = only residue 100 in chain A.
or
Union — atoms that match either condition. Broadens the selection. chain A or chain B = all atoms in A and B combined.
not
Complement — atoms that do not match the condition. not resn HOH = everything except water molecules.
Boolean operators — practical examples
# AND: must satisfy both conditions
select specific, chain A and resi 100-200 and ss h

# OR: satisfies either condition
select both_ends, resi 1-20 or resi 380-400

# NOT: everything except the condition
select no_water, not resn HOH
select no_backbone, polymer and not name N+CA+C+O

# Combining all three
select complex, (chain A or chain B) and not resn HOH and b > 50

# Parentheses control evaluation order
select interface, (chain A and byres chain B around 5) or \
                   (chain B and byres chain A around 5)

Named selections

Named selections — created with the select command — appear in the PyMOL object list as pink dashed outlines on the structure and can be reused in any subsequent command by name. This is the key workflow for complex figures: define your selections once, then reference them repeatedly.

PyMOL command line
# Create named selections for a binding site workflow
select LIG,          resn LIG            # the ligand
select pocket,       byres (LIG around 5) # binding site residues
select h_donors,     pocket and (elem N or elem O) # H-bond donors/acceptors

# Now use the named selections in commands
color slate, pocket
show sticks, pocket
util.cbag LIG
distance hbonds, LIG, pocket, mode=2

# Update an existing named selection
select pocket, byres (LIG around 6)  # redefine with larger radius

# Delete a named selection
delete pocket
Named selections don't update automatically
If you modify the structure after creating a selection — removing atoms, adding hydrogens, or loading a different object — named selections are not recalculated. They remain fixed on the atoms selected at creation time. Recreate selections after any significant structural change.

select vs show — what's the difference

Creates a persistent handle
select name, expression
Creates a named selection object. Reusable in later commands. Appears in the object list. Doesn't change what's displayed. Use when you'll reference the same set of atoms multiple times.
Immediate display action
show representation, expression
Immediately adds a representation to the specified atoms. Doesn't create a named selection. Use for one-off display changes where you don't need to reuse the selection.
select vs show — when each is appropriate
# Use select when you'll reuse the set of atoms multiple times
select active_site, resi 175+248+273 and chain A
color red, active_site
show sticks, active_site
label active_site and name CA, resn+resi    # reuse 3× — worth naming

# Use show directly for one-off display (no selection needed)
show sticks, resi 100 and chain A           # one-off — just show it
color green, resi 100 and chain A

Real-world examples

Binding site visualization
fetch 4XYZ
as cartoon
hide everything, resn HOH
select LIG, hetatm and not resn HOH
select pocket, byres (LIG around 5)
show sticks, pocket
show sticks, LIG
color slate, pocket
util.cbag LIG
zoom pocket
AlphaFold confidence regions
load AF-P04637-F1-model_v4.pdb
as cartoon
select confident,  b > 70
select uncertain,  b >= 50 and b <= 70
select disordered, b < 50
color blue,  confident
color yellow, uncertain
color red,   disordered
Protein-protein interface
fetch 1ACB
as cartoon
util.cbc
select iface_E, chain E and byres (chain I around 4)
select iface_I, chain I and byres (chain E around 4)
show sticks, iface_E or iface_I
distance contacts, iface_E, iface_I, 4
color tv_red,  iface_E
color tv_blue, iface_I
zoom iface_E or iface_I

Selections in one paragraph

Every PyMOL command targets a selection expression. The six keywords you'll use in 90% of cases are chain, resi, resn, name, hetatm, and b. Combine them with and, or, and not to narrow, broaden, or exclude. Use byres (...around N) for binding sites — it returns complete residues rather than partial ones. Create named selections with select when you'll reuse the same set of atoms multiple times. Use the selection expression directly in show, color, hide, or distance for one-off commands. That's the entire selection system — everything else is combinations of these patterns.

Last updated on

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *