Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fixes #1795 sphzone selection regression #1818

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion package/MDAnalysis/core/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def _apply_distmat(self, group):
sel = self.sel.apply(group)
box = self.validate_dimensions(group.dimensions)
periodic = box is not None
ref = sel.center_of_geometry(pbc=periodic).reshape(1, 3).\
ref = sel.center_of_geometry().reshape(1, 3).\
astype(np.float32)
d = distances.distance_array(ref,
group.positions,
Expand Down
42 changes: 27 additions & 15 deletions testsuite/MDAnalysisTests/core/test_atomselections.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#
from __future__ import division, absolute_import

from six.moves import range
from six.moves import range, zip

import itertools
import numpy as np
Expand Down Expand Up @@ -542,20 +542,6 @@ def test_spherical_layer(self, u, meth, periodic):

assert ref == set(result.indices)

@pytest.mark.parametrize('meth, periodic', methods)
def test_spherical_zone(self, u, meth, periodic):
sel = Parser.parse('sphzone 5.0 resid 1', u.atoms)
sel = self.choosemeth(sel, meth, periodic)
result = sel.apply(u.atoms)

r1 = u.select_atoms('resid 1')
box = u.dimensions if periodic else None
cog = r1.center_of_geometry(pbc=periodic).reshape(1, 3)
d = distance_array(u.atoms.positions, cog, box=box)
ref = set(np.where(d < 5.0)[0])

assert ref == set(result.indices)

@pytest.mark.parametrize('meth, periodic', methods)
def test_point(self, u, meth, periodic):
sel = Parser.parse('point 5.0 5.0 5.0 3.0', u.atoms)
Expand Down Expand Up @@ -602,12 +588,38 @@ def test_cyzone(self, u, meth, periodic):

assert ref == set(result.indices)

@pytest.mark.parametrize('input_val, expected',
zip(BaseDistanceSelection.methods,
[25, 31, 33, 25]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means that kdtree and non-kdtree are returning a different result for periodic=True

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean more changes are needed or we need to think about this a bit more?

def test_spherical_zone(self, u, input_val, expected):
# NOTE: this has been modified to regression test
# only for resolution of Issue #1795
# pending proper pbc & wrapping implementations
# in the future
sel = Parser.parse('sphzone 5.0 resid 1', u.atoms)
sel = self.choosemeth(sel, input_val[0], input_val[1])
result = len(sel.apply(u.atoms))
assert result == expected


class TestTriclinicDistanceSelections(BaseDistanceSelection):
@pytest.fixture()
def u(self):
return mda.Universe(GRO)

@pytest.mark.parametrize('input_val, expected',
zip(BaseDistanceSelection.methods,
[55, 55, 55, 55]))
def test_spherical_zone(self, u, input_val, expected):
# NOTE: this has been modified to regression test
# only for resolution of Issue #1795
# pending proper pbc & wrapping implementations
# in the future
sel = Parser.parse('sphzone 5.0 resid 1', u.atoms)
sel = self.choosemeth(sel, input_val[0], input_val[1])
result = len(sel.apply(u.atoms))
assert result == expected


class TestTriclinicSelections(object):
"""Non-KDTree based selections
Expand Down