Python API¶
Autogenerated from the xpict package with
mkdocstrings.
Public surface¶
xpict
¶
xpict — molecule depiction.
Two first-class APIs (same paint as JS / Rust):
Single molecule — mol / render / to_svg::
from xpict import mol, render, to_svg
benzene = mol("c1ccccc1")
rendered = render(benzene, {"color": "#0b6e4f"})
svg = to_svg(rendered.scene)
Declarative document — nested DepictSpec via Rust two-pass depict::
from xpict import depict, to_svg
rows = depict({"type": "mol", "smiles": "CCO"})
svg = to_svg(rows[0].scene)
Mol
dataclass
¶
Input molecule — SMILES / CXSMILES / molfile plus optional align frame.
ensure_frame
¶
Materialize (and cache) a coord-bearing molblock for align_to.
Source code in python/xpict/client.py
Rendered
dataclass
¶
MolRenderOptions
dataclass
¶
MolRenderOptions(
id: str | None = None,
color: str | None = None,
atom_shade: list[float] | None = None,
bond_shade: list[float] | None = None,
mark_atoms: list[int] | None = None,
mark_bonds: list[tuple[int, int]] | None = None,
star_labels: list[str | None] | None = None,
weight: float | None = None,
scale: float | None = None,
align_to: Mol | Rendered | None = None,
atom_map: list[tuple[int, int]] | None = None,
)
Render options — parity with JS / Rust MolRenderOptions.
Pict
¶
Configured depiction engine.
Backend and output options are runtime config — not part of PictSpec JSON.
Reaction / network diagrams render via the live Rust reaction_scheme path.
Source code in python/xpict/api.py
layout
¶
Lay out molecules for the legacy Pict/draw path (internal helper).
Source code in python/xpict/api.py
DepictSpec
¶
Bases: DepictSpec
Live document root — generated wire model + host mols() helper.
mols
¶
Flatten mol nodes in document order (skips edge children).
Source code in python/xpict/contracts/__init__.py
Scene
¶
Bases: StrictModel
Full drawable document before SVG/HTML serialization.
PictBackendWarning
¶
Bases: UserWarning
Raised when a layout backend ignores or only partially supports an option.
mol
¶
Construct a Mol (JS / Rust xpict.mol).
to_svg
¶
Scene JSON / Scene → SVG string (JS xpict.toSvg).
depict
¶
Declarative document → list[Rendered] via core plan/paint + RDKit edge.
reaction_scheme roots are composed into one Rendered (ELK layout
+ edge overlays in Rust). mol / group stay one row per molecule.
Source code in python/xpict/depict_spec.py
Single molecule¶
xpict.client
¶
Single-molecule client — parity with JS xpict.mol / render / toSvg.
All three languages ship the same surface:
mol(source) → render(mol, opts?) → Rendered → to_svg(scene)
align_to accepts a prior Mol or Rendered (pose molblock under the
hood). Layout + MCS align use RDKit at the language edge; paint is
xpict._native.depict_molecule.
Mol
dataclass
¶
Rendered
dataclass
¶
Rendered(
width: float,
height: float,
scene: Scene,
molecule: dict[str, Any],
source: str,
frame_molblock: str,
coords: list[SvgAtom],
svg_coords: list[SvgAtom],
bonds: list[SvgBond],
mol: Mol | None = None,
)
Painted depiction — editable scene plus alignment frame.
to_svg
¶
MolRenderOptions
dataclass
¶
MolRenderOptions(
id: str | None = None,
color: str | None = None,
atom_shade: list[float] | None = None,
bond_shade: list[float] | None = None,
mark_atoms: list[int] | None = None,
mark_bonds: list[tuple[int, int]] | None = None,
star_labels: list[str | None] | None = None,
weight: float | None = None,
scale: float | None = None,
align_to: Mol | Rendered | None = None,
atom_map: list[tuple[int, int]] | None = None,
)
Render options — parity with JS / Rust MolRenderOptions.
mol
¶
Construct a Mol (JS / Rust xpict.mol).
render
¶
Layout → native depict_molecule → Rendered (JS xpict.render).
Source code in python/xpict/client.py
to_svg
¶
Scene JSON / Scene → SVG string (JS xpict.toSvg).
Contracts (document)¶
xpict.contracts.depict
¶
DepictSpec — live document ABI from xpict-core (schemars).
DepictSpec
¶
Bases: RootModel[DepictSpecRoot]
Declarative document (mol, group, or reaction_scheme root).
model_dump
¶
MolNode
¶
Bases: StrictModel
Mol node — [MolOpts] fields + non-cascading identity / scores / align.
align_to
class-attribute
instance-attribute
¶
align_to: Annotated[
AlignTo | None,
Field(
description='Template id string, or `{ "ref", "atom_map"?, "min_atoms"? }`.'
),
] = None
label
class-attribute
instance-attribute
¶
label: Annotated[
Label | None,
Field(
description="Caption: [`Label`] (string id, list, or `{id, pos?}` — text-node refs)."
),
] = None
opts
class-attribute
instance-attribute
¶
opts: Annotated[
Opts | None,
Field(
description="Cascade patches for this node (list or singleton)."
),
] = None
shade
class-attribute
instance-attribute
¶
shade: Annotated[
ShadeSpec | None,
Field(
description="Shade **scores** (+ legacy window); window also cascades via [`Opts`]."
),
] = None
GroupNode
¶
Bases: StrictModel
align
class-attribute
instance-attribute
¶
align: bool = Field(
default=False,
description="When true, later children align onto the first (or each `align_to`).",
)
children
class-attribute
instance-attribute
¶
children: list[Node] = Field(
default_factory=list,
description="Child **nodes** — mol | text (no edges).",
)
opts
class-attribute
instance-attribute
¶
opts: Annotated[
Opts | None,
Field(
description="Group-level cascade bag (list container for child inheritance)."
),
] = None
Engine¶
xpict.api
¶
Public Pict / render API.
Pict
¶
Configured depiction engine.
Backend and output options are runtime config — not part of PictSpec JSON.
Reaction / network diagrams render via the live Rust reaction_scheme path.
Source code in python/xpict/api.py
layout
¶
Lay out molecules for the legacy Pict/draw path (internal helper).
Source code in python/xpict/api.py
render
¶
render(
spec: PictSpec | LegacyPictSpec | dict[str, Any],
*,
backend: str | None = None,
format: OutputFormat = "svg",
) -> str
Shorthand for Pict(backend=...).render(spec).