-
Notifications
You must be signed in to change notification settings - Fork 731
FIX: LAMMPSDUMP Convert forces from kcal to kJ units #5117
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
base: develop
Are you sure you want to change the base?
FIX: LAMMPSDUMP Convert forces from kcal to kJ units #5117
Conversation
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.
Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on GitHub Discussions so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS
as part of this PR.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5117 +/- ##
===========================================
- Coverage 93.88% 85.82% -8.07%
===========================================
Files 180 180
Lines 22422 22496 +74
Branches 3186 3202 +16
===========================================
- Hits 21052 19308 -1744
- Misses 902 2722 +1820
+ Partials 468 466 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@hmacdope I have tentatively assigned you as PR shepherd. If you don't have the bandwidth, please find someone else or un-assign yourself and let me know. Thanks. |
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 does seem reasonably solid at first glance:
- no old tests were modified, only new tests added
- 3/4 of the new tests fail before the new source patch is applied, and all pass after
I made a few small suggestions. I'm not a LAMMPS expert (though it is heavily used here).
|
||
assert DumpReader.units == expected_units | ||
|
||
def test_force_unit_conversion_factor(self): |
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 is the only test that doesn't fail when the source patch in this PR is reverted.
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 test appears to be now passing?
|
||
# Test that native forces are unchanged when convert_units=False | ||
# Just check they are reasonable values (not zero everywhere) | ||
assert not np.allclose(forces_native, 0.0) |
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.
Hmm, this check is perhaps a bit less convincing. What about checking the first and last force with LAMMPS
or another reader library and ensuring those are preserved in MDA with convert_units=False
?
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 is assuming that the forces in native units are zero? Consider using assert_allclose
with the forces values copied directly from the dump file
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.
Thanks for doing this! It looks like these changes would commit the DumpReader
to expecting real
units, however, lj
and metal
are also very common options. You're going to have to implement the timeunit
and lengthunit
keywords and then introduce an energy keyword energyunit
. This would be consistent with the LAMMPS.DCDReader
and then the documentation accordingly:
self.units["time"] = kwargs.pop("timeunit", self.units["time"])
self.units["length"] = kwargs.pop("lengthunit", self.units["length"])
… conversion, and native-force preservation test
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.
The changes look great. Only ~40% of the lines of code are covered by these tests, once that's up to 100% and we go through the tests I think it'll be ready
|
||
# Test that native forces are unchanged when convert_units=False | ||
# Just check they are reasonable values (not zero everywhere) | ||
assert not np.allclose(forces_native, 0.0) |
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 is assuming that the forces in native units are zero? Consider using assert_allclose
with the forces values copied directly from the dump file
|
||
assert DumpReader.units == expected_units | ||
|
||
def test_force_unit_conversion_factor(self): |
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 test appears to be now passing?
# MDAnalysis.analysis.lineardensity | ||
|
||
|
||
@pytest.fixture(scope="module", params=params_for_cls(LinearDensity)) |
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.
Don't remove that.
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.
Don't change anything in this file unless you have to.
Fixes #5115
Changes made in this Pull Request:
units
attribute toDumpReader
class specifying LAMMPS "real" units (time: fs, length: Angstrom, velocity: Angstrom/fs, force: kcal/(mol*Angstrom))_read_next_timestep()
method to convert forces from native kcal/(molAngstrom) to MDAnalysis base units kJ/(molAngstrom)convert_units=True
(default behavior)convert_units=False
optionThis fix resolves the inconsistency where LAMMPSDUMP forces remained in kcal/(molAngstrom) while other trajectory formats (GROMACS TRR, AMBER NetCDF) properly converted forces to kJ/(molAngstrom). Now all trajectory formats use consistent force units for downstream analysis.
PR Checklist
package/CHANGELOG
file updated?package/AUTHORS
? (If it is not, add it!)Developers Certificate of Origin
I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.
📚 Documentation preview 📚: https://mdanalysis--5117.org.readthedocs.build/en/5117/