Scientific background#

Structural comparison is at the heart of conformational analysis, docking, trajectory processing, and molecular shape workflows. The classical Cartesian RMSD fails whenever two structures differ by atom ordering, local symmetry, or rotameric permutations. In such cases the RMSD becomes artificially large even though the molecular properties (e.g. IR/Raman spectra, NMR shifts, energies) are identical.

The permutation-invariant RMSD#

The RMSD with optimal alignment and permutation is defined as

\[\mathrm{iRMSD}(\mathbf{X}, \mathbf{Y}) = \min_{\mathbf{P},\mathbf{U}} \sqrt{ \frac{1}{N} \sum_{i=1}^{N} \left\lVert \mathbf{X}_i - (\mathbf{P}\mathbf{U}\mathbf{Y})_i \right\rVert^2 }\]

where X and Y are the Cartesian coordinates of the two structures, U is a rotation matrix, and P is a permutation matrix representing the atom–atom assignment. The minimization yields the best superposition together with the best atom correspondence.

The iRMSD implemented in this package obtains U and P by

  • assigning canonical atom identities that do not depend on the input atom order,

  • performing a symmetry-aware alignment via a divide-and-conquer approach,

  • solving the linear sum assignment problem (LSAP, Hungarian algorithm) in Fortran,

  • handling false enantiomers when appropriate,

  • using cached memory and a single-precision LSAP kernel for speed.

This makes the iRMSD applicable to large ensembles (thousands of conformers), proteins, and noncovalent clusters. The method is described in detail in

P. Pracht, J. Chem. Inf. Model. 2025, 65 (9), 4501–4511. doi:10.1021/acs.jcim.4c02143 (open-access preprint: doi:10.26434/chemrxiv-2024-qmcz4)

Example: restoring atom order#

The two structures below are copies of the same fluoxetine conformer. Both have an entirely random atom order and are randomly rotated.

Fluoxetine, first copy Fluoxetine, second copy
Coordinates, examples/xyz/fluoxetine_1.xyz
40

C  -0.0198   0.2158   0.5308
F  -5.0246  -0.2464   0.5593
H  -2.0207   0.0761   3.2888
H   2.0221   5.0303   0.4892
C  -0.4032   0.2003   1.8748
H   1.4542   5.1890  -1.1937
C   2.1773   2.6686  -0.7626
F  -4.6775   0.8294   2.4172
F  -4.3667  -1.3218   2.3289
N   3.0555   3.8290  -0.9233
C   2.3371   5.0467  -0.5601
H   3.7051   1.1947  -0.3434
O   1.3305   0.2076   0.3364
C  -2.3576   0.1386  -0.0950
C   3.3367  -3.7475  -2.0944
C  -2.7426   0.0481   1.2484
C  -4.1855  -0.1659   1.6292
C   2.4651  -1.1750  -1.3319
H   1.7906   2.6512   0.2660
C   2.8963   1.3473  -1.0679
H   1.3203   2.7752  -1.4405
C   1.8806   0.1908  -0.9905
H  -0.7865   0.2662  -1.5101
H   3.3527   1.3925  -2.0651
H   1.1282   0.3962  -1.7541
H   2.8529  -0.6554  -3.3999
H   2.9547  -4.3108  -0.0530
H   3.8626   3.7250  -0.3037
H   0.3581   0.2294   2.6522
C  -1.7511   0.1165   2.2345
H   2.9886   5.9146  -0.7002
H   2.1980  -2.0723   0.6278
H   3.6193  -2.9009  -4.0530
H  -3.1084   0.1174  -0.8845
C   2.5162  -2.2260  -0.4015
C  -1.0075   0.2216  -0.4508
H   3.6502  -4.7430  -2.3936
C   2.9433  -3.5025  -0.7811
C   2.8862  -1.4373  -2.6475
C   3.3158  -2.7117  -3.0256
Coordinates, examples/xyz/fluoxetine_2.xyz
40

C  -0.2470  -1.0143  -0.4213
H   0.0828   4.2564  -4.4517
C  -2.1193   2.6178   0.0144
C   1.2089  -1.8204   1.8160
C   0.0619  -0.0804   0.5643
C   0.9632  -2.7436   0.7925
H  -5.9431   1.8117   2.4085
H  -3.2933   0.8099   0.1366
H   2.4555   4.5828  -3.8102
H  -0.0328  -3.0384  -1.1072
H  -3.9856   3.0777   1.8789
H  -2.4640   1.2332   1.6473
C  -0.4255   3.2037  -2.6383
H   1.7581   2.5331  -0.1112
C   1.3640   2.9121  -1.0521
C   1.5502  -4.1306   0.8575
C  -5.0208   1.3357   2.0622
H  -4.4695   0.9920   2.9447
F   1.1253  -4.8340   1.9430
C   2.2338   3.5914  -1.9111
H  -1.7744   3.4140   0.6847
C   0.4427   3.8850  -3.4947
C   0.7599  -0.5019   1.6995
F   1.2525  -4.8990  -0.2270
H  -1.3360   1.0931  -1.2358
H   1.7763  -2.1151   2.6974
H   0.9785   0.2106   2.4926
H  -5.3029   0.4654   1.4587
H  -0.8129  -0.7679  -1.3112
H  -2.6932   3.0927  -0.7916
C  -0.9181   1.8428  -0.5615
F   2.9112  -4.1100   0.9336
H  -1.4519   3.0470  -2.9556
H   3.2752   3.7325  -1.6299
C   1.7755   4.0721  -3.1352
C   0.0230   2.6924  -1.4078
N  -4.2396   2.2887   1.2797
O  -0.2303   1.2522   0.5528
C  -3.0176   1.6462   0.7923
C   0.1996  -2.3349  -0.3081

The iRMSD aligns the structures (determines U) and restores the atom order (determines P):

$ irmsd compare examples/xyz/fluoxetine_1.xyz examples/xyz/fluoxetine_2.xyz | tail -1
iRMSD: 0.0000879250 Å

The aligned copies agree to about 1e-4 Å, the precision of the input coordinates, while the quaternion-based Cartesian RMSD of the same pair in the atom order of the files (--quaternion) is 5.13 Å.

Further examples are collected in Examples.

Known limitations#

  • Atom exchange between fragments in noncovalent complexes: the canonical assignment of two subgraphs (molecules that share no covalent bond) is done independently. Atoms of the same element may therefore exchange across fragments, as in the (H2O)21 and LJ75 examples. If the largest bonded fragment holds less than half of the heavy atoms, the result of the LSAP is used without the bond-preserving selection.

  • Constitutional isomers, structures that share a sum formula but differ in connectivity, are not flagged. If their number of atoms per canonical rank differs, the comparison falls back to matching atoms by element; otherwise it pairs ranks that do not correspond chemically. In both cases a value is returned without a warning (e.g. 1.40 Å for n-pentane against neopentane).

  • Bond detection: bonds are derived from a coordination-number criterion. Noisy or distorted structures close to that threshold can change the detected bond graph, after which the comparison falls back to element types or a plain RMSD.

  • Local search: the bond-preserving assignment is polished by changing one choice at a time, so coupled choices can be missed and the iRMSD can end up slightly above the lowest bond-preserving RMSD (7 of 200 ibuprofen conformer pairs in the tests).

  • Pairwise comparisons over an ensemble: every call of get_irmsd_molecule (or irmsd compare) sets up the canonical ranks of both structures and allocates its work memory anew. Looping it over the pairs of a large set of structures repeats this setup for every pair, which dominates the run time for large molecules. Attaching the canonical identifiers once per structure (Canonical atom identifiers) removes the repeated rank setup. The ensemble sorter (irmsd sort, sorter_irmsd_molecule, prune) goes further: it sets up the ranks once per structure and the work memory once per thread, skips structures already assigned to a group, and runs in parallel. For 30 BPTI copies (435 pairs, one thread), the pairwise loop takes 14.7 s, 8.4 s with the identifiers attached, and the sorter 0.7 s.

Two limitations of earlier versions no longer apply. Highly symmetric structures (e.g. C60, adamantane) have degenerate rotational axes, which version 0.1.2 could not always resolve: of 50 randomized copies with 0.02 Å coordinate noise, it misaligned 8 for adamantane and 33 for C60, by up to 0.9 Å, while the current version matches all of them. The iRMSD of two different conformers could exceed their quaternion RMSD in the original implementation (Example 4, panel b); since version 0.1.2 this no longer occurs for that ensemble (see Comparison with later versions).