I have two molecules in "XYZ" format and I want to align them.

As I am using Mathematica version 12.0, which does not have this MoleculeAlign function (Introduced in v12.3) I am looking for alternatives.

Here are the molecules B1 and C1

c1 = Import["https://www.dropbox.com/s/9j5bcpwbpx044if/C1.xyz?dl=1", "XYZ"];
b1 = Import["https://www.dropbox.com/s/5k8z6ilzrw6vi86/B1.xyz?dl=1", "XYZ"];
  • 1
    $\begingroup$ You could try aligning them in the Cloud version, which does have MoleculeAlign[]. Otherwise, you're effectively asking people to re-implement something nontrivial on your behalf, when you haven't even made an attempt of your own. $\endgroup$ Aug 1, 2022 at 9:41
  • $\begingroup$ Thanks for the suggestion. I am able to do it in the Cloud version. $\endgroup$ Aug 1, 2022 at 9:57

2 Answers 2


Build your own

I can't personally test this in V12, however, the functions I use were introduced in v12, and the OP report this works fine for them.

I extract the coordinates using MoleculeValue[m1, "AtomCoordinates"], centre the first molecule, and then FindGeometricTransform with the option TransformationClass->"Rigid" to rotate and translate the second into the first.

    {cm1,cm2, tcm1, tcm2, transform, tm1, tm2},
    cm1 =  QuantityMagnitude[MoleculeValue[m1, "AtomCoordinates"], "Angstroms"]; (* Coordinates molecule 1 *)
    cm2 =  QuantityMagnitude[MoleculeValue[m2, "AtomCoordinates"], "Angstroms"]; (* Coordinates molecule 2 *)

    tcm1 = TranslationTransform[-Mean[cm1]][Normal@cm1]; (* Centered coordinates molecule 1 *)
    transform = Last@FindGeometricTransform[tcm1,cm2, TransformationClass->"Rigid"]; (* Rotate+Translate Transformation *)
    tcm2 = transform[cm2]; (* Aligned coordinates molecule 2 *)
    (* Molecules with updated coordinates *)
    tm1 = Molecule[m1, AtomCoordinates-> Quantity[tcm1,"Angstroms"] ];
    tm2 = Molecule[m2, AtomCoordinates-> Quantity[tcm2,"Angstroms"] ];



enter image description here

  • 1
    $\begingroup$ Thank you for the help. This code is working in V12. $\endgroup$ Aug 1, 2022 at 13:09

Do it in a free kernel V13

This was tested in $Version


13.1.0 for Linux x86 (64-bit) (June 16, 2022)

Wolfram Engine (free):

13.0.0 for Microsoft Windows (64-bit) (December 10, 2021)

So this works even if you don't have a license for Mathematica V12.3 or above

c1 = Import["https://www.dropbox.com/s/9j5bcpwbpx044if/C1.xyz?dl=1", "XYZ"];
b1 = Import["https://www.dropbox.com/s/5k8z6ilzrw6vi86/B1.xyz?dl=1", "XYZ"];

Before aligning

Show @@ MoleculePlot3D[{c1, b1}] 

enter image description here



enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.