in fitsnap-reaxff, im trying to optimize as much as possible every cycle of the lammps calculator because its called millions of times for small configs. i want to avoid delete_atoms group all
and recreating the atoms every time so i create an original box with [-99,99]^3 and the maximum number of atoms then i want to change the values with the extracted pointers in python interface:
def allocate_per_config(self, configs: list):
self._configs = configs
ncpn = self.pt.get_ncpn(len(configs))
if self.dipole: self._lmp.command("compute dipole all dipole fixedorigin")
if self.quadrupole: self._lmp.command("compute quadrupole all quadrupole")
max_atoms = max(c["NumAtoms"] for c in configs)
self._lmp.create_atoms( n=max_atoms, id=None,
type=(max_atoms * c_int)(*([1] * max_atoms)),
x=(max_atoms * 3 * c_double)(*([0.0] * max_atoms * 3))
)
self._nlocal = self._lmp.extract_global("nlocal")
self._boxlo = self._lmp.extract_global("boxlo")
self._boxhi = self._lmp.extract_global("boxhi")
self._sublo = self._lmp.extract_global("sublo")
self._subhi = self._lmp.extract_global("subhi")
self._type = self._lmp.extract_atom("type")
self._x = self._lmp.extract_atom("x")
self._q = self._lmp.extract_atom("q")
# --------------------------------------------------------------------------------------------
def _prepare_lammps(self):
self._nlocal = self._data["NumAtoms"]
#self._boxlo[:] = self._data["Bounds"][0]
#self._boxhi[:] = self._data["Bounds"][1]
#self._sublo[:] = self._data["Bounds"][0]
#self._subhi[:] = self._data["Bounds"][1]
self._lmp.reset_box(self._data["Bounds"][0], self._data["Bounds"][1], 0.0, 0.0, 0.0)
if self.esp:
self._lmp.command("compute esp all esp/grid spacing 1.0")
self._esp_reference = self._lmp.numpy.extract_compute('esp',
LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR)
self._esp_reference[:] = self._data["ESP"][:]
for i, (x, y, z) in enumerate(self._data["Positions"]):
self._type[i] = self.type_mapping[self._data["AtomTypes"][i]]
self._x[i][0], self._x[i][1], self._x[i][2] = x, y, z
self._q[i] = self._data["Charges"][i][0]
however because of the way the bounds are extracted in library.cpp, they are not updated when the extracted values are changed in python. if i use reset_box
instead then i get “Calling lammps_reset_box() not supported when atoms exist”.
doing a clear
and rebuilding everything from scratch at each cycle adds ~40% overhead that im trying to avoid.
any suggestions how to get around this ?