How to Color Proteins in PyMOL: Every Method Explained
Coloring is the single most expressive tool in PyMOL — it’s what turns a grey blob into a figure that communicates something specific about structure, function, or confidence. This guide covers every coloring method, when each is appropriate, and the exact commands for each.
Before any coloring command, make sure you have a structure loaded and displaying as cartoon. The quickest setup:
fetch 4XYZ # or: load your_structure.pdb
as cartoon
hide everything, resn HOH # remove water clutter
Color by chain assigns a distinct color to each polypeptide chain. It’s the standard first coloring for any multi-chain structure — complexes, dimers, antibody-antigen pairs — because it immediately makes chain boundaries visible without requiring any structural knowledge.
# Color all chains automatically (most common)
util.cbc
# Color specific chains manually
color slate, chain A
color salmon, chain B
color palegreen, chain C
# Color by chain but only for a specific object
util.cbc protein_name
util.cbc stands for “color by chain” and cycles through a built-in set of distinct, publication-friendly colors. It’s a single-command solution that works for any number of chains. For figures where you need specific colors per chain — to match other figure panels, or to use your journal’s preferred palette — override individual chains with color color_name, chain X after running util.cbc.
Coloring by secondary structure makes alpha helices, beta sheets, and loops immediately distinguishable. It’s particularly useful when explaining a protein’s fold to an audience that may not be familiar with the structure — the coloring communicates topology without requiring any annotation.
# Standard secondary structure coloring
util.cbs
# Manually set colors for each element type
color red, ss h # helices
color yellow, ss s # sheets (strands)
color green, ss l # loops
color green, ss "" # unassigned (same as loops)
dss (detect secondary structure) first to assign helix/sheet/loop classification from the backbone geometry before running util.cbs.
PyMOL’s spectrum command colors each atom by the value in its B-factor column — which in crystal structures reflects thermal motion (higher B-factor = more flexible) and in AlphaFold structures holds the pLDDT confidence score (higher = more confident). This is the standard visualization for showing which regions of a predicted structure are reliable.
# AlphaFold pLDDT coloring (standard scale)
# Blue = very high confidence, red = very low
spectrum b, blue_cyan_yellow_orange_red, minimum=50, maximum=100
# Crystal structure B-factor coloring
spectrum b, blue_white_red
# Simple two-color gradient
spectrum b, blue_red
# Green to white to red (neutral midpoint)
spectrum b, green_white_red
The minimum and maximum arguments clamp the color scale. For AlphaFold structures, using minimum=50, maximum=100 means anything with pLDDT below 50 gets the same “lowest” color and the full gradient covers the meaningful 50–100 range. Without these arguments PyMOL scales to the actual min/max values in the file, which can compress the useful range.
color slate, protein first, then spectrum b, blue_red, binding_site_selection. This draws attention directly to the confidence of the region that matters most for your analysis.
CPK coloring (named after Corey, Pauling, and Koltun) assigns colors based on element — the universal chemistry convention that anyone familiar with molecular models will immediately recognize. It’s the standard coloring for ligands, active site residues shown as sticks, and any context where individual atoms need to be identified.
# CPK with white carbons (standard for protein context)
util.cbaw selection
# CPK with green carbons (standard for ligands)
util.cbag selection
# CPK with cyan carbons (common for second molecule in figure)
util.cbac selection
# CPK with yellow carbons
util.cbay selection
# Typical binding site figure: protein gray, ligand green CPK
color gray80, binding_site_residues
util.cbag LIG
The suffix letter in util.cba_ sets the carbon color: w=white, g=green, c=cyan, y=yellow, m=magenta, n=marine. When showing multiple ligands or molecules in the same figure, using different carbon colors (green for ligand, cyan for second molecule, white for protein) is the standard way to keep them visually distinct while keeping all non-carbon atoms on the universal CPK scheme.
The spectrum command maps any per-atom numeric property to a color gradient. Beyond B-factor and pLDDT, it can color by residue number (N→C direction), chain count, or any custom property you assign. It’s the most flexible coloring tool in PyMOL.
# N-terminus → C-terminus rainbow (communicates chain direction)
spectrum count, rainbow
# N→C with a specific two-color gradient
spectrum count, blue_red
# Color by residue number within a specific range
spectrum resi, blue_red, minimum=100, maximum=200
# Color by hydrophobicity (built-in property)
spectrum hydrophobicity, white_orange, selection=protein
# Color surface by custom property (after running calculations)
spectrum my_property, blue_white_red
PyMOL’s built-in color palettes for spectrum include: rainbow, blue_red, blue_white_red, green_white_red, blue_cyan_yellow_orange_red, white_orange, white_blue. For any two named colors, PyMOL will generate a smooth gradient between them automatically.
When the built-in PyMOL colors don’t match your journal’s color scheme, your figure panel requirements, or your personal preference, you can define any color by its RGB values and use it exactly like any named color.
# Define a custom color with RGB values (0.0 to 1.0 scale)
set_color structblue, [0.17, 0.35, 0.63]
set_color lightgray, [0.85, 0.85, 0.85]
set_color warmred, [0.75, 0.15, 0.10]
# Use exactly like any named color
color structblue, chain A
color lightgray, chain B
color warmred, active_site
# Convert hex color to RGB for PyMOL
# #2B5AA0 → R=43/255=0.169, G=90/255=0.353, B=160/255=0.627
set_color pymolblue, [0.169, 0.353, 0.627]
#2B5AA0: R = 43÷255 = 0.169, G = 90÷255 = 0.353, B = 160÷255 = 0.627. Add the set_color lines to your PyMOL script so the colors are defined automatically every time the script runs.
Combining methods in one figure
The most effective publication figures layer multiple coloring methods — a gray protein context with a CPK ligand, or chain-colored chains with highlighted active site residues. The key is applying colors in the right order: broad strokes first, specific highlights second.
# 1. Set protein context color (neutral gray)
color gray70, protein
# 2. Highlight binding site residues (sticks + color)
select site, byres (LIG around 5)
show sticks, site
color slate, site
# 3. Color ligand by atom type (green carbons)
show sticks, LIG
util.cbag LIG
# 4. Color key catalytic residues specifically
color red, resi 273 and chain A
color red, resi 248 and chain A
# 1. Color by chain as foundation
util.cbc
# 2. Override specific chains with preferred colors
color slate, chain A # receptor
color salmon, chain B # ligand protein / partner
# 3. Highlight interface residues
select iface_A, chain A and (byres chain B around 4)
color tv_red, iface_A
Quick reference
| Command | When to use it |
|---|---|
| util.cbc | First thing you do with any multi-chain structure |
| util.cbs | Explaining fold topology to a non-expert audience |
| spectrum b, blue_cyan_yellow_orange_red, min=50, max=100 | Showing AlphaFold pLDDT confidence |
| spectrum b, blue_white_red | Showing crystal structure B-factor flexibility |
| util.cbag LIG | Ligand in binding site (green carbons) |
| util.cbaw active_site | Active site residues as sticks (white carbons) |
| spectrum count, rainbow | Showing N→C direction and chain continuity |
| set_color name, [r, g, b] | Matching journal or lab color scheme |
| color gray70, protein | Neutral protein background in binding site figures |
Coloring in one paragraph
Start every structure with util.cbc to see the chain architecture. Switch to util.cbs when the topology is the story. Use spectrum b for any AlphaFold structure — it’s the most important information about reliability. Apply CPK colors (util.cbag, util.cbaw) to ligands and active site residues in sticks. Layer colors by applying broad strokes first, then overriding specific regions: gray protein background, colored binding site, CPK ligand. Define custom colors with set_color for any figure that needs to match a specific palette. Every good publication figure is really just these six methods combined in the right order.