Awesome Open Source
Awesome Open Source

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_.

.. _RMSD: .. _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 ========== =========== ==========

.. |begin| image:: .. |translate| image:: .. |rotate| image::


Please cite this project when using it for scientific publications.


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

.. code-block:: bash

pip install rmsd

or download the project from GitHub via

.. code-block:: bash

git clone

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

.. code-block:: bash

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.

.. code-block:: bash

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.

.. code-block:: bash

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).

.. _Hungarian:

.. code-block:: bash

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 99. Easiest way to abide to the code standard is to install the following package.

.. code-block:: bash

pip install pre-commit

and run the following command in your repository

.. code-block:: bash

pre-commit install

This will install a hook in your git and re-format your code to adhere to the standard. As well as check for code quality.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (50,919
alignment (49
structure (28
pdb (26
molecule (19

Find Open Source By Browsing 7,000 Topics Across 59 Categories