Skip to content

changing DL_Poly units #4983

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
4 changes: 2 additions & 2 deletions package/MDAnalysis/coordinates/DLPoly.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _read_first_frame(self):
if has_vels:
velocities = np.array(velocities, dtype=np.float32)
if has_forces:
forces = np.array(forces, dtype=np.float32)
forces = np.array(forces, dtype=np.float32) / 100
Copy link
Member

Choose a reason for hiding this comment

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

add a comment above this line stating that forces in DL_POLY are 10 J/(mol.Å) and mention issue #2393 — this is weird enough to warrant a hint for future coders

Copy link
Member

Choose a reason for hiding this comment

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

Actually, we should not just divide by 100 here. Instead we should use the normal conversion machinery where you store the native force units in _DLPOLY_UNITS and store the conversion factor in units, then use convert_from_native.

See also https://userguide.mdanalysis.org/stable/units.html .

self.n_atoms = len(coords)

if ids:
Expand Down Expand Up @@ -196,7 +196,7 @@ def _read_next_timestep(self, ts=None):
if self._has_vels:
ts._velocities[i] = self._file.readline().split()
if self._has_forces:
ts._forces[i] = self._file.readline().split()
ts._forces[i] = np.array(self._file.readline().split(), dtype=np.float32) / 100
i += 1

if ids:
Expand Down
22 changes: 0 additions & 22 deletions package/MDAnalysis/coordinates/TRZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def __init__(self, trzfilename, n_atoms=None, **kwargs):
self._read_trz_header()
self.ts = Timestep(self.n_atoms,
velocities=True,
forces=self.has_force,
reader=self,
**self._ts_kwargs)

Expand Down Expand Up @@ -164,17 +163,6 @@ def __init__(self, trzfilename, n_atoms=None, **kwargs):
('vy', readarg),
('pad6', '<2i4'),
('vz', readarg)]
if not self.has_force:
frame_contents += [('pad7', '<i4')]
else:
frame_contents += [
('pad7', '<2i4'),
('fx', readarg),
('pad8', '<2i4'),
('fy', readarg),
('pad9', '<2i4'),
('fz', readarg),
('pad10', '<i4')]
self._dtype = np.dtype(frame_contents)

self._read_next_timestep()
Expand All @@ -189,12 +177,6 @@ def _read_trz_header(self):
('p3', '<i4')])
data = np.fromfile(self.trzfile, dtype=self._headerdtype, count=1)
self.title = ''.join(c.decode('utf-8') for c in data['title'][0]).strip()
if data['force'] == 10:
self.has_force = False
elif data['force'] == 20:
self.has_force = True
else:
raise IOError

def _read_next_timestep(self, ts=None):
if ts is None:
Expand Down Expand Up @@ -223,10 +205,6 @@ def _read_next_timestep(self, ts=None):
ts._velocities[:, 0] = data['vx']
ts._velocities[:, 1] = data['vy']
ts._velocities[:, 2] = data['vz']
if self.has_force:
ts._forces[:, 0] = data['fx']
ts._forces[:, 1] = data['fy']
ts._forces[:, 2] = data['fz']
except IndexError: # Raises indexerror if data has no data (EOF)
raise IOError from None
else:
Expand Down
3 changes: 2 additions & 1 deletion testsuite/MDAnalysisTests/coordinates/test_dlpoly.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def test_vel(self, u):
ref = np.array([2.637614561, 0.5778767520e-01, -1.704765568])
assert_allclose(u.atoms[2].velocity, ref)

# modified to original numbers / 100
Copy link
Member

Choose a reason for hiding this comment

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

remove comment

Copy link
Member

@cbouy cbouy Apr 2, 2025

Choose a reason for hiding this comment

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

def test_for(self, u):
ref = np.array([150.3309776, -812.6932914, 1429.413120])
ref = np.array([1.503309776, -8.126932914, 14.29413120])
assert_allclose(u.atoms[2].force, ref)

def test_number(self, u):
Expand Down
Loading