How to read lammps dump files
I want to try out dynasor with some old lammps results that I have lying around (so I don't have the velocity.gz files as in the tutorials), but I'm getting errors when trying to read in a lammps dump file. Is there some easy conversion that I can apply?
In particular the error I'm getting is
---------------------------------------------------------------------------
UserWarning Traceback (most recent call last)
Cell In[29], line 1
----> 1 dynasor.Trajectory('path/to/lammps.dump', trajectory_format='lammpsdump')
File ~/.local/lib/python3.10/site-packages/dynasor/trajectory/trajectory.py:100, in Trajectory.__init__(self, filename, trajectory_format, atomic_indices, length_unit, time_unit, frame_start, frame_stop, frame_step)
98 logger.debug(f'Using trajectory reader: {reader.__name__}')
99 if reader == MDAnalysisTrajectoryReader:
--> 100 self._reader_obj = reader(self._filename, trajectory_format,
101 length_unit=length_unit, time_unit=time_unit)
102 else:
103 self._reader_obj = reader(self._filename, length_unit=length_unit, time_unit=time_unit)
File ~/.local/lib/python3.10/site-packages/dynasor/trajectory/mdanalysis_trajectory_reader.py:43, in MDAnalysisTrajectoryReader.__init__(self, filename, trajectory_format, length_unit, time_unit)
40 with warnings.catch_warnings():
41 warnings.filterwarnings('ignore', category=UserWarning,
42 message='Guessed all Masses to 1.0')
---> 43 u = mda.Universe(filename, format=trajectory_format, convert_units=False)
44 self._frame_index = count(0)
45 self._trajectory = u.trajectory
File ~/.local/lib/python3.10/site-packages/MDAnalysis/core/universe.py:375, in Universe.__init__(self, topology, all_coordinates, format, topology_format, transformations, guess_bonds, vdwradii, fudge_factor, lower_bound, in_memory, in_memory_step, *coordinates, **kwargs)
370 coordinates = _resolve_coordinates(self.filename, *coordinates,
371 format=format,
372 all_coordinates=all_coordinates)
374 if coordinates:
--> 375 self.load_new(coordinates, format=format, in_memory=in_memory,
376 in_memory_step=in_memory_step, **kwargs)
378 if transformations:
379 if callable(transformations):
File ~/.local/lib/python3.10/site-packages/MDAnalysis/core/universe.py:580, in Universe.load_new(self, filename, format, in_memory, in_memory_step, **kwargs)
577 # supply number of atoms for readers that cannot do it for themselves
578 kwargs['n_atoms'] = self.atoms.n_atoms
--> 580 self.trajectory = reader(filename, format=format, **kwargs)
581 if self.trajectory.n_atoms != len(self.atoms):
582 raise ValueError("The topology and {form} trajectory files don't"
583 " have the same number of atoms!\n"
584 "Topology number of atoms {top_n_atoms}\n"
(...)
588 fname=filename,
589 trj_n_atoms=self.trajectory.n_atoms))
File ~/.local/lib/python3.10/site-packages/MDAnalysis/lib/util.py:2553, in store_init_arguments.<locals>.wrapper(self, *args, **kwargs)
2551 else:
2552 self._kwargs[key] = arg
-> 2553 return func(self, *args, **kwargs)
File ~/.local/lib/python3.10/site-packages/MDAnalysis/coordinates/LAMMPS.py:543, in DumpReader.__init__(self, filename, lammps_coordinate_convention, unwrap_images, **kwargs)
539 self._cache = {}
541 self._reopen()
--> 543 self._read_next_timestep()
File ~/.local/lib/python3.10/site-packages/MDAnalysis/coordinates/LAMMPS.py:598, in DumpReader._read_next_timestep(self)
596 step_num = int(f.readline())
597 ts.data['step'] = step_num
--> 598 ts.data['time'] = step_num * ts.dt
600 f.readline() # ITEM NUMBER OF ATOMS
601 n_atoms = int(f.readline())
File ~/.local/lib/python3.10/site-packages/MDAnalysis/coordinates/timestep.pyx:937, in MDAnalysis.coordinates.timestep.Timestep.dt.__get__()
UserWarning: Reader has no dt information, set to 1.0 ps
The error originates in MDAnalysis, but from dynasors API I have no way to supply the dt
parameter that it complains about. I did manage to silence the error by setting up a warnings.filterwarning
rule, but I haven't set the default rule as error
, so it sounds like it might be related to this issue.
I then switched to reading the lammps.dump
with ase.io.read
and write each structure in an extxyz
file including the velocities, like this
traj = ase.io.read('path/to/lammps.dump', index=':')
with open('traj.xyz', 'w') as f:
for s in traj:
s.symbols[:] = 'Al'
s.write(f, format='extxyz')
dynasor.Trajectory('traj.xyz', trajectory_format='xyz')
but then I get this error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[27], line 1
----> 1 dynasor.Trajectory('traj.xyz', trajectory_format='xyz')
File ~/.local/lib/python3.10/site-packages/dynasor/trajectory/trajectory.py:100, in Trajectory.__init__(self, filename, trajectory_format, atomic_indices, length_unit, time_unit, frame_start, frame_stop, frame_step)
98 logger.debug(f'Using trajectory reader: {reader.__name__}')
99 if reader == MDAnalysisTrajectoryReader:
--> 100 self._reader_obj = reader(self._filename, trajectory_format,
101 length_unit=length_unit, time_unit=time_unit)
102 else:
103 self._reader_obj = reader(self._filename, length_unit=length_unit, time_unit=time_unit)
File ~/.local/lib/python3.10/site-packages/dynasor/trajectory/mdanalysis_trajectory_reader.py:74, in MDAnalysisTrajectoryReader.__init__(self, filename, trajectory_format, length_unit, time_unit)
72 ts.velocities *= length_scaling/time_scaling
73 return ts
---> 74 self._trajectory.add_transformations(convert_units)
76 else: # Units from user, even if trajectory has units
77 if (length_unit != trajectory_length_unit and trajectory_length_unit is not None) or \
78 (time_unit != trajectory_time_unit and trajectory_time_unit is not None):
File ~/.local/lib/python3.10/site-packages/MDAnalysis/coordinates/base.py:1431, in ProtoReader.add_transformations(self, *transformations)
1429 raise ValueError(errmsg) from None
1430 else:
-> 1431 self.ts = self._apply_transformations(self.ts)
File ~/.local/lib/python3.10/site-packages/MDAnalysis/coordinates/base.py:1441, in ProtoReader._apply_transformations(self, ts)
1438 """Applies all the transformations given by the user """
1440 for transform in self.transformations:
-> 1441 ts = transform(ts)
1443 return ts
File ~/.local/lib/python3.10/site-packages/dynasor/trajectory/mdanalysis_trajectory_reader.py:70, in MDAnalysisTrajectoryReader.__init__.<locals>.convert_units(ts)
66 time_scaling = mda.units.get_conversion_factor('time',
67 trajectory_time_unit,
68 'fs')
69 ts.positions *= length_scaling
---> 70 ts.triclinic_dimensions *= length_scaling
71 if ts.has_velocities:
72 ts.velocities *= length_scaling/time_scaling
TypeError: unsupported operand type(s) for *=: 'NoneType' and 'float'
Supplying time_unit
and length_unit
to Trajectory
did not help this issue.
I can upload a small test dump file if that makes debugging easier.