-
Notifications
You must be signed in to change notification settings - Fork 647
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 AtomGroup.center when using compounds + unwrapping #2992
Conversation
… with unwrapping (closes #2984).
Hello @mnmelo! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:
|
Codecov Report
@@ Coverage Diff @@
## develop #2992 +/- ##
========================================
Coverage 93.05% 93.05%
========================================
Files 186 186
Lines 24609 24611 +2
Branches 3187 3188 +1
========================================
+ Hits 22900 22902 +2
Misses 1661 1661
Partials 48 48
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of changes of indentation for split lines that are make the linter complain. Other than that there only is a small change on one test that I think would improve the PR.
@@ -1058,6 +1064,12 @@ def test_UnWrapFlag_residues(self, ag, ref_Unwrap_residues): | |||
assert_almost_equal(ag.moment_of_inertia(unwrap=True, compound='residues'), ref_Unwrap_residues['MOI'], self.prec) | |||
assert_almost_equal(ag.asphericity(unwrap=True, compound='residues'), ref_Unwrap_residues['Asph'], self.prec) | |||
|
|||
def test_UnWrapFlag_residues_unordered(self, unordered_ag, ref_Unwrap_residues): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be parametrized so each AG method is tested separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You suggest also parameterizing the method? Like this?
@pytest.mark.parametrize('method_name', ('center_of_geometry', 'center_of_mass',
'moment_of_inertia', 'asphericity'))
def test_UnWrapFlag_residues_unordered(self, unordered_ag, ref_Unwrap_residues, method_name):
method = getattr(unordered_ag, method_name)
# requires that the keys of ref_Unwrap_residues are changed to match the method names
assert_almost_equal(method(unwrap=True, compound='residues'),
ref_Unwrap_residues[method_name], self.prec)
I'm all for it, but several more tests are begging for the same cleanup. It seems a targeted refactoring effort would make more sense. If you think that at least new tests should be parameterized as above, I'm cool with having it thus.
@@ -1058,6 +1064,12 @@ def test_UnWrapFlag_residues(self, ag, ref_Unwrap_residues): | |||
assert_almost_equal(ag.moment_of_inertia(unwrap=True, compound='residues'), ref_Unwrap_residues['MOI'], self.prec) | |||
assert_almost_equal(ag.asphericity(unwrap=True, compound='residues'), ref_Unwrap_residues['Asph'], self.prec) | |||
|
|||
def test_UnWrapFlag_residues_unordered(self, unordered_ag, ref_Unwrap_residues): | |||
assert_almost_equal(unordered_ag.center_of_geometry(unwrap=True, compound='residues'), ref_Unwrap_residues['COG'], self.prec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines could be split.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really just kept them long to conform to how all other such tests are. I can split (shall I also split the analogous ones in neighboring tests?)
In the end, most of the non-parameterization or lint in the tests is to conform to the existing standard of neighboring tests. I'll gladly introduce these tests as exceptions and examples to follow from now on, but I think a refactor should be its own PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring the tests is out of scope for this PR and I agree there is some value in keeping internal consistency. I openned an issue about the cleaning of the tests in that file: #2995.
… with unwrapping (PR MDAnalysis#2992) fixes MDAnalysis#2984 (cherry picked from commit beb5232)
… with (MDAnalysis#2992) unwrapping (closes MDAnalysis#2984).
Fixes #2984
In
AtomGroup.center
, coordinates are now properly sorted after unwrapping, in tandem withcompound_indices
andweights
. Additionally, sorting is now only even done if thecompound_indices
are not already monotonically increasing. Monotonicity is a rather cheap check for the most frequent use case, compared to the expensive sorting that's only really needed for the rarer cases of unordered/noncontiguous compounds.PR Checklist