Skip to content
Merged
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
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Chronological list of authors
- Leonardo Barneschi
- Henrik Jäger
- Jan Stevens
- Orion Cohen

External code
-------------
Expand Down
4 changes: 3 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ The rules for this file:
lilyminium, daveminh, jbarnoud, yuxuanzhuang, VOD555, ianmkenney,
calcraven,xiki-tempula, mieczyslaw, manuel.nuno.melo, PicoCentauri,
hanatok, rmeli, aditya-kamath, tirkarthi, LeonardoBarneschi, hejamu,
biogen98
biogen98, orioncohen

* 2.0.0

Fixes
* Fixed 'sphzone', 'sphlayer', 'cyzone', and 'cylayer' to return empty if the
zone/layer is empty, consistent with 'around' (Issue #2915)
* A Universe created from an ROMol with no atoms returns now a Universe
with 0 atoms (Issue #3142)
* ValueError raised when empty atomgroup is given to DensityAnalysis
Expand Down
8 changes: 7 additions & 1 deletion package/MDAnalysis/core/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def apply(self, group):
return func(self, group)
return apply


class _Selectionmeta(type):
def __init__(cls, name, bases, classdict):
type.__init__(type, name, bases, classdict)
Expand Down Expand Up @@ -352,6 +353,8 @@ def __init__(self, parser, tokens):
def apply(self, group):
indices = []
sel = self.sel.apply(group)
if len(sel) == 0:
return group[[]]
box = self.validate_dimensions(group.dimensions)
periodic = box is not None
ref = sel.center_of_geometry().reshape(1, 3).astype(np.float32)
Expand All @@ -378,6 +381,8 @@ def __init__(self, parser, tokens):
def apply(self, group):
indices = []
sel = self.sel.apply(group)
if len(sel) == 0:
return group[[]]
box = self.validate_dimensions(group.dimensions)
periodic = box is not None
ref = sel.center_of_geometry().reshape(1, 3).astype(np.float32)
Expand All @@ -394,7 +399,8 @@ class CylindricalSelection(Selection):
@return_empty_on_apply
def apply(self, group):
sel = self.sel.apply(group)

if len(sel) == 0:
return group[[]]
# Calculate vectors between point of interest and our group
vecs = group.positions - sel.center_of_geometry()

Expand Down
16 changes: 16 additions & 0 deletions testsuite/MDAnalysisTests/core/test_atomselections.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ def test_cylayer(self, universe, selstr):
sel = universe.select_atoms(selstr)
assert_equal(len(sel), 88)

def test_empty_cylayer(self, universe):
empty = universe.select_atoms('cylayer 4.0 6.0 10 -10 name NOT_A_NAME')
assert_equal(len(empty), 0)

@pytest.mark.parametrize('selstr', [
'cyzone 6.0 10 -10 bynum 1281',
'cyzone 6.0 10 -10 index 1280'
Expand All @@ -218,6 +222,10 @@ def test_cyzone(self, universe, selstr):
sel = universe.select_atoms(selstr)
assert_equal(len(sel), 166)

def test_empty_cyzone(self, universe):
empty = universe.select_atoms('cyzone 6.0 10 -10 name NOT_A_NAME')
assert_equal(len(empty), 0)

def test_point(self, universe):
ag = universe.select_atoms('point 5.0 5.0 5.0 3.5')

Expand Down Expand Up @@ -770,6 +778,10 @@ def test_sphlayer(self, u):

assert idx == set(ag.indices)

def test_empty_sphlayer(self, u):
empty = u.select_atoms('sphlayer 2.4 6.0 name NOT_A_NAME')
assert len(empty) == 0

def test_sphzone(self, u):
r1 = u.select_atoms('resid 1')
cog = r1.center_of_geometry().reshape(1, 3)
Expand All @@ -781,6 +793,10 @@ def test_sphzone(self, u):

assert idx == set(ag.indices)

def test_empty_sphzone(self, u):
empty = u.select_atoms('sphzone 5.0 name NOT_A_NAME')
assert len(empty) == 0

def test_point_1(self, u):
# The example selection
ag = u.select_atoms('point 5.0 5.0 5.0 3.5')
Expand Down