Skip to content

Commit

Permalink
Make compute angle an internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfriedman22 committed Oct 7, 2024
1 parent 3addd41 commit c21bd0d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
14 changes: 0 additions & 14 deletions ensemble_md/tests/test_coordinate_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,6 @@ def test_find_rotation_angle():
assert np.isclose(angle, test_angle, 10**(-5))


def test_compute_angle():
coords_1 = [
np.array([0.0, 0.0, 0.0]),
np.array([1.0, 0.0, 0.0]),
np.array([0.0, 1.0, 0.0])
]
coords_2 = coords_1[-1::-1]
coords_3 = [coords_1[1], coords_1[0], coords_1[2]]

assert np.isclose(coordinate_swap.compute_angle(coords_1), np.pi / 4)
assert np.isclose(coordinate_swap.compute_angle(coords_2), np.pi / 4)
assert np.isclose(coordinate_swap.compute_angle(coords_3), np.pi / 2)


def test_add_or_swap():
test_file = open('test_add_or_swap.gro', 'w')
df = pd.read_csv(f'{input_path}/coord_swap/df_atom_swap.csv')
Expand Down
41 changes: 22 additions & 19 deletions ensemble_md/utils/coordinate_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,28 @@ def get_miss_coord(mol_align, mol_ref, name_align, name_ref, df_atom_swap, dir,
df_atom_swap : pandas.DataFrame
Same dataframe as the input, but with coordinates for the missing atoms.
"""
def compute_angle(coords):
"""
Computes the angle between two vectors.
Parameters
----------
coords : list
A list of numpy arrays containing the XYZ coordinates of 3 points, for which the angle 1-2-3 is to be computed.
Returns
-------
angle : int
Angle in radians between the two points.
"""
vec1 = coords[0] - coords[1]
vec2 = coords[2] - coords[1]

angle = np.arccos(np.dot(vec1, vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2)))

return angle


# Create a new column for coordinates if one does not exist
if 'X Coordinates' not in df_atom_swap.columns:
df_atom_swap['X Coordinates'] = np.NaN
Expand Down Expand Up @@ -974,26 +996,7 @@ def find_rotation_angle(initial_point, vertex, rotated_point, axis):
return angle


def compute_angle(coords):
"""
Computes the angle between two vectors.

Parameters
----------
coords : list
A list of numpy arrays containing the XYZ coordinates of 3 points, for which the angle 1-2-3 is to be computed.
Returns
-------
angle : int
Angle in radians between the two points.
"""
vec1 = coords[0] - coords[1]
vec2 = coords[2] - coords[1]

angle = np.arccos(np.dot(vec1, vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2)))

return angle


def add_or_swap(df_select, file_new, resnum, resname, vel, atom_num, orig_coor, skip_line, R_o_D_num, pick):
Expand Down

0 comments on commit c21bd0d

Please sign in to comment.