Lesson 5 of 13 · 11 min
PyMOL: Representations, Coloring, and Publication Figures
PyMOL builds a molecular figure by stacking independent representations onto an atom selection, then coloring and rendering them. Because every step is a command, an entire publication figure can be captured as a short script that regenerates the identical image on any machine. This lesson covers the representation, coloring, camera, and ray-tracing commands you need for reproducible, high-resolution figures.
Representations With show/hide
fetch 4hhb, async=0
hide everything
show cartoon, polymer
show sticks, hetatm and not resn HOH
show spheres, elem Fe
set sphere_scale, 0.4, elem FeRepresentations are additive: show adds a rep to a selection without touching the others, and hide removes only the named rep. Selections use PyMOL's algebra, so hetatm and not resn HOH drops crystallographic waters and keeps the bound heteroatoms — the four heme groups (plus any crystallization ions) — while elem Fe picks just the heme irons. Surfaces are the most expensive rep to compute and ray-trace, so restrict them to the chain you care about with show surface, chain A and drop surface_quality to -1 (its default is 0) while iterating.
Coloring Strategies
bg_color white
# color the protein by chain, ligands by element (CPK)
util.cbc()
util.cnc("hetatm and not resn HOH")
# alternative scheme: color the backbone by crystallographic B-factor
spectrum b, blue_white_red, polymer and name CA Spectrum: range = 15.30 to 84.72
Tip: For a B-factor figure, pair spectrum b with cartoon putty (set cartoon_putty_scale_max first, then cartoon putty and show cartoon) so tube radius also encodes flexibility. Set ray_opaque_background, 0 to write a transparent PNG that drops cleanly onto any journal background, and prefer a diverging palette like blue_white_red over rainbow, whose uneven brightness invents false boundaries that aren't in the data.
Views, Scenes, and Export
orient polymer
set ray_opaque_background, 0
set ray_shadows, 0
set antialias, 2
# print the current camera; paste the set_view(...) block back to restore it
get_view
# store the styled camera and reps as a named scene (recall with: scene F1)
scene F1, store
# ray-trace at explicit pixel dimensions, then write a PNG tagged 300 DPI
ray 2400, 1800
png /data/figures/4hhb_bfactor.png, dpi=300### cut below here and paste into script ###
set_view (\
0.638072908, -0.176906988, 0.749390602,\
-0.187744021, 0.905735910, 0.379648834,\
-0.746740460, -0.384833544, 0.543828726,\
0.000000000, 0.000000000, -287.514801025,\
16.428998947, 17.789674759, 10.379617691,\
226.719360352, 348.310241699, -20.000000000 )
### cut above here and paste into script ###
Ray: render time: 4.21 sec. = 855.1 frames/hour (4.21 sec. accum.).
ScenePNG: wrote 2400x1800 pixel image to file "/data/figures/4hhb_bfactor.png".
Try it yourself: Fetch 1ubq (ubiquitin, a single chain), hide everything, and show cartoon. Color the backbone by flexibility with spectrum b, blue_white_red, name CA. Show the Ile44 hydrophobic patch (resi 8+44+68+70) as sticks and recolor it by element with util.cnc("resi 8+44+68+70"). Set bg_color white, orient, store the camera with scene S1, store, then ray 1600, 1200 and png ubq_bfactor.png, dpi=300. Confirm the flexible C-terminal tail renders red (high B-factor) against a blue, rigid core.