The Complete PyMOL Guide for Structural Biologists: Visualization, Analysis and Publication Figures
PyMOL is the most widely used molecular visualization tool in structural biology — present on virtually every researcher’s laptop, featured in virtually every published structure paper. This guide covers everything: what PyMOL is, how to install it for free, the interface, the commands you’ll use every day, coloring and surface representations, making publication-quality figures, and the scripting basics that save hours of repetitive work.
What PyMOL is and why structural biologists use it
PyMOL is a molecular visualization system — software that reads atomic coordinate files (PDB, CIF, mmCIF) and renders the 3D positions of every atom in a protein, nucleic acid, or small molecule as an interactive 3D model you can rotate, zoom, color, and annotate. Originally written by Warren DeLano in the early 2000s, it has become the dominant tool in structural biology because of its combination of power, flexibility, and relatively shallow learning curve for basic use.
What distinguishes PyMOL from other visualization tools is the depth of its command interface. Everything you can do through the GUI menus, you can also do by typing a command — and everything you can type as a command, you can script in Python. This makes PyMOL equally useful as a quick interactive viewer and as an automated figure-generation pipeline. A researcher can load a structure, make a figure, and export it to a journal-ready PNG without ever touching a menu.
PyMOL is maintained by Schrödinger Inc., which sells a commercial license. However, it is also available as open-source software and through free educational licenses, making it genuinely accessible to academic researchers.
Installation — free options for every platform
Install via conda (recommended)
The fastest way to get PyMOL running on any platform — Windows, Mac, or Linux — is through conda. If you don’t have conda, install Miniconda first from conda.io.
# Create a dedicated PyMOL environment (keeps dependencies clean)
conda create -n pymol python=3.10 -y
conda activate pymol
# Install open-source PyMOL from conda-forge
conda install -c conda-forge pymol-open-source -y
# Launch PyMOL
pymol
Install on macOS via Homebrew
# Install Homebrew first if not installed: brew.sh
brew install pymol
The PyMOL interface
When PyMOL opens, you see two windows: the Viewer (the 3D display window) and the External GUI (the control panel with menus, the command line, and the object list). Understanding which window does what saves significant confusion for new users.
The five letter buttons next to each object in the panel — A, S, H, L, C — are the core GUI controls. A = Actions (rename, copy, delete), S = Show (add a representation), H = Hide (remove a representation), L = Label, C = Color. Most beginners use these menus initially and migrate to command-line equivalents as they become comfortable.
The command line at the bottom accepts any PyMOL command. This is where experienced users live — it’s faster than the menus for everything you do repeatedly.
Essential commands — loading, selecting, displaying
Loading structures
# Load from a local PDB file
load /path/to/protein.pdb
# Fetch directly from the RCSB PDB (requires internet)
fetch 4XYZ
# Fetch and name the object something descriptive
fetch 4XYZ, egfr_kinase
# Load multiple structures
fetch 4XYZ 5ABC 6DEF
Selections
PyMOL’s selection syntax is its most important feature. Almost every command you run targets a selection. The selection language uses keywords like chain, resi, resn, name, and boolean operators and, or, not.
# Select all of chain A
select chainA, chain A
# Select residues 100-150 in chain B
select loop, chain B and resi 100-150
# Select by residue name (e.g. all lysines)
select all_lys, resn LYS
# Select residues within 5 Å of the ligand
select binding_site, byres (ligand around 5)
# Select all alpha carbons
select ca_atoms, name CA
Display representations
| Command | What it does |
|---|---|
| show cartoon | Ribbon cartoon representation — the standard view for proteins |
| show sticks | All bonds shown as sticks — for ligands and active site residues |
| show lines | Thin line bonds — useful for background context |
| show spheres | Space-filling CPK representation |
| show surface | Molecular surface — see separate section below |
| show dots | Dot surface — accessible surface area |
| hide everything | Hide all representations for the selection |
| as cartoon | Show cartoon and hide everything else simultaneously |
fetch 4XYZ
as cartoon # cartoon + hide everything else
hide everything, resn HOH # remove water molecules
color slate # color the whole protein
zoom # fit structure to viewer
orient # orient along principal axes
Coloring schemes
Coloring in PyMOL is almost always the difference between a figure that communicates clearly and one that doesn’t. The right coloring scheme encodes structural or functional information the viewer can immediately interpret.
# Color entire structure by chain (most common starting point)
util.cbc
# Color AlphaFold structure by pLDDT (stored in B-factor)
spectrum b, blue_cyan_yellow_orange_red, minimum=50, maximum=100
# Color N→C terminus rainbow
spectrum count, rainbow
# Color ligand by atom type (classic CPK colors)
util.cbaw ligand
# Set a specific residue to red
color red, resi 273 and chain A
# Custom color with RGB values (0-1 scale)
set_color myblue, [0.1, 0.4, 0.8]
color myblue, chain A
Surface representations
Surfaces are among the most powerful ways to communicate structural information — they show solvent accessibility, binding pockets, electrostatic character, and overall protein shape in a way that cartoon representations cannot. PyMOL generates three types of surface.
- Molecular surface — the contact surface between the protein and a rolling probe sphere. This is what you see in most publications and is what
show surfacegenerates. - Solvent-accessible surface — the surface traced by the center of the rolling probe. Larger than the molecular surface; used for area calculations.
- Cavities and pockets — by adjusting surface quality and probe radius, PyMOL can highlight internal cavities that represent potential binding sites.
# Show molecular surface
show surface
# Make surface semi-transparent (see cartoon through it)
set transparency, 0.4
# Surface + cartoon together (classic figure style)
show cartoon
show surface
set transparency, 0.6
# Color surface by charge (requires running APBS first)
apbs_gui
# Color surface by hydrophobicity
spectrum hydrophobicity, white_orange, selection=protein
# Show only binding site surface (residues within 5Å of ligand)
select pocket, byres (ligand around 5)
show surface, pocket
as cartoon, show surface, set transparency, 0.5, then color the cartoon one way and the surface another (e.g., color slate for the surface and color red, chain B for a bound partner chain).
Basic analysis — measurements and alignments
Measurements
# Measure distance between two atoms (click two atoms first, or specify)
distance d1, /4XYZ//A/GLU`273/OE1, /4XYZ//A/ARG`175/NH1
# Show all H-bonds between two selections
distance hbonds, chain A, chain B, mode=2
# Measure angle between three atoms
angle a1, atom1, atom2, atom3
# Hide the distance labels after measuring (keep lines only)
hide labels
Structure alignment and RMSD
# Align two structures (sequence-aware) — reports RMSD
align mobile, reference
# Structure-based alignment ignoring sequence (better for distant homologs)
super mobile, reference
# CE alignment (best for structural topology comparison)
cealign mobile, reference
# Align on specific chains only
align mobile and chain A, reference and chain A
# Calculate RMSD without moving structures
rms_cur mobile and backbone, reference and backbone
Making publication-quality figures
A publication-quality PyMOL figure requires attention to five things: representation, lighting, background, resolution, and export format. Most researchers get the first two right and neglect the last three — which is why so many published figures look blurry or have gray backgrounds when viewed in print.
-
Set a white background. The default PyMOL background is black. Journals require white. Run
bg_color whitebefore rendering anything. Also runset ray_opaque_background, 1to ensure the background is truly white in the exported PNG rather than transparent. -
Adjust lighting. The default lighting is serviceable but flat. For publication figures, try
set ambient, 0.4andset specular, 0.3to soften highlights. Thelight_countsetting (default 2) can be increased to 4 for a more professional look. -
Set the cartoon appearance.
set cartoon_fancy_helices, 1gives helices a round ribbon look instead of the default flat ribbon — this is the standard for publications.set cartoon_smooth_loops, 1smooths out loop regions. -
Choose the right orientation. Rotate to your most informative view, then record it. The command
get_viewprints the current camera matrix — save this to reproduce the exact orientation later or share it with collaborators. -
Ray trace and export at high resolution. Use the
raycommand with width and height in pixels. For a typical journal figure panel (80 mm at 300 DPI), that’s about 945 pixels wide. For a full-page figure, use 2480 × 3508 at 300 DPI.
# 1. Set up the scene
bg_color white
set cartoon_fancy_helices, 1
set cartoon_smooth_loops, 1
set ray_opaque_background, 1
# 2. Adjust lighting
set ambient, 0.4
set specular, 0.3
set light_count, 4
# 3. Color your structure (example)
color slate, protein
util.cbaw ligand
color red, binding_site_residues
# 4. Orient to your desired view, then:
get_view # copy this output to reproduce the view
# 5. Ray trace at publication resolution (300 DPI, single-column width)
ray 1200, 900
# 6. Export
png figure1a.png, dpi=300
| Setting | Recommended value | Effect |
|---|---|---|
| ray_trace_mode | 1 | Production-quality ray trace with shadows |
| ray_shadow | 1 | Enables cast shadows for depth |
| cartoon_fancy_helices | 1 | Rounded ribbon helices (publication standard) |
| cartoon_smooth_loops | 1 | Smooth interpolation through loop regions |
| ambient | 0.35–0.45 | Ambient light level — higher = softer shadows |
| specular | 0.2–0.4 | Surface shininess — lower = more matte |
| ray_opaque_background | 1 | White background in exported PNG |
Scripting basics
Every command you type in PyMOL can be saved in a plain text file with a .pml extension and run as a script. This is the single biggest productivity upgrade available to regular PyMOL users — save your figure generation workflow as a script, and you can reproduce any figure in seconds rather than recreating it from memory.
# Load and display
fetch 4XYZ
as cartoon
hide everything, resn HOH
# Color
util.cbc
set cartoon_fancy_helices, 1
# Figure setup
bg_color white
set ray_opaque_background, 1
set ambient, 0.4
# Restore orientation (paste get_view output here)
set_view (\
0.92, -0.21, 0.32,\
-0.18, 0.45, 0.87,\
-0.35, -0.87, 0.35,\
0.00, 0.00, -85.0,\
12.5, 8.3, 10.2,\
65.0, 105.0, -20.0)
# Render and save
ray 1200, 900
png figure1a.png, dpi=300
pymol -c make_figure.pml # -c = command-line mode, no GUI
For more complex automation — iterating over multiple structures, batch-generating figures for a set of mutants, extracting measurements — PyMOL’s full Python API is available through the cmd module. This bridges naturally into the Python for structural biology pillar on this site.
.pml script can include Python code directly, and PyMOL commands are available as Python functions via from pymol import cmd. This means the same Python skills you use for GROMACS analysis, BioPython, and data visualization translate directly into PyMOL automation — there is no separate scripting language to learn.
Next steps
This guide covers the PyMOL fundamentals that underpin almost every structural biology workflow. The tutorials linked below go deeper on each specific use case — coloring AlphaFold structures by confidence, visualizing binding sites and protein-ligand interactions, making figures for specific journal requirements, and writing Python scripts that generate figures automatically.
PyMOL in one paragraph
PyMOL is the standard molecular visualization tool in structural biology — present in virtually every research group, required for virtually every structure paper. Install it free via conda. The command line is faster than the menus for everything you do repeatedly. The five essential operations are loading structures, making selections, choosing representations, coloring, and exporting figures. For publication figures, set a white background, enable fancy helices, ray trace at 300 DPI, and save the view matrix so the exact orientation is reproducible. Save every figure workflow as a .pml script — the ten minutes this takes will save hours across a PhD.