Skip to content
Open
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
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Chronological list of authors
- Raúl Lois-Cuns
- Pranay Pelapkar
- Shreejan Dolai
- Tanisha Dubey

External code
-------------
Expand Down
27 changes: 11 additions & 16 deletions testsuite/MDAnalysisTests/analysis/test_msd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#


from MDAnalysis.analysis.msd import EinsteinMSD as MSD
import MDAnalysis as mda

from numpy.testing import assert_almost_equal, assert_equal, assert_allclose
from numpy.testing import assert_allclose, assert_equal
import numpy as np

from MDAnalysisTests.datafiles import (
Expand Down Expand Up @@ -143,7 +142,7 @@ def test_simple_step_traj_all_dims(
m_simple = MSD(step_traj, "all", msd_type=dim, fft=False)
m_simple.run()
poly = characteristic_poly(NSTEP, dim_factor)
assert_almost_equal(m_simple.results.timeseries, poly, decimal=4)
assert_allclose(m_simple.results.timeseries, poly, rtol=1e-4)

@pytest.mark.parametrize(
"dim, dim_factor",
Expand All @@ -166,17 +165,15 @@ def test_simple_start_stop_step_all_dims(
m_simple.run(start=10, stop=1000, step=10)
poly = characteristic_poly(NSTEP, dim_factor)
# polynomial must take offset start into account
assert_almost_equal(
m_simple.results.timeseries, poly[0:990:10], decimal=4
)
assert_allclose(m_simple.results.timeseries, poly[0:990:10], rtol=1e-4)

def test_random_walk_u_simple(self, random_walk_u):
# regress against random_walk test data
msd_rw = MSD(random_walk_u, "all", msd_type="xyz", fft=False)
msd_rw.run()
norm = np.linalg.norm(msd_rw.results.timeseries)
val = 3932.39927487146
assert_almost_equal(norm, val, decimal=5)
assert norm == pytest.approx(val, rel=1e-5)


@pytest.mark.skipif(
Expand All @@ -196,13 +193,13 @@ def test_fft_vs_simple_default(self, msd, msd_fft):
# testing on the PSF, DCD trajectory
timeseries_simple = msd.results.timeseries
timeseries_fft = msd_fft.results.timeseries
assert_almost_equal(timeseries_simple, timeseries_fft, decimal=4)
assert_allclose(timeseries_simple, timeseries_fft, rtol=1e-4)

def test_fft_vs_simple_default_per_particle(self, msd, msd_fft):
# check fft and simple give same result per particle
per_particle_simple = msd.results.msds_by_particle
per_particle_fft = msd_fft.results.msds_by_particle
assert_almost_equal(per_particle_simple, per_particle_fft, decimal=4)
assert_allclose(per_particle_simple, per_particle_fft, rtol=1e-4)

@pytest.mark.parametrize("dim", ["xyz", "xy", "xz", "yz", "x", "y", "z"])
def test_fft_vs_simple_all_dims(self, u, SELECTION, dim):
Expand All @@ -213,7 +210,7 @@ def test_fft_vs_simple_all_dims(self, u, SELECTION, dim):
m_fft = MSD(u, SELECTION, msd_type=dim, fft=True)
m_fft.run()
timeseries_fft = m_fft.results.timeseries
assert_almost_equal(timeseries_simple, timeseries_fft, decimal=4)
assert_allclose(timeseries_simple, timeseries_fft, rtol=1e-4)

@pytest.mark.parametrize("dim", ["xyz", "xy", "xz", "yz", "x", "y", "z"])
def test_fft_vs_simple_all_dims_per_particle(self, u, SELECTION, dim):
Expand All @@ -225,7 +222,7 @@ def test_fft_vs_simple_all_dims_per_particle(self, u, SELECTION, dim):
m_fft = MSD(u, SELECTION, msd_type=dim, fft=True)
m_fft.run()
per_particle_fft = m_fft.results.msds_by_particle
assert_almost_equal(per_particle_simple, per_particle_fft, decimal=4)
assert_allclose(per_particle_simple, per_particle_fft, rtol=1e-4)

@pytest.mark.parametrize(
"dim, dim_factor",
Expand All @@ -249,7 +246,7 @@ def test_fft_step_traj_all_dims(self, step_traj, NSTEP, dim, dim_factor):
m_simple.run()
poly = characteristic_poly(NSTEP, dim_factor)
# this was relaxed from decimal=4 for numpy=1.13 test
assert_almost_equal(m_simple.results.timeseries, poly, decimal=3)
assert_allclose(m_simple.results.timeseries, poly, rtol=1e-3)

@pytest.mark.parametrize(
"dim, dim_factor",
Expand All @@ -272,17 +269,15 @@ def test_fft_start_stop_step_all_dims(
m_simple.run(start=10, stop=1000, step=10)
poly = characteristic_poly(NSTEP, dim_factor)
# polynomial must take offset start into account
assert_almost_equal(
m_simple.results.timeseries, poly[0:990:10], decimal=3
)
assert_allclose(m_simple.results.timeseries, poly[0:990:10], rtol=1e-3)

def test_random_walk_u_fft(self, random_walk_u):
# regress against random_walk test data
msd_rw = MSD(random_walk_u, "all", msd_type="xyz", fft=True)
msd_rw.run()
norm = np.linalg.norm(msd_rw.results.timeseries)
val = 3932.39927487146
assert_almost_equal(norm, val, decimal=5)
assert norm == pytest.approx(val, rel=1e-4)


class TestMSDNonLinear:
Expand Down
Loading