Skip to content

Commit 6f67266

Browse files
authored
[lammps] Fix handling types when restoring (#344)
For LAMMPS, only unique masses are stored, instead the mass "type" of each particle is stored, and the mass of the `i`th particle can be retrieved as `masses[types][i]`. For this reason we store `(masses, types)` in place of a `masses`, this requires special handling when restoring which we missed initially. Fixing it here.
1 parent 5f5bfc7 commit 6f67266

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pysages/backends/lammps.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ def add_bias(forces, biases):
154154
def add_bias(forces, biases):
155155
forces[:, :3] += factor * biases
156156

157+
def restore_vm(view, snapshot, prev_snapshot):
158+
velocities = view(snapshot.vel_mass[0])
159+
masses_types = snapshot.vel_mass[1]
160+
masses = view(masses_types[0])
161+
types = view(masses_types[1])
162+
prev_masses_types = prev_snapshot.vel_mass[1]
163+
velocities[:] = view(prev_snapshot.vel_mass[0])
164+
masses[:] = view(prev_masses_types[0])
165+
types[:] = view(prev_masses_types[1])
166+
157167
# TODO: check if this can be sped up. # pylint: disable=W0511
158168
def bias(snapshot, state):
159169
"""Adds the computed bias to the forces."""
@@ -166,7 +176,7 @@ def bias(snapshot, state):
166176

167177
snapshot_methods = build_snapshot_methods(sampling_method, on_gpu)
168178
flags = sampling_method.snapshot_flags
169-
restore = partial(restore_fn, view)
179+
restore = partial(restore_fn, view, restore_vm=restore_vm)
170180
helpers = HelperMethods(build_data_querier(snapshot_methods, flags), lambda: dim)
171181

172182
return helpers, restore, bias

0 commit comments

Comments
 (0)