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.
Animated worked examples at the end step through a chain, its walk, and a local-search case.
get_irmsd call decidesUsers 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.
min_rmsd result can still sit in the wrong symmetry class (ibuprofen pair 4: 1.947 instead of 1.659).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.
get_irmsd_fortran. The sorters run the same min_rmsd plus refine_assignment per pair and only differ in how often ranks are computed.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.
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).min_rmsdThe 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.
min_rmsd (crest_mods/irmsd_module.f90). The total LSAP cost picks the orientation; the RMSD itself is computed once at the end.| Distinct moments | Case | Orientations tried | With mirror |
|---|---|---|---|
| all three | 0 | 4: identity and 180 deg about x, y, z | 8 |
| only A (long axis) | 1 | 8: the 4 above, again after a 90 deg tilt about x | 16 |
| only C (short axis) | 2 | 8: the 4 above, again after a 90 deg tilt about z | 16 |
| none (spherical top) | 3 | 16: the 4 above in 4 tilted frames | 32 |
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.
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.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.
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.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.