The Complete PyMOL Guide for Structural Biologists: Visualization, Analysis and Publication Figures

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

Recommended — free forever
Open-source PyMOL via conda
The open-source version of PyMOL is maintained by the community and free for any use. Install via conda-forge. Missing some commercial features but sufficient for all standard visualization and analysis tasks.
Free for academics
Educational license (Schrödinger)
Full-featured PyMOL free for students and academic researchers. Register at pymol.org with an academic email. Includes all commercial features including the full ray-tracing renderer.

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.

Terminal
# 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

Terminal
# Install Homebrew first if not installed: brew.sh
brew install pymol
Apple Silicon (M1/M2/M3) Macs
The conda-forge package handles Apple Silicon natively. If you install PyMOL via pip directly, you may encounter architecture conflicts. Use the conda route above for the most reliable installation on any Mac.

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.

PyMOL — viewer + control panel
3D Viewer window
Rotate · Zoom · Click to select
Left drag = rotate  |  Right drag = zoom
Middle drag = translate  |  Scroll = zoom
Object list
● 4XYZ  A C H L S
● ligand  A C H L S
Action buttons
A ▾ action
S ▾ show
H ▾ hide
L ▾ label
C ▾ color
PyMOL> color red, chain A

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

PyMOL command line
# 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.

PyMOL command line — selection examples
# 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

Show / Hide commands
CommandWhat it does
show cartoonRibbon cartoon representation — the standard view for proteins
show sticksAll bonds shown as sticks — for ligands and active site residues
show linesThin line bonds — useful for background context
show spheresSpace-filling CPK representation
show surfaceMolecular surface — see separate section below
show dotsDot surface — accessible surface area
hide everythingHide all representations for the selection
as cartoonShow cartoon and hide everything else simultaneously
A typical starting sequence for any protein
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.

By chain
util.cbc
Assigns a distinct color to each chain. The standard view for multi-chain complexes and protein-protein interactions.
By secondary structure
util.cbs
Helices, sheets, and loops each get distinct colors. Good for communicating topology quickly.
By B-factor / pLDDT
spectrum b, blue_red
Colors by the B-factor column — which holds pLDDT values in AlphaFold structures. Essential for showing confidence.
Electrostatics (APBS)
apbs_gui / ramp_new
Negative (red) to positive (blue) electrostatic potential mapped onto the molecular surface. Requires APBS plugin.
By atom type (CPK)
util.cbaw
Classic chemistry colors: C=gray/white, O=red, N=blue, S=yellow. Standard for showing ligands and active site chemistry.
Spectrum N→C
spectrum count, blue_red
N-terminus to C-terminus color gradient. Communicates directionality and chain continuity in a single color scale.
Coloring commands — practical examples
# 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 surface generates.
  • 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.
Essential surface commands
# 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
The two-layer surface figure
The most commonly used figure style in publications is cartoon + semi-transparent surface together — it shows both the ribbon topology (helices, sheets) and the overall shape in one image. The command sequence is: 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

PyMOL command line
# 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

PyMOL command line
# 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.

  1. Set a white background. The default PyMOL background is black. Journals require white. Run bg_color white before rendering anything. Also run set ray_opaque_background, 1 to ensure the background is truly white in the exported PNG rather than transparent.
  2. Adjust lighting. The default lighting is serviceable but flat. For publication figures, try set ambient, 0.4 and set specular, 0.3 to soften highlights. The light_count setting (default 2) can be increased to 4 for a more professional look.
  3. Set the cartoon appearance. set cartoon_fancy_helices, 1 gives helices a round ribbon look instead of the default flat ribbon — this is the standard for publications. set cartoon_smooth_loops, 1 smooths out loop regions.
  4. Choose the right orientation. Rotate to your most informative view, then record it. The command get_view prints the current camera matrix — save this to reproduce the exact orientation later or share it with collaborators.
  5. Ray trace and export at high resolution. Use the ray command 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.
Complete publication figure workflow
# 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
SettingRecommended valueEffect
ray_trace_mode1Production-quality ray trace with shadows
ray_shadow1Enables cast shadows for depth
cartoon_fancy_helices1Rounded ribbon helices (publication standard)
cartoon_smooth_loops1Smooth interpolation through loop regions
ambient0.35–0.45Ambient light level — higher = softer shadows
specular0.2–0.4Surface shininess — lower = more matte
ray_opaque_background1White 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.

make_figure.pml — a reusable figure script
# 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
Terminal — run the script
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.

PyMOL and Python
PyMOL’s scripting environment is Python. Any .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.

Last updated on

Similar Posts

Leave a Reply

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