n2p2 - A neural network potential package
nnp::Atom Struct Reference

Storage for a single atom. More...

#include <Atom.h>

Collaboration diagram for nnp::Atom:

Classes

struct  Neighbor
 Struct to store information on neighbor atoms. More...
 

Public Member Functions

 Atom ()
 Atom constructor, initialize to zero. More...
 
void toNormalizedUnits (double convEnergy, double convLength, double convCharge)
 Switch to normalized length, energy and charge units. More...
 
void toPhysicalUnits (double convEnergy, double convLength, double convCharge)
 Switch to physical length, energy and charge units. More...
 
void allocate (bool all, double const maxCutoffRadius=0.0)
 Allocate vectors related to symmetry functions (G, dEdG). More...
 
void free (bool all, double const maxCutoffRadius=0.0)
 Free vectors related to symmetry functions, opposite of allocate(). More...
 
void clearNeighborList ()
 Clear neighbor list. More...
 
void clearNeighborList (std::size_t const numElements)
 Clear neighbor list and change number of elements. More...
 
std::size_t calculateNumNeighbors (double const cutoffRadius) const
 Calculate number of neighbors for a given cutoff radius. More...
 
std::size_t getStoredMinNumNeighbors (double const cutoffRadius) const
 Return needed number of neighbors for a given cutoff radius from neighborCutoffs map. More...
 
bool isNeighbor (std::size_t index) const
 Return whether atom is a neighbor. More...
 
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. More...
 
Vec3D calculateSelfForceShort () const
 Calculate force resulting from gradient of this atom's (short-ranged) energy contribution with respect to this atom's coordinate. More...
 
Vec3D calculatePairForceShort (Neighbor const &neighbor, std::vector< std::vector< std::size_t > > const *const tableFull=nullptr) const
 Calculate force resulting from gradient of this atom's (short-ranged) energy contribution with respect to neighbor's coordinate. More...
 
Vec3D calculateDChidr (size_t const atomIndexOfR, double const maxCutoffRadius, std::vector< std::vector< size_t > > const *const tableFull=nullptr) const
 Calculate dChi/dr of this atom's Chi with respect to the coordinates of the given atom. More...
 
std::vector< std::string > getForcesLines () const
 Get reference and NN forces for this atoms. More...
 
std::string getChargeLine () const
 Get reference and NN charge for this atoms. More...
 
std::vector< std::string > info () const
 Get atom information as a vector of strings. More...
 

Public Attributes

bool hasNeighborList
 If the neighbor list has been calculated for this atom. More...
 
bool NeighborListIsSorted
 If the neighbor list is sorted by distance. More...
 
bool hasSymmetryFunctions
 If symmetry function values are saved for this atom. More...
 
bool hasSymmetryFunctionDerivatives
 If symmetry function derivatives are saved for this atom. More...
 
bool useChargeNeuron
 If an additional charge neuron in the short-range NN is present. More...
 
std::size_t index
 Index number of this atom. More...
 
std::size_t indexStructure
 Index number of structure this atom belongs to. More...
 
int64_t tag
 Tag number of this atom. More...
 
std::size_t element
 Element index of this atom. More...
 
std::size_t numNeighbors
 Total number of neighbors. More...
 
std::size_t numNeighborsUnique
 Number of unique neighbor indices (don't count multiple PBC images). More...
 
std::size_t numSymmetryFunctions
 Number of symmetry functions used to describe the atom environment. More...
 
double energy
 Atomic energy determined by neural network. More...
 
double dEelecdQ
 Derivative of electrostatic energy with respect to this atom's charge. More...
 
double chi
 Atomic electronegativity determined by neural network. More...
 
double charge
 Atomic charge determined by neural network. More...
 
double chargeRef
 Atomic reference charge. More...
 
Vec3D r
 Cartesian coordinates. More...
 
Vec3D f
 Force vector calculated by neural network. More...
 
Vec3D fElec
 Force vector resulting from electrostatics. More...
 
Vec3D fRef
 Reference force vector from data set. More...
 
Vec3D pEelecpr
 Partial derivative of electrostatic energy with respect to this atom's coordinates. More...
 
std::vector< std::size_t > neighborsUnique
 List of unique neighbor indices (don't count multiple PBC images). More...
 
std::vector< std::size_t > numNeighborsPerElement
 Number of neighbors per element. More...
 
std::vector< std::size_t > numSymmetryFunctionDerivatives
 Number of neighbor atom symmetry function derivatives per element. More...
 
std::vector< std::size_t > cacheSizePerElement
 Cache size for each element. More...
 
std::vector< double > G
 Symmetry function values. More...
 
std::vector< double > dEdG
 Derivative of atomic energy with respect to symmetry functions. More...
 
std::vector< double > dQdG
 Derivative of atomic charge with respect to symmetry functions. More...
 
std::vector< double > dChidG
 Derivative of electronegativity with respect to symmetry functions. More...
 
std::vector< Vec3DdGdr
 Derivative of symmetry functions with respect to this atom's coordinates. More...
 
std::vector< Vec3DdQdr
 Derivative of charges with respect to this atom's coordinates. More...
 
std::vector< Vec3DdAdrQ
 If dQdr has been calculated for respective components. More...
 
std::vector< Neighborneighbors
 Neighbor array (maximum number defined in macros.h. More...
 
std::unordered_map< double, size_t > neighborCutoffs
 Map stores number of neighbors needed for the corresponding cut-off. More...
 

Detailed Description

Storage for a single atom.

Definition at line 32 of file Atom.h.

Constructor & Destructor Documentation

◆ Atom()

Atom::Atom ( )

Atom constructor, initialize to zero.

Definition at line 27 of file Atom.cpp.

27 : hasNeighborList (false),
31 useChargeNeuron (false),
32 index (0 ),
33 indexStructure (0 ),
34 tag (0 ),
35 element (0 ),
36 numNeighbors (0 ),
39 energy (0.0 ),
40 dEelecdQ (0.0 ),
41 chi (0.0 ),
42 charge (0.0 ),
43 chargeRef (0.0 )
44{
45}
std::size_t numSymmetryFunctions
Number of symmetry functions used to describe the atom environment.
Definition: Atom.h:113
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for this atom.
Definition: Atom.h:97
double charge
Atomic charge determined by neural network.
Definition: Atom.h:121
std::size_t index
Index number of this atom.
Definition: Atom.h:101
bool useChargeNeuron
If an additional charge neuron in the short-range NN is present.
Definition: Atom.h:99
bool NeighborListIsSorted
If the neighbor list is sorted by distance.
Definition: Atom.h:93
double chi
Atomic electronegativity determined by neural network.
Definition: Atom.h:119
std::size_t indexStructure
Index number of structure this atom belongs to.
Definition: Atom.h:103
int64_t tag
Tag number of this atom.
Definition: Atom.h:105
std::size_t element
Element index of this atom.
Definition: Atom.h:107
bool hasSymmetryFunctions
If symmetry function values are saved for this atom.
Definition: Atom.h:95
bool hasNeighborList
If the neighbor list has been calculated for this atom.
Definition: Atom.h:91
double dEelecdQ
Derivative of electrostatic energy with respect to this atom's charge.
Definition: Atom.h:117
double energy
Atomic energy determined by neural network.
Definition: Atom.h:115
double chargeRef
Atomic reference charge.
Definition: Atom.h:123
std::size_t numNeighborsUnique
Number of unique neighbor indices (don't count multiple PBC images).
Definition: Atom.h:111
std::size_t numNeighbors
Total number of neighbors.
Definition: Atom.h:109

Member Function Documentation

◆ toNormalizedUnits()

void Atom::toNormalizedUnits ( double  convEnergy,
double  convLength,
double  convCharge 
)

Switch to normalized length, energy and charge units.

Parameters
[in]convEnergyMultiplicative energy unit conversion factor.
[in]convLengthMultiplicative length unit conversion factor.
[in]convChargeMultiplicative charge unit conversion factor.

Definition at line 78 of file Atom.cpp.

81{
82 energy *= convEnergy;
83 r *= convLength;
84 f *= convEnergy / convLength;
85 fRef *= convEnergy / convLength;
86 charge *= convCharge;
87 chargeRef *= convCharge;
89 {
90 for (size_t i = 0; i < numSymmetryFunctions; ++i)
91 {
92 dEdG.at(i) *= convEnergy;
93 dGdr.at(i) /= convLength;
94#ifdef N2P2_FULL_SFD_MEMORY
95 dGdxia.at(i) /= convLength;
96#endif
97 }
98 // Take care of extra charge neuron.
100 dEdG.at(numSymmetryFunctions) *= convEnergy / convCharge;
101 }
102
103 if (hasNeighborList)
104 {
105 for (vector<Neighbor>::iterator it = neighbors.begin();
106 it != neighbors.end(); ++it)
107 {
108 it->d *= convLength;
109 it->dr *= convLength;
111 {
112 for (size_t i = 0; i < dGdr.size(); ++i)
113 {
114 dGdr.at(i) /= convLength;
115 }
116 }
117 }
118 }
119
120 return;
121}
std::vector< Neighbor > neighbors
Neighbor array (maximum number defined in macros.h.
Definition: Atom.h:170
Vec3D r
Cartesian coordinates.
Definition: Atom.h:125
std::vector< double > dEdG
Derivative of atomic energy with respect to symmetry functions.
Definition: Atom.h:149
Vec3D f
Force vector calculated by neural network.
Definition: Atom.h:127
Vec3D fRef
Reference force vector from data set.
Definition: Atom.h:131
std::vector< Vec3D > dGdr
Derivative of symmetry functions with respect to this atom's coordinates.
Definition: Atom.h:161

References charge, chargeRef, dEdG, dGdr, energy, f, fRef, hasNeighborList, hasSymmetryFunctionDerivatives, neighbors, numSymmetryFunctions, r, and useChargeNeuron.

◆ toPhysicalUnits()

void Atom::toPhysicalUnits ( double  convEnergy,
double  convLength,
double  convCharge 
)

Switch to physical length, energy and charge units.

Parameters
[in]convEnergyMultiplicative energy unit conversion factor.
[in]convLengthMultiplicative length unit conversion factor.
[in]convChargeMultiplicative charge unit conversion factor.

Definition at line 123 of file Atom.cpp.

126{
127 energy /= convEnergy;
128 r /= convLength;
129 f /= convEnergy / convLength;
130 fRef /= convEnergy / convLength;
131 charge /= convCharge;
132 chargeRef /= convCharge;
134 {
135 for (size_t i = 0; i < numSymmetryFunctions; ++i)
136 {
137 dEdG.at(i) /= convEnergy;
138 dGdr.at(i) *= convLength;
139#ifdef N2P2_FULL_SFD_MEMORY
140 dGdxia.at(i) *= convLength;
141#endif
142 }
143 // Take care of extra charge neuron.
144 if (useChargeNeuron)
145 dEdG.at(numSymmetryFunctions) /= convEnergy / convCharge;
146 }
147
148 if (hasNeighborList)
149 {
150 for (vector<Neighbor>::iterator it = neighbors.begin();
151 it != neighbors.end(); ++it)
152 {
153 it->d /= convLength;
154 it->dr /= convLength;
156 {
157 for (size_t i = 0; i < dGdr.size(); ++i)
158 {
159 dGdr.at(i) *= convLength;
160 }
161 }
162 }
163 }
164
165 return;
166}

References charge, chargeRef, dEdG, dGdr, energy, f, fRef, hasNeighborList, hasSymmetryFunctionDerivatives, neighbors, numSymmetryFunctions, r, and useChargeNeuron.

◆ allocate()

void Atom::allocate ( bool  all,
double const  maxCutoffRadius = 0.0 
)

Allocate vectors related to symmetry functions (G, dEdG).

Parameters
[in]allIf true allocate also vectors corresponding to derivatives of symmetry functions (dEdG, dGdr, #dGdxia and Neighbor::dGdr, neighbors must be present). If false allocate only G.
[in]maxCutoffRadiusMaximum cutoff radius of symmetry functions.

Warning: numSymmetryFunctions and numSymmetryFunctionDerivatives need to be set first (the latter only in case of argument all == true.

Definition at line 168 of file Atom.cpp.

169{
170 if (numSymmetryFunctions == 0)
171 {
172 throw range_error("ERROR: Number of symmetry functions set to"
173 "zero, cannot allocate.\n");
174 }
175
176 // Clear all symmetry function related vectors (also for derivatives).
177 G.clear();
178 dEdG.clear();
179 dQdG.clear();
180 dChidG.clear();
181#ifdef N2P2_FULL_SFD_MEMORY
182 dGdxia.clear();
183#endif
184 dGdr.clear();
185
186 // Don't need any allocation of neighbors outside the symmetry function
187 // cutoff.
188 size_t const numSymFuncNeighbors = getStoredMinNumNeighbors(maxCutoffRadius);
189 for (size_t i = 0; i < numSymFuncNeighbors; ++i)
190 {
191 Neighbor& n = neighbors.at(i);
192#ifndef N2P2_NO_SF_CACHE
193 n.cache.clear();
194#endif
195 n.dGdr.clear();
196 }
197
198 // Reset status of symmetry functions and derivatives.
199 hasSymmetryFunctions = false;
201
202 // Resize vectors (derivatives only if requested).
203 G.resize(numSymmetryFunctions, 0.0);
204 if (all)
205 {
206#ifndef N2P2_FULL_SFD_MEMORY
207 if (numSymmetryFunctionDerivatives.size() == 0)
208 {
209 throw range_error("ERROR: Number of symmetry function derivatives"
210 " unset, cannot allocate.\n");
211 }
212#endif
213 if (useChargeNeuron) dEdG.resize(numSymmetryFunctions + 1, 0.0);
214 else dEdG.resize(numSymmetryFunctions, 0.0);
215 dQdG.resize(numSymmetryFunctions, 0.0);
216 dChidG.resize(numSymmetryFunctions,0.0);
217#ifdef N2P2_FULL_SFD_MEMORY
218 dGdxia.resize(numSymmetryFunctions, 0.0);
219#endif
221 }
222 for (size_t i = 0; i < numSymFuncNeighbors; ++i)
223 {
224 Neighbor& n = neighbors.at(i);
225#ifndef N2P2_NO_SF_CACHE
226 n.cache.resize(cacheSizePerElement.at(n.element),
227 -numeric_limits<double>::max());
228#endif
229 if (all)
230 {
231#ifndef N2P2_FULL_SFD_MEMORY
232 n.dGdr.resize(numSymmetryFunctionDerivatives.at(n.element));
233#else
234 n.dGdr.resize(numSymmetryFunctions);
235#endif
236 }
237 }
238
239 return;
240}
std::vector< double > dQdG
Derivative of atomic charge with respect to symmetry functions.
Definition: Atom.h:151
std::size_t getStoredMinNumNeighbors(double const cutoffRadius) const
Return needed number of neighbors for a given cutoff radius from neighborCutoffs map.
Definition: Atom.cpp:329
std::vector< std::size_t > numSymmetryFunctionDerivatives
Number of neighbor atom symmetry function derivatives per element.
Definition: Atom.h:140
std::vector< std::size_t > cacheSizePerElement
Cache size for each element.
Definition: Atom.h:143
std::vector< double > G
Symmetry function values.
Definition: Atom.h:146
std::vector< double > dChidG
Derivative of electronegativity with respect to symmetry functions.
Definition: Atom.h:153

References nnp::Atom::Neighbor::cache, cacheSizePerElement, dChidG, dEdG, nnp::Atom::Neighbor::dGdr, dGdr, dQdG, nnp::Atom::Neighbor::element, G, getStoredMinNumNeighbors(), hasSymmetryFunctionDerivatives, hasSymmetryFunctions, neighbors, numSymmetryFunctionDerivatives, numSymmetryFunctions, and useChargeNeuron.

Referenced by nnp::Mode::calculateSymmetryFunctionGroups(), and nnp::Mode::calculateSymmetryFunctions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free()

void Atom::free ( bool  all,
double const  maxCutoffRadius = 0.0 
)

Free vectors related to symmetry functions, opposite of allocate().

Parameters
[in]allIf true free all vectors (G, dEdG, dGdr, #dGdxia and Neighbor::dGdr) otherwise free only dEdG, dGdr, #dGdxia and Neighbor::dGdr.
[in]maxCutoffRadiusMaximum cutoff radius of symmetry functions.

Definition at line 242 of file Atom.cpp.

243{
244 size_t const numSymFuncNeighbors = getStoredMinNumNeighbors(maxCutoffRadius);
245 if (all)
246 {
247 G.clear();
248 vector<double>(G).swap(G);
249 hasSymmetryFunctions = false;
250
251#ifndef N2P2_NO_SF_CACHE
252 for (size_t i = 0; i < numSymFuncNeighbors; ++i)
253 {
254 Neighbor& n = neighbors.at(i);
255 n.cache.clear();
256 vector<double>(n.cache).swap(n.cache);
257 }
258#endif
259 }
260
261 dEdG.clear();
262 vector<double>(dEdG).swap(dEdG);
263 dQdG.clear();
264 vector<double>(dQdG).swap(dQdG);
265 dChidG.clear();
266 vector<double>(dChidG).swap(dChidG);
267#ifdef N2P2_FULL_SFD_MEMORY
268 dGdxia.clear();
269 vector<double>(dGdxia).swap(dGdxia);
270#endif
271 dGdr.clear();
272 vector<Vec3D>(dGdr).swap(dGdr);
273
274 for (size_t i = 0; i < numSymFuncNeighbors; ++i)
275 {
276 Neighbor& n = neighbors.at(i);
277 n.dGdr.clear();
278 vector<Vec3D>(n.dGdr).swap(n.dGdr);
279 }
281
282 return;
283}

References nnp::Atom::Neighbor::cache, dChidG, dEdG, nnp::Atom::Neighbor::dGdr, dGdr, dQdG, G, getStoredMinNumNeighbors(), hasSymmetryFunctionDerivatives, hasSymmetryFunctions, and neighbors.

Here is the call graph for this function:

◆ clearNeighborList() [1/2]

void Atom::clearNeighborList ( )

Clear neighbor list.

Note
Also clears symmetry function data.

Definition at line 285 of file Atom.cpp.

286{
288
289 return;
290}
void clearNeighborList()
Clear neighbor list.
Definition: Atom.cpp:285
std::vector< std::size_t > numNeighborsPerElement
Number of neighbors per element.
Definition: Atom.h:138

References clearNeighborList(), and numNeighborsPerElement.

Referenced by clearNeighborList(), and nnp::Structure::clearNeighborList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearNeighborList() [2/2]

void nnp::Atom::clearNeighborList ( std::size_t const  numElements)

Clear neighbor list and change number of elements.

Parameters
[in]numElementsNumber of elements present.
Note
Also clears symmetry function data. The number of elements is necessary to allocate the numNeighborsPerElement vector. Use the overloaded version clearNeighborList() if the number of elements stays the same.

◆ calculateNumNeighbors()

size_t Atom::calculateNumNeighbors ( double const  cutoffRadius) const

Calculate number of neighbors for a given cutoff radius.

Parameters
[in]cutoffRadiusDesired cutoff radius.

This function assumes that the neighbor list has already been calculated for a large cutoff radius and now the number of neighbor atoms for a smaller cutoff is requested.

Definition at line 307 of file Atom.cpp.

308{
309 // neighborCutoffs map is only constructed when the neighbor list is sorted.
310 if (unorderedMapContainsKey(neighborCutoffs, cutoffRadius))
311 return neighborCutoffs.at(cutoffRadius);
312 else
313 {
314 size_t numNeighborsLocal = 0;
315
316 for (vector<Neighbor>::const_iterator it = neighbors.begin();
317 it != neighbors.end(); ++it)
318 {
319 if (it->d <= cutoffRadius)
320 {
321 numNeighborsLocal++;
322 }
323 }
324
325 return numNeighborsLocal;
326 }
327}
bool unorderedMapContainsKey(std::unordered_map< T, U > const &stdMap, T key)
Test if unordered map contains specified key.
Definition: utility.h:179
std::unordered_map< double, size_t > neighborCutoffs
Map stores number of neighbors needed for the corresponding cut-off.
Definition: Atom.h:172

References neighborCutoffs, neighbors, and nnp::unorderedMapContainsKey().

Referenced by nnp::Mode::calculateSymmetryFunctionGroups(), and nnp::Mode::calculateSymmetryFunctions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStoredMinNumNeighbors()

size_t Atom::getStoredMinNumNeighbors ( double const  cutoffRadius) const

Return needed number of neighbors for a given cutoff radius from neighborCutoffs map.

If it isn't setup, return number of all neighbors in list.

Parameters
[in]cutoffRadiusDesired cutoff radius.
Returns
Integer with the number of neighbors corresponding to the cutoff radius.

Definition at line 329 of file Atom.cpp.

330{
331 // neighborCutoffs map is only constructed when the neighbor list is sorted.
332 if (unorderedMapContainsKey(neighborCutoffs, cutoffRadius))
333 return neighborCutoffs.at(cutoffRadius);
334 else
335 {
336 return numNeighbors;
337 }
338}

References neighborCutoffs, numNeighbors, and nnp::unorderedMapContainsKey().

Referenced by allocate(), nnp::SymFncExpAngn::calculate(), nnp::SymFncExpRad::calculate(), nnp::SymGrpExpAngn::calculate(), nnp::SymGrpExpRad::calculate(), nnp::Structure::calculateDAdrQ(), calculateDChidr(), nnp::Structure::calculateElectrostaticEnergy(), nnp::Mode::calculateForces(), nnp::Structure::calculateScreeningEnergy(), and free().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNeighbor()

bool Atom::isNeighbor ( std::size_t  index) const

Return whether atom is a neighbor.

Parameters
[in]indexIndex of atom in question.
Returns
True if atom is neighbor of this atom.

Definition at line 340 of file Atom.cpp.

341{
342 for (auto const& n : neighbors) if (n.index == index) return true;
343
344 return false;
345}

References index, and neighbors.

◆ updateError()

void Atom::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.

Parameters
[in]propertyOne of "force" or "charge".
[in,out]errorInput error metric map to be updated.
[in,out]countInput counter to be updated.

Definition at line 347 of file Atom.cpp.

350{
351 if (property == "force")
352 {
353 count += 3;
354 error.at("RMSE") += (fRef - f).norm2();
355 error.at("MAE") += (fRef - f).l1norm();
356 }
357 else if (property == "charge")
358 {
359 count++;
360 error.at("RMSE") += (chargeRef - charge) * (chargeRef - charge);
361 error.at("MAE") += fabs(chargeRef - charge);
362 }
363 else
364 {
365 throw runtime_error("ERROR: Unknown property for error update.\n");
366 }
367
368 return;
369}

References charge, chargeRef, f, and fRef.

◆ calculateSelfForceShort()

Vec3D Atom::calculateSelfForceShort ( ) const

Calculate force resulting from gradient of this atom's (short-ranged) energy contribution with respect to this atom's coordinate.

Returns
calculated force vector.

Definition at line 371 of file Atom.cpp.

372{
373 Vec3D selfForce{};
374 for (size_t i = 0; i < numSymmetryFunctions; ++i)
375 {
376 selfForce -= dEdG.at(i) * dGdr.at(i);
377 }
378 return selfForce;
379}
Vector in 3 dimensional real space.
Definition: Vec3D.h:30

References dEdG, dGdr, and numSymmetryFunctions.

Referenced by nnp::Mode::calculateForces().

Here is the caller graph for this function:

◆ calculatePairForceShort()

Vec3D Atom::calculatePairForceShort ( Neighbor const &  neighbor,
std::vector< std::vector< std::size_t > > const *const  tableFull = nullptr 
) const

Calculate force resulting from gradient of this atom's (short-ranged) energy contribution with respect to neighbor's coordinate.

Parameters
[in]neighborNeighbor of which the gradient is considered.
[in]tableFullPointer to ymmetry function table if it is used.
Returns
calculated force vector.

Definition at line 381 of file Atom.cpp.

384{
385 Vec3D pairForce{};
386#ifndef NNP_FULL_SFD_MEMORY
387 if (!tableFull) throw runtime_error(
388 "ERROR: tableFull must not be null pointer");
389 vector<size_t> const& table = tableFull->at(neighbor.element);
390 for (size_t i = 0; i < neighbor.dGdr.size(); ++i)
391 {
392 pairForce -= dEdG.at(table.at(i)) * neighbor.dGdr.at(i);
393 }
394#else
395 for (size_t i = 0; i < numSymmetryFunctions; ++i)
396 {
397 pairForce -= dEdG.at(i) * neighbor.dGdr.at(i);
398 }
399#endif
400 return pairForce;
401}

References dEdG, nnp::Atom::Neighbor::dGdr, nnp::Atom::Neighbor::element, and numSymmetryFunctions.

Referenced by nnp::Mode::calculateForces().

Here is the caller graph for this function:

◆ calculateDChidr()

Vec3D Atom::calculateDChidr ( size_t const  atomIndexOfR,
double const  maxCutoffRadius,
std::vector< std::vector< size_t > > const *const  tableFull = nullptr 
) const

Calculate dChi/dr of this atom's Chi with respect to the coordinates of the given atom.

Parameters
[in]atomIndexOfRIndex of the atom corresponding to the coordinates r.
[in]maxCutoffRadiusLargest cut-off of the symmetry functions.
[in]tableFullPointer to symmetry function table if it is used.
Returns
3D Vector containing the derivative dChi/dr.

Definition at line 403 of file Atom.cpp.

406{
407#ifndef NNP_FULL_SFD_MEMORY
408 if (!tableFull) throw runtime_error(
409 "ERROR: tableFull must not be null pointer");
410#endif
411 Vec3D dChidr{};
412 // need to add this case because the loop over the neighbors
413 // does not include the contribution dChi_i/dr_i.
414 if (atomIndexOfR == index)
415 {
416 for (size_t k = 0; k < numSymmetryFunctions; ++k)
417 {
418 dChidr += dChidG.at(k) * dGdr.at(k);
419 }
420 }
421
422 size_t numNeighbors = getStoredMinNumNeighbors(maxCutoffRadius);
423 for (size_t m = 0; m < numNeighbors; ++m)
424 {
425 Atom::Neighbor const& n = neighbors.at(m);
426 // atomIndexOfR must not be larger than ~max(int64_t)/2.
427 if (n.tag == (int64_t)atomIndexOfR)
428 {
429#ifndef NNP_FULL_SFD_MEMORY
430 vector<size_t> const& table = tableFull->at(n.element);
431 for (size_t k = 0; k < n.dGdr.size(); ++k)
432 {
433 dChidr += dChidG.at(table.at(k)) * n.dGdr.at(k);
434 }
435#else
436 for (size_t k = 0; k < numSymmetryFunctions; ++k)
437 {
438 dChidr += dChidG.at(k) * n.dGdr.at(k);
439 }
440#endif
441 }
442 }
443 return dChidr;
444}
Struct to store information on neighbor atoms.
Definition: Atom.h:36
std::size_t element
Element index of neighbor atom.
Definition: Atom.h:42
int64_t tag
Tag of neighbor atom.
Definition: Atom.h:40
std::vector< Vec3D > dGdr
Derivatives of symmetry functions with respect to neighbor coordinates.
Definition: Atom.h:60

References dChidG, nnp::Atom::Neighbor::dGdr, dGdr, nnp::Atom::Neighbor::element, getStoredMinNumNeighbors(), index, neighbors, numNeighbors, numSymmetryFunctions, and nnp::Atom::Neighbor::tag.

Referenced by nnp::Structure::calculateDQdr(), and nnp::Mode::calculateForces().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getForcesLines()

vector< string > Atom::getForcesLines ( ) const

Get reference and NN forces for this atoms.

Returns
Vector of strings with indexStructure, index, fRef, f values.

Definition at line 446 of file Atom.cpp.

447{
448 vector<string> v;
449 for (size_t i = 0; i < 3; ++i)
450 {
451 v.push_back(strpr("%10zu %10zu %16.8E %16.8E\n",
453 index,
454 fRef[i],
455 f[i]));
456 }
457
458 return v;
459}
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90

References f, fRef, index, indexStructure, and nnp::strpr().

Here is the call graph for this function:

◆ getChargeLine()

string Atom::getChargeLine ( ) const

Get reference and NN charge for this atoms.

Returns
Line with indexStructure, index, chargeRef, charge values.

Definition at line 461 of file Atom.cpp.

462{
463 return strpr("%10zu %10zu %16.8E %16.8E\n",
465 index,
466 chargeRef,
467 charge);
468}

References charge, chargeRef, index, indexStructure, and nnp::strpr().

Here is the call graph for this function:

◆ info()

vector< string > Atom::info ( ) const

Get atom information as a vector of strings.

Returns
Lines with atom information.

Definition at line 470 of file Atom.cpp.

471{
472 vector<string> v;
473
474 v.push_back(strpr("********************************\n"));
475 v.push_back(strpr("ATOM \n"));
476 v.push_back(strpr("********************************\n"));
477 v.push_back(strpr("hasNeighborList : %d\n", hasNeighborList));
478 v.push_back(strpr("hasSymmetryFunctions : %d\n", hasSymmetryFunctions));
479 v.push_back(strpr("hasSymmetryFunctionDerivatives : %d\n", hasSymmetryFunctionDerivatives));
480 v.push_back(strpr("useChargeNeuron : %d\n", useChargeNeuron));
481 v.push_back(strpr("index : %d\n", index));
482 v.push_back(strpr("indexStructure : %d\n", indexStructure));
483 v.push_back(strpr("tag : %" PRId64 "\n", tag));
484 v.push_back(strpr("element : %d\n", element));
485 v.push_back(strpr("numNeighbors : %d\n", numNeighbors));
486 v.push_back(strpr("numNeighborsUnique : %d\n", numNeighborsUnique));
487 v.push_back(strpr("numSymmetryFunctions : %d\n", numSymmetryFunctions));
488 v.push_back(strpr("energy : %16.8E\n", energy));
489 v.push_back(strpr("chi : %16.8E\n", chi));
490 v.push_back(strpr("charge : %16.8E\n", charge));
491 v.push_back(strpr("chargeRef : %16.8E\n", chargeRef));
492 v.push_back(strpr("r : %16.8E %16.8E %16.8E\n", r[0], r[1], r[2]));
493 v.push_back(strpr("f : %16.8E %16.8E %16.8E\n", f[0], f[1], f[2]));
494 v.push_back(strpr("fRef : %16.8E %16.8E %16.8E\n", fRef[0], fRef[1], fRef[2]));
495 v.push_back(strpr("--------------------------------\n"));
496 v.push_back(strpr("neighborsUnique [*] : %d\n", neighborsUnique.size()));
497 v.push_back(strpr("--------------------------------\n"));
498 for (size_t i = 0; i < neighborsUnique.size(); ++i)
499 {
500 v.push_back(strpr("%29d : %d\n", i, neighborsUnique.at(i)));
501 }
502 v.push_back(strpr("--------------------------------\n"));
503 v.push_back(strpr("--------------------------------\n"));
504 v.push_back(strpr("numNeighborsPerElement [*] : %d\n", numNeighborsPerElement.size()));
505 v.push_back(strpr("--------------------------------\n"));
506 for (size_t i = 0; i < numNeighborsPerElement.size(); ++i)
507 {
508 v.push_back(strpr("%29d : %d\n", i, numNeighborsPerElement.at(i)));
509 }
510 v.push_back(strpr("--------------------------------\n"));
511 v.push_back(strpr("--------------------------------\n"));
512 v.push_back(strpr("numSymmetryFunctionDeriv. [*] : %d\n", numSymmetryFunctionDerivatives.size()));
513 v.push_back(strpr("--------------------------------\n"));
514 for (size_t i = 0; i < numSymmetryFunctionDerivatives.size(); ++i)
515 {
516 v.push_back(strpr("%29d : %d\n", i, numSymmetryFunctionDerivatives.at(i)));
517 }
518#ifndef N2P2_NO_SF_CACHE
519 v.push_back(strpr("--------------------------------\n"));
520 v.push_back(strpr("--------------------------------\n"));
521 v.push_back(strpr("cacheSizePerElement [*] : %d\n", cacheSizePerElement.size()));
522 v.push_back(strpr("--------------------------------\n"));
523 for (size_t i = 0; i < cacheSizePerElement.size(); ++i)
524 {
525 v.push_back(strpr("%29d : %d\n", i, cacheSizePerElement.at(i)));
526 }
527#endif
528 v.push_back(strpr("--------------------------------\n"));
529 v.push_back(strpr("--------------------------------\n"));
530 v.push_back(strpr("G [*] : %d\n", G.size()));
531 v.push_back(strpr("--------------------------------\n"));
532 for (size_t i = 0; i < G.size(); ++i)
533 {
534 v.push_back(strpr("%29d : %16.8E\n", i, G.at(i)));
535 }
536 v.push_back(strpr("--------------------------------\n"));
537 v.push_back(strpr("--------------------------------\n"));
538 v.push_back(strpr("dEdG [*] : %d\n", dEdG.size()));
539 v.push_back(strpr("--------------------------------\n"));
540 for (size_t i = 0; i < dEdG.size(); ++i)
541 {
542 v.push_back(strpr("%29d : %16.8E\n", i, dEdG.at(i)));
543 }
544 v.push_back(strpr("--------------------------------\n"));
545 v.push_back(strpr("--------------------------------\n"));
546 v.push_back(strpr("dQdG [*] : %d\n", dQdG.size()));
547 v.push_back(strpr("--------------------------------\n"));
548 for (size_t i = 0; i < dQdG.size(); ++i)
549 {
550 v.push_back(strpr("%29d : %16.8E\n", i, dQdG.at(i)));
551 }
552 v.push_back(strpr("--------------------------------\n"));
553#ifdef N2P2_FULL_SFD_MEMORY
554 v.push_back(strpr("--------------------------------\n"));
555 v.push_back(strpr("dGdxia [*] : %d\n", dGdxia.size()));
556 v.push_back(strpr("--------------------------------\n"));
557 for (size_t i = 0; i < dGdxia.size(); ++i)
558 {
559 v.push_back(strpr("%29d : %16.8E\n", i, dGdxia.at(i)));
560 }
561 v.push_back(strpr("--------------------------------\n"));
562#endif
563 v.push_back(strpr("--------------------------------\n"));
564 v.push_back(strpr("dGdr [*] : %d\n", dGdr.size()));
565 v.push_back(strpr("--------------------------------\n"));
566 for (size_t i = 0; i < dGdr.size(); ++i)
567 {
568 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]));
569 }
570 v.push_back(strpr("--------------------------------\n"));
571 v.push_back(strpr("--------------------------------\n"));
572 v.push_back(strpr("neighbors [*] : %d\n", neighbors.size()));
573 v.push_back(strpr("--------------------------------\n"));
574 for (size_t i = 0; i < neighbors.size(); ++i)
575 {
576 v.push_back(strpr("%29d :\n", i));
577 vector<string> vn = neighbors[i].info();
578 v.insert(v.end(), vn.begin(), vn.end());
579 }
580 v.push_back(strpr("--------------------------------\n"));
581 v.push_back(strpr("********************************\n"));
582
583 return v;
584}
std::vector< std::size_t > neighborsUnique
List of unique neighbor indices (don't count multiple PBC images).
Definition: Atom.h:136

References cacheSizePerElement, charge, chargeRef, chi, dEdG, dGdr, dQdG, element, energy, f, fRef, G, hasNeighborList, hasSymmetryFunctionDerivatives, hasSymmetryFunctions, index, indexStructure, neighbors, neighborsUnique, numNeighbors, numNeighborsPerElement, numNeighborsUnique, numSymmetryFunctionDerivatives, numSymmetryFunctions, r, nnp::strpr(), tag, and useChargeNeuron.

Here is the call graph for this function:

Member Data Documentation

◆ hasNeighborList

bool nnp::Atom::hasNeighborList

If the neighbor list has been calculated for this atom.

Definition at line 91 of file Atom.h.

Referenced by info(), toNormalizedUnits(), and toPhysicalUnits().

◆ NeighborListIsSorted

bool nnp::Atom::NeighborListIsSorted

If the neighbor list is sorted by distance.

Definition at line 93 of file Atom.h.

◆ hasSymmetryFunctions

bool nnp::Atom::hasSymmetryFunctions

If symmetry function values are saved for this atom.

Definition at line 95 of file Atom.h.

Referenced by allocate(), nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), free(), info(), and nnp::InterfaceLammps::setLocalAtoms().

◆ hasSymmetryFunctionDerivatives

bool nnp::Atom::hasSymmetryFunctionDerivatives

◆ useChargeNeuron

bool nnp::Atom::useChargeNeuron

If an additional charge neuron in the short-range NN is present.

Definition at line 99 of file Atom.h.

Referenced by allocate(), nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), info(), toNormalizedUnits(), and toPhysicalUnits().

◆ index

◆ indexStructure

std::size_t nnp::Atom::indexStructure

◆ tag

int64_t nnp::Atom::tag

Tag number of this atom.

Definition at line 105 of file Atom.h.

Referenced by nnp::Atom::Neighbor::info(), info(), and nnp::Element::updateSymmetryFunctionStatistics().

◆ element

◆ numNeighbors

◆ numNeighborsUnique

std::size_t nnp::Atom::numNeighborsUnique

Number of unique neighbor indices (don't count multiple PBC images).

Definition at line 111 of file Atom.h.

Referenced by info().

◆ numSymmetryFunctions

◆ energy

double nnp::Atom::energy

Atomic energy determined by neural network.

Definition at line 115 of file Atom.h.

Referenced by nnp::InterfaceLammps::getAtomicEnergy(), info(), toNormalizedUnits(), and toPhysicalUnits().

◆ dEelecdQ

double nnp::Atom::dEelecdQ

Derivative of electrostatic energy with respect to this atom's charge.

Definition at line 117 of file Atom.h.

Referenced by nnp::Structure::calculateElectrostaticEnergyDerivatives(), nnp::Structure::calculateForceLambdaElec(), and nnp::Structure::calculateForceLambdaTotal().

◆ chi

double nnp::Atom::chi

Atomic electronegativity determined by neural network.

Definition at line 119 of file Atom.h.

Referenced by nnp::Structure::calculateElectrostaticEnergy(), info(), and nnp::Training::update().

◆ charge

◆ chargeRef

double nnp::Atom::chargeRef

Atomic reference charge.

Definition at line 123 of file Atom.h.

Referenced by getChargeLine(), info(), toNormalizedUnits(), toPhysicalUnits(), nnp::Training::update(), and updateError().

◆ r

◆ f

Vec3D nnp::Atom::f

◆ fElec

Vec3D nnp::Atom::fElec

Force vector resulting from electrostatics.

Definition at line 129 of file Atom.h.

◆ fRef

Vec3D nnp::Atom::fRef

Reference force vector from data set.

Definition at line 131 of file Atom.h.

Referenced by getForcesLines(), info(), main(), nnp::Training::sortUpdateCandidates(), toNormalizedUnits(), toPhysicalUnits(), nnp::Training::update(), and updateError().

◆ pEelecpr

Vec3D nnp::Atom::pEelecpr

Partial derivative of electrostatic energy with respect to this atom's coordinates.

Definition at line 134 of file Atom.h.

Referenced by nnp::Structure::calculateElectrostaticEnergyDerivatives().

◆ neighborsUnique

std::vector<std::size_t> nnp::Atom::neighborsUnique

List of unique neighbor indices (don't count multiple PBC images).

Definition at line 136 of file Atom.h.

Referenced by nnp::Mode::calculateForces(), and info().

◆ numNeighborsPerElement

std::vector<std::size_t> nnp::Atom::numNeighborsPerElement

◆ numSymmetryFunctionDerivatives

std::vector<std::size_t> nnp::Atom::numSymmetryFunctionDerivatives

Number of neighbor atom symmetry function derivatives per element.

Definition at line 140 of file Atom.h.

Referenced by allocate(), nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), and info().

◆ cacheSizePerElement

std::vector<std::size_t> nnp::Atom::cacheSizePerElement

Cache size for each element.

Definition at line 143 of file Atom.h.

Referenced by allocate(), nnp::Mode::calculateSymmetryFunctionGroups(), nnp::Mode::calculateSymmetryFunctions(), and info().

◆ G

◆ dEdG

std::vector<double> nnp::Atom::dEdG

Derivative of atomic energy with respect to symmetry functions.

Also contains dEdQ in the last element if HDNNP-4G is used.

Definition at line 149 of file Atom.h.

Referenced by allocate(), nnp::Structure::calculateForceLambdaTotal(), calculatePairForceShort(), calculateSelfForceShort(), free(), info(), toNormalizedUnits(), and toPhysicalUnits().

◆ dQdG

std::vector<double> nnp::Atom::dQdG

Derivative of atomic charge with respect to symmetry functions.

Definition at line 151 of file Atom.h.

Referenced by allocate(), free(), and info().

◆ dChidG

std::vector<double> nnp::Atom::dChidG

Derivative of electronegativity with respect to symmetry functions.

Definition at line 153 of file Atom.h.

Referenced by allocate(), calculateDChidr(), free(), and nnp::Training::update().

◆ dGdr

◆ dQdr

std::vector<Vec3D> nnp::Atom::dQdr

Derivative of charges with respect to this atom's coordinates.

Definition at line 163 of file Atom.h.

Referenced by nnp::Structure::calculateDQdr().

◆ dAdrQ

std::vector<Vec3D> nnp::Atom::dAdrQ

If dQdr has been calculated for respective components.

Derivative of A-matrix with respect to this atom's coordinates contracted with the charges.

Definition at line 168 of file Atom.h.

Referenced by nnp::Structure::calculateDAdrQ(), nnp::Structure::calculateDQdr(), and nnp::Structure::calculateElectrostaticEnergyDerivatives().

◆ neighbors

◆ neighborCutoffs

std::unordered_map<double, size_t> nnp::Atom::neighborCutoffs

Map stores number of neighbors needed for the corresponding cut-off.

Definition at line 172 of file Atom.h.

Referenced by calculateNumNeighbors(), and getStoredMinNumNeighbors().


The documentation for this struct was generated from the following files: