Skip to content

Commit

Permalink
non-uniform weights should be working again. (This fixes a bug which …
Browse files Browse the repository at this point in the history
…was introduced in v1.1.0.)
  • Loading branch information
jewettaij committed Feb 24, 2022
1 parent c63b3f9 commit f02e476
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def Superpose3D(X, # <-- Nx3 array of coords for the "frozen" point cloud

url='https://github.com/jewettaij/superpose3d',

download_url='https://github.com/jewettaij/superpose3d/archive/v1.2.0.zip',
download_url='https://github.com/jewettaij/superpose3d/archive/v1.3.0.zip',

version='1.2.0',
version='1.3.0',

install_requires=[
'numpy',
Expand Down
2 changes: 1 addition & 1 deletion superpose3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def Superpose3D(aaXf_orig, # <-- coordinates for the "frozen" object
sum_sqr_dist = 0.0
"""
# new code (avoiding for-loops)
E0 = np.sum((aaXf - c*aaXm)**2)
E0 = np.sum(aWeights * (aaXf - c*aaXm)**2)
sum_sqr_dist = max(0, E0 - c * 2.0 * pPp)

rmsd = 0.0
Expand Down
14 changes: 9 additions & 5 deletions test_superpose3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_superpose3d():
x=[[0,0,0],[0,1.05,0],[0,1,-1],[1,1,-1]] # (a slightly modified rotated X)

result = Superpose3D(X,x, None, False, True)
print('weights: '+str([1.0,1.0,1.0,1.0]))
print(' (quaternion = '+str(result[1])+')\n')

Xshifted = [ [X[i][0],X[i][1]+100, X[i][2]] for i in range(0,len(X))]
Expand All @@ -19,7 +20,7 @@ def test_superpose3d():
# Now try again using the translated, rescaled coordinates:

# now test weights, rescale, and quaternions
w = [1.0, 1.0, 1.0, 1.0]
w = [2.0, 2.0, 1.0, 1.0]
result = Superpose3D(X, xscshift, w, True)
# Does the RMSD returned in result[0] match the RMSD calculated manually?
R = np.array(result[1]) # rotation matrix
Expand All @@ -35,6 +36,7 @@ def test_superpose3d():

print('1st (frozen) point cloud:\n'+str(X))
print('2nd (mobile) point cloud:\n'+str(xscshift))
print('weights: '+str(w))
print('2nd (mobile) point cloud after scale(c), rotation(R), translation(T):\n' +
str(xprime))
print('rmsd = '+str(result[0]))
Expand All @@ -44,13 +46,15 @@ def test_superpose3d():
print('transformation used: x_i\' = Sum_over_j c*R_ij*x_j + T_i')

RMSD = 0.0
sum_w = 0.0
for i in range(0, len(X)):
RMSD += ((X[i][0] - xprime[i][0])**2 +
(X[i][1] - xprime[i][1])**2 +
(X[i][2] - xprime[i][2])**2)
RMSD += w[i]*((X[i][0] - xprime[i][0])**2 +
(X[i][1] - xprime[i][1])**2 +
(X[i][2] - xprime[i][2])**2)
sum_w += w[i]

if len(X) > 0:
RMSD = sqrt(RMSD / len(X))
RMSD = sqrt(RMSD / sum_w)

assert(abs(RMSD - result[0]) < 1.0e-6)

Expand Down

0 comments on commit f02e476

Please sign in to comment.