Skip to content

Commit

Permalink
fix error in returning backbone vector
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Dec 19, 2023
1 parent 9cff1f1 commit 3613e48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmeutils/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_backbone_vector(coordinates):
_, _, V = np.linalg.svd(centered_coordinates)
# The first principal component (V[0]) is the vec of the best-fit line
direction_vector = V[0]
return np.abs(direction_vector)
return direction_vector


def get_plane_normal(points):
Expand Down
8 changes: 4 additions & 4 deletions cmeutils/tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class TestGeometry(BaseTest):
def test_backbone_vector(self):
z_coords = np.array([[0, 0, 1], [0, 0, 2], [0, 0, 3]])
backbone = get_backbone_vector(z_coords)
assert np.allclose(backbone, np.array([0, 0, 1]), atol=1e-5)
assert np.allclose(np.abs(backbone), np.array([0, 0, 1]), atol=1e-5)

x_coords = np.array([[1, 0, 0], [2, 0, 0], [3, 0, 0]])
backbone = get_backbone_vector(x_coords)
assert np.allclose(backbone, np.array([1, 0, 0]), atol=1e-5)
assert np.allclose(np.abs(backbone), np.array([1, 0, 0]), atol=1e-5)

mb_chain = Alkane(n=20)
chain_backbone = get_backbone_vector(mb_chain.xyz)
assert np.allclose(chain_backbone, np.array([0, 1, 0]), atol=1e-2)
backbone = get_backbone_vector(mb_chain.xyz)
assert np.allclose(np.abs(backbone), np.array([0, 1, 0]), atol=1e-2)

def test_backbone_vector_bad_input(self):
with pytest.raises(ValueError):
Expand Down

0 comments on commit 3613e48

Please sign in to comment.