Skip to content

Instantly share code, notes, and snippets.

@matteoferla
Created May 9, 2024 16:36
Show Gist options
  • Save matteoferla/3f1c9739072770ed20900352634dc92e to your computer and use it in GitHub Desktop.
Save matteoferla/3f1c9739072770ed20900352634dc92e to your computer and use it in GitHub Desktop.
RDKit fix reference frame of molecule
# I am sure I have pasted this snippet somewhere, but I always forget where —so may be a duplicate.
wrong_ref: Chem.Mol = ... # the reference mol in former frame/location/crystal
right_ref: Chem.Mol = ... # the reference mol in desired frame
wrong: Chem.Mol = ... # the target
affine_matrix = AllChem.GetAlignmentTransform(wrong_ref, right_ref)[1]
AllChem.TransformConformer(wrong.GetConformer(), affine_matrix) # this is in place
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment