FIX: LAMMPSDUMP Convert forces from kcal to kJ units
Fixes #5115
Changes made in this Pull Request:
- Add
unitsattribute toDumpReaderclass specifying LAMMPS "real" units (time: fs, length: Angstrom, velocity: Angstrom/fs, force: kcal/(mol*Angstrom)) - Implement force unit conversion in
_read_next_timestep()method to convert forces from native kcal/(molAngstrom) to MDAnalysis base units kJ/(molAngstrom) - Add unit conversion calls for positions, velocities, and forces when
convert_units=True(default behavior) - Update docstring to document the automatic force unit conversion behavior
- Add comprehensive tests for force unit conversion functionality:
- Test units attribute definition
- Test conversion factor calculation (4.184)
- Test actual force conversion using existing test files
- Test conversion consistency across all trajectory frames
- Ensure backward compatibility with
convert_units=Falseoption
This 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
- [ ] Issue raised/referenced?
- [ ] Tests updated/added?
- [ ] Documentation updated/added?
- [ ]
package/CHANGELOGfile updated? - [ ] Is your name in
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/
Codecov Report
:x: Patch coverage is 46.93878% with 26 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 85.82%. Comparing base (519ac56) to head (518bca9).
:warning: Report is 27 commits behind head on develop.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| package/MDAnalysis/coordinates/LAMMPS.py | 46.93% | 18 Missing and 8 partials :warning: |
:exclamation: There is a different number of reports uploaded between BASE (519ac56) and HEAD (518bca9). Click for more details.
HEAD has 3 uploads less than BASE
Flag BASE (519ac56) HEAD (518bca9) 6 3
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@hmacdope @jaclark5 could you review this PR? I think you both have some LAMMPS experience. Or can you think of someone else?
@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.