n2p2 - A neural network potential package
nnp::SymFncCompAngn Class Reference

Narrow angular symmetry function with compact support (type 21) More...

#include <SymFncCompAngn.h>

Inheritance diagram for nnp::SymFncCompAngn:
Collaboration diagram for nnp::SymFncCompAngn:

Public Member Functions

 SymFncCompAngn (ElementMap const &elementMap)
 Constructor, sets type = 21. More...
 
virtual bool operator== (SymFnc const &rhs) const
 Overload == operator. More...
 
virtual bool operator< (SymFnc const &rhs) const
 Overload < operator. More...
 
virtual void calculate (Atom &atom, bool const derivatives) const
 Calculate symmetry function for one atom. More...
 
- Public Member Functions inherited from nnp::SymFncBaseCompAng
virtual void setParameters (std::string const &parameterString)
 Set symmetry function parameters. More...
 
virtual void changeLengthUnit (double convLength)
 Change length unit. More...
 
virtual std::string getSettingsLine () const
 Get settings file line from currently set parameters. More...
 
void getCompactAngle (double const x, double &fx, double &dfx) const
 
void getCompactRadial (double const x, double &fx, double &dfx) const
 
virtual std::string parameterLine () const
 Give symmetry function parameters in one line. More...
 
virtual std::vector< std::string > parameterInfo () const
 Get description with parameter names and values. More...
 
std::size_t getE1 () const
 Get private e1 member variable. More...
 
std::size_t getE2 () const
 Get private e2 member variable. More...
 
double getAngleLeft () const
 Get private angleLeft member variable. More...
 
double getAngleRight () const
 Get private angleRight member variable. More...
 
virtual double calculateRadialPart (double distance) const
 Calculate (partial) symmetry function value for one given distance. More...
 
virtual double calculateAngularPart (double angle) const
 Calculate (partial) symmetry function value for one given angle. More...
 
virtual bool checkRelevantElement (std::size_t index) const
 Check whether symmetry function is relevant for given element. More...
 
virtual std::vector< std::string > getCacheIdentifiers () const
 Get unique cache identifiers. More...
 
- Public Member Functions inherited from nnp::SymFncBaseComp
virtual std::vector< std::string > parameterInfo () const
 Get description with parameter names and values. More...
 
void setCompactFunction (std::string subtype)
 Set radial compact function. More...
 
std::string getSubtype () const
 Get private subtype member variable. More...
 
double getRl () const
 Get private rl member variable. More...
 
- Public Member Functions inherited from nnp::SymFnc
virtual ~SymFnc ()
 Virtual destructor. More...
 
virtual bool operator== (SymFnc const &rhs) const =0
 Overload == operator. More...
 
virtual bool operator< (SymFnc const &rhs) const =0
 Overload < operator. More...
 
bool operator!= (SymFnc const &rhs) const
 Overload != operator. More...
 
bool operator> (SymFnc const &rhs) const
 Overload > operator. More...
 
bool operator<= (SymFnc const &rhs) const
 Overload <= operator. More...
 
bool operator>= (SymFnc const &rhs) const
 Overload >= operator. More...
 
virtual void setParameters (std::string const &parameterString)=0
 Set parameters. More...
 
virtual void changeLengthUnit (double convLength)=0
 Change length unit. More...
 
virtual std::string getSettingsLine () const =0
 Get settings file line from currently set parameters. More...
 
virtual void calculate (Atom &atom, bool const derivatives) const =0
 Calculate symmetry function for one atom. More...
 
virtual std::string parameterLine () const =0
 Give symmetry function parameters in one line. More...
 
virtual std::vector< std::string > parameterInfo () const
 Get description with parameter names and values. More...
 
void setScalingType (ScalingType scalingType, std::string statisticsLine, double Smin, double Smax)
 Set symmetry function scaling type. More...
 
double scale (double value) const
 Apply symmetry function scaling and/or centering. More...
 
double unscale (double value) const
 Undo symmetry function scaling and/or centering. More...
 
std::size_t getType () const
 Get private type member variable. More...
 
std::size_t getIndex () const
 Get private index member variable. More...
 
std::size_t getLineNumber () const
 Get private lineNumber member variable. More...
 
std::size_t getEc () const
 Get private ec member variable. More...
 
std::size_t getMinNeighbors () const
 Get private minNeighbors member variable. More...
 
double getRc () const
 Get private rc member variable. More...
 
double getGmin () const
 Get private Gmin member variable. More...
 
double getGmax () const
 Get private Gmax member variable. More...
 
double getScalingFactor () const
 Get private scalingFactor member variable. More...
 
double getConvLength () const
 Get private convLength member variable. More...
 
std::set< std::string > getParameters () const
 Get private parameters member variable. More...
 
std::vector< std::size_t > getIndexPerElement () const
 Get private indexPerElement member variable. More...
 
void setIndex (std::size_t index)
 Set private index member variable. More...
 
void setIndexPerElement (std::size_t elementIndex, std::size_t index)
 Set private indexPerElement member variable. More...
 
void setLineNumber (std::size_t lineNumber)
 Set line number. More...
 
std::string scalingLine () const
 Get string with scaling information. More...
 
virtual double calculateRadialPart (double distance) const =0
 Calculate (partial) symmetry function value for one given distance. More...
 
virtual double calculateAngularPart (double angle) const =0
 Calculate (partial) symmetry function value for one given angle. More...
 
virtual bool checkRelevantElement (std::size_t index) const =0
 Check whether symmetry function is relevant for given element. More...
 
virtual std::vector< std::string > getCacheIdentifiers () const
 Get unique cache identifiers. More...
 
void addCacheIndex (std::size_t element, std::size_t cacheIndex, std::string cacheIdentifier)
 Add one cache index for given neighbor element and check identifier. More...
 
std::vector< std::vector< std::size_t > > getCacheIndices () const
 Getter for cacheIndices. More...
 

Additional Inherited Members

- Public Types inherited from nnp::SymFnc
enum  ScalingType {
  ST_NONE , ST_SCALE , ST_CENTER , ST_SCALECENTER ,
  ST_SCALESIGMA
}
 List of available scaling types. More...
 
- Protected Types inherited from nnp::SymFnc
typedef std::map< std::string, std::pair< std::string, std::string > > PrintFormat
 
typedef std::vector< std::string > PrintOrder
 
- Protected Member Functions inherited from nnp::SymFncBaseCompAng
 SymFncBaseCompAng (std::size_t type, ElementMap const &)
 Constructor, initializes type. More...
 
- Protected Member Functions inherited from nnp::SymFncBaseComp
 SymFncBaseComp (std::size_t type, ElementMap const &)
 Constructor, initializes type. More...
 
- Protected Member Functions inherited from nnp::SymFnc
 SymFnc (std::size_t type, ElementMap const &)
 Constructor, initializes type. More...
 
std::string getPrintFormat () const
 Generate format string for symmetry function parameter printing. More...
 
- Static Protected Member Functions inherited from nnp::SymFnc
static PrintFormat const initializePrintFormat ()
 Initialize static print format map for all possible parameters. More...
 
static PrintOrder const initializePrintOrder ()
 Initialize static print order vector for all possible parameters. More...
 
- Protected Attributes inherited from nnp::SymFncBaseCompAng
std::size_t e1
 Element index of neighbor atom 1. More...
 
std::size_t e2
 Element index of neighbor atom 2. More...
 
double angleLeft
 Left angle boundary. More...
 
double angleRight
 Right angle boundary. More...
 
double angleLeftRadians
 Left angle boundary in radians. More...
 
double angleRightRadians
 Right angle boundary in radians. More...
 
CompactFunction ca
 Compact function member for angular part. More...
 
- Protected Attributes inherited from nnp::SymFncBaseComp
bool asymmetric
 If asymmetric version of polynomials should be used. More...
 
double rl
 Lower bound of compact function, \(r_{l}\). More...
 
std::string subtype
 Subtype string (specifies e.g. polynom type). More...
 
CompactFunction cr
 Compact function for radial part. More...
 
- Protected Attributes inherited from nnp::SymFnc
std::size_t type
 Symmetry function type. More...
 
ElementMap elementMap
 Copy of element map. More...
 
std::size_t index
 Symmetry function index (per element). More...
 
std::size_t lineNumber
 Line number. More...
 
std::size_t ec
 Element index of center atom. More...
 
std::size_t minNeighbors
 Minimum number of neighbors required. More...
 
double Smin
 Minimum for scaling range. More...
 
double Smax
 Maximum for scaling range. More...
 
double Gmin
 Minimum unscaled symmetry function value. More...
 
double Gmax
 Maximum unscaled symmetry function value. More...
 
double Gmean
 Mean unscaled symmetry function value. More...
 
double Gsigma
 Sigma of unscaled symmetry function values. More...
 
double rc
 Cutoff radius \(r_c\). More...
 
double scalingFactor
 Scaling factor. More...
 
double convLength
 Data set normalization length conversion factor. More...
 
ScalingType scalingType
 Symmetry function scaling type used by this symmetry function. More...
 
std::set< std::string > parameters
 Set with symmetry function parameter IDs (lookup for printing). More...
 
std::vector< std::size_t > indexPerElement
 Per-element index for derivative memory in Atom::Neighbor::dGdr arrays. More...
 
std::vector< std::vector< std::size_t > > cacheIndices
 Cache indices for each element. More...
 
- Static Protected Attributes inherited from nnp::SymFnc
static std::size_t const sfinfoWidth = 12
 Width of the SFINFO parameter description field (see parameterInfo()). More...
 
static PrintFormat const printFormat = initializePrintFormat()
 Map of parameter format strings and empty strings. More...
 
static PrintOrder const printOrder = initializePrintOrder()
 Vector of parameters in order of printing. More...
 

Detailed Description

Narrow angular symmetry function with compact support (type 21)

\[ G^{21}_i = \sum_{\substack{j,k\neq i \\ j < k}} C(r_{ij}, r_l, r_c) C(r_{ik}, r_l, r_c) C(r_{jk}, r_l, r_c) C(\theta_{ijk}, \theta_l, \theta_r), \]

where \(C(x, x_\text{low}, x_\text{high})\) is a function with compact support \(\left[x_\text{low}, x_\text{high}\right]\).

Parameter string:

<element-central> 21 <element-neighbor1> <element-neighbor2> <rlow> <rcutoff> <left> <right> <subtype>
std::string subtype
Subtype string (specifies e.g. polynom type).

where

  • <element-central> ..... element symbol of central atom
  • <element-neighbor1> ... element symbol of neighbor atom 1
  • <element-neighbor2> ... element symbol of neighbor atom 2
  • <rlow> ................ low radius boundary \(r_{l}\)
  • <rcutoff> ............. high radius boundary \(r_{c}\)
  • <left> ................ left angle boundary \(\theta_l\)
  • <right> ............... right angle boundary \(\theta_r\)
  • <subtype> ............. compact function specifier

See the description of SymFncBaseComp::setCompactFunction() for possible values of the <subtype> argument.

Note
If <subtype> specifies an asymmetric version of a polynomial core function the asymmetry only applies to the radial parts, i.e. "p2a" sets a "p2a" radial compact function and a "p2" angular compact function.

Definition at line 65 of file SymFncCompAngn.h.

Constructor & Destructor Documentation

◆ SymFncCompAngn()

SymFncCompAngn::SymFncCompAngn ( ElementMap const &  elementMap)

Constructor, sets type = 21.

Definition at line 31 of file SymFncCompAngn.cpp.

32 :
34{
35}
SymFncBaseCompAng(std::size_t type, ElementMap const &)
Constructor, initializes type.
ElementMap elementMap
Copy of element map.
Definition: SymFnc.h:270

Member Function Documentation

◆ operator==()

bool SymFncCompAngn::operator== ( SymFnc const &  rhs) const
virtual

Overload == operator.

Implements nnp::SymFnc.

Definition at line 37 of file SymFncCompAngn.cpp.

38{
39 if (ec != rhs.getEc() ) return false;
40 if (type != rhs.getType()) return false;
41 SymFncCompAngn const& c = dynamic_cast<SymFncCompAngn const&>(rhs);
42 if (subtype != c.getSubtype()) return false;
43 if (e1 != c.e1 ) return false;
44 if (e2 != c.e2 ) return false;
45 if (rc != c.rc ) return false;
46 if (rl != c.rl ) return false;
47 if (angleLeft != c.angleLeft ) return false;
48 if (angleRight != c.angleRight ) return false;
49 return true;
50}
double angleLeft
Left angle boundary.
double angleRight
Right angle boundary.
std::size_t e2
Element index of neighbor atom 2.
std::size_t e1
Element index of neighbor atom 1.
std::string getSubtype() const
Get private subtype member variable.
double rl
Lower bound of compact function, .
Narrow angular symmetry function with compact support (type 21)
std::size_t type
Symmetry function type.
Definition: SymFnc.h:268
double rc
Cutoff radius .
Definition: SymFnc.h:292
std::size_t ec
Element index of center atom.
Definition: SymFnc.h:276

References nnp::SymFncBaseCompAng::angleLeft, nnp::SymFncBaseCompAng::angleRight, nnp::SymFncBaseCompAng::e1, nnp::SymFncBaseCompAng::e2, nnp::SymFnc::ec, nnp::SymFnc::getEc(), nnp::SymFncBaseComp::getSubtype(), nnp::SymFnc::getType(), nnp::SymFnc::rc, nnp::SymFncBaseComp::rl, nnp::SymFncBaseComp::subtype, and nnp::SymFnc::type.

Here is the call graph for this function:

◆ operator<()

bool SymFncCompAngn::operator< ( SymFnc const &  rhs) const
virtual

Overload < operator.

Implements nnp::SymFnc.

Definition at line 52 of file SymFncCompAngn.cpp.

53{
54 if (ec < rhs.getEc() ) return true;
55 else if (ec > rhs.getEc() ) return false;
56 if (type < rhs.getType()) return true;
57 else if (type > rhs.getType()) return false;
58 SymFncCompAngn const& c = dynamic_cast<SymFncCompAngn const&>(rhs);
59 if (subtype < c.getSubtype()) return true;
60 else if (subtype > c.getSubtype()) return false;
61 if (e1 < c.e1 ) return true;
62 else if (e1 > c.e1 ) return false;
63 if (e2 < c.e2 ) return true;
64 else if (e2 > c.e2 ) return false;
65 if (rc < c.rc ) return true;
66 else if (rc > c.rc ) return false;
67 if (rl < c.rl ) return true;
68 else if (rl > c.rl ) return false;
69 if (angleLeft < c.angleLeft ) return true;
70 else if (angleLeft > c.angleLeft ) return false;
71 if (angleRight < c.angleRight ) return true;
72 else if (angleRight > c.angleRight ) return false;
73 return false;
74}

References nnp::SymFncBaseCompAng::angleLeft, nnp::SymFncBaseCompAng::angleRight, nnp::SymFncBaseCompAng::e1, nnp::SymFncBaseCompAng::e2, nnp::SymFnc::ec, nnp::SymFnc::getEc(), nnp::SymFncBaseComp::getSubtype(), nnp::SymFnc::getType(), nnp::SymFnc::rc, nnp::SymFncBaseComp::rl, nnp::SymFncBaseComp::subtype, and nnp::SymFnc::type.

Here is the call graph for this function:

◆ calculate()

void SymFncCompAngn::calculate ( Atom atom,
bool const  derivatives 
) const
virtual

Calculate symmetry function for one atom.

Parameters
[in,out]atomAtom for which the symmetry function is caluclated.
[in]derivativesIf also symmetry function derivatives will be calculated and saved.

Implements nnp::SymFnc.

Definition at line 76 of file SymFncCompAngn.cpp.

77{
78 double r2l = 0.0;
79 if (rl > 0.0) r2l = rl * rl;
80 double r2c = rc * rc;
81 double result = 0.0;
82
83 size_t numNeighbors = atom.numNeighbors;
84 // Prevent problematic condition in loop test below (j < numNeighbors - 1).
85 if (numNeighbors == 0) numNeighbors = 1;
86
87 for (size_t j = 0; j < numNeighbors - 1; j++)
88 {
89 Atom::Neighbor& nj = atom.neighbors[j];
90 size_t const nej = nj.element;
91 double const rij = nj.d;
92 if ((e1 == nej || e2 == nej) && rij < rc && rij > rl)
93 {
94 double radij;
95 double dradij;
96#ifndef N2P2_NO_SF_CACHE
97 if (cacheIndices[nej].size() == 0) cr.fdf(rij, radij, dradij);
98 else
99 {
100 double& crad = nj.cache[cacheIndices[nej][0]];
101 double& cdrad = nj.cache[cacheIndices[nej][1]];
102 if (crad < 0) cr.fdf(rij, crad, cdrad);
103 radij = crad;
104 dradij = cdrad;
105 }
106#else
107 cr.fdf(rij, radij, dradij);
108#endif
109 for (size_t k = j + 1; k < numNeighbors; k++)
110 {
111 Atom::Neighbor& nk = atom.neighbors[k];
112 size_t const nek = nk.element;
113 if ((e1 == nej && e2 == nek) ||
114 (e2 == nej && e1 == nek))
115 {
116 double const rik = nk.d;
117 if (rik < rc && rik > rl)
118 {
119 // Energy calculation.
120 Vec3D drij = nj.dr;
121 Vec3D drik = nk.dr;
122 Vec3D drjk = nk.dr - nj.dr;
123 double rjk = drjk.norm2();
124 if (rjk >= r2c || rjk <= r2l) continue;
125 rjk = sqrt(rjk);
126
127 double radik;
128 double dradik;
129#ifndef N2P2_NO_SF_CACHE
130 if (cacheIndices[nek].size() == 0)
131 {
132 cr.fdf(rik, radik, dradik);
133 }
134 else
135 {
136 double& crad = nk.cache[cacheIndices[nek][0]];
137 double& cdrad = nk.cache[cacheIndices[nek][1]];
138 if (crad < 0) cr.fdf(rik, crad, cdrad);
139 radik = crad;
140 dradik = cdrad;
141 }
142#else
143 cr.fdf(rik, radik, dradik);
144#endif
145 double radjk;
146 double dradjk;
147 cr.fdf(rjk, radjk, dradjk);
148
149 double costijk = drij * drik;
150 double rinvijik = 1.0 / rij / rik;
151 costijk *= rinvijik;
152
153 // By definition, our polynomial is zero at 0 and 180 deg.
154 // Therefore, skip the whole rest which might yield some NaN
155 if (costijk <= -1.0 || costijk >= 1.0) continue;
156
157 // Regroup later: Get acos(cos)
158 double const acostijk = acos(costijk);
159 // Only go on if we are within our compact support
160 if (acostijk < angleLeftRadians ||
161 acostijk > angleRightRadians) continue;
162 double ang = 0.0;
163 double dang = 0.0;
164 ca.fdf(acostijk, ang, dang);
165
166 double const rad = radij * radik * radjk; // product of cutoff fcts
167 result += rad * ang;
168
169 // Force calculation.
170 if (!derivatives) continue;
171
172 double const dacostijk = -1.0
173 / sqrt(1.0 - costijk * costijk);
174 dang *= dacostijk;
175 double const rinvij = rinvijik * rik;
176 double const rinvik = rinvijik * rij;
177 double const rinvjk = 1.0 / rjk;
178 double phiijik = rinvij * (rinvik - rinvij*costijk);
179 double phiikij = rinvik * (rinvij - rinvik*costijk);
180 double psiijik = rinvijik; // careful: sign flip w.r.t. notes due to nj.dGd...
181 phiijik *= dang;
182 phiikij *= dang;
183 psiijik *= dang;
184
185 // Cutoff function might be a divide by zero, but we screen that case before
186 double const chiij = rinvij * dradij * radik * radjk;
187 double const chiik = rinvik * radij * dradik * radjk;
188 double const chijk = -rinvjk * radij * radik * dradjk;
189
190 // rijs/rij due to the shifted radial part of the Gaussian
191 double const p1 = rad * phiijik + ang * chiij;
192 double const p2 = rad * phiikij + ang * chiik;
193 double const p3 = rad * psiijik + ang * chijk;
194 drij *= p1 * scalingFactor;
195 drik *= p2 * scalingFactor;
196 drjk *= p3 * scalingFactor;
197
198 // Save force contributions in Atom storage.
199 atom.dGdr[index] += drij + drik;
200#ifndef N2P2_FULL_SFD_MEMORY
201 nj.dGdr[indexPerElement[nej]] -= drij + drjk;
202 nk.dGdr[indexPerElement[nek]] -= drik - drjk;
203#else
204 nj.dGdr[index] -= drij + drjk;
205 nk.dGdr[index] -= drik - drjk;
206#endif
207 } // rik <= rc
208 } // elem
209 } // k
210 } // rij <= rc
211 } // j
212
213 atom.G[index] = scale(result);
214
215 return;
216}
void fdf(double a, double &fa, double &dfa) const
Calculate compact function and derivative at once.
double angleRightRadians
Right angle boundary in radians.
CompactFunction ca
Compact function member for angular part.
double angleLeftRadians
Left angle boundary in radians.
CompactFunction cr
Compact function for radial part.
std::size_t index
Symmetry function index (per element).
Definition: SymFnc.h:272
double scalingFactor
Scaling factor.
Definition: SymFnc.h:294
std::vector< std::vector< std::size_t > > cacheIndices
Cache indices for each element.
Definition: SymFnc.h:306
double scale(double value) const
Apply symmetry function scaling and/or centering.
Definition: SymFnc.cpp:169
std::vector< std::size_t > indexPerElement
Per-element index for derivative memory in Atom::Neighbor::dGdr arrays.
Definition: SymFnc.h:302
Struct to store information on neighbor atoms.
Definition: Atom.h:36
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
std::vector< Vec3D > dGdr
Derivatives of symmetry functions with respect to neighbor coordinates.
Definition: Atom.h:60
std::vector< Neighbor > neighbors
Neighbor array (maximum number defined in macros.h.
Definition: Atom.h:170
std::vector< Vec3D > dGdr
Derivative of symmetry functions with respect to this atom's coordinates.
Definition: Atom.h:161
std::vector< double > G
Symmetry function values.
Definition: Atom.h:146
std::size_t numNeighbors
Total number of neighbors.
Definition: Atom.h:109
Vector in 3 dimensional real space.
Definition: Vec3D.h:30
double norm2() const
Calculate square of norm of vector.
Definition: Vec3D.h:299

References nnp::SymFncBaseCompAng::angleLeftRadians, nnp::SymFncBaseCompAng::angleRightRadians, nnp::SymFncBaseCompAng::ca, nnp::Atom::Neighbor::cache, nnp::SymFnc::cacheIndices, nnp::SymFncBaseComp::cr, nnp::Atom::Neighbor::d, nnp::Atom::Neighbor::dGdr, nnp::Atom::dGdr, nnp::Atom::Neighbor::dr, nnp::SymFncBaseCompAng::e1, nnp::SymFncBaseCompAng::e2, nnp::Atom::Neighbor::element, nnp::CompactFunction::fdf(), nnp::Atom::G, nnp::SymFnc::index, nnp::SymFnc::indexPerElement, nnp::Atom::neighbors, nnp::Vec3D::norm2(), nnp::Atom::numNeighbors, nnp::SymFnc::rc, nnp::SymFncBaseComp::rl, nnp::SymFnc::scale(), and nnp::SymFnc::scalingFactor.

Here is the call graph for this function:

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