Python¶
Package xpict on PyPI — source under python/xpict/. Paint goes through
the Rust extension xpict._native; RDKit is required for the single-mol client
layout edge (pip install 'xpict[rdkit]').
Single molecule¶
Same shape as JS / Rust: mol → render → to_svg.
from xpict import mol, render, to_svg
benzene = mol("c1ccccc1")
rendered = render(benzene, {
"color": "#0b6e4f",
"atom_shade": [0, 0, 0.2, 0, 0, 0.9],
})
svg = to_svg(rendered.scene)
aligned = render(mol("Cc1ccccc1"), {"align_to": benzene}) # or align_to=rendered
align_to accepts a prior Mol or Rendered. Options: color, atom_shade,
bond_shade, star_labels, weight, scale, align_to, id.
Declarative document¶
Live nested DepictSpec is Rust-first two-pass (same as JS / Rust):
- Core
plan_edge→EdgePlan - Host RDKit
process_edge_plan - Core
render_doc→ scenes (chrome applied in Rust)
depict(doc) returns list[Rendered]; render(doc) is a SVG convenience wrapper.
from xpict import depict, render, to_svg
rows = depict({
"type": "mol",
"smiles": "CCO",
"color": "#0b6e4f",
"shade": {"atoms": [0.0, 0.2, 0.9], "vmin": 0.0, "vmax": 1.0},
})
svg = to_svg(rows[0].scene)
# Or SVG directly:
svg = render({
"type": "group",
"children": [
{"type": "mol", "cxsmiles": "*c1ccccc1Cl |$R1;;;;;$|"},
{"type": "mol", "smiles": "c1ccccc1O"},
],
})
Contracts: DepictSpec / MolNode in xpict.contracts.depict. Chem scripts:
Label markup.