27Atom::Atom() : hasNeighborList (false),
28 hasSymmetryFunctions (false),
29 hasSymmetryFunctionDerivatives(false),
30 useChargeNeuron (false),
36 numNeighborsUnique (0 ),
37 numSymmetryFunctions (0 ),
44#ifdef N2P2_FULL_SFD_MEMORY
45void Atom::collectDGdxia(
size_t indexAtom,
size_t indexComponent)
47 for (
size_t i = 0; i < dGdxia.size(); i++)
57 dGdxia[j] +=
neighbors[i].dGdr[j][indexComponent];
61 if (
index == indexAtom)
65 dGdxia[i] +=
dGdr[i][indexComponent];
77 f *= convEnergy / convLength;
78 fRef *= convEnergy / convLength;
83 dEdG.at(i) *= convEnergy;
84 dGdr.at(i) /= convLength;
85#ifdef N2P2_FULL_SFD_MEMORY
86 dGdxia.at(i) /= convLength;
95 for (vector<Neighbor>::iterator it =
neighbors.begin();
102 for (
size_t i = 0; i <
dGdr.size(); ++i)
104 dGdr.at(i) /= convLength;
117 f /= convEnergy / convLength;
118 fRef /= convEnergy / convLength;
123 dEdG.at(i) /= convEnergy;
124 dGdr.at(i) *= convLength;
125#ifdef N2P2_FULL_SFD_MEMORY
126 dGdxia.at(i) *= convLength;
135 for (vector<Neighbor>::iterator it =
neighbors.begin();
139 it->dr /= convLength;
142 for (
size_t i = 0; i <
dGdr.size(); ++i)
144 dGdr.at(i) *= convLength;
157 throw range_error(
"ERROR: Number of symmetry functions set to"
158 "zero, cannot allocate.\n");
165#ifdef N2P2_FULL_SFD_MEMORY
169 for (vector<Neighbor>::iterator it =
neighbors.begin();
172#ifndef N2P2_NO_SF_CACHE
186#ifndef N2P2_FULL_SFD_MEMORY
189 throw range_error(
"ERROR: Number of symmetry function derivatives"
190 " unset, cannot allocate.\n");
196#ifdef N2P2_FULL_SFD_MEMORY
201 for (vector<Neighbor>::iterator it =
neighbors.begin();
204#ifndef N2P2_NO_SF_CACHE
206 -numeric_limits<double>::max());
210#ifndef N2P2_FULL_SFD_MEMORY
226 vector<double>(
G).swap(
G);
228#ifndef N2P2_NO_SF_CACHE
229 for (vector<Neighbor>::iterator it =
neighbors.begin();
233 vector<double>(it->cache).swap(it->cache);
242#ifdef N2P2_FULL_SFD_MEMORY
244 vector<double>(dGdxia).swap(dGdxia);
248 for (vector<Neighbor>::iterator it =
neighbors.begin();
252 vector<Vec3D>(it->dGdr).swap(it->dGdr);
283 size_t numNeighborsLocal = 0;
285 for (vector<Neighbor>::const_iterator it =
neighbors.begin();
288 if (it->d <= cutoffRadius)
294 return numNeighborsLocal;
298 map<string, double>& error,
301 if (property ==
"force")
304 error.at(
"RMSE") += (
fRef -
f).norm2();
305 error.at(
"MAE") += (
fRef -
f).l1norm();
307 else if (property ==
"charge")
315 throw runtime_error(
"ERROR: Unknown property for error update.\n");
324 for (
size_t i = 0; i < 3; ++i)
326 v.push_back(
strpr(
"%10zu %10zu %16.8E %16.8E\n",
338 return strpr(
"%10zu %10zu %16.8E %16.8E\n",
349 v.push_back(
strpr(
"********************************\n"));
350 v.push_back(
strpr(
"ATOM \n"));
351 v.push_back(
strpr(
"********************************\n"));
358 v.push_back(
strpr(
"tag : %" PRId64
"\n",
tag));
366 v.push_back(
strpr(
"r : %16.8E %16.8E %16.8E\n",
r[0],
r[1],
r[2]));
367 v.push_back(
strpr(
"f : %16.8E %16.8E %16.8E\n",
f[0],
f[1],
f[2]));
369 v.push_back(
strpr(
"--------------------------------\n"));
371 v.push_back(
strpr(
"--------------------------------\n"));
376 v.push_back(
strpr(
"--------------------------------\n"));
377 v.push_back(
strpr(
"--------------------------------\n"));
379 v.push_back(
strpr(
"--------------------------------\n"));
384 v.push_back(
strpr(
"--------------------------------\n"));
385 v.push_back(
strpr(
"--------------------------------\n"));
387 v.push_back(
strpr(
"--------------------------------\n"));
392#ifndef N2P2_NO_SF_CACHE
393 v.push_back(
strpr(
"--------------------------------\n"));
394 v.push_back(
strpr(
"--------------------------------\n"));
396 v.push_back(
strpr(
"--------------------------------\n"));
402 v.push_back(
strpr(
"--------------------------------\n"));
403 v.push_back(
strpr(
"--------------------------------\n"));
404 v.push_back(
strpr(
"G [*] : %d\n",
G.size()));
405 v.push_back(
strpr(
"--------------------------------\n"));
406 for (
size_t i = 0; i <
G.size(); ++i)
408 v.push_back(
strpr(
"%29d : %16.8E\n", i,
G.at(i)));
410 v.push_back(
strpr(
"--------------------------------\n"));
411 v.push_back(
strpr(
"--------------------------------\n"));
412 v.push_back(
strpr(
"dEdG [*] : %d\n",
dEdG.size()));
413 v.push_back(
strpr(
"--------------------------------\n"));
414 for (
size_t i = 0; i <
dEdG.size(); ++i)
416 v.push_back(
strpr(
"%29d : %16.8E\n", i,
dEdG.at(i)));
418 v.push_back(
strpr(
"--------------------------------\n"));
419 v.push_back(
strpr(
"--------------------------------\n"));
420 v.push_back(
strpr(
"dQdG [*] : %d\n",
dQdG.size()));
421 v.push_back(
strpr(
"--------------------------------\n"));
422 for (
size_t i = 0; i <
dQdG.size(); ++i)
424 v.push_back(
strpr(
"%29d : %16.8E\n", i,
dQdG.at(i)));
426 v.push_back(
strpr(
"--------------------------------\n"));
427#ifdef N2P2_FULL_SFD_MEMORY
428 v.push_back(
strpr(
"--------------------------------\n"));
429 v.push_back(
strpr(
"dGdxia [*] : %d\n", dGdxia.size()));
430 v.push_back(
strpr(
"--------------------------------\n"));
431 for (
size_t i = 0; i < dGdxia.size(); ++i)
433 v.push_back(
strpr(
"%29d : %16.8E\n", i, dGdxia.at(i)));
435 v.push_back(
strpr(
"--------------------------------\n"));
437 v.push_back(
strpr(
"--------------------------------\n"));
438 v.push_back(
strpr(
"dGdr [*] : %d\n",
dGdr.size()));
439 v.push_back(
strpr(
"--------------------------------\n"));
440 for (
size_t i = 0; i <
dGdr.size(); ++i)
442 v.push_back(
strpr(
"%29d : %16.8E %16.8E %16.8E\n", i,
dGdr.at(i)[0],
dGdr.at(i)[1],
dGdr.at(i)[2]));
444 v.push_back(
strpr(
"--------------------------------\n"));
445 v.push_back(
strpr(
"--------------------------------\n"));
447 v.push_back(
strpr(
"--------------------------------\n"));
448 for (
size_t i = 0; i <
neighbors.size(); ++i)
450 v.push_back(
strpr(
"%29d :\n", i));
452 v.insert(v.end(), vn.begin(), vn.end());
454 v.push_back(
strpr(
"--------------------------------\n"));
455 v.push_back(
strpr(
"********************************\n"));
470 if (
d != rhs.
d )
return false;
478 if (
d < rhs.
d )
return true;
479 else if (
d > rhs.
d )
return false;
487 v.push_back(
strpr(
"********************************\n"));
488 v.push_back(
strpr(
"NEIGHBOR \n"));
489 v.push_back(
strpr(
"********************************\n"));
491 v.push_back(
strpr(
"tag : %" PRId64
"\n",
tag));
493 v.push_back(
strpr(
"d : %16.8E\n",
d));
494 v.push_back(
strpr(
"dr : %16.8E %16.8E %16.8E\n", dr[0], dr[1], dr[2]));
495 v.push_back(
strpr(
"--------------------------------\n"));
496#ifndef N2P2_NO_SF_CACHE
497 v.push_back(
strpr(
"cache [*] : %d\n", cache.size()));
498 v.push_back(
strpr(
"--------------------------------\n"));
499 for (
size_t i = 0; i < cache.size(); ++i)
501 v.push_back(
strpr(
"%29d : %16.8E\n", i, cache.at(i)));
503 v.push_back(
strpr(
"--------------------------------\n"));
504 v.push_back(
strpr(
"--------------------------------\n"));
506 v.push_back(
strpr(
"dGdr [*] : %d\n",
dGdr.size()));
507 v.push_back(
strpr(
"--------------------------------\n"));
508 for (
size_t i = 0; i <
dGdr.size(); ++i)
510 v.push_back(
strpr(
"%29d : %16.8E %16.8E %16.8E\n", i,
dGdr.at(i)[0],
dGdr.at(i)[1],
dGdr.at(i)[2]));
512 v.push_back(
strpr(
"--------------------------------\n"));
513 v.push_back(
strpr(
"********************************\n"));
string strpr(const char *format,...)
String version of printf function.
Struct to store information on neighbor atoms.
Neighbor()
Neighbor constructor, initialize to zero.
std::size_t element
Element index of neighbor atom.
double d
Distance to neighbor atom.
bool operator==(Neighbor const &rhs) const
Overload == operator.
std::vector< std::string > info() const
Get atom information as a vector of strings.
bool operator<(Neighbor const &rhs) const
Overload < operator.
std::vector< Neighbor > neighbors
Neighbor array (maximum number defined in macros.h.
std::vector< std::string > info() const
Get atom information as a vector of strings.
std::size_t numSymmetryFunctions
Number of symmetry functions used to describe the atom environment.
Vec3D r
Cartesian coordinates.
std::vector< double > dEdG
Derivative of atomic energy with respect to symmetry functions.
Vec3D f
Force vector calculated by neural network.
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for this atom.
std::vector< double > dQdG
Derivative of atomic charge with respect to symmetry functions.
double charge
Atomic charge determined by neural network.
void allocate(bool all)
Allocate vectors related to symmetry functions (G, dEdG).
std::size_t index
Index number of this atom.
std::vector< std::size_t > numSymmetryFunctionDerivatives
Number of neighbor atom symmetry function derivatives per element.
Vec3D fRef
Reference force vector from data set.
bool useChargeNeuron
If an additional charge neuron in the short-range NN is present.
std::vector< Vec3D > dGdr
Derivative of symmetry functions with respect to this atom's coordinates.
void toPhysicalUnits(double convEnergy, double convLength)
Switch to physical length and energy units.
void clearNeighborList()
Clear neighbor list.
std::size_t indexStructure
Index number of structure this atom belongs to.
int64_t tag
Tag number of this atom.
std::size_t element
Element index of this atom.
bool hasSymmetryFunctions
If symmetry function values are saved for this atom.
void updateError(std::string const &property, std::map< std::string, double > &error, std::size_t &count) const
Update property error metrics with data from this atom.
std::vector< std::size_t > cacheSizePerElement
Cache size for each element.
void toNormalizedUnits(double convEnergy, double convLength)
Switch to normalized length and energy units.
bool hasNeighborList
If the neighbor list has been calculated for this atom.
double energy
Atomic energy determined by neural network.
std::vector< double > G
Symmetry function values.
std::vector< std::size_t > neighborsUnique
List of unique neighbor indices (don't count multiple PBC images).
double chargeRef
Atomic reference charge.
std::vector< std::size_t > numNeighborsPerElement
Number of neighbors per element.
std::vector< std::string > getForcesLines() const
Get reference and NN forces for this atoms.
std::string getChargeLine() const
Get reference and NN charge for this atoms.
std::size_t numNeighborsUnique
Number of unique neighbor indices (don't count multiple PBC images).
std::size_t getNumNeighbors(double cutoffRadius) const
Calculate number of neighbors for a given cutoff radius.
void free(bool all)
Free vectors related to symmetry functions, opposite of allocate().
std::size_t numNeighbors
Total number of neighbors.