vibesketch.chem.clean

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

A hand-drawn structure has bonds of uneven length and angles that are almost 120°. Cleaning replaces its coordinates with a standard depiction, every bond the same length and every angle the textbook one, that still looks like what was drawn:

  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).

Functions

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.

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

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

rdkit, mimic or coordgen.

Type:

The layout that won

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

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 has every bond 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