Skip to main content

Calculate root-mean-square deviation (RMSD) between two sets of cartesian coordinates (XYZ or PDB format), using rotation (fx. Kabsch algorithm), atom reordering (fx. Hungarian algorithm), and axis reflections, resulting in the minimal RMSD.

Project description

Calculate Root-mean-square deviation (RMSD) of Two Molecules Using Rotation

The root-mean-square deviation (RMSD) is calculated, using Kabsch algorithm (1976) or Quaternion algorithm (1991) for rotation, between two Cartesian coordinates in either .xyz or .pdb format, resulting in the minimal RMSD.

For more information please read RMSD and Kabsch algorithm.


You have molecule A and B and want to calculate the structural difference between those two. If you just calculate the RMSD straight-forward you might get a too big of a value as seen below. You would need to first recenter the two molecules and then rotate them unto each other to get the true minimal RMSD. This is what this script does.

No Changes Re-centered Rotated
begin translate rotate
RMSD 2.50 RMSD 1.07 RMSD 0.25


  • Implementation:
    Calculate Root-mean-square deviation (RMSD) of Two Molecules Using Rotation, GitHub,, <git commit hash or version number>
  • Kabsch algorithm:
    Kabsch W., 1976, A solution for the best rotation to relate two sets of vectors, Acta Crystallographica, A32:922-923, doi:
  • Quaternion algorithm:
    Michael W. Walker and Lejun Shao and Richard A. Volz, 1991, Estimating 3-D location parameters using dual number quaternions, CVGIP: Image Understanding, 54:358-367, doi:

Please cite this project when using it for scientific publications.


Easiest is to get the program vis PyPi under the package name rmsd,

pip install rmsd

or download the project from GitHub via

git clone

There is only one Python file, so you can also download and put it in your bin folder.

wget -O calculate_rmsd
chmod +x calculate_rmsd

Usage examples

Use calculate_rmsd --help to see all the features. Usage is pretty straight forward, call calculate_rmsd with two structures in either .xyz or .pdb. In this example Ethane has the exact same structure, but is translated in space, so the RMSD should be zero.

calculate_rmsd tests/ tests/

It is also possible to ignore all hydrogens (useful for larger molecules where hydrogens move around indistinguishable) and print the rotated structure for visual comparison. The output will be in XYZ format.

calculate_rmsd --no-hydrogen --print tests/ tests/

If the atoms are scrambled and not aligned you can use the --reorder argument which will align the atoms from structure B unto A. Use --reorder-method to select what method for reordering. Choose between Hungarian (default), distance (very approximate) and brute force (slow).

calculate_rmsd --reorder tests/ tests/

It is also possible to use RMSD as a library in other scripts, see for example usage.


Submit issues or pull requests on GitHub.


Please note that we are using black with line length of 79. Easiest way to abide to the code standard is to install the following packages.

pip install black flake8 autoflake isort pytest


make format test lint

to auto-format and test the code.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rmsd, version 1.4
Filename, size File type Python version Upload date Hashes
Filename, size rmsd-1.4-py3-none-any.whl (16.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size rmsd-1.4.tar.gz (18.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page