Skip to content

Commit

Permalink
Quick fix for atommethods to return empty residue group (#3089)
Browse files Browse the repository at this point in the history
Returns empty residue group for _get_prev_residues_by_resid and _get_next_residues_by_resid
  • Loading branch information
aditya-kamath authored Jan 4, 2021
1 parent 8f7e338 commit 87e71bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ Chronological list of authors
- Nicholas Craven
- Mieczyslaw Torchala
- Haochuan Chen

2021
- Aditya Kamath

External code
-------------

Expand Down
3 changes: 2 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ The rules for this file:
??/??/?? tylerjereddy, richardjgowers, IAlibay, hmacdope, orbeckst, cbouy,
lilyminium, daveminh, jbarnoud, yuxuanzhuang, VOD555, ianmkenney,
calcraven,xiki-tempula, mieczyslaw, manuel.nuno.melo, PicoCentauri,
hanatok, rmeli
hanatok, rmeli, aditya-kamath

* 2.0.0

Fixes
* atommethods(_get_prev/next_residues_by_resid) returns empty residue group when given empty residue group (Issue #3089)
* MOL2 files without bonds can now be read and written (Issue #3057)
* Write `CONECT` record only once in multi-model PDB files (Issue #3018)
* Add '.nc' as a recognised extension for the NCDFWriter (Issue #3030)
Expand Down
10 changes: 8 additions & 2 deletions package/MDAnalysis/core/topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,10 @@ def _get_next_residues_by_resid(residues):
.. versionadded:: 1.0.0
"""
u = residues[0].universe
try:
u = residues[0].universe
except IndexError:
return residues
nxres = np.array([None]*len(residues), dtype=object)
ix = np.arange(len(residues))
# no guarantee residues is ordered or unique
Expand Down Expand Up @@ -914,7 +917,10 @@ def _get_prev_residues_by_resid(residues):
.. versionadded:: 1.0.0
"""
u = residues[0].universe
try:
u = residues[0].universe
except IndexError:
return residues
pvres = np.array([None]*len(residues))
pvres[:] = prev = u.residues[residues.ix-1]
rsid = residues.segids
Expand Down
12 changes: 12 additions & 0 deletions testsuite/MDAnalysisTests/core/test_topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ class TestAtomnames(TestAtomAttr):
single_value = 'Ca2'
attrclass = tpattrs.Atomnames

@pytest.fixture()
def u(self):
return mda.Universe(PSF, DCD)

def test_prev_emptyresidue(self, u):
assert_equal(u.residues[[]]._get_prev_residues_by_resid(),
u.residues[[]])

def test_next_emptyresidue(self, u):
assert_equal(u.residues[[]]._get_next_residues_by_resid(),
u.residues[[]])


class AggregationMixin(TestAtomAttr):
def test_get_residues(self, attr):
Expand Down

0 comments on commit 87e71bb

Please sign in to comment.