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

Fixes chi1_selections (#4108) #4109

Merged
merged 5 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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)
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change to using a selection instead of keeping the faster array construct?

Unless there's a good reason, change back. You can time the two approaches and I am sure you'll find that select_atoms is substantially slower.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code fails when cg_name includes multiple names. E.g. if cg_name='CG CG1 OG OG1 SG' then the old code checks whether each atom's name is equal to the entire string 'CG CG1 OG OG1 SG'. This always returns False. So changing this line is a key part of fixing the bug.

I based my fix on chi1_selection, which also uses atom selection. But I agree that this is slow. I wrote an alternate version that avoids atom selection. In my testing, the newest code takes 18 us while the atom selection code takes 147 us.

Should I submit a PR to change chi1_selection to use the faster procedure? For now, I'm just going to push a version with the newest chi1_selections.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation.

Please push an update for your chi1_selections with faster code.

Let us have a look at it. We can then decide if we want to update chi1_selection right away or in a separate PR.

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]
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
results[keepix] = [sum(atoms) for atoms in zip(*ags)]
return list(results)

Expand Down