28#include "neigh_list.h"
39 "ML-HDNNP package: doi:10.1021/acs.jctc.8b00770\n\n"
40 "@Article{Singraber19,\n"
41 " author = {Singraber, Andreas and Behler, J{\"o}rg and Dellago, Christoph},\n"
42 " title = {Library-Based {LAMMPS} Implementation of High-Dimensional\n"
43 " Neural Network Potentials},\n"
47 " pages = {1827--1840},\n"
48 " doi = {10.1021/acs.jctc.8b00770},\n"
49 " journal = {J.~Chem.\\ Theory Comput.},\n"
55PairHDNNP::PairHDNNP(LAMMPS *lmp) :
Pair(lmp)
67 interface = new
nnp::InterfaceLammps();
75 memory->destroy(setflag);
76 memory->destroy(cutsq);
83 ev_init(eflag, vflag);
113 if (vflag_fdotr) virial_fdotr_compute();
124 if (narg < 1) error->all(FLERR,
"Illegal pair_style command");
140 while (iarg < narg) {
142 if (strcmp(arg[iarg],
"dir") == 0) {
143 if (iarg + 2 > narg) error->all(FLERR,
"Illegal pair_style command");
145 directory = utils::strdup(arg[iarg + 1]);
148 }
else if (strcmp(arg[iarg],
"showew") == 0) {
149 if (iarg + 2 > narg) error->all(FLERR,
"Illegal pair_style command");
150 showew = utils::logical(FLERR, arg[iarg + 1],
false, lmp) == 1;
153 }
else if (strcmp(arg[iarg],
"showewsum") == 0) {
154 if (iarg + 2 > narg) error->all(FLERR,
"Illegal pair_style command");
155 showewsum = utils::inumeric(FLERR, arg[iarg + 1],
false, lmp);
158 }
else if (strcmp(arg[iarg],
"maxew") == 0) {
159 if (iarg + 2 > narg) error->all(FLERR,
"Illegal pair_style command");
160 maxew = utils::inumeric(FLERR, arg[iarg + 1],
false, lmp);
163 }
else if (strcmp(arg[iarg],
"resetew") == 0) {
164 if (iarg + 2 > narg) error->all(FLERR,
"Illegal pair_style command");
165 resetew = utils::logical(FLERR, arg[iarg + 1],
false, lmp) == 1;
168 }
else if (strcmp(arg[iarg],
"cflength") == 0) {
169 if (iarg + 2 > narg) error->all(FLERR,
"Illegal pair_style command");
170 cflength = utils::numeric(FLERR, arg[iarg + 1],
false, lmp);
173 }
else if (strcmp(arg[iarg],
"cfenergy") == 0) {
174 if (iarg + 2 > narg) error->all(FLERR,
"Illegal pair_style command");
175 cfenergy = utils::numeric(FLERR, arg[iarg + 1],
false, lmp);
178 error->all(FLERR,
"Illegal pair_style command");
188 int n = atom->ntypes;
192 if (narg != 2 + n) error->all(FLERR,
"Incorrect args for pair coefficients");
194 if (strcmp(arg[0],
"*") != 0 || strcmp(arg[1],
"*") != 0)
195 error->all(FLERR,
"Incorrect args for pair coefficients");
197 int *map =
new int[n + 1];
198 for (
int i = 0; i < n; i++) map[i] = 0;
201 for (
int i = 2; i < narg; i++) {
202 if (strcmp(arg[i],
"NULL") != 0) {
204 emap += std::to_string(i - 1) +
":" + arg[i];
210 for (
int i = 1; i <= n; i++)
211 for (
int j = i; j <= n; j++)
212 if (map[i] > 0 && map[j] > 0) {
217 if (count == 0) error->all(FLERR,
"Incorrect args for pair coefficients");
228 neighbor->add_request(
this, NeighConst::REQ_FULL);
245 if (maxCutoffRadius < interface->getMaxCutoffRadius())
246 error->all(FLERR,
"Inconsistent cutoff radius");
265 int n = atom->ntypes;
267 memory->create(setflag, n + 1, n + 1,
"pair:setflag");
268 for (
int i = 1; i <= n; i++)
269 for (
int j = i; j <= n; j++) setflag[i][j] = 0;
271 memory->create(cutsq, n + 1, n + 1,
"pair:cutsq");
278 for (
int ii = 0; ii < list->inum; ++ii) {
279 int i = list->ilist[ii];
280 for (
int jj = 0; jj < list->numneigh[i]; ++jj) {
281 int j = list->firstneigh[i][jj];
283 double dx = atom->x[i][0] - atom->x[j][0];
284 double dy = atom->x[i][1] - atom->x[j][1];
285 double dz = atom->x[i][2] - atom->x[j][2];
286 double d2 = dx * dx + dy * dy + dz * dz;
311 long *numEWPerProc =
nullptr;
312 if (comm->me == 0) numEWPerProc =
new long[comm->nprocs];
313 MPI_Gather(&numCurrentEW, 1, MPI_LONG, numEWPerProc, 1, MPI_LONG, 0, world);
316 for (
int i = 1; i < comm->nprocs; i++) {
317 if (numEWPerProc[i] > 0) {
321 MPI_Recv(&bs, 1, MPI_LONG, i, 0, world, &ms);
322 auto buf =
new char[bs];
324 MPI_Recv(buf, bs, MPI_BYTE, i, 0, world, &ms);
330 }
else if (numCurrentEW > 0) {
334 auto buf =
new char[bs];
337 MPI_Send(&bs, 1, MPI_LONG, 0, 0, world);
338 MPI_Send(buf, bs, MPI_BYTE, 0, 0, world);
342 if (comm->me == 0)
delete[] numEWPerProc;
352 utils::logmesg(lmp,
"### NNP EW SUMMARY ### TS: {:10d} EW {:10d} EWPERSTEP {:10.3e}\n",
353 update->ntimestep, globalEW,
double(globalEW) /
showewsum);
360 error->one(FLERR,
"Too many extrapolation warnings");
long numExtrapolationWarningsSummary
void init_style() override
void handleExtrapolationWarnings()
double init_one(int, int) override
void compute(int, int) override
void transferNeighborList()
void settings(int, char **) override
void coeff(int, char **) override
long numExtrapolationWarningsTotal
nnp::InterfaceLammps * interface
long getEWBufferSize() const
Calculate buffer size for extrapolation warning communication.
void process()
Calculate symmetry functions, atomic neural networks and sum of local energy contributions.
void extractEWBuffer(char const *const &buf, int bs)
Extract given buffer to symmetry function statistics class.
void setLocalTags(int const *const atomTag)
Set atom tags (int version, -DLAMMPS_SMALLBIG).
double getEnergy() const
Return sum of local energy contributions.
void fillEWBuffer(char *const &buf, int bs) const
Fill provided buffer with extrapolation warning entries.
double getAtomicEnergy(int index) const
Return energy contribution of one atom.
void getForces(double *const *const &atomF) const
Calculate forces and add to LAMMPS atomic force arrays.
void initialize(char const *const &directory, char const *const &emap, bool showew, bool resetew, int showewsum, int maxew, double cflength, double cfenergy, double lammpsCutoff, int lammpsNtypes, int myRank)
Initialize the LAMMPS interface.
bool isInitialized() const
Check if this interface is correctly initialized.
void writeExtrapolationWarnings()
Write extrapolation warnings to log.
void setLocalAtoms(int numAtomsLocal, int const *const atomType)
(Re)set structure to contain only local LAMMPS atoms.
void clearExtrapolationWarnings()
Clear extrapolation warnings storage.
void addNeighbor(int i, int j, int64_t tag, int type, double dx, double dy, double dz, double d2)
Add one neighbor to atom (int64_t version, -DLAMMPS_BIGBIG).
void registerCFilePointer(FILE **const &filePointer)
Register new C-style FILE* pointer for output.
std::size_t getNumExtrapolationWarnings() const
Count total number of extrapolation warnings encountered for all elements and symmetry functions.
static const char cite_user_hdnnp_package[]