
Pymol
Run headless PyMOL scripts from an agent to render molecular structures and export PNGs without a GPU or GUI.
Overview
PyMOL is an agent skill for the Build phase that teaches headless PyMOL initialization, OSMesa-safe rendering, and selection syntax for molecular visualization scripts.
Install
npx skills add https://github.com/google-deepmind/science-skills --skill pymolWhat is this skill?
- Mandatory init sequence: import pymol, set pymol_argv to ["pymol", "-cq"], finish_launching(), then from pymol import cm
- OSMesa software rendering — no GPU or X display; prefer cmd.png over cmd.draw or hardware OpenGL
- Selection cheatsheet for chain, resi ranges/lists, resn, name CA, and ss h/s/l
- Ray tracing via cmd.ray when quality matters; cmd.set ray_opaque_background for white backgrounds
Adoption & trust: 559 installs on skills.sh; 1.7k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need publication-quality structure images from an agent but PyMOL crashes when startup order is wrong or the environment has no GPU display.
Who is it for?
Solo builders automating structure figures in CI, remote servers, or agent-driven Python pipelines.
Skip if: Interactive PyMOL GUI tutoring, non-PyMOL viewers, or workflows that require real-time hardware OpenGL drawing.
When should I use this skill?
Agent is writing or fixing PyMOL Python scripts for headless rendering and structure selection.
What do I get? / Deliverables
After the skill runs, agents emit valid `-cq` PyMOL scripts that export PNGs with correct selections instead of GUI-only or OpenGL-dependent calls.
- PyMOL Python scripts with mandatory init boilerplate
- PNG renders via cmd.png with documented selections
Recommended Skills
Journey fit
Canonical shelf is Build because the skill documents executable PyMOL automation and selection recipes agents emit as code, not lab operations monitoring. agent-tooling fits agent-authored `-cq` scripts, `cmd.png` exports, and selection-syntax snippets rather than a shipped app frontend.
How it compares
Reference skill for scriptable PyMOL, not a molecular dynamics or docking package.
Common Questions / FAQ
Who is pymol for?
Researchers, indie science developers, and agent users who script PyMOL on headless or OSMesa-only machines.
When should I use pymol?
During Build when generating visualization code, when exporting figures on servers without displays, or when agents must select chains, residues, or secondary structure reliably.
Is pymol safe to install?
Review the Security Audits panel on this Prism page before running generated scripts that execute PyMOL or write files on your system.
SKILL.md
READMESKILL.md - Pymol
# PyMOL Quick Reference ## Mandatory Initialization Boilerplate Every PyMOL script **must** start with this exact sequence. The order matters — reversing the import and `finish_launching()` will crash. ```python import pymol pymol.pymol_argv = ["pymol", "-cq"] pymol.finish_launching() from pymol import cmd ``` - `-c` = command-line mode (no GUI) - `-q` = quiet (suppress startup messages) ## Rendering Backend PyMOL runs with **OSMesa** (software rendering). There is no GPU or X display. - Use `cmd.png(path, width, height, dpi)` for output. - `cmd.ray()` works but is slow — use it only when you need ray-traced quality. - Never use `cmd.draw()` (requires hardware OpenGL). - Always set `cmd.set("ray_opaque_background", 1)` if you want a white background instead of transparent. ## Selection Syntax ### Identifiers Selector | Example | Selects -------------- | ------------------ | ---------------------------------- `chain` | `chain A` | All atoms in chain A `resi` | `resi 100` | Residue number 100 `resi` (range) | `resi 100-200` | Residues 100 through 200 `resi` (list) | `resi 100+102+150` | Specific residues `resn` | `resn ALA` | All alanine residues `name` | `name CA` | All C-alpha atoms `ss` | `ss h` | Helices (h), sheets (s), loops (l) ### Structure types Selector | Selects ----------------- | ------------------------------------------ `polymer.protein` | All protein atoms `organic` | Organic ligands (non-polymer, non-solvent) `solvent` | Water molecules `hetatm` | Heteroatoms (ligands, ions, water) `all` | Everything ### Logical operators Operator | Example | Meaning -------- | -------------------------------- | ------------ `and` | `chain A and resi 100` | Intersection `or` | `resn ALA or resn GLY` | Union `not` | `not solvent` | Negation `()` | `chain A and (not resi 100-110)` | Grouping ### Proximity selectors Selector | Example ------------------------- | --------------------------------------------- `within X of (selection)` | `polymer.protein within 4 of organic` `byres (selection)` | `byres (polymer.protein within 4 of organic)` `around X` | `resi 100 around 5` ### Named selections ```python cmd.select("binding_site", "byres (polymer.protein within 4 of organic)") cmd.select("alpha_carbons", "name CA and polymer.protein") ``` ## File Paths - When running with `uv run`, files are accessed directly from the host filesystem. - Paths are relative to the directory where you run the command, or you can use absolute paths. - Ensure output directories exist before trying to write to them. ## Common Commands ### Loading structures ```python cmd.load("data/structure.cif", "myprotein") cmd.load("data/structure.pdb", "myprotein") ``` ### Display modes ```python cmd.show("cartoon", "polymer.protein") cmd.show("sticks", "resi 100-110") cmd.show("surface", "polymer.protein") cmd.show("spheres", "resi 50") cmd.hide("everything", "solvent") ``` ### Coloring ```python cmd.color("green", "ss h") cmd.color("cyan", "chain A") cmd.spectrum("b", "red_white_blue", "polymer.protein") cmd.spectrum("count", "rainbow", "polymer.protein") ``` ### Structural operations ```python cmd.align("mobile", "target") cmd.super("mobile", "target") cmd.select("site", "resi 100-120 and chain A") cmd.distance("dist1", "resi 100 and name CA", "resi 200 and name CA") ``` ### Output ```python cmd.png("output/image.png", width=1200, height=900, dpi=150) cmd.save("output/modified.pdb", "myprotein") ``` ### Cleanup (REQUIRED) ```python cmd.quit() ``` ## Common Pitfalls 1. **`cmd.quit()` is mandatory** — without it, the PyMOL process hangs and the container will time out. 2. **Selection case sensitivity** — `"chain a"` is NOT the s