py3Dmol — Molecular Visualization
Purpose
Interactive 3D molecular visualization in Jupyter notebooks and scripts.
Wraps 3Dmol.js (WebGL). Used for docking pose inspection, protein-ligand
complexes, conformer overlays, trajectory snapshots.
When to Use This Skill
- Visualizing docking poses from Vina/Gnina
- Inspecting protein-ligand binding pockets
- Displaying conformer ensembles
- Annotating pharmacophore features on 3D structures
- Quick structure QC after homology modeling or MD prep
Reference Files
| File |
Content |
references/basics.md |
Installation, view creation, loading PDB/SDF/SMILES, stick/sphere/cartoon/surface basics |
references/protein-ligand.md |
Protein+ligand display, binding pocket zoom, dual-structure overlay, docking pose batch |
references/selections-styles.md |
Selection language (chain/resi/resn/atom), color schemes, surfaces, labels, transparency |
references/jupyter-patterns.md |
Jupyter embed, ipywidgets sliders, NGLview alternative, saving PNG, RDKit interop |
Quick Routing
"Show me a docking pose" → protein-ligand.md
"Show all conformers overlaid" → jupyter-patterns.md (animation loop)
"Highlight binding pocket / surface" → selections-styles.md
"I just need a quick look at a molecule" → basics.md
Minimal Pattern
import py3Dmol
view = py3Dmol.view(width=800, height=500)
view.addModel(open('complex.pdb').read(), 'pdb')
view.setStyle({'cartoon': {'color': 'spectrum'}}) # protein
view.setStyle({'resn': 'LIG'}, {'stick': {'colorscheme': 'greenCarbon'}})
view.zoomTo({'resn': 'LIG'})
view.show()
Key Facts
py3Dmol renders via 3Dmol.js in Jupyter — requires a running notebook kernel
- For non-Jupyter contexts: use
view.png() → base64 PNG, or view.write_html()
- NGLview is an alternative with better trajectory support (use for MD)
setStyle is cumulative by default; use setStyle({}, {}) to reset all
- Ligand residue name varies: 'LIG', 'UNL', 'MOL' — check with grep before scripting
1---2name: py3dmol3description: Use when creating 3D molecular visualizations with py3Dmol (3Dmol.js). Covers PDB/SDF/SMILES loading, cartoon/stick/sphere styles, protein-ligand complexes, docking pose viewers, selection language, PNG/HTML export, and NGLview for MD trajectories.4---56# py3Dmol — Molecular Visualization78## Purpose9Interactive 3D molecular visualization in Jupyter notebooks and scripts.10Wraps 3Dmol.js (WebGL). Used for docking pose inspection, protein-ligand11complexes, conformer overlays, trajectory snapshots.1213## When to Use This Skill14- Visualizing docking poses from Vina/Gnina15- Inspecting protein-ligand binding pockets16- Displaying conformer ensembles17- Annotating pharmacophore features on 3D structures18- Quick structure QC after homology modeling or MD prep1920## Reference Files2122| File | Content |23|------|---------|24| `references/basics.md` | Installation, view creation, loading PDB/SDF/SMILES, stick/sphere/cartoon/surface basics |25| `references/protein-ligand.md` | Protein+ligand display, binding pocket zoom, dual-structure overlay, docking pose batch |26| `references/selections-styles.md` | Selection language (chain/resi/resn/atom), color schemes, surfaces, labels, transparency |27| `references/jupyter-patterns.md` | Jupyter embed, ipywidgets sliders, NGLview alternative, saving PNG, RDKit interop |2829## Quick Routing3031**"Show me a docking pose"** → `protein-ligand.md`3233**"Show all conformers overlaid"** → `jupyter-patterns.md` (animation loop)3435**"Highlight binding pocket / surface"** → `selections-styles.md`3637**"I just need a quick look at a molecule"** → `basics.md`3839## Minimal Pattern4041```python42import py3Dmol4344view = py3Dmol.view(width=800, height=500)45view.addModel(open('complex.pdb').read(), 'pdb')46view.setStyle({'cartoon': {'color': 'spectrum'}}) # protein47view.setStyle({'resn': 'LIG'}, {'stick': {'colorscheme': 'greenCarbon'}})48view.zoomTo({'resn': 'LIG'})49view.show()50```5152## Key Facts53- `py3Dmol` renders via 3Dmol.js in Jupyter — requires a running notebook kernel54- For non-Jupyter contexts: use `view.png()` → base64 PNG, or `view.write_html()`55- NGLview is an alternative with better trajectory support (use for MD)56- `setStyle` is cumulative by default; use `setStyle({}, {})` to reset all57- Ligand residue name varies: 'LIG', 'UNL', 'MOL' — check with grep before scripting