38PairHDNNPExternal::PairHDNNPExternal(LAMMPS *lmp) :
Pair(lmp)
54 if(eflag || vflag) ev_setup(eflag,vflag);
55 else evflag = vflag_fdotr = eflag_global = eflag_atom = 0;
75 for (
int i = 0; i < atom->nlocal; ++i)
90 string com =
"cd " + string(
directory) +
"; " + string(
command) +
" > external.out";
96 if (!f.is_open()) error->all(FLERR,
"Could not open energy output file");
100 while (getline(f, line))
102 if ((line.size() > 0) && (line.at(0) !=
'#'))
105 sscanf(line.c_str(),
"%*s %*s %*s %lf", &energy);
113 ev_tally(0,0,atom->nlocal,1,energy,0.0,0.0,0.0,0.0,0.0);
116 f.open(
string(
directory) +
"nnforces.out");
117 if (!f.is_open()) error->all(FLERR,
"Could not open force output file");
121 while (getline(f, line))
123 if ((line.size() > 0) && (line.at(0) !=
'#'))
125 if (c > atom->nlocal - 1) error->all(FLERR,
"Too many atoms in force file.");
129 sscanf(line.c_str(),
"%*s %*s %*s %*s %*s %lf %lf %lf", &fx, &fy, &fz);
130 atom->f[c][0] = fx / cfforce;
131 atom->f[c][1] = fy / cfforce;
132 atom->f[c][2] = fz / cfforce;
142 if (vflag_fdotr) virial_fdotr_compute();
154 if (narg < 1) error->all(FLERR,
"Illegal pair_style command");
157 int len = strlen(arg[iarg]) + 1;
163 if (screen) fp.push_back(screen);
164 if (logfile) fp.push_back(logfile);
168 len = strlen(
"hdnnp/") + 1;
171 len = strlen(
"nnp-predict 0") + 1;
173 strcpy(
command,
"nnp-predict 0");
179 if (strcmp(arg[iarg],
"dir") == 0) {
181 error->all(FLERR,
"Illegal pair_style command");
183 len = strlen(arg[iarg+1]) + 2;
188 }
else if (strcmp(arg[iarg],
"command") == 0) {
190 error->all(FLERR,
"Illegal pair_style command");
192 len = strlen(arg[iarg+1]) + 1;
194 sprintf(
command,
"%s", arg[iarg+1]);
197 }
else if (strcmp(arg[iarg],
"cflength") == 0) {
199 error->all(FLERR,
"Illegal pair_style command");
200 cflength = utils::numeric(FLERR,arg[iarg+1],
false,lmp);
203 }
else if (strcmp(arg[iarg],
"cfenergy") == 0) {
205 error->all(FLERR,
"Illegal pair_style command");
206 cfenergy = utils::numeric(FLERR,arg[iarg+1],
false,lmp);
208 }
else error->all(FLERR,
"Illegal pair_style command");
213 fprintf(f,
"*****************************************"
214 "**************************************\n");
215 fprintf(f,
"pair_style hdnnp/external settings:\n");
216 fprintf(f,
"-----------------------------------\n");
217 fprintf(f,
"elements = %s\n",
elements);
219 fprintf(f,
"command = %s\n",
command);
220 fprintf(f,
"cflength = %16.8E\n",
cflength);
221 fprintf(f,
"cfenergy = %16.8E\n",
cfenergy);
222 fprintf(f,
"*****************************************"
223 "**************************************\n");
224 fprintf(f,
"CAUTION: Explicit element mapping is not available for hdnnp/external,\n");
225 fprintf(f,
" please carefully check whether this map between LAMMPS\n");
226 fprintf(f,
" atom types and element strings is correct:\n");
227 fprintf(f,
"---------------------------\n");
228 fprintf(f,
"LAMMPS type | NNP element\n");
229 fprintf(f,
"---------------------------\n");
230 int lammpsNtypes =
em.
size();
231 for (
int i = 0; i < lammpsNtypes; ++i)
233 fprintf(f,
"%11d <-> %2s (%3zu)\n",
236 fprintf(f,
"*****************************************"
237 "**************************************\n");
249 if (narg != 3) error->all(FLERR,
"Incorrect args for pair coefficients");
252 utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error);
253 utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error);
259 for(
int i=ilo; i<=ihi; i++) {
260 for(
int j=MAX(jlo,i); j<=jhi; j++) {
266 if (count == 0) error->all(FLERR,
"Incorrect args for pair coefficients");
275 if (comm->nprocs > 1)
277 error->all(FLERR,
"MPI is not supported for this pair_style");
298 int n = atom->ntypes;
300 memory->create(setflag,n+1,n+1,
"pair:setflag");
301 for (
int i = 1; i <= n; i++)
302 for (
int j = i; j <= n; j++)
305 memory->create(cutsq,n+1,n+1,
"pair:cutsq");
~PairHDNNPExternal() override
void coeff(int, char **) override
void settings(int, char **) override
double init_one(int, int) override
void compute(int, int) override
void init_style() override
std::size_t registerElements(std::string const &elementLine)
Extract all elements and store in element map.
std::size_t size() const
Get element map size.
std::size_t atomicNumber(std::size_t index) const
Get atomic number from element index.
Storage for a single atom.
Vec3D r
Cartesian coordinates.
std::size_t element
Element index of this atom.
Vec3D box[3]
Simulation box vectors.
bool isTriclinic
If the simulation box is triclinic.
void writeToFile(std::string const fileName="output.data", bool const ref=true, bool const append=false) const
Write configuration to file.
bool isPeriodic
If periodic boundary conditions apply.
void setElementMap(ElementMap const &elementMap)
Set element map of structure.
void reset()
Reset everything but elementMap.
std::size_t numAtoms
Total number of atoms present in this structure.
std::vector< Atom > atoms
Vector of all atoms in this structure.