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

Add arbitrary TopologyAttr selection #2927

Merged
merged 17 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
5 changes: 4 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Fixes
would create a test artifact (Issue #2979, PR #2981)

Enhancements
* Added automatic selection class generation for TopologyAttrs,
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
FloatRangeSelection, and BoolSelection (Issues #2925, #2875; PR #2927)
* Added selection of negative resids (Issue #3054, PR #2927)
* Improved performance of the ParmEd converter (Issue #3028, PR #3029)
* Improved analysis class docstrings, and added missing classes to the
`__all__` list (PR #2998)
Expand Down Expand Up @@ -111,7 +114,7 @@ Enhancements
'protein' selection (#2751 PR #2755)
* Added an RDKit converter that works for any input with all hydrogens
explicit in the topology (Issue #2468, PR #2775)

Changes
* Continuous integration uses mamba rather than conda to install the
dependencies (PR #2983)
Expand Down
19 changes: 14 additions & 5 deletions package/MDAnalysis/core/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,9 @@ def ts(self):

# As with universe.select_atoms, needing to fish out specific kwargs
# (namely, 'updating') doesn't allow a very clean signature.
def select_atoms(self, sel, *othersel, **selgroups):

def select_atoms(self, sel, *othersel, periodic=True, rtol=1e-05,
atol=1e-08, updating=False, **selgroups):
"""Select atoms from within this Group using a selection string.

Returns an :class:`AtomGroup` sorted according to their index in the
Expand All @@ -2623,6 +2625,12 @@ def select_atoms(self, sel, *othersel, **selgroups):
periodic : bool (optional)
for geometric selections, whether to account for atoms in different
periodic images when searching
atol : float, optional
lilyminium marked this conversation as resolved.
Show resolved Hide resolved
The absolute tolerance parameter for float comparisons.
Passed to :func:``numpy.isclose``.
rtol : float, optional
The relative tolerance parameter for float comparisons.
Passed to :func:``numpy.isclose``.
updating : bool (optional)
force the selection to be re evaluated each time the Timestep of the
trajectory is changed. See section on **Dynamic selections** below.
Expand Down Expand Up @@ -2894,16 +2902,15 @@ def select_atoms(self, sel, *othersel, **selgroups):
periodic are now on by default (as with default flags)
.. versionchanged:: 2.0.0
Added the *smarts* selection.
.. versionchanged:: 2.0.0
lilyminium marked this conversation as resolved.
Show resolved Hide resolved
Added `atol` and `rtol` keywords to select float values.
"""

if not sel:
warnings.warn("Empty string to select atoms, empty group returned.",
UserWarning)
return self[[]]

periodic = selgroups.pop('periodic', True)

updating = selgroups.pop('updating', False)
sel_strs = (sel,) + othersel

for group, thing in selgroups.items():
Expand All @@ -2912,7 +2919,9 @@ def select_atoms(self, sel, *othersel, **selgroups):
"You provided {} for group '{}'".format(
thing.__class__.__name__, group))

selections = tuple((selection.Parser.parse(s, selgroups, periodic=periodic)
selections = tuple((selection.Parser.parse(s, selgroups,
periodic=periodic,
atol=atol, rtol=rtol)
for s in sel_strs))
if updating:
atomgrp = UpdatingAtomGroup(self, selections, sel_strs)
Expand Down
Loading