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 <string> // std::string
25#include <vector> // std::vector
26
27namespace nnp
28{
29
31struct Atom
32{
34 struct Neighbor
35 {
37 std::size_t index;
39 int64_t tag;
41 std::size_t element;
43 double d;
46#ifndef N2P2_NO_SF_CACHE
48 std::vector<double> cache;
49#endif
59 std::vector<Vec3D> dGdr;
60
63 Neighbor();
66 bool operator==(Neighbor const& rhs) const;
69 bool operator!=(Neighbor const& rhs) const;
72 bool operator<(Neighbor const& rhs) const;
75 bool operator>(Neighbor const& rhs) const;
78 bool operator<=(Neighbor const& rhs) const;
81 bool operator>=(Neighbor const& rhs) const;
86 std::vector<std::string> info() const;
87 };
88
98 std::size_t index;
100 std::size_t indexStructure;
102 int64_t tag;
104 std::size_t element;
106 std::size_t numNeighbors;
112 double energy;
114 double charge;
116 double chargeRef;
124 std::vector<std::size_t> neighborsUnique;
126 std::vector<std::size_t> numNeighborsPerElement;
128 std::vector<std::size_t> numSymmetryFunctionDerivatives;
129#ifndef N2P2_NO_SF_CACHE
131 std::vector<std::size_t> cacheSizePerElement;
132#endif
134 std::vector<double> G;
136 std::vector<double> dEdG;
138 std::vector<double> dQdG;
139#ifdef N2P2_FULL_SFD_MEMORY
142 std::vector<double> dGdxia;
143#endif
146 std::vector<Vec3D> dGdr;
148 std::vector<Neighbor> neighbors;
149
152 Atom();
153#ifdef N2P2_FULL_SFD_MEMORY
171 void collectDGdxia(std::size_t indexAtom,
172 std::size_t indexComponent);
173#endif
179 void toNormalizedUnits(double convEnergy,
180 double convLength);
186 void toPhysicalUnits(double convEnergy,
187 double convLength);
198 void allocate(bool all);
205 void free(bool all);
210 void clearNeighborList();
220 void clearNeighborList(std::size_t const numElements);
229 std::size_t getNumNeighbors(double cutoffRadius) const;
236 void updateError(
237 std::string const& property,
238 std::map<std::string, double>& error,
239 std::size_t& count) const;
245 std::vector<std::string> getForcesLines() const;
250 std::string getChargeLine() const;
255 std::vector<std::string> info() const;
256};
257
258inline bool Atom::Neighbor::operator!=(Atom::Neighbor const& rhs) const
259{
260 return !((*this) == rhs);
261}
262
263inline bool Atom::Neighbor::operator>(Atom::Neighbor const& rhs) const
264{
265 return rhs < (*this);
266}
267
268inline bool Atom::Neighbor::operator<=(Atom::Neighbor const& rhs) const
269{
270 return !((*this) > rhs);
271}
272
273inline bool Atom::Neighbor::operator>=(Atom::Neighbor const& rhs) const
274{
275 return !((*this) < rhs);
276}
277
278}
279
280#endif
Definition: Atom.h:28
Struct to store information on neighbor atoms.
Definition: Atom.h:35
bool operator!=(Neighbor const &rhs) const
Overload != operator.
Definition: Atom.h:258
Neighbor()
Neighbor constructor, initialize to zero.
Definition: Atom.cpp:460
std::size_t index
Index of neighbor atom.
Definition: Atom.h:37
std::vector< double > cache
Symmetry function cache (e.g. for cutoffs, compact functions).
Definition: Atom.h:48
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
bool operator>=(Neighbor const &rhs) const
Overload >= operator.
Definition: Atom.h:273
bool operator==(Neighbor const &rhs) const
Overload == operator.
Definition: Atom.cpp:467
bool operator<=(Neighbor const &rhs) const
Overload <= operator.
Definition: Atom.h:268
int64_t tag
Tag of neighbor atom.
Definition: Atom.h:39
std::vector< std::string > info() const
Get atom information as a vector of strings.
Definition: Atom.cpp:483
std::vector< Vec3D > dGdr
Derivatives of symmetry functions with respect to neighbor coordinates.
Definition: Atom.h:59
bool operator<(Neighbor const &rhs) const
Overload < operator.
Definition: Atom.cpp:474
bool operator>(Neighbor const &rhs) const
Overload > operator.
Definition: Atom.h:263
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::vector< std::string > info() const
Get atom information as a vector of strings.
Definition: Atom.cpp:345
std::size_t numSymmetryFunctions
Number of symmetry functions used to describe the atom environment.
Definition: Atom.h:110
void clearNeighborList(std::size_t const numElements)
Clear neighbor list and change number of elements.
Vec3D r
Cartesian coordinates.
Definition: Atom.h:118
std::vector< double > dEdG
Derivative of atomic energy with respect to symmetry functions.
Definition: Atom.h:136
Vec3D f
Force vector calculated by neural network.
Definition: Atom.h:120
bool hasSymmetryFunctionDerivatives
If symmetry function derivatives are saved for this atom.
Definition: Atom.h:94
std::vector< double > dQdG
Derivative of atomic charge with respect to symmetry functions.
Definition: Atom.h:138
double charge
Atomic charge determined by neural network.
Definition: Atom.h:114
void allocate(bool all)
Allocate vectors related to symmetry functions (G, dEdG).
Definition: Atom.cpp:153
std::size_t index
Index number of this atom.
Definition: Atom.h:98
std::vector< std::size_t > numSymmetryFunctionDerivatives
Number of neighbor atom symmetry function derivatives per element.
Definition: Atom.h:128
Vec3D fRef
Reference force vector from data set.
Definition: Atom.h:122
bool useChargeNeuron
If an additional charge neuron in the short-range NN is present.
Definition: Atom.h:96
std::vector< Vec3D > dGdr
Derivative of symmetry functions with respect to this atom's coordinates.
Definition: Atom.h:146
void toPhysicalUnits(double convEnergy, double convLength)
Switch to physical length and energy units.
Definition: Atom.cpp:113
void clearNeighborList()
Clear neighbor list.
Definition: Atom.cpp:259
std::size_t indexStructure
Index number of structure this atom belongs to.
Definition: Atom.h:100
int64_t tag
Tag number of this atom.
Definition: Atom.h:102
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
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:297
std::vector< std::size_t > cacheSizePerElement
Cache size for each element.
Definition: Atom.h:131
Atom()
Atom constructor, initialize to zero.
Definition: Atom.cpp:27
void toNormalizedUnits(double convEnergy, double convLength)
Switch to normalized length and energy units.
Definition: Atom.cpp:73
bool hasNeighborList
If the neighbor list has been calculated for this atom.
Definition: Atom.h:90
double energy
Atomic energy determined by neural network.
Definition: Atom.h:112
std::vector< double > G
Symmetry function values.
Definition: Atom.h:134
std::vector< std::size_t > neighborsUnique
List of unique neighbor indices (don't count multiple PBC images).
Definition: Atom.h:124
double chargeRef
Atomic reference charge.
Definition: Atom.h:116
std::vector< std::size_t > numNeighborsPerElement
Number of neighbors per element.
Definition: Atom.h:126
std::vector< std::string > getForcesLines() const
Get reference and NN forces for this atoms.
Definition: Atom.cpp:321
std::string getChargeLine() const
Get reference and NN charge for this atoms.
Definition: Atom.cpp:336
std::size_t numNeighborsUnique
Number of unique neighbor indices (don't count multiple PBC images).
Definition: Atom.h:108
std::size_t getNumNeighbors(double cutoffRadius) const
Calculate number of neighbors for a given cutoff radius.
Definition: Atom.cpp:281
void free(bool all)
Free vectors related to symmetry functions, opposite of allocate().
Definition: Atom.cpp:221
std::size_t numNeighbors
Total number of neighbors.
Definition: Atom.h:106
Vector in 3 dimensional real space.
Definition: Vec3D.h:29