Skip to content

Commit

Permalink
added test avg_mean with wrap True and False
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeda-e committed Jul 30, 2021
1 parent ec11488 commit 1ee79e9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
14 changes: 10 additions & 4 deletions membrane_curvature/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://membrane-curvature.readthedocs.io/en/latest/source/pages/Usage.html>`_
page.
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion membrane_curvature/data/test_po4_small.gro
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 28 additions & 2 deletions membrane_curvature/tests/test_membrane_curvature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1ee79e9

Please sign in to comment.