Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rmsd/calculate_rmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,7 @@ def kabsch_weighted(
CMP = np.zeros(3)
CMQ = np.zeros(3)
C = np.zeros((3, 3))
if W is None:
W = np.ones(len(P)) / len(P)
W = np.ones(len(P)) / len(P) if W is None else W
W = np.array([W, W, W]).T
iw = 3.0 / W.sum()
n = len(P)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_kabsch_weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ def test_kabsch_weighted_fit_pdb() -> None:
new_p_coord = rmsdlib.kabsch_fit(p_coord, q_coord, weights)

np.testing.assert_array_almost_equal(q_coord[300], new_p_coord[300], decimal=2)


def test_kabsch_weighted_defaults_to_uniform_weights() -> None:
filename_1 = RESOURCE_PATH / "ci2_12.pdb"
filename_2 = RESOURCE_PATH / "ci2_2.pdb"

_, p_coord = rmsdlib.get_coordinates_pdb(filename_1)
_, q_coord = rmsdlib.get_coordinates_pdb(filename_2)

uniform_weights = np.ones(len(p_coord)) / len(p_coord)

actual_rotation, actual_translation, actual_rmsd = rmsdlib.kabsch_weighted(p_coord, q_coord)
expected_rotation, expected_translation, expected_rmsd = rmsdlib.kabsch_weighted(
p_coord, q_coord, uniform_weights
)

np.testing.assert_allclose(actual_rotation, expected_rotation)
np.testing.assert_allclose(actual_translation, expected_translation)
np.testing.assert_allclose(actual_rmsd, expected_rmsd)