Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ Chronological list of authors
- Amruthesh Thirumalaiswamy
- Ch Zhang
- Raúl Lois-Cuns
- Kushagar Garg
- Shreejan Dolai

External code
Expand Down
101 changes: 54 additions & 47 deletions testsuite/MDAnalysisTests/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
from unittest import TestCase
from numpy.testing import (
assert_equal,
assert_almost_equal,
assert_array_almost_equal,
assert_allclose,
)

Expand Down Expand Up @@ -118,21 +116,23 @@ def test_dt(self):
def test_coordinates(self):
A10CA = self.universe.select_atoms("name CA")[10]
# restrict accuracy to maximum in PDB files (3 decimals)
assert_almost_equal(
assert_allclose(
A10CA.position,
self.ref_coordinates["A10CA"],
3,
atol=1e-3,
rtol=0,
err_msg="wrong coordinates for A10:CA",
)

def test_distances(self):
NTERM = self.universe.select_atoms("name N")[0]
CTERM = self.universe.select_atoms("name C")[-1]
d = mda.lib.mdamath.norm(NTERM.position - CTERM.position)
assert_almost_equal(
assert_allclose(
d,
self.ref_distances["endtoend"],
self.prec,
atol=10**(-self.prec),
rtol=0,
err_msg="distance between M1:N and G214:C",
)

Expand Down Expand Up @@ -322,21 +322,21 @@ def test_get_writer_2(self, ref, reader, tmpdir):
assert_equal(W.n_atoms, 100)

def test_dt(self, ref, reader):
assert_almost_equal(reader.dt, ref.dt, decimal=ref.prec)
assert_allclose(reader.dt, ref.dt, atol=10**(-ref.prec), rtol=0)

def test_ts_dt_matches_reader(self, reader):
assert_equal(reader.ts.dt, reader.dt)

def test_total_time(self, ref, reader):
assert_almost_equal(reader.totaltime, ref.totaltime, decimal=ref.prec)
assert_allclose(reader.totaltime, ref.totaltime, atol=10**(-ref.prec), rtol=0)

def test_first_dimensions(self, ref, reader):
reader.rewind()
if ref.dimensions is None:
assert reader.ts.dimensions is None
else:
assert_array_almost_equal(
reader.ts.dimensions, ref.dimensions, decimal=ref.prec
assert_allclose(
reader.ts.dimensions, ref.dimensions, atol=10**(-ref.prec), rtol=0
)

def test_changing_dimensions(self, ref, reader):
Expand All @@ -345,25 +345,26 @@ def test_changing_dimensions(self, ref, reader):
if ref.dimensions is None:
assert reader.ts.dimensions is None
else:
assert_array_almost_equal(
reader.ts.dimensions, ref.dimensions, decimal=ref.prec
assert_allclose(
reader.ts.dimensions, ref.dimensions, atol=10**(-ref.prec), rtol=0
)
reader[1]
if ref.dimensions_second_frame is None:
assert reader.ts.dimensions is None
else:
assert_array_almost_equal(
assert_allclose(
reader.ts.dimensions,
ref.dimensions_second_frame,
decimal=ref.prec,
atol=10**(-ref.prec),
rtol=0
)

def test_volume(self, ref, reader):
reader.rewind()
vol = reader.ts.volume
# Here we can only be sure about the numbers upto the decimal point due
# to floating point impressions.
assert_almost_equal(vol, ref.volume, 0)
assert_allclose(vol, ref.volume, atol=1, rtol=0)

def test_iter(self, ref, reader):
for i, ts in enumerate(reader):
Expand All @@ -387,9 +388,11 @@ def test_remove_nonexistant_auxiliary_raises_ValueError(self, reader):
def test_iter_auxiliary(self, ref, reader):
# should go through all steps in 'highf'
for i, auxstep in enumerate(reader.iter_auxiliary("highf")):
assert_almost_equal(
assert_allclose(
auxstep.data,
ref.aux_highf_all_data[i],
atol=1e-7,
rtol = 0,
err_msg="Auxiliary data does not match for "
"step {}".format(i),
)
Expand Down Expand Up @@ -453,8 +456,8 @@ def test_transformations_iter(self, ref, transformed):
v2 = np.float32((0, 0, 0.33))
for i, ts in enumerate(transformed):
idealcoords = ref.iter_ts(i).positions + v1 + v2
assert_array_almost_equal(
ts.positions, idealcoords, decimal=ref.prec
assert_allclose(
ts.positions, idealcoords, atol=10**(-ref.prec), rtol=0
)

def test_transformations_2iter(self, ref, transformed):
Expand All @@ -465,21 +468,21 @@ def test_transformations_2iter(self, ref, transformed):
idealcoords = []
for i, ts in enumerate(transformed):
idealcoords.append(ref.iter_ts(i).positions + v1 + v2)
assert_array_almost_equal(
ts.positions, idealcoords[i], decimal=ref.prec
assert_allclose(
ts.positions, idealcoords[i], atol=10**(-ref.prec), rtol=0
)

for i, ts in enumerate(transformed):
assert_almost_equal(ts.positions, idealcoords[i], decimal=ref.prec)
assert_allclose(ts.positions, idealcoords[i], atol=10**(-ref.prec), rtol=0)

def test_transformations_slice(self, ref, transformed):
# Are the transformations applied when iterating over a slice of the trajectory?
v1 = np.float32((1, 1, 1))
v2 = np.float32((0, 0, 0.33))
for i, ts in enumerate(transformed[2:3:1]):
idealcoords = ref.iter_ts(ts.frame).positions + v1 + v2
assert_array_almost_equal(
ts.positions, idealcoords, decimal=ref.prec
assert_allclose(
ts.positions, idealcoords, atol=10**(-ref.prec), rtol=0
)

def test_transformations_switch_frame(self, ref, transformed):
Expand All @@ -490,26 +493,26 @@ def test_transformations_switch_frame(self, ref, transformed):
v2 = np.float32((0, 0, 0.33))
first_ideal = ref.iter_ts(0).positions + v1 + v2
if len(transformed) > 1:
assert_array_almost_equal(
transformed[0].positions, first_ideal, decimal=ref.prec
assert_allclose(
transformed[0].positions, first_ideal, atol=10**(-ref.prec), rtol=0
)
second_ideal = ref.iter_ts(1).positions + v1 + v2
assert_array_almost_equal(
transformed[1].positions, second_ideal, decimal=ref.prec
assert_allclose(
transformed[1].positions, second_ideal, atol=10**(-ref.prec), rtol=0
)

# What if we comeback to the previous frame?
assert_array_almost_equal(
transformed[0].positions, first_ideal, decimal=ref.prec
assert_allclose(
transformed[0].positions, first_ideal, atol=10**(-ref.prec), rtol=0
)

# How about we switch the frame to itself?
assert_array_almost_equal(
transformed[0].positions, first_ideal, decimal=ref.prec
assert_allclose(
transformed[0].positions, first_ideal, atol=10**(-ref.prec), rtol=0
)
else:
assert_array_almost_equal(
transformed[0].positions, first_ideal, decimal=ref.prec
assert_allclose(
transformed[0].positions, first_ideal, atol=10**(-ref.prec), rtol=0
)

def test_transformation_rewind(self, ref, transformed):
Expand All @@ -519,8 +522,8 @@ def test_transformation_rewind(self, ref, transformed):
v2 = np.float32((0, 0, 0.33))
ideal_coords = ref.iter_ts(0).positions + v1 + v2
transformed.rewind()
assert_array_almost_equal(
transformed[0].positions, ideal_coords, decimal=ref.prec
assert_allclose(
transformed[0].positions, ideal_coords, atol=10**(-ref.prec), rtol=0
)

def test_transformations_copy(self, ref, transformed):
Expand All @@ -536,8 +539,8 @@ def test_transformations_copy(self, ref, transformed):
)
for i, ts in enumerate(new):
ideal_coords = ref.iter_ts(i).positions + v1 + v2
assert_array_almost_equal(
ts.positions, ideal_coords, decimal=ref.prec
assert_allclose(
ts.positions, ideal_coords, atol=10**(-ref.prec), rtol=0
)

def test_add_another_transformations_raises_ValueError(self, transformed):
Expand Down Expand Up @@ -812,8 +815,8 @@ def test_write_different_box(self, ref, universe, tmpdir):

for ts_ref, ts_w in zip(universe.trajectory, written):
universe.dimensions[:3] += 1
assert_array_almost_equal(
universe.dimensions, ts_w.dimensions, decimal=ref.prec
assert_allclose(
universe.dimensions, ts_w.dimensions, atol=10**(-ref.prec), rtol = 0
)

def test_write_trajectory_atomgroup(self, ref, reader, universe, tmpdir):
Expand Down Expand Up @@ -853,10 +856,11 @@ def test_write_selection(

copy = ref.reader(outfile)
for orig_ts, copy_ts in zip(universe.trajectory, copy):
assert_array_almost_equal(
assert_allclose(
copy_ts._pos,
sel.atoms.positions,
ref.prec,
atol=10**(-ref.prec),
rtol=0,
err_msg="coordinate mismatch between original and written "
"trajectory at frame {} (orig) vs {} (copy)".format(
orig_ts.frame, copy_ts.frame
Expand Down Expand Up @@ -933,10 +937,11 @@ def assert_timestep_almost_equal(A, B, decimal=6, verbose=True):
)

if A.has_positions:
assert_array_almost_equal(
assert_allclose(
A.positions,
B.positions,
decimal=decimal,
atol=10**(-decimal),
rtol=0,
err_msg="Timestep positions",
verbose=verbose,
)
Expand All @@ -949,10 +954,11 @@ def assert_timestep_almost_equal(A, B, decimal=6, verbose=True):
)
)
if A.has_velocities:
assert_array_almost_equal(
assert_allclose(
A.velocities,
B.velocities,
decimal=decimal,
atol=10**(-decimal),
rtol=0,
err_msg="Timestep velocities",
verbose=verbose,
)
Expand All @@ -965,10 +971,11 @@ def assert_timestep_almost_equal(A, B, decimal=6, verbose=True):
)
)
if A.has_forces:
assert_array_almost_equal(
assert_allclose(
A.forces,
B.forces,
decimal=decimal,
atol=10**(-decimal),
rtol=0,
err_msg="Timestep forces",
verbose=verbose,
)
Expand Down
Loading