mol-render
Generate high-quality 3D ball-and-stick model PNG images from SMILES strings or PDB structures, rendered with POV-Ray ray tracing.
Dependencies
Required:
- rdkit — SMILES parsing & 3D conformer generation
- numpy — coordinate transforms
- povray — ray tracing renderer
Optional (PDB mode only):
- biopython — PDB file parsing
Install:
pip install rdkit numpy
apt-get install -y povray
# For PDB support:
pip install biopython
Usage
SMILES Mode
python3 scripts/smiles_to_3d.py "SMILES" -o output.png
Arguments:
SMILES — (positional) SMILES string (required)
-o, --output — output PNG path (default: molecule.png)
--bg — background color: black / white / blue (default: blue)
--no-hydrogen — hide hydrogen atoms
--kekulize — convert aromatic bonds to alternating single/double bonds
Examples:
# Ethanol
python3 scripts/smiles_to_3d.py "CCO" -o ethanol.png
# Benzene (white background, Kekulé style)
python3 scripts/smiles_to_3d.py "c1ccccc1" -o benzene.png --bg white --kekulize
# Caffeine
python3 scripts/smiles_to_3d.py "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" -o caffeine.png
# Aspirin (no hydrogens)
python3 scripts/smiles_to_3d.py "CC(=O)OC1=CC=CC=C1C(=O)O" -o aspirin.png --no-hydrogen
PDB Mode
python3 scripts/pdb_to_3d.py --pdb <PDB_ID_or_file> -o output.png
Arguments:
--pdb — PDB file path or 4-character PDB ID (auto-downloads from RCSB) (required)
-o, --output — output PNG path (default: pdb_molecule.png)
--chain — select specific chain (e.g., A)
--residues — residue range (e.g., 1-50 or 10,20,30-40)
--ligand-only — render only ligands (HETATM, excluding water)
--no-hydrogen — hide hydrogen atoms
--no-water / --keep-water — filter/keep water molecules (default: filter)
--bg — background color: black / white / blue (default: blue)
--view — viewing angle: auto / side / top / front or θ,φ in degrees (default: auto)
--resolution — resolution multiplier, e.g., 0.5 for half, 2.0 for double (default: 1.0)
--sphere-scale — override sphere scale factor (default: auto)
--bond-radius — override bond radius (default: auto)
Examples:
# Download and render G-quadruplex from RCSB
python3 scripts/pdb_to_3d.py --pdb 1KF1 --no-hydrogen -o g4.png
# Side view
python3 scripts/pdb_to_3d.py --pdb 1KF1 --no-hydrogen --view side -o g4_side.png
# Ligands only
python3 scripts/pdb_to_3d.py --pdb 1KF1 --ligand-only -o ligands.png
# Specific chain and residues
python3 scripts/pdb_to_3d.py --pdb 1KF1 --chain A --residues 1-12 -o partial.png
# Local PDB file
python3 scripts/pdb_to_3d.py --pdb structure.pdb -o out.png
# Large protein at lower resolution
python3 scripts/pdb_to_3d.py --pdb 2HYY --no-hydrogen --resolution 0.5 -o protein.png
Output
- 1200×1200 PNG with POV-Ray ray tracing
- CPK color scheme (C=dark gray, O=red, N=blue, H=white, P=orange, S=yellow, K=purple, ...)
- Aromatic bonds rendered as solid + dashed lines (SMILES mode)
- Double bonds rendered as two parallel solid lines
--kekulize option converts aromatic bonds to alternating single/double
- Metal ions displayed with ionic radius (large spheres), no coordination bonds drawn
- Auto-selects best viewing angle (PCA-based)
- Auto-scales sphere/bond sizes for large molecules
- Water molecules filtered by default (PDB mode)
Known Limitations
- Very large molecules (>2000 atoms) may be slow to render (use
--resolution 0.5)
- PDB mode renders all bonds as single bonds (no double/aromatic distinction)
- Metal coordination bonds are not rendered
- POV-Ray must be installed (
which povray)
biopython required only for PDB mode (optional dependency)
License
MIT
1---
2name: mol-render
3description: Generate high-quality 3D ball-and-stick molecular renderings from SMILES strings or PDB structures using POV-Ray ray tracing.
4metadata:
5 source: https://skillmd.com/skills/modbender/mol-render
6 openclaw:
7 emoji: "🧪"
8 requires:
9 bins: ["povray", "python3"]
10 pip: ["rdkit", "numpy"]
11 optionalPip: ["biopython"]
12---
13
14# mol-render
15
16Generate high-quality 3D ball-and-stick model PNG images from SMILES strings or PDB structures, rendered with POV-Ray ray tracing.
17
18## Dependencies
19
20**Required:**
21- **rdkit** — SMILES parsing & 3D conformer generation
22- **numpy** — coordinate transforms
23- **povray** — ray tracing renderer
24
25**Optional (PDB mode only):**
26- **biopython** — PDB file parsing
27
28Install:
29```bash
30pip install rdkit numpy
31apt-get install -y povray
32
33# For PDB support:
34pip install biopython
35```
36
37## Usage
38
39### SMILES Mode
40
41```bash
42python3 scripts/smiles_to_3d.py "SMILES" -o output.png
43```
44
45**Arguments:**
46- `SMILES` — (positional) SMILES string (required)
47- `-o`, `--output` — output PNG path (default: `molecule.png`)
48- `--bg` — background color: `black` / `white` / `blue` (default: `blue`)
49- `--no-hydrogen` — hide hydrogen atoms
50- `--kekulize` — convert aromatic bonds to alternating single/double bonds
51
52**Examples:**
53
54```bash
55# Ethanol
56python3 scripts/smiles_to_3d.py "CCO" -o ethanol.png
57
58# Benzene (white background, Kekulé style)
59python3 scripts/smiles_to_3d.py "c1ccccc1" -o benzene.png --bg white --kekulize
60
61# Caffeine
62python3 scripts/smiles_to_3d.py "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" -o caffeine.png
63
64# Aspirin (no hydrogens)
65python3 scripts/smiles_to_3d.py "CC(=O)OC1=CC=CC=C1C(=O)O" -o aspirin.png --no-hydrogen
66```
67
68### PDB Mode
69
70```bash
71python3 scripts/pdb_to_3d.py --pdb <PDB_ID_or_file> -o output.png
72```
73
74**Arguments:**
75- `--pdb` — PDB file path or 4-character PDB ID (auto-downloads from RCSB) (required)
76- `-o`, `--output` — output PNG path (default: `pdb_molecule.png`)
77- `--chain` — select specific chain (e.g., `A`)
78- `--residues` — residue range (e.g., `1-50` or `10,20,30-40`)
79- `--ligand-only` — render only ligands (HETATM, excluding water)
80- `--no-hydrogen` — hide hydrogen atoms
81- `--no-water` / `--keep-water` — filter/keep water molecules (default: filter)
82- `--bg` — background color: `black` / `white` / `blue` (default: `blue`)
83- `--view` — viewing angle: `auto` / `side` / `top` / `front` or `θ,φ` in degrees (default: `auto`)
84- `--resolution` — resolution multiplier, e.g., `0.5` for half, `2.0` for double (default: `1.0`)
85- `--sphere-scale` — override sphere scale factor (default: auto)
86- `--bond-radius` — override bond radius (default: auto)
87
88**Examples:**
89
90```bash
91# Download and render G-quadruplex from RCSB
92python3 scripts/pdb_to_3d.py --pdb 1KF1 --no-hydrogen -o g4.png
93
94# Side view
95python3 scripts/pdb_to_3d.py --pdb 1KF1 --no-hydrogen --view side -o g4_side.png
96
97# Ligands only
98python3 scripts/pdb_to_3d.py --pdb 1KF1 --ligand-only -o ligands.png
99
100# Specific chain and residues
101python3 scripts/pdb_to_3d.py --pdb 1KF1 --chain A --residues 1-12 -o partial.png
102
103# Local PDB file
104python3 scripts/pdb_to_3d.py --pdb structure.pdb -o out.png
105
106# Large protein at lower resolution
107python3 scripts/pdb_to_3d.py --pdb 2HYY --no-hydrogen --resolution 0.5 -o protein.png
108```
109
110## Output
111
112- 1200×1200 PNG with POV-Ray ray tracing
113- CPK color scheme (C=dark gray, O=red, N=blue, H=white, P=orange, S=yellow, K=purple, ...)
114- Aromatic bonds rendered as solid + dashed lines (SMILES mode)
115- Double bonds rendered as two parallel solid lines
116- `--kekulize` option converts aromatic bonds to alternating single/double
117- Metal ions displayed with ionic radius (large spheres), no coordination bonds drawn
118- Auto-selects best viewing angle (PCA-based)
119- Auto-scales sphere/bond sizes for large molecules
120- Water molecules filtered by default (PDB mode)
121
122## Known Limitations
123
124- Very large molecules (>2000 atoms) may be slow to render (use `--resolution 0.5`)
125- PDB mode renders all bonds as single bonds (no double/aromatic distinction)
126- Metal coordination bonds are not rendered
127- POV-Ray must be installed (`which povray`)
128- `biopython` required only for PDB mode (optional dependency)
129
130## License
131
132MIT