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

Fix for issue #3383 triclinic lammpsdump #3403

Merged
merged 9 commits into from
Mar 23, 2022

Conversation

alexgorfer
Copy link
Contributor

@alexgorfer alexgorfer commented Aug 24, 2021

Fixes #3383

Changes made in this Pull Request:

PR Checklist

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

@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #3403 (5056fd5) into develop (e0a44cd) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #3403      +/-   ##
===========================================
+ Coverage    94.11%   94.15%   +0.03%     
===========================================
  Files          190      190              
  Lines        24654    24659       +5     
  Branches      3309     3309              
===========================================
+ Hits         23204    23217      +13     
+ Misses        1404     1396       -8     
  Partials        46       46              
Impacted Files Coverage Δ
package/MDAnalysis/coordinates/LAMMPS.py 96.14% <100.00%> (+2.90%) ⬆️
MDAnalysisTests/coordinates/base.py 95.35% <0.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 e0a44cd...5056fd5. Read the comment docs.

@hmacdope
Copy link
Member

Sorry @Agorfa, I am trying to triage and get to this ASAP.

@alexgorfer
Copy link
Contributor Author

Hey @hmacdope no problem, thanks so much! With triaging you mean the failing checks or the issue this pr is concerned with? These checks for python builds 3.7+ all fail due to not having permission to read 'C:\Users\VssAdministrator\AppData\Local\Temp\pytest-of-VssAdministrator\pytest-0\popen-gw1\test_write_with_drivers_core_0h5md-writer-test.h5md' which should be something unrelated!?

For the actual issue I couldnt find versions older than 2019 of lammps to see if this has always been their way of dumping boxes.

@IAlibay
Copy link
Member

IAlibay commented Aug 31, 2021

@Agorfa for the H5MD failures, if you could update your branch against develop that should be fixed now.

@hmacdope
Copy link
Member

Sorry @Agorfa, by triage I meant hopefully move up my priority list. :) Don't worry about the CI failures, they are unrelated as @IAlibay has just pointed out as I write this. :)

@alexgorfer
Copy link
Contributor Author

Ah ok awesome :) Will do!

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Just an initial quick review, it'd be really useful if you could add some tests that cover the use case being covered.

@@ -560,10 +560,15 @@ def _read_next_timestep(self):

triclinic = len(f.readline().split()) == 9 # ITEM BOX BOUNDS
if triclinic:
xlo, xhi, xy = map(float, f.readline().split())
ylo, yhi, xz = map(float, f.readline().split())
xlo_bound, xhi_bound, xy = map(float, f.readline().split())
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to add a relevant test (maybe based on the issue this aims to fix) that covers these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah of course, I can write a test that reads in a triclinic box. This would test that it doesnt fail. Testing that the actual issue would be resolved is difficult/impossible?. I think one would have to create a triclinic box in lammps, then actually run lammps and read the output to see if the dimensions are the same.

Copy link
Member

Choose a reason for hiding this comment

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

So here that's what we would require to do - create a triclinic box in lammps and then check that we reproduce expected outcomes (calculated by hand and/or comparing to a lammps output).

If we can't do such a correctness check then we might have to discuss further whether or not we can offer this option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a first correctness check here:
triclinic_lammps_2021_09_02.zip
I use the values from the input data file for lammps that require xlo, xhi etc. directly and compare those dimensions to the ones imported from the lammpsdump file of the same system:

import MDAnalysis as mda
import numpy as np
from MDAnalysis.lib import mdamath

u = mda.Universe("dump.atom", topology_format='LAMMPSDUMP')

## Direct values from lammps data file
xlo = -0.32115478301032807
xhi = 16.831069399898624
ylo = -0.12372358703610897 
yhi = 25.95896427399614
zlo = -0.045447071698045266 
zhi = 12.993982724334792
xy = 1.506743915478767
xz = - 6.266414551929444 
yz = - 0.42179319547892025

box = np.zeros((3, 3), dtype=np.float64)
box[0] = xhi - xlo, 0.0, 0.0
box[1] = xy, yhi - ylo, 0.0
box[2] = xz, yz, zhi - zlo

direct_dimensions = mdamath.triclinic_box(*box)

print(direct_dimensions == u.dimensions)

resulting in the same dimensions

[ True  True  True  True  True  True]

Would this be sufficient? Should I then write this procedure into a test file or what would be the best practice for testing specifications set in other software?

Copy link
Member

Choose a reason for hiding this comment

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

You can write something like this into the testsuite! the relevant file is here.

You will need to learn a bit of pytest, and use the text fixtures but hopefully the file is commented enough to be comprehensible. The numpy testing functions will be very helpful. See here for how to run the testsuite.

If you need to add an additional file to the test data, please do add it to the mdanalysis/testsuite/MDAnalysisTests/data/lammps folder and import it in
mdanalysis/testsuite/MDAnalysisTests/datafiles.py

I am going to tag @richardjgowers in case I am missing something about ortho vs triclinic in MDA/LAMMPS here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah awesome thank you! I will get the keywords you recommended and then write it up in there!

@hmacdope
Copy link
Member

hmacdope commented Sep 2, 2021

Note we should also improve checking for keywords in the ITEM BOX BOUND check, just checking for triclinic = len(f.readline().split()) == 9 is not super safe.

@hmacdope
Copy link
Member

hmacdope commented Sep 2, 2021

Sorry for the spam, but it might be good to use the thermo_style custom cella, cellb, cellc, cellalpha, cellbeta, cellgamma, keyword for to generate test data that we can compare our triclinic representation to directly.

@alexgorfer
Copy link
Contributor Author

Sorry for the spam, but it might be good to use the thermo_style custom cella, cellb, cellc, cellalpha, cellbeta, cellgamma, keyword for to generate test data that we can compare our triclinic representation to directly.

Ah thats a good idea! I will do a short simulation with these keywords

@pep8speaks
Copy link

pep8speaks commented Sep 7, 2021

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

Line 139:28: E261 at least two spaces before inline comment
Line 139:80: E501 line too long (113 > 79 characters)
Line 144:28: E261 at least two spaces before inline comment
Line 144:80: E501 line too long (113 > 79 characters)
Line 495:80: E501 line too long (87 > 79 characters)
Line 500:80: E501 line too long (87 > 79 characters)

Comment last updated at 2022-03-23 01:39:02 UTC

@hmacdope
Copy link
Member

hmacdope commented Sep 7, 2021

Just ping me when you want a review @Agorfa 👍

@hmacdope
Copy link
Member

hmacdope commented Nov 1, 2021

Hey @Agorfa, any progress on this? No rush, but I think it would be good to fix this up so that LAMMPs users are getting the right triclinic boxes. :) I'm happy to contribute code and/or discuss if anything is unclear.

@alexgorfer
Copy link
Contributor Author

Hey @hmacdope! Sorry, it has really been on my mind but I didnt do all that much yet.. Yes, I think it would be really good to finish this. I will try to make good progress this week!

@hmacdope
Copy link
Member

hmacdope commented Nov 2, 2021

No rush :) Only when you have time 👍

@alexgorfer
Copy link
Contributor Author

Hey @hmacdope, at long last, I finally have something new to show. In my test I compare the boxes between a .dump file to the .data file to my expectation, all for the same system. Is this ok?

@hmacdope
Copy link
Member

Hi @Agorfa thank you! This seems like the right approach to me. :) I will leave a detailed review soon.

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.

Hi @agorfa looking really good! Just a few nitpicks here and there.

testsuite/MDAnalysisTests/datafiles.py Outdated Show resolved Hide resolved
testsuite/MDAnalysisTests/datafiles.py Outdated Show resolved Hide resolved
testsuite/MDAnalysisTests/coordinates/test_lammps.py Outdated Show resolved Hide resolved
package/MDAnalysis/coordinates/LAMMPS.py Show resolved Hide resolved
@alexgorfer
Copy link
Contributor Author

Thanks so much for the review! I will implement it as soon as I can!

@hmacdope
Copy link
Member

hmacdope commented Mar 8, 2022

@Agorfa, we would love to get this fixed soon if you are interested in continuing this PR. :)

@alexgorfer
Copy link
Contributor Author

Hi @hmacdope ! Yes sry of course I will implement it asap!

@hmacdope
Copy link
Member

hmacdope commented Mar 8, 2022

@Agorfa no need to apologise! We are super grateful for the contribution. :)

@alexgorfer
Copy link
Contributor Author

Hey I implemented your conversations! I dont understand why codecov/project complains :S

@alexgorfer alexgorfer requested a review from hmacdope March 9, 2022 01:45
@hmacdope hmacdope requested a review from orbeckst March 9, 2022 02:15
@hmacdope
Copy link
Member

hmacdope commented Mar 9, 2022

@orbeckst I would love a second set of eyes on this box math

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.

I only reviewed the triclinic math. This all looks good to me so I approve. Thank you for your contribution!

Please update the docs for the LAMMPS reader to note that triclinic boxes are read and link to the LAMMPS documentation.

I am leaving it to @hmacdope and @IAlibay to also make sure that you also add yourself to AUTHORS and include a CHANGELOG entry.

package/MDAnalysis/coordinates/LAMMPS.py Show resolved Hide resolved
package/MDAnalysis/coordinates/LAMMPS.py Outdated Show resolved Hide resolved
@hmacdope
Copy link
Member

hmacdope commented Mar 9, 2022

Thanks @orbeckst!

@Agorfa, would you be able to update the docs as suggested and add yourself to AUTHORS and an entry to CHANGELOG please? Then we will be ready to merge. 🥇

@IAlibay
Copy link
Member

IAlibay commented Mar 9, 2022

@Agorfa we're trying to get a means of contacting folks in the future as we consider changing the MDAnalysis license. Could you please send an email to the MDAnalysis developer list introducing yourself (with your GitHub handle) before we merge this PR?

@alexgorfer
Copy link
Contributor Author

Hey everyone! Thanks so much for your guidance! I wrote docs, changelogs and authors. I'm not sure about the .. versionchanged:: 2.2.0 I added I guessed it is helpful for some users? I hope everything else is at the right place

@alexgorfer
Copy link
Contributor Author

Hey @IAlibay of course I just sent it!

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.

This all looks good to me with CHANGELOG and CONTRIBUTORS updated along with adequate docs Thanks so much for your contribution @Agorfa. Have I missed anything @IAlibay?

@hmacdope
Copy link
Member

@IAlibay have your proposed changes been addressed?

@Agorfa If you could resolve conflicts that would be amazing so I can merge pending @IAlibay.

@alexgorfer
Copy link
Contributor Author

Should be resolved!

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Just a couple of small things, please do address. I'll give this an approval so my review isn't blocking.

length unit (Å), and angles are in degrees.

.. versionchanged:: 2.2.0
Triclinic simulation boxes are supported. (Issue #3383)
Copy link
Member

Choose a reason for hiding this comment

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

It might be good to make that issue number a link to the actual issue.

package/CHANGELOG Outdated Show resolved Hide resolved
package/MDAnalysis/coordinates/LAMMPS.py Outdated Show resolved Hide resolved
@alexgorfer
Copy link
Contributor Author

Ah sorry thanks I got confused with the order when I resolved the conflict.. I also made the link and pep8 seems happy

@hmacdope hmacdope merged commit 7670dad into MDAnalysis:develop Mar 23, 2022
@hmacdope
Copy link
Member

Congratulations @Agorfa! We appreciate your contribution.

@orbeckst
Copy link
Member

Thank you for your contribution @Agorfa , well done! I hope you feel encouraged to contribute more in the future!

@IAlibay IAlibay added the defect label Sep 25, 2023
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.

LAMMPS DumpReader returns incorrect triclinic box dimensions
5 participants