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§
- Atom
Feat - Bond
Feat - Mapping
Result - MolGraph
- Search
Limits - Caps for
cost_mapping_with_generators_limited. Empty limits = unbounded. - Search
Stats
Enums§
Constants§
- ALIGN_
HOUSE_ MAX_ STATES - House branch-and-bound state cap (wasm-safe even if
Instantis inert). - ALIGN_
HOUSE_ TIMEOUT_ MS - House wall-clock budget for document / EdgePlan MCS (not the unbounded
cost_mappinglibrary 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 housestrict_atomsstill pairs them; C↔hetero staysCOST_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 featurescost_mapping_with_generatorschecks. Generators are projected onto atom vertices. - signed_
side - substituents_
same_ side