WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3c3c81c
FIX: LAMMPSDUMP Convert forces from kcal to kJ units
Rupesh-Singh-Karki Sep 27, 2025
0671174
Fixed failing lint tests
Rupesh-Singh-Karki Sep 27, 2025
518bca9
LAMMPS DumpReader: unit overrides (time/length/energy), default force…
Rupesh-Singh-Karki Oct 9, 2025
e5ee9ac
mark analysis.rdf.InterRDF and analysis.rdf.InterRDF_s as not paralli…
tanishy7777 Jan 7, 2025
f960696
Adds parallization for analysis.rdf.InterRDF
tanishy7777 Jan 8, 2025
04ee5ae
Minor changes
tanishy7777 Jan 8, 2025
4887d03
Adds custom aggregegator for InterRDF_s
tanishy7777 Jan 18, 2025
9af7feb
Fixes aggregation of results.edges
tanishy7777 Jan 18, 2025
080fdae
Parallizes InterRDF_s
tanishy7777 Jan 18, 2025
7b59148
Minor changes
tanishy7777 Jan 18, 2025
89d98e3
Fixes linter
tanishy7777 Jan 18, 2025
74c83f2
Fixes linter
tanishy7777 Jan 18, 2025
e517777
Tests for parallization
tanishy7777 Jan 18, 2025
4fe2f50
refactor custom aggregator for rdf
tanishy7777 Mar 23, 2025
8ef74d8
remove uneccesary variables
tanishy7777 Mar 23, 2025
77435a4
Update CHANGELOG
tanishy7777 Jan 20, 2025
740084a
adds tests for nested_array_sum
tanishy7777 Apr 1, 2025
eeeccb5
fixes formatting
tanishy7777 Apr 1, 2025
530db92
fixes formatting
tanishy7777 Apr 1, 2025
f0e1060
Remove unused code from test_nested_array_sum
p-j-smith Oct 8, 2025
aba969f
remove unnecessary tests from test_rdf and test_rdf_s
p-j-smith Oct 8, 2025
cd1fc7f
Make linters happy
p-j-smith Oct 8, 2025
4785029
Merge branch 'develop' into fix/convert-units-of-trajectory
Rupesh-Singh-Karki Oct 9, 2025
930eb12
Merge branch 'develop' into fix/convert-units-of-trajectory
orbeckst Oct 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions package/MDAnalysis/coordinates/LAMMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,12 @@ class DumpReader(base.ReaderBase):
**kwargs
Other keyword arguments used in :class:`~MDAnalysis.coordinates.base.ReaderBase`

Note
----
This reader assumes LAMMPS "real" units where time is in femtoseconds,
length is in Angstroms, velocities in Angstrom/femtosecond, and forces
in kcal/(mol*Angstrom). Forces are automatically converted to MDAnalysis
base units (kJ/(mol*Angstrom)) for consistency with other trajectory formats.

.. versionchanged:: 2.8.0
Reading of arbitrary, additional columns is now supported.
Expand All @@ -631,6 +637,12 @@ class DumpReader(base.ReaderBase):
"""

format = "LAMMPSDUMP"
units = {
'time': 'fs',
'length': 'Angstrom',
'velocity': 'Angstrom/fs',
'force': 'kcal/(mol*Angstrom)'
}
_conventions = [
"auto",
"unscaled",
Expand Down Expand Up @@ -910,4 +922,12 @@ def _read_next_timestep(self):
# Transform to origin after transformation of scaled variables
ts.positions -= np.array([xlo, ylo, zlo])[None, :]

# Convert units if requested
if self.convert_units:
self.convert_pos_from_native(ts.positions)
if self._has_vels:
self.convert_velocities_from_native(ts.velocities)
if self._has_forces:
self.convert_forces_from_native(ts.forces)

return ts
94 changes: 94 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,100 @@ def test_warning(self, system, request):
with pytest.warns(match="Some of the additional"):
request.getfixturevalue(system)

def test_dump_reader_units_attribute(self):
"""Test that DumpReader has proper units defined"""
from MDAnalysis.coordinates.LAMMPS import DumpReader

expected_units = {
'time': 'fs',
'length': 'Angstrom',
'velocity': 'Angstrom/fs',
'force': 'kcal/(mol*Angstrom)'
}

assert DumpReader.units == expected_units

def test_force_unit_conversion_factor(self):
Copy link
Member

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.

Copy link
Contributor

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 the force conversion factor is correct"""
from MDAnalysis import units

# Get conversion factor from kcal/(mol*Angstrom) to kJ/(mol*Angstrom)
factor = units.get_conversion_factor(
'force',
'kcal/(mol*Angstrom)', # from (LAMMPS native)
'kJ/(mol*Angstrom)' # to (MDAnalysis base)
)

expected_factor = 4.184 # 1 kcal = 4.184 kJ
assert_allclose(factor, expected_factor, rtol=1e-6)

def test_force_conversion_with_image_vf_file(self):
"""Test force unit conversion using existing test file with forces"""
# Test with convert_units=True (default)
u_converted = mda.Universe(
LAMMPS_image_vf,
LAMMPSDUMP_image_vf,
format="LAMMPSDUMP"
)

# Test with convert_units=False
u_native = mda.Universe(
LAMMPS_image_vf,
LAMMPSDUMP_image_vf,
format="LAMMPSDUMP",
convert_units=False
)

# Both should have forces
assert hasattr(u_converted.atoms, 'forces')
assert hasattr(u_native.atoms, 'forces')

# Go to last frame where we know forces exist
u_converted.trajectory[-1]
u_native.trajectory[-1]

forces_converted = u_converted.atoms.forces
forces_native = u_native.atoms.forces

# Check that forces are different (converted vs native)
# The conversion factor should be 4.184
expected_factor = 4.184
forces_expected = forces_native * expected_factor

# Test that converted forces match expected values
assert_allclose(forces_converted, forces_expected, rtol=1e-6)

# 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)
Copy link
Member

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?

Copy link
Contributor

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


def test_force_conversion_consistency_across_frames(self):
"""Test that force conversion works consistently across all frames"""
u_converted = mda.Universe(
LAMMPS_image_vf,
LAMMPSDUMP_image_vf,
format="LAMMPSDUMP"
)

u_native = mda.Universe(
LAMMPS_image_vf,
LAMMPSDUMP_image_vf,
format="LAMMPSDUMP",
convert_units=False
)

conversion_factor = 4.184

# Test conversion in all frames
for ts_conv, ts_native in zip(u_converted.trajectory, u_native.trajectory):
if ts_conv.has_forces:
forces_converted = ts_conv.forces
forces_native = ts_native.forces
forces_expected = forces_native * conversion_factor

assert_allclose(forces_converted, forces_expected, rtol=1e-6,
err_msg=f"Force conversion failed at frame {ts_conv.frame}")


@pytest.mark.parametrize(
"convention", ["unscaled", "unwrapped", "scaled_unwrapped"]
Expand Down
Loading