Skip to content

Commit

Permalink
Fixes chi1_selections (MDAnalysis#4108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Evans committed Apr 1, 2023
1 parent bdb1352 commit 14ffcfd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Chronological list of authors
- Xiaoxu Ruan
- Egor Marin
- Shaivi Malik
- Daniel J. Evans

External code
-------------
Expand Down
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The rules for this file:
* 2.5.0

Fixes
* Fix chi1_selections incorrectly returning None (Issue #4108)
* Fix parsing of box vector in H5MD reader (Issue #4076)
* Fix the misleading 'AtomGroup.guess_bonds()' docs and passed missing
arguments (PR #4059)
Expand Down
8 changes: 4 additions & 4 deletions package/MDAnalysis/core/topologyattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ def chi1_selection(residue, n_name='N', ca_name='CA', cb_name='CB',
transplants[Residue].append(('chi1_selection', chi1_selection))

def chi1_selections(residues, n_name='N', ca_name='CA', cb_name='CB',
cg_name='CG'):
cg_name='CG CG1 OG OG1 SG'):
"""Select list of AtomGroups corresponding to the chi1 sidechain dihedral
N-CA-CB-CG.
Expand All @@ -1266,13 +1266,13 @@ def chi1_selections(residues, n_name='N', ca_name='CA', cb_name='CB',
"""
results = np.array([None]*len(residues))
names = [n_name, ca_name, cb_name, cg_name]
keep = [all(sum(r.atoms.names == n) == 1 for n in names)
keep = [all(len(r.atoms.select_atoms(f"name {n}")) == 1
for n in names)
for r in residues]
keepix = np.where(keep)[0]
residues = residues[keep]

atnames = residues.atoms.names
ags = [residues.atoms[atnames == n] for n in names]
ags = [residues.atoms.select_atoms(f"name {n}") for n in names]
results[keepix] = [sum(atoms) for atoms in zip(*ags)]
return list(results)

Expand Down

0 comments on commit 14ffcfd

Please sign in to comment.