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, MolRenderOptions(color="#0b6e4f"))
svg = to_svg(rendered.scene)
Declarative document — nested DepictSpec via Rust depict::
from xpict import depict, to_svg
rows = depict({"type": "mol", "smiles": "CCO"})
svg = to_svg(rows[0].scene)
Mol
dataclass
¶
Mol(
source: str,
frame_molblock: str | None = None,
id: str | None = None,
align_to: str | None = None,
label: str | None = None,
label_pos: LabelPos | None = None,
label_color: str | None = None,
label_scale: float | None = None,
)
Bases: PictBase
Input molecule — SMILES / CXSMILES / molfile plus optional align frame.
with_label
¶
with_label(
text: str,
*,
pos: LabelPos | None = None,
color: str | None = None,
scale: float | None = None,
) -> Mol
Return a copy with a caption (mol(..., name=...) equivalent).
Source code in python/xpict/spec.py
to_node
¶
Build a MolNode from this source (smiles / cxsmiles / molfile).
Source code in python/xpict/spec.py
to_caption_nodes
¶
to_spec
¶
Document for paint — identity on the mol; cascade via .opts bag.
Source code in python/xpict/spec.py
Rendered
dataclass
¶
Rendered(
width: float,
height: float,
scene: Scene,
molecule: MoleculeIn,
source: str,
frame_molblock: str,
coords: list[SvgAtom],
svg_coords: list[SvgAtom],
bonds: list[SvgBond],
mol: Mol | None = None,
)
Bases: PictBase
Painted depiction — editable scene plus alignment frame.
MolRenderOptions
dataclass
¶
MolRenderOptions(
id: str | None = None,
color: str | None = None,
atom_shade: list[float] | None = None,
bond_shade: list[float] | None = None,
circle: CircleField | None = None,
star_labels: list[str | None] | None = None,
weight: float | None = None,
scale: float | None = None,
aromatic: AromaticStyle | None = None,
debug_box: bool | None = None,
debug_align: bool | None = None,
align_to: Mol | Rendered | None = None,
atom_map: list[tuple[int, int]] | None = None,
)
Render options — parity with JS / Rust MolRenderOptions.
cascade_keywords
¶
Universal MolOpts keys for the document opts bag.
Source code in python/xpict/spec.py
shade_scores
¶
Non-cascading per-atom / per-bond scores (leaf MolNode.shade).
Source code in python/xpict/spec.py
reference_mol
¶
align_to as a Mol (unwraps Rendered).
Source code in python/xpict/spec.py
Pict
¶
Native Rust depiction engine (no layout-backend switch).
Source code in python/xpict/api.py
layout
¶
Lay out molecules via Rust depict (MoleculeIn from painted rows).
DepictSpec
¶
Bases: PictBase, DepictSpec
Live document root — generated wire model + host operators via PictBase.
Scene
¶
Bases: StrictModel
Full drawable document before SVG/HTML serialization.
mol
¶
mol(
smiles_or_molfile: str,
*,
id: str | None = None,
align_to: str | None = None,
name: str | None = None,
label: str | None = None,
label_pos: LabelPos | None = None,
label_color: str | None = None,
label_scale: float | None = None,
) -> Mol
Construct a Mol (JS / Rust xpict.mol).
name (preferred) / label (alias) set wire MolNode.name — painted
inside the mol SVG by Rust. Default side is below; optional label_pos /
color / scale map onto styled MolText.
Source code in python/xpict/spec.py
render
¶
render(
input: Mol
| str
| DepictSpec
| DepictSpecDict
| PictSpec,
opts: MolRenderOptions | None = None,
*,
format: OutputFormat = "svg",
) -> Rendered | str
Single-mol render(mol, opts) or document render(doc) via Rust.
Source code in python/xpict/__init__.py
to_svg
¶
Scene JSON / Scene → SVG string (JS xpict.toSvg).
depict
¶
One Rust render: layout, mol-spec paint, pack cells.
Single molecule¶
xpict.spec
¶
Host DepictSpec + single-mol sugar (mol / render).
Mol
dataclass
¶
Mol(
source: str,
frame_molblock: str | None = None,
id: str | None = None,
align_to: str | None = None,
label: str | None = None,
label_pos: LabelPos | None = None,
label_color: str | None = None,
label_scale: float | None = None,
)
Bases: PictBase
Input molecule — SMILES / CXSMILES / molfile plus optional align frame.
render
¶
ensure_frame
¶
with_label
¶
with_label(
text: str,
*,
pos: LabelPos | None = None,
color: str | None = None,
scale: float | None = None,
) -> Mol
Return a copy with a caption (mol(..., name=...) equivalent).
Source code in python/xpict/spec.py
to_node
¶
Build a MolNode from this source (smiles / cxsmiles / molfile).
Source code in python/xpict/spec.py
to_caption_nodes
¶
to_spec
¶
Document for paint — identity on the mol; cascade via .opts bag.
Source code in python/xpict/spec.py
MolRenderOptions
dataclass
¶
MolRenderOptions(
id: str | None = None,
color: str | None = None,
atom_shade: list[float] | None = None,
bond_shade: list[float] | None = None,
circle: CircleField | None = None,
star_labels: list[str | None] | None = None,
weight: float | None = None,
scale: float | None = None,
aromatic: AromaticStyle | None = None,
debug_box: bool | None = None,
debug_align: bool | None = None,
align_to: Mol | Rendered | None = None,
atom_map: list[tuple[int, int]] | None = None,
)
Render options — parity with JS / Rust MolRenderOptions.
cascade_keywords
¶
Universal MolOpts keys for the document opts bag.
Source code in python/xpict/spec.py
shade_scores
¶
Non-cascading per-atom / per-bond scores (leaf MolNode.shade).
Source code in python/xpict/spec.py
reference_mol
¶
align_to as a Mol (unwraps Rendered).
Source code in python/xpict/spec.py
align_wire
¶
Source code in python/xpict/spec.py
mol
¶
mol(
smiles_or_molfile: str,
*,
id: str | None = None,
align_to: str | None = None,
name: str | None = None,
label: str | None = None,
label_pos: LabelPos | None = None,
label_color: str | None = None,
label_scale: float | None = None,
) -> Mol
Construct a Mol (JS / Rust xpict.mol).
name (preferred) / label (alias) set wire MolNode.name — painted
inside the mol SVG by Rust. Default side is below; optional label_pos /
color / scale map onto styled MolText.
Source code in python/xpict/spec.py
Contracts (document)¶
xpict.contracts.depict
¶
DepictSpec — live document ABI from xpict-core (schemars).
DepictSpec
¶
Bases: RootModel[DepictSpecRoot]
Declarative document (mol, group, reaction_scheme, or grid 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"?, "mode"?, "timeout_ms"? }`.'
),
] = None
aromatic
class-attribute
instance-attribute
¶
aromatic: Annotated[
AromaticStyle | None,
Field(
description="Aromatic ring paint: ``circle`` (default) or ``kekule``."
),
] = None
atom_label
class-attribute
instance-attribute
¶
atom_label: Annotated[
AtomLabelSpec | None,
Field(
description='Per-atom arbitrary text map (`{ "1": "α" }` or `{ "labels": {…}, "scale"? }`).'
),
] = None
atom_number
class-attribute
instance-attribute
¶
atom_number: Annotated[
AtomNumberSpec | None,
Field(
description='Atom index / map-number labels (`"index"` | `"mapno"` | policy object).'
),
] = None
callout
class-attribute
instance-attribute
¶
circle
class-attribute
instance-attribute
¶
circle: Annotated[
CircleField | None,
Field(
description="Atom / bond / ring highlight circle(s)."
),
] = None
debug_align
class-attribute
instance-attribute
¶
debug_align: Annotated[
bool | None,
Field(
description="Paint alignment correspondence (matched atom tags + mol role badge)."
),
] = None
debug_box
class-attribute
instance-attribute
¶
debug_box: Annotated[
bool | None,
Field(
description="Paint dashed debug rectangles for layout boxes (labels / mol / scene)."
),
] = None
label
class-attribute
instance-attribute
¶
label: Annotated[
Label | None,
Field(
description="Caption: [`Label`] (string id, list, or `{id, pos?}` — text-node refs)."
),
] = None
name
class-attribute
instance-attribute
¶
name: Annotated[
MolText | None,
Field(
description="Privileged figure name / caption painted inside the mol SVG (default below)."
),
] = None
opts
class-attribute
instance-attribute
¶
opts: Annotated[
Opts | None,
Field(
description="Cascade patches for this node (list or singleton)."
),
] = None
pad
class-attribute
instance-attribute
¶
pad: Annotated[
float | None,
Field(
description="Post-layout SVG viewBox pad (px). Omit → small house default (rarely override)."
),
] = None
region
class-attribute
instance-attribute
¶
region: Annotated[
RegionField | None,
Field(
description="Region highlight(s) — one object or a list."
),
] = 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).",
)
debug_align
class-attribute
instance-attribute
¶
debug_align: Annotated[
bool | None,
Field(
description="Paint alignment correspondence (matched atom tags + mol role badge)."
),
] = None
opts
class-attribute
instance-attribute
¶
opts: Annotated[
Opts | None,
Field(
description="Group-level cascade bag (list container for child inheritance)."
),
] = None
pad
class-attribute
instance-attribute
¶
pad: Annotated[
float | None,
Field(
description="Post-layout SVG viewBox pad (px). Omit → small house default."
),
] = None