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 AtomGroup.center when using compounds + unwrapping #2992

Merged
merged 1 commit into from
Oct 18, 2020

Conversation

mnmelo
Copy link
Member

@mnmelo mnmelo commented Oct 17, 2020

Fixes #2984

In AtomGroup.center, coordinates are now properly sorted after unwrapping, in tandem with compound_indices and weights. Additionally, sorting is now only even done if the compound_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

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

@pep8speaks
Copy link

Hello @mnmelo! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 1024:31: E201 whitespace after '['
Line 1027:31: E201 whitespace after '['
Line 1067:80: E501 line too long (84 > 79 characters)
Line 1068:80: E501 line too long (133 > 79 characters)
Line 1069:80: E501 line too long (129 > 79 characters)
Line 1070:80: E501 line too long (132 > 79 characters)
Line 1071:80: E501 line too long (127 > 79 characters)
Line 1303:39: E127 continuation line over-indented for visual indent
Line 1315:39: E127 continuation line over-indented for visual indent
Line 1344:39: E127 continuation line over-indented for visual indent
Line 1358:39: E127 continuation line over-indented for visual indent

@codecov
Copy link

codecov bot commented Oct 17, 2020

Codecov Report

Merging #2992 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
package/MDAnalysis/core/groups.py 98.58% <100.00%> (+<0.01%) ⬆️

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 26880f0...2a91314. Read the comment docs.

Copy link
Contributor

@jbarnoud jbarnoud left a 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):
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

Copy link
Member Author

@mnmelo mnmelo Oct 17, 2020

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?)

@mnmelo
Copy link
Member Author

mnmelo commented Oct 17, 2020

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.

Copy link
Contributor

@jbarnoud jbarnoud left a 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.

@jbarnoud jbarnoud merged commit beb5232 into develop Oct 18, 2020
@jbarnoud jbarnoud deleted the issue-2984-center_components_unwrapping branch October 18, 2020 09:35
orbeckst pushed a commit that referenced this pull request Oct 23, 2020
… with unwrapping (PR #2992)

fixes #2984

(cherry picked from commit beb5232)
orbeckst pushed a commit that referenced this pull request Oct 24, 2020
… with unwrapping (PR #2992)

fixes #2984

(cherry picked from commit beb5232)
lilyminium pushed a commit to lilyminium/mdanalysis that referenced this pull request Dec 9, 2020
PicoCentauri pushed a commit to PicoCentauri/mdanalysis that referenced this pull request Mar 30, 2021
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.

AtomGroup.center fails for compounds+wrapping
3 participants