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.

{{FIG0}}
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.

{{FIG1}}
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.

{{FIG2}}
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.

{{FIG3}}
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.

{{FIG4}}
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.

{{FIG5}}
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