diff --git a/package/MDAnalysis/coordinates/LAMMPS.py b/package/MDAnalysis/coordinates/LAMMPS.py index e5d758816f2..19fc6750a17 100644 --- a/package/MDAnalysis/coordinates/LAMMPS.py +++ b/package/MDAnalysis/coordinates/LAMMPS.py @@ -55,8 +55,9 @@ Dump files ---------- -The DumpReader expects ascii dump files written with the default -`LAMMPS dump format`_ of 'atom' +The DumpReader expects ascii dump files. Currently supported are +coordinates (dump style atom) and velocities for custom dump styles. +Other columns are ignored. Example: Loading a LAMMPS simulation @@ -462,6 +463,7 @@ class DumpReader(base.ReaderBase): coordinate convention (xs,ys,zs) or scaled unwrapped coordinate convention (xsu,ysu,zsu) they will automatically be converted from their scaled/fractional representation to their real values. + Velocities (vx, vy, vz) can be parsed, too. .. versionchanged:: 2.0.0 @@ -502,7 +504,7 @@ def _reopen(self): self.close() self._file = util.anyopen(self.filename) self.ts = self._Timestep(self.n_atoms, **self._ts_kwargs) - self.ts.frame = -1 + self.ts.frame = 0 @property @cached('n_atoms') @@ -606,15 +608,32 @@ def _read_next_timestep(self): coord_cols = convention_to_col_ix[self.lammps_coordinate_convention] + # pass possible additional fields from LAMMPS dump + # pass velocities + velocity_col_names = ["vx", "vy", "vz"] + if any(item in attrs for item in velocity_col_names): + for cv_name, cv_col_names in enumerate(velocity_col_names): + try: + velocity_cols = [attr_to_col_ix[x] for x in velocity_col_names] + ts.has_velocities = True + except KeyError: + raise ValueError("Velocities detected in LAMMPS Dump file but MDAnalysis can only deal with all entries vx, vy, vz present") + ids = "id" in attr_to_col_ix for i in range(self.n_atoms): fields = f.readline().split() if ids: indices[i] = fields[attr_to_col_ix["id"]] ts.positions[i] = [fields[dim] for dim in coord_cols] + if ts.has_velocities: + ts.velocities[i] = [fields[dim] for dim in velocity_cols] order = np.argsort(indices) ts.positions = ts.positions[order] + if ts.has_velocities: + ts.velocities = ts.velocities[order] + # LAMMPS reader only supports real units + ts.velocities *= units.speedUnit_factor['Angstrom/femtosecond'] if (self.lammps_coordinate_convention.startswith("scaled")): # if coordinates are given in scaled format, undo that ts.positions = distances.transform_StoR(ts.positions,