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:
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.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.
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
The most atoms a molecule may have and still be cleaned. |
Functions
|
Reference-table/FIRE cleanup, with the legacy depictor as a fallback. |
|
Standard coordinates for |
Classes
|
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:
objectNew 2D positions for a molecule’s atoms, in its atom order.
- 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.
- vibesketch.chem.clean.legacy_clean_2d(mol, *, bond_length=1.0)[source]¶
Standard coordinates for
molthat follow its drawn 2D conformer.molis one connected molecule with its drawing as conformer 0 and its stereochemistry assigned. The result targets bondsbond_lengthlong and sits where the drawing was.Nonewhen there is nothing to clean (a lone atom) or no layout could be made.