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

atomname methods can handle empty groups #4529

Merged
merged 7 commits into from
Mar 29, 2024
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
2 changes: 2 additions & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ Chronological list of authors
2024
- Aditya Keshari
- Philipp Stärk
- Kai Niklas Spauszus
- Sampurna Mukherjee
- Leon Wehrhan



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

Expand Down
6 changes: 3 additions & 3 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ The rules for this file:
-------------------------------------------------------------------------------
??/??/?? IAlibay, HeetVekariya, marinegor, lilyminium, RMeli,
ljwoods2, aditya292002, pstaerk, PicoCentauri, BFedder,
tyler.je.reddy, SampurnaM, leonwehrhan

tyler.je.reddy, SampurnaM, leonwehrhan, kainszs

* 2.8.0

Fixes
* Add support for TPR files produced by Gromacs 2024.1
* Atomname methods can handle empty groups (Issue #2879, PR #4529)
* Add support for TPR files produced by Gromacs 2024.1 (PR #4523)
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
* Remove mutable data from ``progressbar_kwargs`` argument in ``AnalysisBase.run()``
(PR #4459)
* Fix ChainReader `__repr__()` method when sub-reader is MemoryReader
Expand Down
15 changes: 15 additions & 0 deletions package/MDAnalysis/core/topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,9 @@ def phi_selections(residues, c_name='C', n_name='N', ca_name='CA'):
.. versionadded:: 1.0.0
"""

if not residues:
return []

u = residues[0].universe
prev = u.residues[residues.ix-1] # obv candidates first
rsid = residues.segids
Expand Down Expand Up @@ -1062,6 +1065,10 @@ def psi_selections(residues, c_name='C', n_name='N', ca_name='CA'):

.. versionadded:: 1.0.0
"""

if not residues:
return []

results = np.array([None]*len(residues), dtype=object)
nxtres = residues._get_next_residues_by_resid()
rix = np.where(nxtres)[0]
Expand Down Expand Up @@ -1170,6 +1177,10 @@ def omega_selections(residues, c_name='C', n_name='N', ca_name='CA'):

.. versionadded:: 1.0.0
"""

if not residues:
return []

results = np.array([None]*len(residues), dtype=object)
nxtres = residues._get_next_residues_by_resid()
rix = np.where(nxtres)[0]
Expand Down Expand Up @@ -1267,6 +1278,10 @@ def chi1_selections(residues, n_name='N', ca_name='CA', cb_name='CB',

.. versionadded:: 1.0.0
"""

if not residues:
return []

results = np.array([None]*len(residues))
names = [n_name, ca_name, cb_name, cg_name]
keep = [all(sum(np.isin(r.atoms.names, n.split())) == 1
Expand Down
16 changes: 16 additions & 0 deletions testsuite/MDAnalysisTests/core/test_atomgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ def test_phi_selections_single(self, GRO):
assert_equal(phisel.residues.resids, [9, 10])
assert_equal(phisel.residues.resnames, ['PRO', 'GLY'])

def test_phi_selections_empty(self, GRO):
rgsel = GRO.segments[0].residues[[]].phi_selections()
assert len(rgsel) == 0

def test_phi_selections(self, resgroup):
rgsel = resgroup.phi_selections()
rssel = [r.phi_selection() for r in resgroup]
Expand Down Expand Up @@ -788,6 +792,10 @@ def test_psi_selections_single(self, GRO):
assert_equal(psisel.residues.resids, [10, 11])
assert_equal(psisel.residues.resnames, ['GLY', 'ALA'])

def test_psi_selections_empty(self, GRO):
rgsel = GRO.segments[0].residues[[]].psi_selections()
assert len(rgsel) == 0

def test_psi_selections(self, resgroup):
rgsel = resgroup.psi_selections()
rssel = [r.psi_selection() for r in resgroup]
Expand Down Expand Up @@ -820,6 +828,10 @@ def test_omega_selection_name(self, GRO, kwargs, names):
assert_equal(osel.residues.resids, [8, 9])
assert_equal(osel.residues.resnames, ['ALA', 'PRO'])

def test_omega_selections_empty(self, GRO):
rgsel = GRO.segments[0].residues[[]].omega_selections()
assert len(rgsel) == 0

def test_omega_selections_single(self, GRO):
rgsel = GRO.segments[0].residues[[7]].omega_selections()
assert len(rgsel) == 1
Expand Down Expand Up @@ -869,6 +881,10 @@ def test_chi1_selections_single(self, GRO):
assert_equal(sel.residues.resids, [13])
assert_equal(sel.residues.resnames, ['LYS'])

def test_chi1_selections_empty(self, GRO):
rgsel = GRO.segments[0].residues[[]].chi1_selections()
assert len(rgsel) == 0

def test_chi1_selections(self, resgroup):
rgsel = resgroup.chi1_selections()
rssel = [r.chi1_selection() for r in resgroup]
Expand Down
Loading