Skip to content

Commit

Permalink
fixed a bug causing "c" (the scaling factor) to be calculated incorre…
Browse files Browse the repository at this point in the history
…ctly. This bug was caused by a typo introduced in v1.3.0 (commit 91d30b8) when converting the for-loops into compact numpy expressions.
  • Loading branch information
jewettaij committed Mar 21, 2022
1 parent 29a3372 commit 64da21d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Superpose3D() takes two lists (or numpy arrays) of xyz coordinates
("clouds", **X** and **x**).
Treating them as rigid objects, "Superpose3D()" attempts to superimpose
them using **rotations**, **translations**,
~~and (optionally) **scale** transformations~~
and (optionally) **scale** transformations
in order to minimize the root-mean-squared-distance (RMSD)
between corresponding points from either cloud, where RMSD is defined as:

Expand Down Expand Up @@ -82,13 +82,11 @@ R. Diamond, (1988)
"A Note on the Rotational Superposition Problem",
Acta Cryst. A44, pp. 211-216.

### Scale transformations <-- NOT WORKING (2022-3-07)
### Scale transformations

***Note: The scale transformation feature described below [does not work](https://github.com/jewettaij/superpose3d/issues/3). Please ignore the next paragraph. This will get fixed soon. -Andrew 2022-3-07.***
This version has been augmented slightly to support scale transformations. (I.E. multiplication by scalars. This can be useful for the registration of two different annotated volumetric 3-D images of the same object taken at different magnifications.)

~~This version has been augmented slightly to support scale transformations. (I.E. multiplication by scalars. This can be useful for the registration of two different annotated volumetric 3-D images of the same object taken at different magnifications.)~~

~~Note that if you enable scale transformations (i.e. if *allow_rescale=True*), you should be wary if the function returns a negative **c** value. Negative **c** values correspond to inversions (reflections). For this reason, if you are using this function to compare the conformations of molecules, you should probably set *allow_rescale=False*. This will prevent matching a molecule with its stereoenantiomer.~~
Note that if you enable scale transformations (i.e. if *allow_rescale=True*), you should be wary if the function returns a negative **c** value. Negative **c** values correspond to inversions (reflections). For this reason, if you are using this function to compare the conformations of molecules, you should probably set *allow_rescale=False*. This will prevent matching a molecule with its stereoenantiomer.

## Installation using pip

Expand Down
10 changes: 5 additions & 5 deletions superpose3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
from numpy import linalg as LA
from math import *

def Superpose3D(aaXf_orig, # <-- coordinates for the "frozen" object
aaXm_orig, # <-- coordinates for the "mobile" object
Expand Down Expand Up @@ -183,13 +184,12 @@ def Superpose3D(aaXf_orig, # <-- coordinates for the "frozen" object
WaxaiXai = 0.0
for a in range(0, N):
for i in range(0, 3):
Waxaixai += aWeights[a] * aaXm[a,i] * aaXm[a,i]
WaxaiXai += aWeights[a] * aaXm[a,i] * aaXf[a,i]
Waxaixai += aWeights[a,0] * aaXm[a,i] * aaXm[a,i]
WaxaiXai += aWeights[a,0] * aaXm[a,i] * aaXf[a,i]
"""
# new code (avoiding for-loops)
Waxaixai = np.sum(aWeights * aaXm ** 2)
WaxaiXai = np.sum(aWeights * aaXf ** 2)

Waxaixai = np.sum(aWeights * aaXm * aaXm)
WaxaiXai = np.sum(aWeights * aaXm * aaXf)
c = (WaxaiXai + pPp) / Waxaixai

# Finally compute the RMSD between the two coordinate sets:
Expand Down

0 comments on commit 64da21d

Please sign in to comment.