Skip to main content

Module align_cost

Module align_cost 

Source
Expand description

Exact connected molecular alignment with atom-only branch-and-bound.

Equal-size Relevant Rings are tried first as connected seeds (cyclic maps, unique ring sizes preferred) so fused scaffolds lock before the house budget is spent. Chains still map onto rings: no query ring means the usual atom-pair seeds run (hexane onto cyclohexane). Cyclic atoms with no shared Relevant-Ring size are not seeded (12-crown vs 15-crown), but a locked equal-size ring may grow onto a size-adjacent ring (14- vs 15- macrolide). Fusion atoms that also sit in the matched ring still map. Ring-seed orientation uses exocyclic neighbor elements so a sugar does not flip NMe2 onto a ring methyl. N/O/S in a shared ring size is a cheap heteroatom swap (aza-crown NH onto ether O); O→C is still refused.

cost_mapping / cost_mapping_with_generators stay unbounded (library exact API). Depict / EdgePlan search uses SearchLimits: a house time and node cap, strict_atoms (no element-mismatch pairs), optional greedy-only, and timeout returns the greedy/BnB incumbent. Worst-case search remains exponential when uncapped. Unmatched atoms and bonds are penalized on BOTH sides (query and reference). Bond correspondence is inferred from atom endpoints; missing bonds are allowed. Returns one optimum, not every symmetry-related map or a geometric tie-break. This is a standalone replacement module using the original public graph types. Minimum cost can omit an expensive terminal atom; two original tests requiring a more costly extension have been corrected accordingly.

Entry points:

ⓘ
let result = cost_mapping(&reference, &query); // exact, without symmetry input
let (result, stats) = cost_mapping_with_generators(
    &reference, &query, &reference_generators,
).expect("valid graphs and automorphism generators");
let (result, stats) = cost_mapping_with_generators_limited(
    &reference, &query, &reference_generators, &SearchLimits::house(),
).expect("valid graphs");

Each generator is Vec<u16> with generator[old_atom] = new_atom. Project Cannonaut incidence-vertex permutations onto atom vertices first. An empty generator list is valid and only disables symmetry acceleration. Generators need not generate the whole automorphism group: any valid subgroup is safe. Generators are checked against element, charge, radical, and exact bond order/aromaticity. Stereo-participating reference atoms are then fixed with Schreier stabilizers, conservatively preserving the supplied E/Z policy. No dependency on a particular Cannonaut crate API is assumed.

E/Z follows the attachment’s restrictive side-pairing policy, with every constraint checked independently (no overwritten HashMap requirements). It is not a new general chemical stereoisomorphism implementation. Tetrahedral chirality is intentionally ignored, as in the attachment.

cost_mapping feeds reference automorphism generators from Canonaut (nauty port) on the colored atom–bond incidence graph.

Structs§

AtomFeat
BondFeat
MappingResult
MolGraph
SearchLimits
Caps for cost_mapping_with_generators_limited. Empty limits = unbounded.
SearchStats

Enums§

AtomChirality
EzStereo

Constants§

ALIGN_HOUSE_MAX_STATES
House branch-and-bound state cap (wasm-safe even if Instant is inert).
ALIGN_HOUSE_TIMEOUT_MS
House wall-clock budget for document / EdgePlan MCS (not the unbounded cost_mapping library entry).
COST_BOND_ORDER
COST_CHARGE_RADICAL
COST_ELEMENT
COST_HETERO
N↔O↔S in a shared Relevant-Ring size (aza-crown). Below [PAIR_GAIN] so house strict_atoms still pairs them; C↔hetero stays COST_ELEMENT.
COST_RING
COST_RING_SIZE
Both atoms cyclic with no shared Relevant-Ring size. Mild tie-break only: seeds still refuse a 12-cycle on a 15-cycle, but a sugar seed may grow onto a 14- vs 15-macrolide. Chain↔ring is free.
COST_UNMATCHED

Functions§

cost_mapping
Exact, nonempty, connected map. Empty input graphs return None. Reference symmetry comes from reference_generators (Canonaut). Panics on malformed graphs; use cost_mapping_with_generators for errors.
cost_mapping_with_generators
Pass atom-permutation generators from Cannonaut for reference symmetry. Any valid subgroup is sufficient for correctness. No full group enumeration. Cost ties retain the first optimum; atom indices may affect the representative returned but do not affect the optimal cost.
cost_mapping_with_generators_limited
Like cost_mapping_with_generators, with time / node / greedy-only caps. Timeout or node cap returns the incumbent (greedy or partial BnB), not an error.
mapping_cost
Scores an injective atom map, penalizing unmatched atoms and bonds on both sides, with bonds inferred. As in the original, this scorer does not enforce connectivity or E/Z validity.
reference_generators
Atom-permutation generators of mol’s automorphism group, via Canonaut on the atom–bond incidence graph. Atom vertices are colored by (element, charge, radical) and bond vertices by (order, aromatic), so every generator preserves exactly the features cost_mapping_with_generators checks. Generators are projected onto atom vertices.
signed_side
substituents_same_side