iRMSD matching pipeline

How one pairwise comparison in get_irmsd gets from two sets of coordinates to an atom assignment and an RMSD: rank setup, min_rmsd, and the bond-preserving selection added on top of it.

step decision start / result new since version 0.1.2 (rank setup, bond check, walk) loop back / reference click: jump to that algorithm or example

Animated worked examples at the end step through a chain, its walk, and a local-search case.

0. What a get_irmsd call decides

Users pass two structures and nothing else. The only setting, iinversion, defaults to auto everywhere (API, ASE and RDKit wrappers, CLI). Every branch below is decided by the code from the structures themselves.

Default path of one pairwise call. The walk is not a fallback for broken bonds: it runs for every covalent system, because a bond-preserving min_rmsd result can still sit in the wrong symmetry class (ibuprofen pair 4: 1.947 instead of 1.659).
  1. 1Cluster rule. A small solute in many waters counts as a cluster, so the walk is skipped and the solute can keep a bond-breaking LSAP mapping. Walking each sizeable fragment and leaving only small identical ones to the LSAP would close this.
  2. 2Bonds from coordination numbers. Stretched geometries (transition states, weakly bound metal complexes) can give the two structures different bond graphs. The ranks then do not reconcile, and the call drops to element types or a plain RMSD with only a warning.
  3. 3Mirror decision from the reference. Auto mode tries the mirror image only when the reference has no stereocentre, which is the CREST convention for comparing conformers.

1. One comparison end to end

The ranks decide which atoms may be swapped at all; min_rmsd finds an orientation and an assignment within those ranks; refine_assignment makes sure the final assignment keeps every bond and is as low as the walk can get it.

Sorters (ensembles) same core per pair: ranks once for structure 1 (or per structure, copied when bonds and order match), then min_rmsd + refine_assignment no yes ref, mol (atomic numbers, xyz) optional canonical IDs per atom axis(ref) ref to centre of mass, principal axes setup_irmsd_ranksranks r1, r2 + stereo flagsee figure 2 iinversion? 0: auto mirror tried if ref has no stereocentre 1: mirror always tried 2: never mirror min_rmsdranks -> orientation -> LSAP per ranksee figure 3 io = 0? topology mismatchplain quaternion RMSDor huge value refine_assignmentbond-preserving candidatessee figures 4 and 5 iRMSD (Angstrom) + mol reordered and aligned onto ref
Pairwise path in get_irmsd_fortran. The sorters run the same min_rmsd plus refine_assignment per pair and only differ in how often ranks are computed.

2. Atom ranks

Two atoms may only be exchanged if they share a rank. Ranks come from user-supplied IDs or from the canonical sorter; a second structure with the same element order and bonds simply copies the first one's ranks.

Canonical ranks (canonical.f90) yes no yes no yes no yes no yes no still fails passes ref has IDs? r1 = ref IDs stereo from IDs canonical ranks for ref + stereo flag mol has IDs? r2 = mol IDs same atom types and same bonds as ref? same_graph r2 = r1 (no 2nd canonicalization) canonical ranks for mol checkranks(r1, r2) same atom count per rank? IDs were provided? recompute the provided side(s), check again fallbackranks rank = element use r1, r2 CN bonds -> neighbour lists H atoms: isolated nodes BFS from every heavy atom shell sums rinv over distances other fragments = last shell initial invariant: rank of rinv, element, number of H 1-WL refinement: split ranks by product of neighbour primes (sort; overflow-safe) heavy ranks renumbered, H take their parent's class
setup_irmsd_ranks and, on the right, what the canonical sorter does for one structure. The stereo flag comes from the reference only: without a stereocentre, the mirror image is tried in min_rmsd (auto mode).

3. min_rmsd

The branch point is the number of atoms with a unique rank. Three or more of them pin the orientation directly; otherwise the principal axes of inertia do, with up to 32 candidate orientations because the axes carry sign and degeneracy ambiguities. In both branches each rank group is assigned by an LSAP on squared distances, independently of bonds.

Unique-atom alignment Principal-axis alignment yes no yes no no yes no yes yes no ref, mol, ranks, stereo flag topology check: same size, same max rank, same sorted (element, rank) pairs? warning; plain RMSD without reordering (or huge), io > 0 mol ranks in ref order? sort mol atoms by rank rank_2_order + molatomsort count atoms per rank; ranks with 1 atom are assigned nunique >= 3 ? (atoms with a unique rank) mol to centre of mass Kabsch on the unique atoms rotate mol LSAP for every rank with>1 atom (cost: squareddistance) -> cost c1 mirror allowed? mirror mol (z -> -z), Kabsch uniques, LSAP -> cost c2, unmirror keep lower of c1, c2 (mirror mol again if c2) axis(mol) centre of mass, principal axes, rotational constants distinct principal moments? all 3 4 orientations A or C only 8 (with 90 deg tilt) none 16 (3 tilts) per orientation: 180 deg flipsabout x, y, z; LSAP per rank-> costs 1..16 mirror allowed? mirror z, re-axis, repeat -> costs 17..32; take minimum apply the chosen orientation, mirror and assignment (molatomsort) Kabsch RMSD; align mol if asked-> refine_assignment (figure 4)
Decision tree of min_rmsd (crest_mods/irmsd_module.f90). The total LSAP cost picks the orientation; the RMSD itself is computed once at the end.
Distinct momentsCaseOrientations triedWith mirror
all three04: identity and 180 deg about x, y, z8
only A (long axis)18: the 4 above, again after a 90 deg tilt about x16
only C (short axis)28: the 4 above, again after a 90 deg tilt about z16
none (spherical top)316: the 4 above in 4 tilted frames32

4. Bond-preserving selection

min_rmsd can return an assignment that maps a bonded pair onto a non-bonded one, which makes the RMSD look lower than any real correspondence. The selection compares it with the centre walk and keeps the lowest RMSD among candidates that preserve every bond. Bonds are checked after the terminal-atom refinement, because that step repairs H atoms swapped between parents.

yes no: A only yes min_rmsd output (matched, aligned) CN bond matrices of ref and mol candidate Amin_rmsd's assignment largest fragment >= half of the heavy atoms? candidate Bwalk_assignment(mol)figure 5 mirror allowed? candidate Cwalk_assignment(z-mirrored mol) each candidate: terminal-atom refinement (siblings on one parent, brute force <= 8, 4 starts, alternating with Kabsch) then bond check on the result lowest RMSD among bond-preservingcandidates; if none: candidate A
refine_assignment in fmods/irmsd_refine.f90. Clusters (water, LJ) skip the walk; for them matching whole molecules is an assignment problem the LSAP already solves.

5. Centre walk

The walk builds a correspondence that preserves bonds by construction: it only ever extends along a bond. Choices are made by distance as soon as the matched atoms fix a frame; before that, every possibility is enumerated. Each complete start is polished by alternating a Kabsch fit with a re-walk in that frame, and the best start gets a local search over single choices, which is what finds ring flips and methyl swaps whose benefit only shows in the total RMSD.

Depth-first walk over the order Polish (per start), then local search (best start only) next position no gain yes no yes no order complete yes no improved neighbour lists; heavy atoms with a unique rank are matched up front walk order: BFS from each fragment's centre (min eccentricity), largest first next atom x in the order x has a matchedneighbour p? free same-rank neighbours of p's partner all free same-rank atoms (fragment start) keep y if degree matches and x's matched neighbours map onto exactly y's how many? 0: backtrack to the last choice with untried candidates 1: take it >1: matched atoms define a frame? Kabsch on matched;take nearest, keep rest try each in turn (up to 64 complete assignments) complete heavy-atom assignment H atoms to the nearest H on the parent's partner Kabsch on all atoms -> frame, RMSD re-walk, every choice nearest in that frame assignment changed? best start: try each other candidateat each bond-anchored choice;accept if total RMSD drops best assignment
walk_assignment in fmods/irmsd_walk.f90. Dead ends backtrack to the most recent choice with untried candidates; the walk gives up after 50 steps per atom plus 10,000, and the selection then keeps the min_rmsd result.

6. Worked examples

Flat toy molecules run through a Python transcription of the same steps, so every number shown is computed for these coordinates. Because the molecules are flat, the mirror test changes nothing and the four 180-degree turns of min_rmsd become flips in the plane. H atoms are left out.

reference atom second structure matched pair broken bond atom being matched / candidates colours = rank