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

Quick fix for atommethods to return empty residue group #3089

Merged
merged 8 commits into from
Jan 4, 2021
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
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
aditya-kamath marked this conversation as resolved.
Show resolved Hide resolved

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)
lilyminium marked this conversation as resolved.
Show resolved Hide resolved
* 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