n2p2 - A neural network potential package
InterfaceLammps.cpp
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef N2P2_NO_MPI
18#include <mpi.h>
19#include "mpi-extra.h"
20#endif
21#include "InterfaceLammps.h"
22#include "Atom.h"
23#include "Element.h"
24#include "utility.h"
25#include <cmath>
26#include <string>
27#include <iostream>
28#include <limits>
29
30#define TOLCUTOFF 1.0E-2
31
32using namespace std;
33using namespace nnp;
34
35InterfaceLammps::InterfaceLammps() : myRank (0 ),
36 initialized (false),
37 showew (true ),
38 resetew (false),
39 showewsum (0 ),
40 maxew (0 ),
41 cflength (1.0 ),
42 cfenergy (1.0 )
43
44{
45}
46
47void InterfaceLammps::initialize(char const* const& directory,
48 char const* const& emap,
49 bool showew,
50 bool resetew,
51 int showewsum,
52 int maxew,
53 double cflength,
54 double cfenergy,
55 double lammpsCutoff,
56 int lammpsNtypes,
57 int myRank)
58{
59 this->emap = emap;
60 this->showew = showew;
61 this->resetew = resetew;
62 this->showewsum = showewsum;
63 this->maxew = maxew;
64 this->cflength = cflength;
65 this->cfenergy = cfenergy;
66 this->myRank = myRank;
67 log.writeToStdout = false;
68 string dir(directory);
69 char const separator = '/';
70 if (dir.back() != separator) dir += separator;
72 loadSettingsFile(dir + "input.nn");
74 setupSymmetryFunctionScaling(dir + "scaling.data");
75 bool collectStatistics = false;
76 bool collectExtrapolationWarnings = false;
77 bool writeExtrapolationWarnings = false;
78 bool stopOnExtrapolationWarnings = false;
79 if (showew == true || showewsum > 0 || maxew >= 0)
80 {
81 collectExtrapolationWarnings = true;
82 }
83 setupSymmetryFunctionStatistics(collectStatistics,
84 collectExtrapolationWarnings,
86 stopOnExtrapolationWarnings);
87 setupNeuralNetworkWeights(dir + "weights.%03d.data");
88
89 log << "\n";
90 log << "*** SETUP: LAMMPS INTERFACE *************"
91 "**************************************\n";
92 log << "\n";
93
94 if (showew)
95 {
96 log << "Individual extrapolation warnings will be shown.\n";
97 }
98 else
99 {
100 log << "Individual extrapolation warnings will not be shown.\n";
101 }
102
103 if (showewsum != 0)
104 {
105 log << strpr("Extrapolation warning summary will be shown every %d"
106 " timesteps.\n", showewsum);
107 }
108 else
109 {
110 log << "Extrapolation warning summary will not be shown.\n";
111 }
112
113 if (maxew != 0)
114 {
115 log << strpr("The simulation will be stopped when %d extrapolation"
116 " warnings are exceeded.\n", maxew);
117 }
118 else
119 {
120 log << "No extrapolation warning limit set.\n";
121 }
122
123 if (resetew)
124 {
125 log << "Extrapolation warning counter is reset every time step.\n";
126 }
127 else
128 {
129 log << "Extrapolation warnings are accumulated over all time steps.\n";
130 }
131
132 log << "-----------------------------------------"
133 "--------------------------------------\n";
134 log << "CAUTION: If the LAMMPS unit system differs from the one used\n";
135 log << " during NN training, appropriate conversion factors\n";
136 log << " must be provided (see keywords cflength and cfenergy).\n";
137 log << "\n";
138 log << strpr("Length unit conversion factor: %24.16E\n", cflength);
139 log << strpr("Energy unit conversion factor: %24.16E\n", cfenergy);
140 double sfCutoff = getMaxCutoffRadius();
141 log << "\n";
142 log << "Checking consistency of cutoff radii (in LAMMPS units):\n";
143 log << strpr("LAMMPS Cutoff (via pair_coeff) : %11.3E\n", lammpsCutoff);
144 log << strpr("Maximum symmetry function cutoff: %11.3E\n", sfCutoff);
145 if (lammpsCutoff < sfCutoff)
146 {
147 throw runtime_error("ERROR: LAMMPS cutoff via pair_coeff keyword is"
148 " smaller than maximum symmetry function"
149 " cutoff.\n");
150 }
151 else if (fabs(sfCutoff - lammpsCutoff) / lammpsCutoff > TOLCUTOFF)
152 {
153 log << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
154 log << "WARNING: Potential length units mismatch!\n";
155 log << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
156 }
157 else
158 {
159 log << "Cutoff radii are consistent.\n";
160 }
161
162 log << "-----------------------------------------"
163 "--------------------------------------\n";
164 log << "Element mapping string from LAMMPS to n2p2: \""
165 + this->emap + "\"\n";
166 // Create default element mapping.
167 if (this->emap == "")
168 {
169 if (elementMap.size() != (size_t)lammpsNtypes)
170 {
171 throw runtime_error(strpr("ERROR: No element mapping given and "
172 "number of LAMMPS atom types (%d) and "
173 "NNP elements (%zu) does not match.\n",
174 lammpsNtypes, elementMap.size()));
175 }
176 log << "Element mapping string empty, creating default mapping.\n";
177 for (int i = 0; i < lammpsNtypes; ++i)
178 {
179 mapTypeToElement[i + 1] = i;
180 mapElementToType[i] = i + 1;
181 }
182 }
183 // Read element mapping from pair_style argument.
184 else
185 {
186 vector<string> emapSplit = split(reduce(trim(this->emap), " \t", ""),
187 ',');
188 if (elementMap.size() < emapSplit.size())
189 {
190 throw runtime_error(strpr("ERROR: Element mapping is inconsistent,"
191 " NNP elements: %zu,"
192 " emap elements: %zu.\n",
194 emapSplit.size()));
195 }
196 for (string s : emapSplit)
197 {
198 vector<string> typeString = split(s, ':');
199 if (typeString.size() != 2)
200 {
201 throw runtime_error(strpr("ERROR: Invalid element mapping "
202 "string: \"%s\".\n", s.c_str()));
203 }
204 int t = stoi(typeString.at(0));
205 if (t > lammpsNtypes)
206 {
207 throw runtime_error(strpr("ERROR: LAMMPS type \"%d\" not "
208 "present, there are only %d types "
209 "defined.\n", t, lammpsNtypes));
210 }
211 size_t e = elementMap[typeString.at(1)];
212 mapTypeToElement[t] = e;
213 mapElementToType[e] = t;
214 }
215 }
216 log << "\n";
217 log << "CAUTION: Please ensure that this mapping between LAMMPS\n";
218 log << " atom types and NNP elements is consistent:\n";
219 log << "\n";
220 log << "---------------------------\n";
221 log << "LAMMPS type | NNP element\n";
222 log << "---------------------------\n";
223 for (int i = 1; i <= lammpsNtypes; ++i)
224 {
225 if (mapTypeToElement.find(i) != mapTypeToElement.end())
226 {
227 size_t e = mapTypeToElement.at(i);
228 log << strpr("%11d <-> %2s (%3zu)\n",
229 i,
230 elementMap[e].c_str(),
232 ignoreType[i] = false;
233 }
234 else
235 {
236 log << strpr("%11d <-> --\n", i);
237 ignoreType[i] = true;
238
239 }
240 }
241 log << "---------------------------\n";
242 log << "\n";
243 log << "NNP setup for LAMMPS completed.\n";
244
245 log << "*****************************************"
246 "**************************************\n";
247
249
250 initialized = true;
251}
252
253void InterfaceLammps::setLocalAtoms(int numAtomsLocal,
254 int const* const atomType)
255{
256 for (size_t i = 0; i < numElements; ++i)
257 {
259 }
265 structure.energy = 0.0;
266 structure.atoms.clear();
267 indexMap.clear();
268 indexMap.resize(numAtomsLocal, numeric_limits<size_t>::max());
269 for (int i = 0; i < numAtomsLocal; i++)
270 {
271 if (ignoreType[atomType[i]]) continue;
274 structure.atoms.push_back(Atom());
275 Atom& a = structure.atoms.back();
276 a.index = i;
278 a.element = mapTypeToElement[atomType[i]];
279 a.numNeighbors = 0;
280 a.hasSymmetryFunctions = false;
282 a.neighbors.clear();
283 a.numNeighborsPerElement.clear();
286 }
287
288 return;
289}
290
291void InterfaceLammps::setLocalTags(int const* const atomTag)
292{
293 for (size_t i = 0; i < structure.atoms.size(); i++)
294 {
295 // Implicit conversion from int to int64_t!
296 structure.atoms.at(i).tag = atomTag[i];
297 }
298
299 return;
300}
301
302void InterfaceLammps::setLocalTags(int64_t const* const atomTag)
303{
304 for (size_t i = 0; i < structure.atoms.size(); i++)
305 {
306 structure.atoms.at(i).tag = atomTag[i];
307 }
308
309 return;
310}
311
313 int j,
314 int64_t tag,
315 int type,
316 double dx,
317 double dy,
318 double dz,
319 double d2)
320{
321 if (ignoreType[type] ||
322 indexMap.at(i) == numeric_limits<size_t>::max()) return;
323 Atom& a = structure.atoms[indexMap.at(i)];
324 a.numNeighbors++;
325 a.neighbors.push_back(Atom::Neighbor());
327 Atom::Neighbor& n = a.neighbors.back();
328 n.index = j;
329 n.tag = tag;
330 n.element = mapTypeToElement[type];
331 n.dr[0] = dx * cflength;
332 n.dr[1] = dy * cflength;
333 n.dr[2] = dz * cflength;
334 n.d = sqrt(d2) * cflength;
335 if (normalize)
336 {
337 n.dr[0] *= convLength;
338 n.dr[1] *= convLength;
339 n.dr[2] *= convLength;
340 n.d *= convLength;
341 }
342
343 return;
344}
345
347{
348#ifdef N2P2_NO_SF_GROUPS
350#else
352#endif
355 if (normalize)
356 {
358 }
360
361 return;
362}
363
365{
367 else return maxCutoffRadius / cflength;
368}
369
371{
372 return structure.energy / cfenergy;
373}
374
375double InterfaceLammps::getAtomicEnergy(int index) const
376{
377 Atom const& a = structure.atoms.at(index);
378 Element const& e = elements.at(a.element);
379
380 if (normalize)
381 {
382 return (physical("energy", a.energy)
383 + meanEnergy
385 }
386 else
387 {
388 return (a.energy + e.getAtomicEnergyOffset()) / cfenergy;
389 }
390}
391
392void InterfaceLammps::getForces(double* const* const& atomF) const
393{
394 double const cfforce = cflength / cfenergy;
395 double convForce = 1.0;
396 if (normalize)
397 {
398 convForce = convLength / convEnergy;
399 }
400
401 // Loop over all local atoms. Neural network and Symmetry function
402 // derivatives are saved in the dEdG arrays of atoms and dGdr arrays of
403 // atoms and their neighbors. These are now summed up to the force
404 // contributions of local and ghost atoms.
405 Atom const* a = NULL;
406
407 for (size_t i = 0; i < structure.atoms.size(); ++i)
408 {
409 // Set pointer to atom.
410 a = &(structure.atoms.at(i));
411
412#ifndef N2P2_FULL_SFD_MEMORY
413 vector<vector<size_t> > const& tableFull
414 = elements.at(a->element).getSymmetryFunctionTable();
415#endif
416 // Loop over all neighbor atoms. Some are local, some are ghost atoms.
417 for (vector<Atom::Neighbor>::const_iterator n = a->neighbors.begin();
418 n != a->neighbors.end(); ++n)
419 {
420 // Temporarily save the neighbor index. Note: this is the index for
421 // the LAMMPS force array.
422 size_t const in = n->index;
423 // Now loop over all symmetry functions and add force contributions
424 // (local + ghost atoms).
425#ifndef N2P2_FULL_SFD_MEMORY
426 vector<size_t> const& table = tableFull.at(n->element);
427 for (size_t s = 0; s < n->dGdr.size(); ++s)
428 {
429 double const dEdG = a->dEdG[table.at(s)] * cfforce * convForce;
430#else
431 for (size_t s = 0; s < a->numSymmetryFunctions; ++s)
432 {
433 double const dEdG = a->dEdG[s] * cfforce * convForce;
434#endif
435 double const* const dGdr = n->dGdr[s].r;
436 atomF[in][0] -= dEdG * dGdr[0];
437 atomF[in][1] -= dEdG * dGdr[1];
438 atomF[in][2] -= dEdG * dGdr[2];
439 }
440 }
441 // Temporarily save the atom index. Note: this is the index for
442 // the LAMMPS force array.
443 size_t const ia = a->index;
444 // Loop over all symmetry functions and add force contributions (local
445 // atoms).
446 for (size_t s = 0; s < a->numSymmetryFunctions; ++s)
447 {
448 double const dEdG = a->dEdG[s] * cfforce * convForce;
449 double const* const dGdr = a->dGdr[s].r;
450 atomF[ia][0] -= dEdG * dGdr[0];
451 atomF[ia][1] -= dEdG * dGdr[1];
452 atomF[ia][2] -= dEdG * dGdr[2];
453 }
454 }
455
456 return;
457}
458
460{
461 long bs = 0;
462#ifndef N2P2_NO_MPI
463 int ss = 0; // size_t size.
464 int ds = 0; // double size.
465 int cs = 0; // char size.
466 MPI_Pack_size(1, MPI_SIZE_T, MPI_COMM_WORLD, &ss);
467 MPI_Pack_size(1, MPI_DOUBLE, MPI_COMM_WORLD, &ds);
468 MPI_Pack_size(1, MPI_CHAR , MPI_COMM_WORLD, &cs);
469
470 for (vector<Element>::const_iterator it = elements.begin();
471 it != elements.end(); ++it)
472 {
473 map<size_t, SymFncStatistics::Container> const& m
474 = it->statistics.data;
475 bs += ss; // n.
476 for (map<size_t, SymFncStatistics::Container>::const_iterator
477 it2 = m.begin(); it2 != m.end(); ++it2)
478 {
479 bs += ss; // index (it2->first).
480 bs += ss; // countEW (it2->second.countEW).
481 bs += ss; // type (it2->second.type).
482 bs += ds; // Gmin (it2->second.Gmin).
483 bs += ds; // Gmax (it2->second.Gmax).
484 bs += ss; // element.length() (it2->second.element.length()).
485 bs += (it2->second.element.length() + 1) * cs; // element.
486 size_t countEW = it2->second.countEW;
487 bs += countEW * ss; // indexStructureEW.
488 bs += countEW * ss; // indexAtomEW.
489 bs += countEW * ds; // valueEW.
490 }
491 }
492#endif
493 return bs;
494}
495
496void InterfaceLammps::fillEWBuffer(char* const& buf, int bs) const
497{
498#ifndef N2P2_NO_MPI
499 int p = 0;
500 for (vector<Element>::const_iterator it = elements.begin();
501 it != elements.end(); ++it)
502 {
503 map<size_t, SymFncStatistics::Container> const& m =
504 it->statistics.data;
505 size_t n = m.size();
506 MPI_Pack((void *) &(n), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
507 for (map<size_t, SymFncStatistics::Container>::const_iterator
508 it2 = m.begin(); it2 != m.end(); ++it2)
509 {
510 MPI_Pack((void *) &(it2->first ), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
511 size_t countEW = it2->second.countEW;
512 MPI_Pack((void *) &(countEW ), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
513 MPI_Pack((void *) &(it2->second.type ), 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
514 MPI_Pack((void *) &(it2->second.Gmin ), 1, MPI_DOUBLE, buf, bs, &p, MPI_COMM_WORLD);
515 MPI_Pack((void *) &(it2->second.Gmax ), 1, MPI_DOUBLE, buf, bs, &p, MPI_COMM_WORLD);
516 // it2->element
517 size_t ts = it2->second.element.length() + 1;
518 MPI_Pack((void *) &ts , 1, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
519 MPI_Pack((void *) it2->second.element.c_str() , ts, MPI_CHAR , buf, bs, &p, MPI_COMM_WORLD);
520 MPI_Pack((void *) &(it2->second.indexStructureEW.front()), countEW, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
521 MPI_Pack((void *) &(it2->second.indexAtomEW.front() ), countEW, MPI_SIZE_T, buf, bs, &p, MPI_COMM_WORLD);
522 MPI_Pack((void *) &(it2->second.valueEW.front() ), countEW, MPI_DOUBLE, buf, bs, &p, MPI_COMM_WORLD);
523 }
524 }
525#endif
526 return;
527}
528
529void InterfaceLammps::extractEWBuffer(char const* const& buf, int bs)
530{
531#ifndef N2P2_NO_MPI
532 int p = 0;
533 for (vector<Element>::iterator it = elements.begin();
534 it != elements.end(); ++it)
535 {
536 size_t n = 0;
537 MPI_Unpack((void *) buf, bs, &p, &(n), 1, MPI_SIZE_T, MPI_COMM_WORLD);
538 for (size_t i = 0; i < n; ++i)
539 {
540 size_t index = 0;
541 MPI_Unpack((void *) buf, bs, &p, &(index), 1, MPI_SIZE_T, MPI_COMM_WORLD);
542 SymFncStatistics::Container& d = it->statistics.data[index];
543 size_t countEW = 0;
544 MPI_Unpack((void *) buf, bs, &p, &(countEW ), 1, MPI_SIZE_T, MPI_COMM_WORLD);
545 MPI_Unpack((void *) buf, bs, &p, &(d.type ), 1, MPI_SIZE_T, MPI_COMM_WORLD);
546 MPI_Unpack((void *) buf, bs, &p, &(d.Gmin ), 1, MPI_DOUBLE, MPI_COMM_WORLD);
547 MPI_Unpack((void *) buf, bs, &p, &(d.Gmax ), 1, MPI_DOUBLE, MPI_COMM_WORLD);
548 // d.element
549 size_t ts = 0;
550 MPI_Unpack((void *) buf, bs, &p, &ts , 1, MPI_SIZE_T, MPI_COMM_WORLD);
551 char* element = new char[ts];
552 MPI_Unpack((void *) buf, bs, &p, element , ts, MPI_CHAR , MPI_COMM_WORLD);
553 d.element = element;
554 delete[] element;
555 // indexStructureEW.
556 d.indexStructureEW.resize(d.countEW + countEW);
557 MPI_Unpack((void *) buf, bs, &p, &(d.indexStructureEW[d.countEW]), countEW, MPI_SIZE_T, MPI_COMM_WORLD);
558 // indexAtomEW.
559 d.indexAtomEW.resize(d.countEW + countEW);
560 MPI_Unpack((void *) buf, bs, &p, &(d.indexAtomEW[d.countEW] ), countEW, MPI_SIZE_T, MPI_COMM_WORLD);
561 // valueEW.
562 d.valueEW.resize(d.countEW + countEW);
563 MPI_Unpack((void *) buf, bs, &p, &(d.valueEW[d.countEW] ), countEW, MPI_DOUBLE, MPI_COMM_WORLD);
564
565 d.countEW += countEW;
566 }
567 }
568#endif
569 return;
570}
571
573{
574 for (vector<Element>::const_iterator it = elements.begin();
575 it != elements.end(); ++it)
576 {
577 vector<string> vs = it->statistics.getExtrapolationWarningLines();
578 for (vector<string>::const_iterator it2 = vs.begin();
579 it2 != vs.end(); ++it2)
580 {
581 log << (*it2);
582 }
583 }
584
585 return;
586}
587
589{
590 for (vector<Element>::iterator it = elements.begin();
591 it != elements.end(); ++it)
592 {
593 it->statistics.clear();
594 }
595
596 return;
597}
#define TOLCUTOFF
std::size_t size() const
Get element map size.
Definition: ElementMap.h:140
std::size_t atomicNumber(std::size_t index) const
Get atomic number from element index.
Definition: ElementMap.h:145
Contains element-specific data.
Definition: Element.h:39
double getAtomicEnergyOffset() const
Get atomicEnergyOffset.
Definition: Element.h:280
Structure structure
Structure containing local atoms.
long getEWBufferSize() const
Calculate buffer size for extrapolation warning communication.
bool initialized
Initialization state.
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.
std::map< int, bool > ignoreType
True if atoms of this LAMMPS type will be ignored.
void setLocalTags(int const *const atomTag)
Set atom tags (int version, -DLAMMPS_SMALLBIG).
std::map< int, std::size_t > mapTypeToElement
Map from LAMMPS type to n2p2 element index.
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.
bool resetew
Corresponds to LAMMPS resetew keyword.
void writeExtrapolationWarnings()
Write extrapolation warnings to log.
std::vector< size_t > indexMap
Map from LAMMPS index to n2p2 atom index.
double cfenergy
Corresponds to LAMMPS cfenergy keyword.
void setLocalAtoms(int numAtomsLocal, int const *const atomType)
(Re)set structure to contain only local LAMMPS atoms.
bool showew
Corresponds to LAMMPS showew keyword.
int showewsum
Corresponds to LAMMPS showewsum keyword.
void clearExtrapolationWarnings()
Clear extrapolation warnings storage.
std::map< std::size_t, int > mapElementToType
Map from n2p2 element index to LAMMPS type.
int myRank
Process rank.
double getMaxCutoffRadius() const
Get largest cutoff.
int maxew
Corresponds to LAMMPS maxew keyword.
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).
double cflength
Corresponds to LAMMPS cflength keyword.
std::string emap
Corresponds to LAMMPS map keyword.
bool writeToStdout
Turn on/off output to stdout.
Definition: Log.h:85
double physicalEnergy(Structure const &structure, bool ref=true) const
Undo normalization for a given energy of structure.
Definition: Mode.cpp:1557
bool normalize
Definition: Mode.h:514
double convEnergy
Definition: Mode.h:523
ElementMap elementMap
Global element map, populated by setupElementMap().
Definition: Mode.h:508
void addEnergyOffset(Structure &structure, bool ref=true)
Add atomic energy offsets to reference energy.
Definition: Mode.cpp:1461
void initialize()
Write welcome message with version information.
Definition: Mode.cpp:50
double convLength
Definition: Mode.h:524
double maxCutoffRadius
Definition: Mode.h:520
double meanEnergy
Definition: Mode.h:522
double physical(std::string const &property, double value) const
Undo normalization for a given property.
Definition: Mode.cpp:1549
std::vector< Element > elements
Definition: Mode.h:528
std::size_t numElements
Definition: Mode.h:517
void calculateAtomicNeuralNetworks(Structure &structure, bool const derivatives)
Calculate a single atomic neural network for a given atom and nn type.
Definition: Mode.cpp:1310
virtual void setupNeuralNetworkWeights(std::string const &fileNameFormatShort="weights.%03zu.data", std::string const &fileNameFormatCharge="weightse.%03zu.data")
Set up neural network weights from files.
Definition: Mode.cpp:1126
void calculateEnergy(Structure &structure) const
Calculate potential energy for a given structure.
Definition: Mode.cpp:1366
void calculateSymmetryFunctionGroups(Structure &structure, bool const derivatives)
Calculate all symmetry function groups for all atoms in given structure.
Definition: Mode.cpp:1230
virtual void setupSymmetryFunctionScaling(std::string const &fileName="scaling.data")
Set up symmetry function scaling from file.
Definition: Mode.cpp:532
Log log
Global log file.
Definition: Mode.h:510
void setupGeneric(bool skipNormalize=false)
Combine multiple setup routines and provide a basic NNP setup.
Definition: Mode.cpp:197
void calculateSymmetryFunctions(Structure &structure, bool const derivatives)
Calculate all symmetry functions for all atoms in given structure.
Definition: Mode.cpp:1150
void setupSymmetryFunctionStatistics(bool collectStatistics, bool collectExtrapolationWarnings, bool writeExtrapolationWarnings, bool stopOnExtrapolationWarnings)
Set up symmetry function statistics collection.
Definition: Mode.cpp:923
void loadSettingsFile(std::string const &fileName="input.nn")
Open settings file and load all keywords into memory.
Definition: Mode.cpp:156
#define MPI_SIZE_T
Definition: mpi-extra.h:22
Definition: Atom.h:28
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90
string trim(string const &line, string const &whitespace)
Remove leading and trailing whitespaces from string.
Definition: utility.cpp:47
vector< string > split(string const &input, char delimiter)
Split string at each delimiter.
Definition: utility.cpp:33
string reduce(string const &line, string const &whitespace, string const &fill)
Replace multiple whitespaces with fill.
Definition: utility.cpp:60
size_t p
Definition: nnp-cutoff.cpp:33
double d
Definition: nnp-cutoff.cpp:34
Struct to store information on neighbor atoms.
Definition: Atom.h:35
std::size_t index
Index of neighbor atom.
Definition: Atom.h:37
std::size_t element
Element index of neighbor atom.
Definition: Atom.h:41
double d
Distance to neighbor atom.
Definition: Atom.h:43
Vec3D dr
Distance vector to neighbor atom.
Definition: Atom.h:45
int64_t tag
Tag of neighbor atom.
Definition: Atom.h:39
Storage for a single atom.
Definition: Atom.h:32
std::vector< Neighbor > neighbors
Neighbor array (maximum number defined in macros.h.
Definition: Atom.h:148
std::size_t numSymmetryFunctions
Number of symmetry functions used to describe the atom environment.
Definition: Atom.h:110
std::vector< double > dEdG
Derivative of atomic energy with respect to symmetry functions.
Definition: Atom.h:136
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for this atom.
Definition: Atom.h:94
std::size_t index
Index number of this atom.
Definition: Atom.h:98
std::vector< Vec3D > dGdr
Derivative of symmetry functions with respect to this atom's coordinates.
Definition: Atom.h:146
std::size_t indexStructure
Index number of structure this atom belongs to.
Definition: Atom.h:100
std::size_t element
Element index of this atom.
Definition: Atom.h:104
bool hasSymmetryFunctions
If symmetry function values are saved for this atom.
Definition: Atom.h:92
double energy
Atomic energy determined by neural network.
Definition: Atom.h:112
std::vector< std::size_t > numNeighborsPerElement
Number of neighbors per element.
Definition: Atom.h:126
std::size_t numNeighbors
Total number of neighbors.
Definition: Atom.h:106
std::vector< std::size_t > numAtomsPerElement
Number of atoms of each element in this structure.
Definition: Structure.h:94
void setElementMap(ElementMap const &elementMap)
Set element map of structure.
Definition: Structure.cpp:60
std::size_t index
Index number of this structure.
Definition: Structure.h:66
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for each atom.
Definition: Structure.h:64
double energy
Potential energy determined by neural network.
Definition: Structure.h:76
std::size_t numAtoms
Total number of atoms present in this structure.
Definition: Structure.h:68
std::vector< Atom > atoms
Vector of all atoms in this structure.
Definition: Structure.h:96
bool hasNeighborList
If the neighbor list has been calculated.
Definition: Structure.h:60
bool hasSymmetryFunctions
If symmetry function values are saved for each atom.
Definition: Structure.h:62
Struct containing statistics gathered during symmetry function calculation.