From 2dcbf5cdca39ec0d9448e96886606d3ba9d61b20 Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Fri, 9 Mar 2018 11:50:48 -0700 Subject: [PATCH 1/2] BUG: Fixes #1795 * sphzone selections adjusted to address Issue #1795 * corresponding unit test modified to prevent regression only; proper handling of pbc and wrapping matters is delayed for now --- package/MDAnalysis/core/selection.py | 2 +- .../core/test_atomselections.py | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package/MDAnalysis/core/selection.py b/package/MDAnalysis/core/selection.py index d8a7b6d7815..cd3641dd0ba 100644 --- a/package/MDAnalysis/core/selection.py +++ b/package/MDAnalysis/core/selection.py @@ -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, diff --git a/testsuite/MDAnalysisTests/core/test_atomselections.py b/testsuite/MDAnalysisTests/core/test_atomselections.py index 3a167a1a52d..7f54271d495 100644 --- a/testsuite/MDAnalysisTests/core/test_atomselections.py +++ b/testsuite/MDAnalysisTests/core/test_atomselections.py @@ -542,19 +542,19 @@ 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): + @pytest.mark.parametrize('input_val, expected', + zip(methods, + [25, 31, 33, 25, + 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, 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) + sel = self.choosemeth(sel, input_val[0], input_val[1]) + result = len(sel.apply(u.atoms)) + assert result == expected @pytest.mark.parametrize('meth, periodic', methods) def test_point(self, u, meth, periodic): From f14b7e79795f18d89bdc20863c5f71f9fbb5de6c Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Tue, 13 Mar 2018 08:24:55 -0600 Subject: [PATCH 2/2] TST: test_spherical_zone() now redefined in test subclasses to properly handle regression in Issue #1795. --- .../core/test_atomselections.py | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/testsuite/MDAnalysisTests/core/test_atomselections.py b/testsuite/MDAnalysisTests/core/test_atomselections.py index 7f54271d495..260c74cdc1e 100644 --- a/testsuite/MDAnalysisTests/core/test_atomselections.py +++ b/testsuite/MDAnalysisTests/core/test_atomselections.py @@ -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 @@ -542,20 +542,6 @@ def test_spherical_layer(self, u, meth, periodic): assert ref == set(result.indices) - @pytest.mark.parametrize('input_val, expected', - zip(methods, - [25, 31, 33, 25, - 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 - @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) @@ -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])) + 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