Skip to content

Commit

Permalink
dihedral selection (phi,psi,omega,chi1) methods can handle empty grou…
Browse files Browse the repository at this point in the history
…ps (#4529)

* Fixes #2879
* The AtomGroup methods phi_selections(), psi_selections(), omega_selections(), chi1_selections() 
  can now handle empty groups
  NOTE: Since the methods return a list of atom groups, the methods will also return an empty list
* add tests
* update AUTHORS and CHANGELOG
  • Loading branch information
kainszs authored Mar 29, 2024
1 parent 3cbbab5 commit a2a27aa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,13 @@ Chronological list of authors
2024
- Aditya Keshari
- Philipp Stärk
- Kai Niklas Spauszus
- Sampurna Mukherjee
- Leon Wehrhan
- Valerij Talagayev



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)
* 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

0 comments on commit a2a27aa

Please sign in to comment.