n2p2 - A neural network potential package
Atom.h
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 ATOM_H
18#define ATOM_H
19
20#include "Vec3D.h"
21#include <cstddef> // std::size_t
22#include <cstdint> // int64_t
23#include <map> // std::map
24#include <unordered_map> // std::unordered_map
25#include <string> // std::string
26#include <vector> // std::vector
27
28namespace nnp
29{
30
32struct Atom
33{
35 struct Neighbor
36 {
38 std::size_t index;
40 int64_t tag;
42 std::size_t element;
44 double d;
47#ifndef N2P2_NO_SF_CACHE
49 std::vector<double> cache;
50#endif
60 std::vector<Vec3D> dGdr;
61
64 Neighbor();
67 bool operator==(Neighbor const& rhs) const;
70 bool operator!=(Neighbor const& rhs) const;
73 bool operator<(Neighbor const& rhs) const;
76 bool operator>(Neighbor const& rhs) const;
79 bool operator<=(Neighbor const& rhs) const;
82 bool operator>=(Neighbor const& rhs) const;
87 std::vector<std::string> info() const;
88 };
89
101 std::size_t index;
103 std::size_t indexStructure;
105 int64_t tag;
107 std::size_t element;
109 std::size_t numNeighbors;
115 double energy;
117 double dEelecdQ;
119 double chi;
121 double charge;
123 double chargeRef;
136 std::vector<std::size_t> neighborsUnique;
138 std::vector<std::size_t> numNeighborsPerElement;
140 std::vector<std::size_t> numSymmetryFunctionDerivatives;
141#ifndef N2P2_NO_SF_CACHE
143 std::vector<std::size_t> cacheSizePerElement;
144#endif
146 std::vector<double> G;
149 std::vector<double> dEdG;
151 std::vector<double> dQdG;
153 std::vector<double> dChidG;
154#ifdef N2P2_FULL_SFD_MEMORY
157 std::vector<double> dGdxia;
158#endif
161 std::vector<Vec3D> dGdr;
163 std::vector<Vec3D> dQdr;
165 //bool hasdQdr[3];
168 std::vector<Vec3D> dAdrQ;
170 std::vector<Neighbor> neighbors;
172 std::unordered_map<double, size_t> neighborCutoffs;
173
176 Atom();
177#ifdef N2P2_FULL_SFD_MEMORY
196 void collectDGdxia(std::size_t indexAtom,
197 std::size_t indexComponent,
198 double maxCutoffRadius);
199#endif
206 void toNormalizedUnits(double convEnergy,
207 double convLength,
208 double convCharge);
215 void toPhysicalUnits(double convEnergy,
216 double convLength,
217 double convCharge);
229 void allocate(bool all,
230 double const maxCutoffRadius = 0.0);
238 void free(bool all, double const maxCutoffRadius = 0.0);
243 void clearNeighborList();
253 void clearNeighborList(std::size_t const numElements);
262 std::size_t calculateNumNeighbors(double const cutoffRadius) const;
270 std::size_t getStoredMinNumNeighbors(
271 double const cutoffRadius) const;
278 bool isNeighbor(std::size_t index) const;
285 void updateError(
286 std::string const& property,
287 std::map<std::string, double>& error,
288 std::size_t& count) const;
303 Neighbor const& neighbor,
304 std::vector<std::vector <std::size_t> >
305 const *const tableFull = nullptr) const;
315 size_t const atomIndexOfR,
316 double const maxCutoffRadius,
317 std::vector<std::vector<size_t> >
318 const *const tableFull = nullptr) const;
324 std::vector<std::string> getForcesLines() const;
329 std::string getChargeLine() const;
334 std::vector<std::string> info() const;
335};
336
337inline bool Atom::Neighbor::operator!=(Atom::Neighbor const& rhs) const
338{
339 return !((*this) == rhs);
340}
341
342inline bool Atom::Neighbor::operator>(Atom::Neighbor const& rhs) const
343{
344 return rhs < (*this);
345}
346
347inline bool Atom::Neighbor::operator<=(Atom::Neighbor const& rhs) const
348{
349 return !((*this) > rhs);
350}
351
352inline bool Atom::Neighbor::operator>=(Atom::Neighbor const& rhs) const
353{
354 return !((*this) < rhs);
355}
356
357}
358
359#endif
Definition: Atom.h:29
Struct to store information on neighbor atoms.
Definition: Atom.h:36
bool operator!=(Neighbor const &rhs) const
Overload != operator.
Definition: Atom.h:337
Neighbor()
Neighbor constructor, initialize to zero.
Definition: Atom.cpp:586
std::size_t index
Index of neighbor atom.
Definition: Atom.h:38
std::vector< double > cache
Symmetry function cache (e.g. for cutoffs, compact functions).
Definition: Atom.h:49
std::size_t element
Element index of neighbor atom.
Definition: Atom.h:42
double d
Distance to neighbor atom.
Definition: Atom.h:44
Vec3D dr
Distance vector to neighbor atom.
Definition: Atom.h:46
bool operator>=(Neighbor const &rhs) const
Overload >= operator.
Definition: Atom.h:352
bool operator==(Neighbor const &rhs) const
Overload == operator.
Definition: Atom.cpp:593
bool operator<=(Neighbor const &rhs) const
Overload <= operator.
Definition: Atom.h:347
int64_t tag
Tag of neighbor atom.
Definition: Atom.h:40
std::vector< std::string > info() const
Get atom information as a vector of strings.
Definition: Atom.cpp:612
std::vector< Vec3D > dGdr
Derivatives of symmetry functions with respect to neighbor coordinates.
Definition: Atom.h:60
bool operator<(Neighbor const &rhs) const
Overload < operator.
Definition: Atom.cpp:600
bool operator>(Neighbor const &rhs) const
Overload > operator.
Definition: Atom.h:342
Storage for a single atom.
Definition: Atom.h:33
std::vector< Neighbor > neighbors
Neighbor array (maximum number defined in macros.h.
Definition: Atom.h:170
std::vector< std::string > info() const
Get atom information as a vector of strings.
Definition: Atom.cpp:470
std::size_t numSymmetryFunctions
Number of symmetry functions used to describe the atom environment.
Definition: Atom.h:113
void clearNeighborList(std::size_t const numElements)
Clear neighbor list and change number of elements.
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 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.
Definition: Atom.cpp:403
Vec3D f
Force vector calculated by neural network.
Definition: Atom.h:127
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 respec...
Definition: Atom.cpp:381
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for this atom.
Definition: Atom.h:97
std::vector< double > dQdG
Derivative of atomic charge with respect to symmetry functions.
Definition: Atom.h:151
double charge
Atomic charge determined by neural network.
Definition: Atom.h:121
bool isNeighbor(std::size_t index) const
Return whether atom is a neighbor.
Definition: Atom.cpp:340
std::size_t index
Index number of this atom.
Definition: Atom.h:101
Vec3D calculateSelfForceShort() const
Calculate force resulting from gradient of this atom's (short-ranged) energy contribution with respec...
Definition: Atom.cpp:371
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
Vec3D fRef
Reference force vector from data set.
Definition: Atom.h:131
bool useChargeNeuron
If an additional charge neuron in the short-range NN is present.
Definition: Atom.h:99
std::vector< Vec3D > dGdr
Derivative of symmetry functions with respect to this atom's coordinates.
Definition: Atom.h:161
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
void toPhysicalUnits(double convEnergy, double convLength, double convCharge)
Switch to physical length, energy and charge units.
Definition: Atom.cpp:123
void clearNeighborList()
Clear neighbor list.
Definition: Atom.cpp:285
Vec3D fElec
Force vector resulting from electrostatics.
Definition: Atom.h:129
Vec3D pEelecpr
Partial derivative of electrostatic energy with respect to this atom's coordinates.
Definition: Atom.h:134
void free(bool all, double const maxCutoffRadius=0.0)
Free vectors related to symmetry functions, opposite of allocate().
Definition: Atom.cpp:242
std::size_t indexStructure
Index number of structure this atom belongs to.
Definition: Atom.h:103
std::vector< Vec3D > dAdrQ
If dQdr has been calculated for respective components.
Definition: Atom.h:168
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
std::unordered_map< double, size_t > neighborCutoffs
Map stores number of neighbors needed for the corresponding cut-off.
Definition: Atom.h:172
void allocate(bool all, double const maxCutoffRadius=0.0)
Allocate vectors related to symmetry functions (G, dEdG).
Definition: Atom.cpp:168
void toNormalizedUnits(double convEnergy, double convLength, double convCharge)
Switch to normalized length, energy and charge units.
Definition: Atom.cpp:78
bool hasSymmetryFunctions
If symmetry function values are saved for this atom.
Definition: Atom.h:95
std::size_t calculateNumNeighbors(double const cutoffRadius) const
Calculate number of neighbors for a given cutoff radius.
Definition: Atom.cpp:307
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.
Definition: Atom.cpp:347
std::vector< std::size_t > cacheSizePerElement
Cache size for each element.
Definition: Atom.h:143
Atom()
Atom constructor, initialize to zero.
Definition: Atom.cpp:27
bool hasNeighborList
If the neighbor list has been calculated for this atom.
Definition: Atom.h:91
std::vector< Vec3D > dQdr
Derivative of charges with respect to this atom's coordinates.
Definition: Atom.h:163
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
std::vector< double > G
Symmetry function values.
Definition: Atom.h:146
std::vector< std::size_t > neighborsUnique
List of unique neighbor indices (don't count multiple PBC images).
Definition: Atom.h:136
double chargeRef
Atomic reference charge.
Definition: Atom.h:123
std::vector< std::size_t > numNeighborsPerElement
Number of neighbors per element.
Definition: Atom.h:138
std::vector< std::string > getForcesLines() const
Get reference and NN forces for this atoms.
Definition: Atom.cpp:446
std::string getChargeLine() const
Get reference and NN charge for this atoms.
Definition: Atom.cpp:461
std::size_t numNeighborsUnique
Number of unique neighbor indices (don't count multiple PBC images).
Definition: Atom.h:111
std::vector< double > dChidG
Derivative of electronegativity with respect to symmetry functions.
Definition: Atom.h:153
std::size_t numNeighbors
Total number of neighbors.
Definition: Atom.h:109
Vector in 3 dimensional real space.
Definition: Vec3D.h:30