Skip to content

Commit

Permalink
reformatted with black
Browse files Browse the repository at this point in the history
  • Loading branch information
orbeckst committed May 23, 2024
1 parent e569863 commit 56c792e
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 114 deletions.
5 changes: 2 additions & 3 deletions mdgeom/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def minimage_distance(a, b):
d = calc_bonds(a, b, box=a.dimensions)
return d


def minimage_difference_vector(a, b):
r"""Calculate the minimum image difference vector r_a - r_b
Expand Down Expand Up @@ -120,9 +121,7 @@ def _check_groups(a, b):
if a.dimensions is None and b.dimensions is None:
# it's ok when both AtomGroups have no unitcell
pass
elif (a.dimensions is None) != (b.dimensions is None): # xor
elif (a.dimensions is None) != (b.dimensions is None): # xor
raise ValueError("One AtomGroup does not have unit cell information")
elif not np.allclose(a.dimensions, b.dimensions):
raise ValueError("Unit cell dimensions differ between groups.")


59 changes: 40 additions & 19 deletions mdgeom/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,49 @@ def summary(*universes, labels=None):
There needs to be one element on `labels` for each universe.
"""
data_column_keys = ["n_atoms", "Lx", "Ly", "Lz", "alpha", "beta", "gamma",
"n_frames", "totaltime", "dt"]
data_column_names = ["n_atoms", "Lx/Å", "Ly/Å", "Lz/Å", "alpha", "beta", "gamma",
"n_frames", "totaltime/ns", "dt/ps"]
data_column_keys = [
"n_atoms",
"Lx",
"Ly",
"Lz",
"alpha",
"beta",
"gamma",
"n_frames",
"totaltime",
"dt",
]
data_column_names = [
"n_atoms",
"Lx/Å",
"Ly/Å",
"Lz/Å",
"alpha",
"beta",
"gamma",
"n_frames",
"totaltime/ns",
"dt/ps",
]

if len(labels) != len(universes):
raise ValueError(f"labels {labels} must contain one "
f"label per universe {universes}")
raise ValueError(
f"labels {labels} must contain one "
f"label per universe {universes}"
)

if labels is None:
labels = len(universes) * [None]
column_names = data_column_names
else:
column_names = ["simulation"] + data_column_names


table = prettytable.PrettyTable()
table.field_names = column_names

for u, label in zip(universes, labels):
data = extract(u)
data['totaltime'] /= 1000 # convert ps to ns
data["totaltime"] /= 1000 # convert ps to ns
row = [data[key] for key in data_column_keys]
if label is not None:
row = [label] + row
Expand Down Expand Up @@ -82,17 +103,17 @@ def extract(u):
Lx, Ly, Lz, alpha, beta, gamma = u.dimensions
except TypeError:
# universe without a regular box
Lx, Ly, Lz, alpha, beta, gamma = 0, 0, 0, 0, 0, 0
Lx, Ly, Lz, alpha, beta, gamma = 0, 0, 0, 0, 0, 0
data = {
'n_atoms': u.atoms.n_atoms,
'Lx': Lx, 'Ly': Ly, 'Lz': Lz,
'alpha': alpha, 'beta': beta, 'gamma': gamma,
'n_frames': u.trajectory.n_frames,
'totaltime': u.trajectory.totaltime,
'dt': u.trajectory.dt,
"n_atoms": u.atoms.n_atoms,
"Lx": Lx,
"Ly": Ly,
"Lz": Lz,
"alpha": alpha,
"beta": beta,
"gamma": gamma,
"n_frames": u.trajectory.n_frames,
"totaltime": u.trajectory.totaltime,
"dt": u.trajectory.dt,
}
return data




26 changes: 18 additions & 8 deletions mdgeom/tests/test_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
fret_pairs = [
("resname ALA and resid 55", "resname VAL and resid 169"),
("resname ALA and resid 127", "resname ALA and resid 194"),
("resname ILE and resid 52", "resname LYS* and resid 145")]
("resname ILE and resid 52", "resname LYS* and resid 145"),
]


@pytest.fixture
Expand All @@ -30,6 +31,7 @@ def u_pbc():
# Tests for distances.minimage_distance()
#


def _minimage_distance(u):
# helper function
a = sum(u.select_atoms(pair[0] + " and name CA") for pair in fret_pairs)
Expand All @@ -39,11 +41,13 @@ def _minimage_distance(u):

return r


def test_minimage_distance_nopbc(u_nopbc):
reference = np.array([12.91501288, 30.57278011, 28.92306815])
r = _minimage_distance(u_nopbc)
assert_allclose(r, reference)


def test_minimage_distance_pbc(u_pbc):
reference = np.array([29.67992244, 38.36642607, 42.18877151])
r = _minimage_difference_vector(u_pbc)
Expand All @@ -54,6 +58,7 @@ def test_minimage_distance_pbc(u_pbc):
# Tests for distances.minimage_difference_vector()
#


def _minimage_difference_vector(u):
# helper function
a = sum(u.select_atoms(pair[0] + " and name CA") for pair in fret_pairs)
Expand All @@ -66,18 +71,23 @@ def _minimage_difference_vector(u):

def test_minimage_difference_vector_nopbc(u_nopbc):
reference = np.array(
[[ -6.7521524, -7.5131125, -8.047306 ],
[-21.687479 , -15.805498 , -14.646992 ],
[ 16.235527 , -19.996527 , 13.156384 ]])
[
[-6.7521524, -7.5131125, -8.047306],
[-21.687479, -15.805498, -14.646992],
[16.235527, -19.996527, 13.156384],
]
)
r = _minimage_difference_vector(u_nopbc)
assert_allclose(r, reference)


def test_minimage_difference_vector_pbc(u_pbc):
reference = np.array(
[[-11.659996 , 8.610001 , 25.900003 ],
[ -9.439999 , 37.177002 , 0.8600006],
[-31.1585 , 21.841507 , -18.220566 ]])
[
[-11.659996, 8.610001, 25.900003],
[-9.439999, 37.177002, 0.8600006],
[-31.1585, 21.841507, -18.220566],
]
)
r = _minimage_difference_vector(u_pbc)
assert_allclose(r, reference)

Loading

0 comments on commit 56c792e

Please sign in to comment.