vibesketch.chem.clean

Clean up a drawn structure: standard bond lengths and angles, the drawing kept.

The reference-table objective in vibesketch.chem.depiction refines a standard seed with FIRE. Every seed’s objective, and the gate that compares it with the legacy result, take complex ring systems from one shared list of reference layouts: the legacy result first, then each standard layout. Convergence, geometry and overlap gates retain the legacy result on refusal. The seed/fallback algorithm is described below.

A hand-drawn structure has bonds of uneven length and angles that are almost 120°. The seed layouts standardize lengths and angles, with complex-ring exceptions, while preserving the drawing:

  1. Standard layouts. RDKit’s depictor, RDKit’s depictor told to mimic the drawing’s inter-atom distances (Compute2DCoordsMimicDistmat), and CoordGen each propose a layout with exact bond lengths and angles.

  2. The drawing’s choices. In two dimensions an acyclic single bond can only be drawn one of two ways: the neighbours of its two atoms on the same side of the bond (a U-turn) or on opposite sides (a zig-zag). For every such bond, each layout is made to agree with the drawing by mirroring the smaller side across the bond. A mirror keeps every length and angle, and no other bond’s choice depends on it, so the bonds are settled one at a time and in any order.

  3. Placement. Each layout is rotated, or mirrored, onto the drawing by least squares (W. Kabsch, Acta Cryst. A32, 922-923 (1976)) and put where the drawing was. The layout with the fewest overlapping atoms, then the smallest deviation from the drawing, wins.

Stereochemistry is not this module’s concern: chiral tags and double-bond geometry are inputs to the layouts, and the caller re-derives the wedges and checks the result (vibesketch.document.clean).

Module Attributes

MAX_CLEAN_ATOMS

The most atoms a molecule may have and still be cleaned.

Functions

clean_2d(mol, *[, bond_length])

Reference-table/FIRE cleanup, with the legacy depictor as a fallback.

legacy_clean_2d(mol, *[, bond_length])

Standard coordinates for mol that follow its drawn 2D conformer.

Classes

Cleaned(xy, deviation, layout)

New 2D positions for a molecule's atoms, in its atom order.

vibesketch.chem.clean.MAX_CLEAN_ATOMS = 3000

The most atoms a molecule may have and still be cleaned.

class vibesketch.chem.clean.Cleaned(xy, deviation, layout)[source]

Bases: object

New 2D positions for a molecule’s atoms, in its atom order.

Parameters:
xy: list[tuple[float, float]]
deviation: float

Root-mean-square distance from the drawing, in bond lengths, after alignment.

layout: str

Seed name, or fire-v1:<seed> for an accepted converged refinement.

vibesketch.chem.clean.clean_2d(mol, *, bond_length=1.0)[source]

Reference-table/FIRE cleanup, with the legacy depictor as a fallback.

Only converged, non-regressing refinements are accepted. Complex ring seeds may come from RDKit’s public template API; no template data or global template settings are changed. The document caller verifies stereo and retries the legacy layout on refusal.

Parameters:
Return type:

Cleaned | None

vibesketch.chem.clean.legacy_clean_2d(mol, *, bond_length=1.0)[source]

Standard coordinates for mol that follow its drawn 2D conformer.

mol is one connected molecule with its drawing as conformer 0 and its stereochemistry assigned. The result targets bonds bond_length long and sits where the drawing was. None when there is nothing to clean (a lone atom) or no layout could be made.

Parameters:
Return type:

Cleaned | None