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

Feature minimise vectors #3472

Merged
merged 18 commits into from
Jan 11, 2022
Merged

Feature minimise vectors #3472

merged 18 commits into from
Jan 11, 2022

Conversation

richardjgowers
Copy link
Member

@richardjgowers richardjgowers commented Nov 30, 2021

Towards MDAnalysis/waterdynamics#19 and #3471

Changes made in this Pull Request:

  • added a function for minimising vectors

PR Checklist

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

@pep8speaks
Copy link

pep8speaks commented Nov 30, 2021

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

Line 2072:80: E501 line too long (83 > 79 characters)

Line 1383:80: E501 line too long (97 > 79 characters)
Line 1385:80: E501 line too long (94 > 79 characters)
Line 1389:80: E501 line too long (86 > 79 characters)
Line 1390:80: E501 line too long (98 > 79 characters)

Comment last updated at 2022-01-11 11:03:08 UTC


@cython.boundscheck(False)
@cython.wraparound(False)
cdef inline void _minimum_image_orthogonal(cython.floating[:] dx, cython.floating[:] box, cython.floating[:] inverse_box):
Copy link
Member Author

Choose a reason for hiding this comment

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

Our current implementations in calc_distances.h are a weird mixed but mostly single precision. I've rewritten these here using cython fused types (aka templates) to allow both single and double precision

@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #3472 (eedc243) into develop (062143b) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    MDAnalysis/mdanalysis#3472      +/-   ##
===========================================
+ Coverage    93.77%   93.87%   +0.09%     
===========================================
  Files          176      176              
  Lines        23214    23282      +68     
  Branches      3302     3302              
===========================================
+ Hits         21769    21856      +87     
+ Misses        1394     1373      -21     
- Partials        51       53       +2     
Impacted Files Coverage Δ
package/MDAnalysis/lib/c_distances.pyx 100.00% <100.00%> (ø)
package/MDAnalysis/lib/distances.py 98.46% <100.00%> (+0.04%) ⬆️
package/MDAnalysis/lib/util.py 90.57% <100.00%> (+0.02%) ⬆️
package/MDAnalysis/units.py 100.00% <0.00%> (ø)
package/MDAnalysis/coordinates/chemfiles.py 97.22% <0.00%> (+0.44%) ⬆️
package/MDAnalysis/analysis/hole2/hole.py 79.21% <0.00%> (+4.73%) ⬆️

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 062143b...eedc243. Read the comment docs.

@orbeckst
Copy link
Member

orbeckst commented Nov 30, 2021

Hooray for minimising_vectors()!

@orbeckst orbeckst added the PBC label Nov 30, 2021
@richardjgowers
Copy link
Member Author

I would have thought someone would have asked for minimizing with a z by now. We use American spelling iirc?

@orbeckst
Copy link
Member

orbeckst commented Nov 30, 2021 via email

@lilyminium
Copy link
Member

Z please :-) might as well keep, or move towards, one standard.

@richardjgowers
Copy link
Member Author

ok @MDAnalysis/coredevs I think this is ready for review

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

I will post my 3/4 review covering all the calling and ortho code. I'll work through the inner loop triclinic code ASAP, but is detailed paper work, hopefully have it done by end of week.

Overall looking really good! Mostly just queries and nitpicks

package/MDAnalysis/lib/c_distances.pyx Show resolved Hide resolved
package/MDAnalysis/lib/c_distances.pyx Show resolved Hide resolved
package/MDAnalysis/lib/c_distances.pyx Outdated Show resolved Hide resolved
package/MDAnalysis/lib/c_distances.pyx Outdated Show resolved Hide resolved
package/MDAnalysis/lib/c_distances.pyx Show resolved Hide resolved
package/MDAnalysis/lib/distances.py Show resolved Hide resolved
Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Last third of my review, looking really good just a few nitpicks mostly.

package/MDAnalysis/lib/c_distances.pyx Show resolved Hide resolved
package/MDAnalysis/lib/c_distances.pyx Show resolved Hide resolved
package/MDAnalysis/lib/c_distances.pyx Show resolved Hide resolved
package/MDAnalysis/lib/c_distances.pyx Show resolved Hide resolved
# this technically doesn't alter the vector because of periodic boundaries
shifted_vec = (vec + (box.T * shift).sum(axis=1)).astype(dtype)

box2 = mdamath.triclinic_box(*box).astype(dtype)
Copy link
Member

Choose a reason for hiding this comment

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

I found this slightly confusing for the ortho case until I ran through it and realised that this eventually returns an ortho box for np.eye(3) through the check_box call. in minimize_vectors

Perhaps a quick note will help for clarity and future readability.


res = distances.minimize_vectors(shifted_vec, box2)

assert_almost_equal(res, vec, decimal=5)
Copy link
Member

Choose a reason for hiding this comment

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

I think assert_allclose() or one of the _ulp() numpy comparisons is preferred now @tylerjereddy?

Copy link
Member

Choose a reason for hiding this comment

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

@richardjgowers just this one and then good to go

@richardjgowers richardjgowers added this to the 2.1.0 milestone Jan 9, 2022
@richardjgowers
Copy link
Member Author

Ok hopefully good to go @hmacdope and @MDAnalysis/coredevs

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

All good to rumble!

Would be great if you could change the testing assert to 'assert_allclose' but will leave it up to you :)

@richardjgowers richardjgowers merged commit 3488df3 into develop Jan 11, 2022
@richardjgowers richardjgowers deleted the feature_minimise_vectors branch January 11, 2022 13:31
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.

6 participants