Skip to content

Commit

Permalink
Fixed issue MDAnalysis#2915 and added a pytest to demonstrate the fix…
Browse files Browse the repository at this point in the history
…. Sphzone operating on an empty selection now returns an empty atom group.
  • Loading branch information
orionarcher committed Apr 2, 2021
1 parent 6282385 commit 7a57af1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package/MDAnalysis/core/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,13 @@ def __init__(self, parser, tokens):
self.sel = parser.parse_expression(self.precedence)

@return_empty_on_apply
def apply(self, group):
def apply(self, group): # TODO fix atom selection
indices = []
sel = self.sel.apply(group)
box = self.validate_dimensions(group.dimensions)
periodic = box is not None
if len(sel) == 0:
return group[[]]
ref = sel.center_of_geometry().reshape(1, 3).astype(np.float32)
pairs = distances.capped_distance(ref, group.positions, self.cutoff,
box=box,
Expand Down
5 changes: 5 additions & 0 deletions testsuite/MDAnalysisTests/core/test_atomselections.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ def test_sphzone(self, u, periodic, expected):

assert len(sel) == expected

@pytest.mark.parametrize('periodic,expected', ([True, 33], [False, 25]))
def test_sphzone(self, u, periodic, expected):
sel = u.select_atoms('sphzone 5.0 name NOT_A_NAME', periodic=periodic)
assert len(sel) == 0


class TestTriclinicDistanceSelections(BaseDistanceSelection):
@pytest.fixture()
Expand Down

0 comments on commit 7a57af1

Please sign in to comment.