vibesketch.document.derive

Derive the normalized layer of a document from its canvas.

The canvas (KET) is what the user drew; the normalized layer is what the compute side reads. Each time the canvas changes, this module rebuilds the species and reactions from it:

  • Species are the distinct molecules on the canvas, identified by InChIKey. A species that was there before keeps its id, label, name, conformers and a multiplicity someone set, so jobs and edits survive a redraw. Charge is the sum of the formal charges; multiplicity defaults from the radical count, is checked against the electron count, and is flagged for review when the species contains a transition metal.

  • Reactions come from the straight arrows; curved arrows (electron pushing in a mechanism) and crossed-out ones are not reactions. With one arrow, each molecule is a reactant, a reagent or a product by where it lies along the arrow. With several, pointing any way, each arrow takes the molecules beside it as reagents, the nearest molecule ahead of its head as its product and the nearest behind its tail as its reactant, each with what a plus sign joins to it and what is drawn close beside it; the steps follow the molecules they share, then the reading order. Text beside an arrow becomes its condition lines; a short number under a molecule becomes its compound label.

Molecules that cannot be a single structure (query features, polymer brackets, valence errors) stay on the canvas and are reported, never guessed.

Functions

arrow_kind(mode)

The document's arrow for a KET arrow mode.

derive(document)

Rebuild document's species and reactions from its canvas.

fragments(document)

The canvas's fragments, for callers that need coordinates.

is_reaction_arrow(mode)

Whether a KET arrow mode draws a reaction step: not a curved (electron-pushing) arrow, not a crossed-out one.

Classes

Derivation(document, warnings)

class vibesketch.document.derive.Derivation(document: 'Document', warnings: 'list[str]' = <factory>)

Bases: object

Parameters:
document: Document
warnings: list[str]
vibesketch.document.derive.arrow_kind(mode)

The document’s arrow for a KET arrow mode.

Parameters:

mode (str)

Return type:

str

vibesketch.document.derive.derive(document)

Rebuild document’s species and reactions from its canvas.

Parameters:

document (Document)

Return type:

Derivation

vibesketch.document.derive.is_reaction_arrow(mode)

Whether a KET arrow mode draws a reaction step: not a curved (electron-pushing) arrow, not a crossed-out one.

Parameters:

mode (str)

Return type:

bool