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 relprop for atom selection and corresponding UT #4841

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ChiahsinChu
Copy link
Contributor

@ChiahsinChu ChiahsinChu commented Dec 18, 2024

Implementaton of #4838

Changes made in this Pull Request:

  • add relprop keyword for atom selection
  • add UT for this keyword

I will update the User Guide once this implementation (especially the interface to users) is accepted.

PR Checklist

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

Developers certificate of origin


📚 Documentation preview 📚: https://mdanalysis--4841.org.readthedocs.build/en/4841/

Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 6 lines in your changes missing coverage. Please review.

Project coverage is 93.60%. Comparing base (a3672f2) to head (08f8b98).

Files with missing lines Patch % Lines
package/MDAnalysis/core/selection.py 78.57% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4841      +/-   ##
===========================================
- Coverage    93.65%   93.60%   -0.06%     
===========================================
  Files          177      189      +12     
  Lines        21774    22868    +1094     
  Branches      3064     3065       +1     
===========================================
+ Hits         20393    21405    +1012     
- Misses         929     1010      +81     
- Partials       452      453       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Looks sensible at first glance.

In addition to the inline comments, could you please also add documentation to core.groups.AtomGroup.select_atoms() after prop

def select_atoms(self, sel, *othersel, periodic=True, rtol=1e-05,
which is the primary documentation for all selections? Include an example in the docs (follow prop 's docs) so that we can see how users would use it.

UPDATE: I added a few more comments after submitting my review. Please look at these, too. In particular, can you please explain the rationale for comparing to the COM of the reference group instead of calculating all distances and then comparing the min?

Additionally, the comparison needs to be able to take into account PBC (periodic=True).

try:
col = {"x": 0, "y": 1, "z": 2}[self.prop]
except KeyError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

It looks to me that you shouldn't pass here as there's no meaningful way to return results. Please look into the case when line 1385 is executed. A test for this case would probably reveal the issue.

Comment on lines +1357 to +1359
"""Some of the possible properties:
x, y, z,

Copy link
Member

Choose a reason for hiding this comment

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

Please add more documentation, explaining what this operator is doing.

except NoDataError:
attr = self.props[self.prop]
errmsg = f"This Universe does not contain {attr} information"
raise SelectionError(errmsg) from None
Copy link
Member

Choose a reason for hiding this comment

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

ultimately we will also need a test for this failure case

values = values[:, col]
sel = self.sel.apply(group)
rel_value = (
sel.center_of_geometry().reshape(3).astype(np.float32)[col]
Copy link
Member

Choose a reason for hiding this comment

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

Your docs should make clear that the COM of the second group is used.

Is this what this selection should do? Or should it calculate all-vs-all distances and then compute the min over all distances and then compare this minimal distance to the value?

Copy link
Member

@orbeckst orbeckst Dec 19, 2024

Choose a reason for hiding this comment

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

When using center_of_geometry you also need to think carefully to what value wrap and unwrap needs to be set, especially if the user does not get a choice in setting it.

def __init__(self, parser, tokens):
super().__init__(parser, tokens)
self.sel = parser.parse_expression(self.precedence)
# self.ori_value = self.value
Copy link
Member

Choose a reason for hiding this comment

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

remove

rel_value = (
sel.center_of_geometry().reshape(3).astype(np.float32)[col]
)
values -= rel_value
Copy link
Member

Choose a reason for hiding this comment

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

This calculation may not be correct under PBC.

Look into MDAnalysis.lib.distances.distance_array (or probably better MDAnalysis.lib.distances.capped_distance) and MDAnalysis.lib.distances.minimize_vectors for fast functions that can calculate distances under PBC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add RelPropertySelection to select atoms based on positions relative to a given selection
2 participants