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

Angular symmetry function (type 3) More...

#include <SymFncExpAngn.h>

Inheritance diagram for nnp::SymFncExpAngn:
Collaboration diagram for nnp::SymFncExpAngn:

Public Member Functions

 SymFncExpAngn (ElementMap const &elementMap)
 Constructor, sets type = 3. 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::SymFncBaseExpAng
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...
 
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...
 
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...
 
bool getUseIntegerPow () const
 Get private useIntegerPow member variable. More...
 
std::size_t getE1 () const
 Get private e1 member variable. More...
 
std::size_t getE2 () const
 Get private e2 member variable. More...
 
int getZetaInt () const
 Get private zetaInt member variable. More...
 
double getLambda () const
 Get private lambda member variable. More...
 
double getEta () const
 Get private eta member variable. More...
 
double getZeta () const
 Get private zeta member variable. More...
 
double getRs () const
 Get private rs member variable. More...
 
- Public Member Functions inherited from nnp::SymFncBaseCutoff
virtual std::vector< std::string > parameterInfo () const
 Get description with parameter names and values. More...
 
void setCutoffFunction (CutoffFunction::CutoffType cutoffType, double cutoffAlpha)
 Set cutoff function type and parameter. More...
 
double getCutoffAlpha () const
 Get private cutoffAlpha member variable. More...
 
std::string getSubtype () const
 Get private subtype member variable. More...
 
CutoffFunction::CutoffType getCutoffType () const
 Get private cutoffType 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::SymFncBaseExpAng
 SymFncBaseExpAng (std::size_t type, ElementMap const &)
 Constructor, initializes type. More...
 
- Protected Member Functions inherited from nnp::SymFncBaseCutoff
 SymFncBaseCutoff (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::SymFncBaseExpAng
bool useIntegerPow
 Whether to use integer version of power function (faster). More...
 
std::size_t e1
 Element index of neighbor atom 1. More...
 
std::size_t e2
 Element index of neighbor atom 2. More...
 
int zetaInt
 Integer version of \(\zeta\). More...
 
double lambda
 Cosine shift factor. More...
 
double eta
 Width \(\eta\) of gaussian. More...
 
double zeta
 Exponent \(\zeta\) of cosine term. More...
 
double rs
 Shift \(r_s\) of gaussian. More...
 
- Protected Attributes inherited from nnp::SymFncBaseCutoff
double cutoffAlpha
 Cutoff parameter \(\alpha\). More...
 
std::string subtype
 Subtype string (specifies cutoff type). More...
 
CutoffFunction fc
 Cutoff function used by this symmetry function. More...
 
CutoffFunction::CutoffType cutoffType
 Cutoff type used by this symmetry function. 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

Angular symmetry function (type 3)

\[ G^3_i = 2^{1-\zeta} \sum_{\substack{j,k\neq i \\ j < k}} \left( 1 + \lambda \cos \theta_{ijk} \right)^\zeta \mathrm{e}^{-\eta( (r_{ij}-r_s)^2 + (r_{ik}-r_s)^2 + (r_{jk}-r_s)^2 ) } f_c(r_{ij}) f_c(r_{ik}) f_c(r_{jk}) \]

Parameter string:

<element-central> 3 <element-neighbor1> <element-neighbor2> <eta> <lambda> <zeta> <rcutoff> <<rshift>>
double lambda
Cosine shift factor.
double zeta
Exponent of cosine term.
double eta
Width of gaussian.

where

  • <element-central> ..... element symbol of central atom
  • <element-neighbor1> ... element symbol of neighbor atom 1
  • <element-neighbor2> ... element symbol of neighbor atom 2
  • <eta> ................. \(\eta\)
  • <lambda> .............. \(\lambda\)
  • <zeta> ................ \(\zeta\)
  • <rcutoff> ............. \(r_c\)
  • <<rshift>> ............ \(r_s\) (optional, default \(r_s = 0\))

Definition at line 54 of file SymFncExpAngn.h.

Constructor & Destructor Documentation

◆ SymFncExpAngn()

SymFncExpAngn::SymFncExpAngn ( ElementMap const &  elementMap)

Constructor, sets type = 3.

Definition at line 30 of file SymFncExpAngn.cpp.

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

Member Function Documentation

◆ operator==()

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

Overload == operator.

Implements nnp::SymFnc.

Definition at line 35 of file SymFncExpAngn.cpp.

36{
37 if (ec != rhs.getEc() ) return false;
38 if (type != rhs.getType()) return false;
39 SymFncExpAngn const& c = dynamic_cast<SymFncExpAngn const&>(rhs);
40 if (cutoffType != c.cutoffType ) return false;
41 if (cutoffAlpha != c.cutoffAlpha) return false;
42 if (rc != c.rc ) return false;
43 if (eta != c.eta ) return false;
44 if (zeta != c.zeta ) return false;
45 if (lambda != c.lambda ) return false;
46 if (e1 != c.e1 ) return false;
47 if (e2 != c.e2 ) return false;
48 return true;
49}
CutoffFunction::CutoffType cutoffType
Cutoff type used by this symmetry function.
double cutoffAlpha
Cutoff parameter .
std::size_t e1
Element index of neighbor atom 1.
std::size_t e2
Element index of neighbor atom 2.
Angular symmetry function (type 3)
Definition: SymFncExpAngn.h:55
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::SymFncBaseCutoff::cutoffAlpha, nnp::SymFncBaseCutoff::cutoffType, nnp::SymFncBaseExpAng::e1, nnp::SymFncBaseExpAng::e2, nnp::SymFnc::ec, nnp::SymFncBaseExpAng::eta, nnp::SymFnc::getEc(), nnp::SymFnc::getType(), nnp::SymFncBaseExpAng::lambda, nnp::SymFnc::rc, nnp::SymFnc::type, and nnp::SymFncBaseExpAng::zeta.

Here is the call graph for this function:

◆ operator<()

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

Overload < operator.

Implements nnp::SymFnc.

Definition at line 51 of file SymFncExpAngn.cpp.

52{
53 if (ec < rhs.getEc() ) return true;
54 else if (ec > rhs.getEc() ) return false;
55 if (type < rhs.getType()) return true;
56 else if (type > rhs.getType()) return false;
57 SymFncExpAngn const& c = dynamic_cast<SymFncExpAngn const&>(rhs);
58 if (cutoffType < c.cutoffType ) return true;
59 else if (cutoffType > c.cutoffType ) return false;
60 if (cutoffAlpha < c.cutoffAlpha) return true;
61 else if (cutoffAlpha > c.cutoffAlpha) return false;
62 if (rc < c.rc ) return true;
63 else if (rc > c.rc ) return false;
64 if (eta < c.eta ) return true;
65 else if (eta > c.eta ) return false;
66 if (rs < c.rs ) return true;
67 else if (rs > c.rs ) return false;
68 if (zeta < c.zeta ) return true;
69 else if (zeta > c.zeta ) return false;
70 if (lambda < c.lambda ) return true;
71 else if (lambda > c.lambda ) return false;
72 if (e1 < c.e1 ) return true;
73 else if (e1 > c.e1 ) return false;
74 if (e2 < c.e2 ) return true;
75 else if (e2 > c.e2 ) return false;
76 return false;
77}
double rs
Shift of gaussian.

References nnp::SymFncBaseCutoff::cutoffAlpha, nnp::SymFncBaseCutoff::cutoffType, nnp::SymFncBaseExpAng::e1, nnp::SymFncBaseExpAng::e2, nnp::SymFnc::ec, nnp::SymFncBaseExpAng::eta, nnp::SymFnc::getEc(), nnp::SymFnc::getType(), nnp::SymFncBaseExpAng::lambda, nnp::SymFnc::rc, nnp::SymFncBaseExpAng::rs, nnp::SymFnc::type, and nnp::SymFncBaseExpAng::zeta.

Here is the call graph for this function:

◆ calculate()

void SymFncExpAngn::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 79 of file SymFncExpAngn.cpp.

80{
81 double const pnorm = pow(2.0, 1.0 - zeta);
82 double const pzl = zeta * lambda;
83 double const rc2 = rc * rc;
84 double result = 0.0;
85
86 size_t numNeighbors = atom.numNeighbors;
87 // Prevent problematic condition in loop test below (j < numNeighbors - 1).
88 if (numNeighbors == 0) numNeighbors = 1;
89
90 for (size_t j = 0; j < numNeighbors - 1; j++)
91 {
92 Atom::Neighbor& nj = atom.neighbors[j];
93 size_t const nej = nj.element;
94 double const rij = nj.d;
95 if ((e1 == nej || e2 == nej) && rij < rc)
96 {
97 double const r2ij = rij * rij;
98
99 // Calculate cutoff function and derivative.
100 double pfcij;
101 double pdfcij;
102#ifndef N2P2_NO_SF_CACHE
103 if (cacheIndices[nej].size() == 0) fc.fdf(rij, pfcij, pdfcij);
104 else
105 {
106 double& cfc = nj.cache[cacheIndices[nej][0]];
107 double& cdfc = nj.cache[cacheIndices[nej][1]];
108 if (cfc < 0) fc.fdf(rij, cfc, cdfc);
109 pfcij = cfc;
110 pdfcij = cdfc;
111 }
112#else
113 fc.fdf(rij, pfcij, pdfcij);
114#endif
115 for (size_t k = j + 1; k < numNeighbors; k++)
116 {
117 Atom::Neighbor& nk = atom.neighbors[k];
118 size_t const nek = nk.element;
119 if ((e1 == nej && e2 == nek) ||
120 (e2 == nej && e1 == nek))
121 {
122 double const rik = nk.d;
123 if (rik < rc)
124 {
125 Vec3D drjk = nk.dr - nj.dr;
126 double rjk = drjk.norm2();;
127 if (rjk < rc2)
128 {
129 // Energy calculation.
130 double pfcik;
131 double pdfcik;
132#ifndef N2P2_NO_SF_CACHE
133 if (cacheIndices[nej].size() == 0)
134 {
135 fc.fdf(rik, pfcik, pdfcik);
136 }
137 else
138 {
139 double& cfc = nk.cache[cacheIndices[nek][0]];
140 double& cdfc = nk.cache[cacheIndices[nek][1]];
141 if (cfc < 0) fc.fdf(rik, cfc, cdfc);
142 pfcik = cfc;
143 pdfcik = cdfc;
144 }
145#else
146 fc.fdf(rik, pfcik, pdfcik);
147#endif
148 rjk = sqrt(rjk);
149 double pfcjk;
150 double pdfcjk;
151 fc.fdf(rjk, pfcjk, pdfcjk);
152
153 Vec3D drij = nj.dr;
154 Vec3D drik = nk.dr;
155 double costijk = drij * drik;;
156 double rinvijik = 1.0 / rij / rik;
157 costijk *= rinvijik;
158
159 double const pfc = pfcij * pfcik * pfcjk;
160 double const r2ik = rik * rik;
161 double const rijs = rij - rs;
162 double const riks = rik - rs;
163 double const rjks = rjk - rs;
164 double const pexp = exp(-eta * (rijs * rijs +
165 riks * riks +
166 rjks * rjks));
167 double const plambda = 1.0 + lambda * costijk;
168 double fg = pexp;
169 if (plambda <= 0.0) fg = 0.0;
170 else
171 {
172 if (useIntegerPow)
173 {
174 fg *= pow_int(plambda, zetaInt - 1);
175 }
176 else
177 {
178 fg *= pow(plambda, zeta - 1.0);
179 }
180 }
181 result += fg * plambda * pfc;
182
183 // Force calculation.
184 if (!derivatives) continue;
185 fg *= pnorm;
186 rinvijik *= pzl;
187 costijk *= pzl;
188 double const p2etapl = 2.0 * eta * plambda;
189 double const p1 = fg * (pfc * (rinvijik - costijk
190 / r2ij - p2etapl * rijs / rij)
191 + pfcik * pfcjk * pdfcij * plambda
192 / rij);
193 double const p2 = fg * (pfc * (rinvijik - costijk
194 / r2ik - p2etapl * riks / rik)
195 + pfcij * pfcjk * pdfcik * plambda
196 / rik);
197 double const p3 = fg * (pfc * (rinvijik + p2etapl
198 * rjks / rjk) - pfcij * pfcik
199 * pdfcjk * plambda / rjk);
200 drij *= p1 * scalingFactor;
201 drik *= p2 * scalingFactor;
202 drjk *= p3 * scalingFactor;
203
204 // Save force contributions in Atom storage.
205 atom.dGdr[index] += drij + drik;
206#ifndef N2P2_FULL_SFD_MEMORY
207 nj.dGdr[indexPerElement[nej]] -= drij + drjk;
208 nk.dGdr[indexPerElement[nek]] -= drik - drjk;
209#else
210 nj.dGdr[index] -= drij + drjk;
211 nk.dGdr[index] -= drik - drjk;
212#endif
213 } // rjk <= rc
214 } // rik <= rc
215 } // elem
216 } // k
217 } // rij <= rc
218 } // j
219 result *= pnorm;
220
221 atom.G[index] = scale(result);
222
223 return;
224}
void fdf(double r, double &fc, double &dfc) const
Calculate cutoff function and derivative .
CutoffFunction fc
Cutoff function used by this symmetry function.
int zetaInt
Integer version of .
bool useIntegerPow
Whether to use integer version of power function (faster).
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
double pow_int(double x, int n)
Integer version of power function, "fast exponentiation algorithm".
Definition: utility.cpp:285
Struct to store information on neighbor atoms.
Definition: Atom.h:35
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
std::vector< Vec3D > dGdr
Derivatives of symmetry functions with respect to neighbor coordinates.
Definition: Atom.h:59
std::vector< Neighbor > neighbors
Neighbor array (maximum number defined in macros.h.
Definition: Atom.h:148
std::vector< Vec3D > dGdr
Derivative of symmetry functions with respect to this atom's coordinates.
Definition: Atom.h:146
std::vector< double > G
Symmetry function values.
Definition: Atom.h:134
std::size_t numNeighbors
Total number of neighbors.
Definition: Atom.h:106
Vector in 3 dimensional real space.
Definition: Vec3D.h:29
double norm2() const
Calculate square of norm of vector.
Definition: Vec3D.h:261

References nnp::Atom::Neighbor::cache, nnp::SymFnc::cacheIndices, nnp::Atom::Neighbor::d, nnp::Atom::Neighbor::dGdr, nnp::Atom::dGdr, nnp::Atom::Neighbor::dr, nnp::SymFncBaseExpAng::e1, nnp::SymFncBaseExpAng::e2, nnp::Atom::Neighbor::element, nnp::SymFncBaseExpAng::eta, nnp::SymFncBaseCutoff::fc, nnp::CutoffFunction::fdf(), nnp::Atom::G, nnp::SymFnc::index, nnp::SymFnc::indexPerElement, nnp::SymFncBaseExpAng::lambda, nnp::Atom::neighbors, nnp::Vec3D::norm2(), nnp::Atom::numNeighbors, nnp::pow_int(), nnp::SymFnc::rc, nnp::SymFncBaseExpAng::rs, nnp::SymFnc::scale(), nnp::SymFnc::scalingFactor, nnp::SymFncBaseExpAng::useIntegerPow, nnp::SymFncBaseExpAng::zeta, and nnp::SymFncBaseExpAng::zetaInt.

Here is the call graph for this function:

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