From 1ee79e94df44de464832734874a0643c01fec124 Mon Sep 17 00:00:00 2001 From: ojeda-e Date: Fri, 30 Jul 2021 17:41:07 -0600 Subject: [PATCH] added test avg_mean with wrap True and False --- membrane_curvature/base.py | 14 ++++++--- membrane_curvature/data/test_po4_small.gro | 2 +- .../tests/test_membrane_curvature.py | 30 +++++++++++++++++-- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/membrane_curvature/base.py b/membrane_curvature/base.py index 8f9f642..f63ff3a 100644 --- a/membrane_curvature/base.py +++ b/membrane_curvature/base.py @@ -75,9 +75,11 @@ class MembraneCurvature(AnalysisBase): Notes ----- - Use `wrap=True` when `mda.Universe` contains the raw trajectory, and - `wrap=False` for processed trajectories. For more details on when to use - `wrap=True`, check the `Usage + Use `wrap=True` to translates the atoms of your `mda.Universe` back + in the unit cell. Use `wrap=False` for processed trajectories where + rotational/translational fit is performed. + + For more details on when to use `wrap=True`, check the `Usage `_ page. @@ -127,6 +129,7 @@ def __init__(self, universe, select='all', self.n_y_bins = n_y_bins self.x_range = x_range if x_range else (0, universe.dimensions[0]) self.y_range = y_range if y_range else (0, universe.dimensions[1]) + print(universe.dimensions) # Raise if selection doesn't exist if len(self.ag) == 0: @@ -145,10 +148,13 @@ def __init__(self, universe, select='all', # Apply wrapping coordinates if self.wrap: self.ag.wrap() + # Warning else: msg = (" `wrap == False` may result in inaccurate calculation " "of membrane curvature. Surfaces will be derived from " - "a reduced number of atoms.") + "a reduced number of atoms. \n " + " Ignore this warning if your trajectory has " + " rotational/translational fit rotations! ") warnings.warn(msg) logger.warn(msg) diff --git a/membrane_curvature/data/test_po4_small.gro b/membrane_curvature/data/test_po4_small.gro index bff4d61..e5e60d3 100644 --- a/membrane_curvature/data/test_po4_small.gro +++ b/membrane_curvature/data/test_po4_small.gro @@ -9,4 +9,4 @@ Test file 9 lipids in grid 2708POPC PO4 7 0.000 2.000 12.000 2713POPC PO4 8 1.000 2.000 12.000 2999POPC PO4 9 2.000 2.000 12.000 - 3.00000 3.00000 3.00000 + 3.00000 3.00000 30.00000 diff --git a/membrane_curvature/tests/test_membrane_curvature.py b/membrane_curvature/tests/test_membrane_curvature.py index 6bd0e49..7fcaa69 100644 --- a/membrane_curvature/tests/test_membrane_curvature.py +++ b/membrane_curvature/tests/test_membrane_curvature.py @@ -2,7 +2,7 @@ Unit and regression test for the membrane_curvature package. """ -from numpy.lib.stride_tricks import DummyArray + import pytest from membrane_curvature.surface import normalized_grid, derive_surface, get_z_surface from membrane_curvature.curvature import mean_curvature, gaussian_curvature @@ -212,7 +212,7 @@ def test_get_z_surface(x_bin, y_bin, x_range, y_range, expected_surface): class TestMembraneCurvature(object): @pytest.fixture() def universe(self): - return mda.Universe(GRO_PO4_SMALL, XTC_PO4_SMALL) + return mda.Universe(GRO_PO4_SMALL) @pytest.fixture() def universe_dummy(self): @@ -299,6 +299,32 @@ def test_analysis_get_z_surface(self, universe, x_bin, y_bin, expected_surface): avg_surface = mc.results.average_z_surface assert_almost_equal(avg_surface, expected_surface) + # test using wrap=True + def test_analysis_mean_wrap(self, universe): + expected_mean = np.array([[7.50000000e+00, 1.33985392e-01, 2.77315457e-04], + [-2.77315457e-04, -3.53944270e-01, -7.50000000e+00], + [-2.77315457e-04, -5.01100068e-01, -7.50000000e+00]]) + mc = MembraneCurvature(universe, + select='name PO4', + n_x_bins=3, + n_y_bins=3).run() + avg_mean = mc.results.average_mean + assert_almost_equal(avg_mean, expected_mean) + + # test using wrap=False + def test_analysis_mean_no_wrap(self, universe): + expected_mean = np.array([[7.50000000e+00, 1.33985392e-01, 2.77315457e-04], + [-2.77315457e-04, -3.53944270e-01, -7.50000000e+00], + [-2.77315457e-04, -5.01100068e-01, -7.50000000e+00]]) + mc = MembraneCurvature(universe, + select='name PO4', + n_x_bins=3, + n_y_bins=3, + wrap='False').run() + avg_mean = mc.results.average_mean + assert_almost_equal(avg_mean, expected_mean) + + # Expected values update after applying coordinates wrap @pytest.mark.parametrize('x_bin, y_bin, expected_surface', [ (3, 3,