PyMOL
Prerequisites
uv: Read the uv skill and follow its Setup instructions to ensure
uv is installed and on PATH.
- User Notification: If .licenses/pymol_LICENSE.txt does not already exist
in the workspace root directory then (1) prominently notify the user to
check the license at https://www.pymol.org/, then (2) create the file
recording the notification text and timestamp.
Overview
All PyMOL commands run on the host via uv with OSMesa software rendering — no
GPU, display, or X server is needed. Structure files must be downloaded to the
host before running PyMOL.
Do NOT use when:
- The user wants to run AlphaFold predictions.
- The user wants docking or molecular dynamics simulations.
- The user only has a sequence and no structure file — fetch the structure
first. Check if any other installed skills can retrieve structures from the
PDB or AlphaFold Database before proceeding.
Setup (Agent Instructions)
Ensure that uv is installed on the host system. The PyMOL scripts use PEP 0723
headers to declare their dependencies, and uv run will automatically handle
installing them (including pymol-open-source-whl) when the script is executed.
Core Rules
- Output paths must be absolute or relative to the user's project root.
Always run PyMOL scripts from the user's project directory.
- Software rendering only. Use
cmd.png() for output. Never use
cmd.draw() or cmd.ray() with hardware acceleration — OSMesa does not
support it. Set enprojectnment variable PYOPENGL_PLATFORM=osmesa for headless
rendering.
- Always save a
.pse session file alongside any PNG output. This lets
the user open the session in their local PyMOL for further inspection.
- Always call
cmd.quit() at the end of every PyMOL script. Omitting it
causes the process to stop responding.
- Init boilerplate is mandatory. Every PyMOL script must begin with the
initialization sequence.
from pymol import cmd must come after
finish_launching(), not before.
- See references/PYMOL_REFERENCE.md for
selection syntax, common commands, and gotchas.
- Pre-Flight File Check: Before writing the PyMOL script or running it,
you MUST verify that the requested structure file actually exists on the
host machine.
- Verify Structure Load: After loading a structure with
cmd.load(),
always verify it succeeded by checking cmd.count_atoms("all"). If the
result is 0, print an error to stdout and call cmd.quit() immediately.
- Notification: If this skill is used, ensure this is mentioned in the
output.
Quick Start
- Ensure structure files are downloaded to a directory in the user's project.
- Write a PyMOL Python script (e.g.,
render.py) with the required init
boilerplate and PEP 0723 header.
- Run it via
uv run: bash uv run render.py
Minimal example script (render.py)
# /// script
# requires-python = ">=3.10, <3.13"
# dependencies = [
# "pymol-open-source-whl",
# ]
# ///
import os
import sys
# Set enprojectnment variable for headless rendering
os.enprojectn["PYOPENGL_PLATFORM"] = "osmesa"
import pymol # pytype: disable=import-error
pymol.pymol_argv = ["pymol", "-cq"]
pymol.finish_launching()
from pymol import cmd # pytype: disable=import-error
cmd.load("AF-P00520-F1-model_v4.cif", "structure")
cmd.show("cartoon")
cmd.color("green", "ss h")
cmd.color("yellow", "ss s")
cmd.color("gray", "ss l+''")
cmd.orient()
cmd.set("ray_opaque_background", 1)
cmd.png("output/render.png", width=1200, height=900, dpi=150)
cmd.save("output/session.pse")
cmd.quit()
Common Recipes
See references/RECIPES.md for complete, copy-paste
ready recipes. Available recipes:
- Cartoon with secondary structure coloring — basic helix/sheet/loop
coloring
- B-factor (pLDDT) coloring — continuous spectrum coloring by B-factor
- AlphaFold pLDDT coloring — canonical threshold-based confidence colors
- Highlight specific residues — show active site or key residues as sticks
- Surface rendering — transparent surface over cartoon
- Electrostatic surface rendering — vacuum electrostatics (qualitative)
- Multi-chain complex colors — automatic per-chain coloring
- B-factor putty analysis — tube width proportional to flexibility
- Cavity and pocket visualization — surface cavity detection with ligand
focus
- Multi-structure batch rendering — render a directory of structures
- Measure distance between residues — CA–CA distance with labels
- Zoom into binding pocket — simple pocket focus
- Protein-ligand interaction — ligand isolation, styled rendering, polar
contacts
- Two-structure superposition with RMSD — align/cealign with auto-fallback
- In silico mutagenesis — mutate residues with the mutagenesis wizard
- Load and modify an existing session — re-open a
.pse file
Interpreting Output
- The
output/ directory contains PNG images and a .pse session file.
- Any measurements or metrics (distances, RMSD, atom counts) are printed to
stdout by the PyMOL script. Report these values to the user.
- Present PNG images to the user and describe the visualization.
- Tell the user they can open the
.pse file in their local PyMOL to further
explore, rotate, or modify the visualization.
- If the user wants modifications, load the saved
.pse in a new script and
re-run.
- Large sessions with surfaces can exceed the
--max_output_mb limit (default
500 MB). Increase it with --max_output_mb=1000 if needed.
1---2name: pymol3description: Visualize, analyze, and render protein and molecular structures using PyMOL. Use when the user wants to create images of protein structures, perform structural alignments or superposition, measure distances or contacts, highlight binding sites or active site residues, color by B-factor/pLDDT, or analyze protein-ligand interactions. Do not use for docking, molecular dynamics, or sequence-only analysis.4---56# PyMOL78## Prerequisites9101. **`uv`**: Read the `uv` skill and follow its Setup instructions to ensure11 `uv` is installed and on PATH.122. **User Notification**: If .licenses/pymol_LICENSE.txt does not already exist13 in the workspace root directory then (1) prominently notify the user to14 check the license at https://www.pymol.org/, then (2) create the file15 recording the notification text and timestamp.1617## Overview1819All PyMOL commands run on the host via `uv` with OSMesa software rendering — no20GPU, display, or X server is needed. Structure files must be downloaded to the21host before running PyMOL.2223**Do NOT use when:**2425- The user wants to run AlphaFold predictions.26- The user wants docking or molecular dynamics simulations.27- The user only has a sequence and no structure file — fetch the structure28 first. Check if any other installed skills can retrieve structures from the29 PDB or AlphaFold Database before proceeding.3031## Setup (Agent Instructions)3233Ensure that `uv` is installed on the host system. The PyMOL scripts use PEP 072334headers to declare their dependencies, and `uv run` will automatically handle35installing them (including `pymol-open-source-whl`) when the script is executed.3637## Core Rules3839- **Output paths must be absolute or relative to the user's project root.**40 Always run PyMOL scripts from the user's project directory.41- **Software rendering only.** Use `cmd.png()` for output. Never use42 `cmd.draw()` or `cmd.ray()` with hardware acceleration — OSMesa does not43 support it. Set enprojectnment variable `PYOPENGL_PLATFORM=osmesa` for headless44 rendering.45- **Always save a `.pse` session file** alongside any PNG output. This lets46 the user open the session in their local PyMOL for further inspection.47- **Always call `cmd.quit()`** at the end of every PyMOL script. Omitting it48 causes the process to stop responding.49- **Init boilerplate is mandatory.** Every PyMOL script must begin with the50 initialization sequence. `from pymol import cmd` must come after51 `finish_launching()`, not before.52- See [references/PYMOL_REFERENCE.md](references/PYMOL_REFERENCE.md) for53 selection syntax, common commands, and gotchas.54- **Pre-Flight File Check**: Before writing the PyMOL script or running it,55 you MUST verify that the requested structure file actually exists on the56 host machine.57- **Verify Structure Load**: After loading a structure with `cmd.load()`,58 always verify it succeeded by checking `cmd.count_atoms("all")`. If the59 result is 0, print an error to stdout and call `cmd.quit()` immediately.60- **Notification**: If this skill is used, ensure this is mentioned in the61 output.6263## Quick Start6465* Ensure structure files are downloaded to a directory in the user's project.66* Write a PyMOL Python script (e.g., `render.py`) with the required init67 boilerplate and PEP 0723 header.68* Run it via `uv run`: `bash uv run render.py`6970### Minimal example script (`render.py`)7172```python73# /// script74# requires-python = ">=3.10, <3.13"75# dependencies = [76# "pymol-open-source-whl",77# ]78# ///7980import os81import sys8283# Set enprojectnment variable for headless rendering84os.enprojectn["PYOPENGL_PLATFORM"] = "osmesa"8586import pymol # pytype: disable=import-error87pymol.pymol_argv = ["pymol", "-cq"]88pymol.finish_launching()8990from pymol import cmd # pytype: disable=import-error9192cmd.load("AF-P00520-F1-model_v4.cif", "structure")93cmd.show("cartoon")94cmd.color("green", "ss h")95cmd.color("yellow", "ss s")96cmd.color("gray", "ss l+''")97cmd.orient()98cmd.set("ray_opaque_background", 1)99cmd.png("output/render.png", width=1200, height=900, dpi=150)100cmd.save("output/session.pse")101cmd.quit()102```103104## Common Recipes105106See [references/RECIPES.md](references/RECIPES.md) for complete, copy-paste107ready recipes. Available recipes:108109- **Cartoon with secondary structure coloring** — basic helix/sheet/loop110 coloring111- **B-factor (pLDDT) coloring** — continuous spectrum coloring by B-factor112- **AlphaFold pLDDT coloring** — canonical threshold-based confidence colors113- **Highlight specific residues** — show active site or key residues as sticks114- **Surface rendering** — transparent surface over cartoon115- **Electrostatic surface rendering** — vacuum electrostatics (qualitative)116- **Multi-chain complex colors** — automatic per-chain coloring117- **B-factor putty analysis** — tube width proportional to flexibility118- **Cavity and pocket visualization** — surface cavity detection with ligand119 focus120- **Multi-structure batch rendering** — render a directory of structures121- **Measure distance between residues** — CA–CA distance with labels122- **Zoom into binding pocket** — simple pocket focus123- **Protein-ligand interaction** — ligand isolation, styled rendering, polar124 contacts125- **Two-structure superposition with RMSD** — align/cealign with auto-fallback126- **In silico mutagenesis** — mutate residues with the mutagenesis wizard127- **Load and modify an existing session** — re-open a `.pse` file128129## Interpreting Output130131- The `output/` directory contains PNG images and a `.pse` session file.132- Any measurements or metrics (distances, RMSD, atom counts) are printed to133 stdout by the PyMOL script. Report these values to the user.134- Present PNG images to the user and describe the visualization.135- Tell the user they can open the `.pse` file in their local PyMOL to further136 explore, rotate, or modify the visualization.137- If the user wants modifications, load the saved `.pse` in a new script and138 re-run.139- Large sessions with surfaces can exceed the `--max_output_mb` limit (default140 500 MB). Increase it with `--max_output_mb=1000` if needed.