| name | vmd-python-rendering |
| description | Render publication-quality molecular visualizations with vmd-python and Tachyon ray-tracing — environment setup, representations, materials, lighting, camera control, and batch rendering from Python. Use when producing molecular structure or trajectory images programmatically without the VMD GUI. |
VMD-Python Molecular Rendering
Render publication-quality molecular visualizations using vmd-python with Tachyon ray-tracing.
Environment Setup
conda create -n vmd-env python=3.12 -y
conda install -n vmd-env -c conda-forge vmd-python tachyon mdanalysis -y
Basic Usage
from vmd import molecule, molrep, display, render, atomsel, axes, evaltcl
molid = molecule.load("psf", "system.psf")
molecule.read(molid, "dcd", "trajectory.dcd", waitfor=-1)
molecule.set_frame(molid, -1)
sel = atomsel("name CA", molid=molid)
positions = list(zip(sel.x, sel.y, sel.z))
indices = sel.index
while molrep.num(molid) > 0:
molrep.delrep(molid, 0)
molrep.addrep(molid,
style="VDW 1.2 20",
selection="name PT*",
color="ColorID 2",
material="AOShiny")
molrep.addrep(molid,
style="CPK 1.0 0.3 20 20",
selection="resname NEC",
color="Name",
material="AOShiny")
molrep.addrep(molid,
style="Licorice 0.15 20 20",
selection="resname NEC",
color="ColorID 16",
material="AOShiny")
Display Settings
evaltcl('color Display Background white')
axes.set_location('OFF')
display.set(ambientocclusion=True, aoambient=0.8, aodirect=0.3)
display.set(depthcue=False, culling=False)
evaltcl('display resetview')
evaltcl('scale by 2.5')
evaltcl('rotate x by -30')
evaltcl('rotate y by 45')
display.update()
Rendering
Two-Step Process (Headless)
vmd-python in conda is headless - no OpenGL. Use Tachyon external renderer:
render.render('Tachyon', 'scene.dat')
conda run -n vmd-env tachyon scene.dat \
-res 1920 1080 \
-aasamples 4 \
-format TGA \
-o output.tga
from PIL import Image
Image.open('output.tga').save('output.png')
Available Render Methods
from vmd import render
print(render.listall())
Representation Styles
| Style | Syntax | Use Case |
|---|
| VDW | VDW radius resolution | Space-filling spheres |
| CPK | CPK sphere_r bond_r res res | Ball-and-stick |
| Licorice | Licorice radius res res | Bonds only |
| NewCartoon | NewCartoon | Protein secondary structure |
| QuickSurf | QuickSurf radius density gridspacing | Surfaces |
Color Options
color="ColorID 0"
color="ColorID 1"
color="ColorID 2"
color="ColorID 8"
color="ColorID 16"
color="Name"
color="Type"
color="ResName"
color="Beta"
Materials
Best for Tachyon with AO:
AOShiny - Reflective with ambient occlusion
AOChalky - Matte with ambient occlusion
AOEdgy - Sharp edges with AO
Complete Example
"""Render molecule on surface with VMD-Python + Tachyon."""
from vmd import molecule, molrep, display, render, atomsel, axes, evaltcl
import subprocess
from PIL import Image
molid = molecule.load("psf", "system.psf")
molecule.read(molid, "dcd", "traj.dcd", waitfor=-1)
molecule.set_frame(molid, -1)
while molrep.num(molid) > 0:
molrep.delrep(molid, 0)
molrep.addrep(molid, style="VDW 1.2 20", selection="name PT*",
color="ColorID 2", material="AOShiny")
molrep.addrep(molid, style="CPK 0.8 0.2 20 20", selection="resname LIG",
color="Name", material="AOShiny")
evaltcl('color Display Background white')
axes.set_location('OFF')
display.set(ambientocclusion=True, aoambient=0.8, aodirect=0.3)
evaltcl('display resetview')
evaltcl('scale by 3')
display.update()
render.render('Tachyon', 'scene.dat')
subprocess.run([
'tachyon', 'scene.dat',
'-res', '1920', '1080',
'-aasamples', '4',
'-format', 'TGA',
'-o', 'render.tga'
])
Image.open('render.tga').save('render.png')
Limitations
- No TachyonInternal: conda-forge build lacks internal renderer
- Headless only: No interactive display, snapshot renders empty
- Python 3.12 max: Not compatible with Python 3.13+
Tips
- Use
evaltcl() for Tcl commands not exposed in Python API
- Attribute access (
sel.x) preferred over sel.get('x') (deprecated)
- AOShiny material required for ambient occlusion to work
- Higher
-aasamples = smoother edges but slower render