Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed keyword by .
Browse files Browse the repository at this point in the history
ojeda-e committed Jul 24, 2021
1 parent 8de7389 commit 591ad49
Showing 2 changed files with 13 additions and 14 deletions.
17 changes: 8 additions & 9 deletions membrane_curvature/base.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@

import MDAnalysis
from MDAnalysis.analysis.base import AnalysisBase
from MDAnalysis.transformations import wrap

import logging
MDAnalysis.start_logging()
@@ -36,8 +35,8 @@ class MembraneCurvature(AnalysisBase):
select : str or iterable of str, optional.
The selection string of an atom selection to use as a
reference to derive a surface.
pbc : bool, optional
Apply periodic boundary conditions.
wrap : bool, optional
Apply coordinate wrapping.
n_x_bins : int, optional, default: '100'
Number of bins in grid in the x dimension.
n_y_bins : int, optional, default: '100'
@@ -123,11 +122,11 @@ def __init__(self, universe, select='all',
n_x_bins=100, n_y_bins=100,
x_range=None,
y_range=None,
pbc=True, **kwargs):
wrap=True, **kwargs):

super().__init__(universe.universe.trajectory, **kwargs)
self.ag = universe.select_atoms(select)
self.pbc = pbc
self.wrap = wrap
self.n_x_bins = n_x_bins
self.n_y_bins = n_y_bins
self.x_range = x_range if x_range else (0, universe.dimensions[0])
@@ -147,11 +146,11 @@ def __init__(self, universe, select='all',
warnings.warn(msg)
logger.warn(msg)

# Apply PBC conditions
if self.pbc is True:
# Apply wrapping coordinates
if self.wrap:
self.ag.wrap()
else:
warnings.warn(" `PBC == False` may result in inaccurate calculation "
warnings.warn(" `wrap == False` may result in inaccurate calculation "
"of membrane curvature. Surfaces will be derived from "
"a reduced number of atoms.")

@@ -168,7 +167,7 @@ def _prepare(self):
self.n_y_bins), np.nan)

def _single_frame(self):
if self.pbc:
if self.wrap:
self.ag.wrap()
# Populate a slice with np.arrays of surface, mean, and gaussian per frame
self.results.z_surface[self._frame_index] = get_z_surface(self.ag.positions,
10 changes: 5 additions & 5 deletions membrane_curvature/tests/test_membrane_curvature.py
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ def test_analysis_get_z_surface_dummy(self, universe_dummy, x_bin, y_bin, x_rang
avg_surface = mc.results.average_z_surface
assert_almost_equal(avg_surface, expected_surface)

@pytest.mark.xfail(reason="PBC conditions not applied.")
@pytest.mark.xfail(reason="Wrapping coordinates not applied.")
@pytest.mark.parametrize('x_bin, y_bin, expected_surface', [
(3, 3,
np.array([[150., 150., 120.],
@@ -371,10 +371,10 @@ def test_analysis_wrapping_coordinates(self, dummy_array, expected_surface):
x_range=x_range,
y_range=y_range).run()
avg_surface = mc.results.average_z_surface
# assert if default values of pbc z_surface returns correctly
# assert if default values of wrapped coords in z_surface returns correctly
assert_almost_equal(avg_surface, expected_surface)

def test_test_analysis_no_pbc(self, universe):
regex = (r"`PBC == False` may result in inaccurate calculation")
def test_test_analysis_no_wrapping(self, universe):
regex = (r"`wrap == False` may result in inaccurate calculation")
with pytest.warns(UserWarning, match=regex):
MembraneCurvature(universe, pbc=False)
MembraneCurvature(universe, wrap=False)

0 comments on commit 591ad49

Please sign in to comment.