Skip to content

decorate Selection.apply to ignore empty atomgroups#2767

Merged
richardjgowers merged 4 commits intoMDAnalysis:developfrom
lilyminium:fix-2765
Jun 20, 2020
Merged

decorate Selection.apply to ignore empty atomgroups#2767
richardjgowers merged 4 commits intoMDAnalysis:developfrom
lilyminium:fix-2765

Conversation

@lilyminium
Copy link
Member

@lilyminium lilyminium commented Jun 17, 2020

Fixes #2765

Changes made in this Pull Request:

  • if an empty AtomGroup is passed to Selection.apply, just return it

I decorated Selection.apply in _Selectionmeta.__init__, which I baselessly feel is a bit iffy. Any opinions on if I should move it somewhere else?

Edit: alternately it could be expensive to have so many ifs, I could just do the StringSelection and sphzone/layer ones individually

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@codecov
Copy link

codecov bot commented Jun 17, 2020

Codecov Report

Merging #2767 into develop will decrease coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2767      +/-   ##
===========================================
- Coverage    91.14%   91.08%   -0.07%     
===========================================
  Files          177      177              
  Lines        23767    23668      -99     
  Branches      3122     3123       +1     
===========================================
- Hits         21663    21558     -105     
- Misses        1484     1490       +6     
  Partials       620      620              
Impacted Files Coverage Δ
package/MDAnalysis/core/selection.py 99.49% <100.00%> (+0.01%) ⬆️
datafiles.py 21.42% <0.00%> (-9.83%) ⬇️
package/MDAnalysis/topology/DMSParser.py 87.30% <0.00%> (-3.18%) ⬇️
package/MDAnalysis/topology/CRDParser.py 88.88% <0.00%> (-2.03%) ⬇️
package/MDAnalysis/selections/__init__.py 94.11% <0.00%> (-0.62%) ⬇️
package/MDAnalysis/selections/base.py 81.60% <0.00%> (-0.62%) ⬇️
package/MDAnalysis/coordinates/INPCRD.py 90.32% <0.00%> (-0.59%) ⬇️
package/MDAnalysis/lib/NeighborSearch.py 82.75% <0.00%> (-0.58%) ⬇️
package/MDAnalysis/coordinates/GSD.py 86.66% <0.00%> (-0.57%) ⬇️
package/MDAnalysis/topology/LAMMPSParser.py 94.93% <0.00%> (-0.45%) ⬇️
... and 86 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c761ba3...518c11d. Read the comment docs.

Copy link
Member

@richardjgowers richardjgowers left a comment

Choose a reason for hiding this comment

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

In [4]: u = mda.Universe(GRO)                                                                                                           

In [5]: ag = u.atoms[[]]                                                                                                                

In [6]: ag.select_atoms('global name C')                                                                                                
Out[6]: <AtomGroup with 214 atoms>

I think this breaks this fix right?

@richardjgowers
Copy link
Member

I like the fix but it's a little hacky to put the decorator application in the _SelectionMeta - really the Selection going through shouldn't be modified, so maybe it's better to explicitly include the @emptyAGguard decorator onto each apply method

@lilyminium
Copy link
Member Author

I added the decorator to the apply methods the geometric and string selection classes instead.

@orbeckst
Copy link
Member

orbeckst commented Jul 6, 2020

This PR did not include a CHANGELOG comment.

Further discussion in #2765 (comment)

orbeckst pushed a commit that referenced this pull request Jul 6, 2020
* decorate Selection.apply to ignore empty atomgroups
* added test for global selection off empty AG
* fix for global selections and empty AG
* decorate functions instead
* update CHANGELOG

Co-authored-by: richard <richard@nextmovesoftware.com>
(cherry picked from commit 016f2c6)
@lilyminium
Copy link
Member Author

Yes, sorry, we forgot; the CHANGELOG entry was updated in the next merge to develop (by @IAlibay iirc)

orbeckst pushed a commit that referenced this pull request Jul 12, 2020
* decorate Selection.apply to ignore empty atomgroups
* added test for global selection off empty AG
* fix for global selections and empty AG
* decorate functions instead
* update CHANGELOG

Co-authored-by: richard <richard@nextmovesoftware.com>
(cherry picked from commit 016f2c6)
PicoCentauri pushed a commit to PicoCentauri/mdanalysis that referenced this pull request Mar 30, 2021
* decorate Selection.apply to ignore empty atomgroups

* added test for global selection off empty AG

* fix for global selections and empty AG

* decorate functions instead

Co-authored-by: richard <richard@nextmovesoftware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot select atoms with StringSelection from empty AtomGroup

4 participants