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

Radial symmetry function group (type 2) More...

#include <SymGrpExpRad.h>

Inheritance diagram for nnp::SymGrpExpRad:
Collaboration diagram for nnp::SymGrpExpRad:

Public Member Functions

 SymGrpExpRad (ElementMap const &elementMap)
 Constructor, sets type = 2. More...
 
virtual bool operator== (SymGrp const &rhs) const
 Overload == operator. More...
 
virtual bool operator< (SymGrp const &rhs) const
 Overload < operator. More...
 
virtual bool addMember (SymFnc const *const symmetryFunction)
 Potentially add a member to group. More...
 
virtual void sortMembers ()
 Sort member symmetry functions. More...
 
virtual void setScalingFactors ()
 Fill scalingFactors with values from member symmetry functions. More...
 
virtual void calculate (Atom &atom, bool const derivatives) const
 Calculate all symmetry functions of this group for one atom. More...
 
virtual std::vector< std::string > parameterLines () const
 Give symmetry function group parameters on multiple lines. More...
 
- Public Member Functions inherited from nnp::SymGrpBaseCutoff
double getRc () const
 Get private rc member variable. More...
 
- Public Member Functions inherited from nnp::SymGrp
virtual ~SymGrp ()
 Virtual destructor. More...
 
virtual bool operator== (SymGrp const &rhs) const =0
 Overload == operator. More...
 
virtual bool operator< (SymGrp const &rhs) const =0
 Overload < operator. More...
 
bool operator!= (SymGrp const &rhs) const
 Overload != operator. More...
 
bool operator> (SymGrp const &rhs) const
 Overload > operator. More...
 
bool operator<= (SymGrp const &rhs) const
 Overload <= operator. More...
 
bool operator>= (SymGrp const &rhs) const
 Overload >= operator. More...
 
virtual bool addMember (SymFnc const *const symmetryFunction)=0
 Potentially add a member to group. More...
 
virtual void sortMembers ()=0
 Sort member symmetry functions. More...
 
virtual void setScalingFactors ()=0
 Fill scalingFactors with values from member symmetry functions. More...
 
virtual void calculate (Atom &atom, bool const derivatives) const =0
 Calculate all symmetry functions of this group for one atom. More...
 
virtual std::vector< std::string > parameterLines () const =0
 Give symmetry function group parameters on multiple lines. More...
 
void setIndex (std::size_t index)
 Set private index member variable. More...
 
std::size_t getIndex () const
 Get private index member variable. More...
 
std::size_t getType () const
 Get private type member variable. More...
 
std::size_t getEc () const
 Get private ec member variable. More...
 

Private Attributes

std::size_t e1
 Element index of neighbor atom (common feature). More...
 
std::vector< SymFncExpRad const * > members
 Vector of all group member pointers. More...
 
std::vector< double > eta
 Vector containing values of all member symmetry functions. More...
 
std::vector< double > rs
 Vector containing values of all member symmetry functions. More...
 

Additional Inherited Members

- Protected Types inherited from nnp::SymGrp
typedef std::map< std::string, std::pair< std::string, std::string > > PrintFormat
 
typedef std::vector< std::string > PrintOrder
 
- Protected Member Functions inherited from nnp::SymGrpBaseCutoff
 SymGrpBaseCutoff (std::size_t type, ElementMap const &elementMap)
 Constructor, sets type. More...
 
- Protected Member Functions inherited from nnp::SymGrp
 SymGrp (std::size_t type, ElementMap const &elementMap)
 Constructor, sets type. More...
 
std::string getPrintFormatCommon () const
 Get common parameter line format string. More...
 
std::string getPrintFormatMember () const
 Get member parameter line format string. More...
 
- Static Protected Member Functions inherited from nnp::SymGrp
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::SymGrpBaseCutoff
double rc
 Cutoff radius \(r_c\) (common feature). More...
 
double cutoffAlpha
 Cutoff function parameter \(\alpha\) (common feature). More...
 
std::string subtype
 Subtype string (specifies cutoff type) (common feature). More...
 
CutoffFunction fc
 Cutoff function used by this symmetry function group. More...
 
CutoffFunction::CutoffType cutoffType
 Cutoff type used by this symmetry function group (common feature). More...
 
- Protected Attributes inherited from nnp::SymGrp
std::size_t type
 Symmetry function type. More...
 
ElementMap elementMap
 Copy of element map. More...
 
std::size_t index
 Symmetry function group index. More...
 
std::size_t ec
 Element index of center atom (common feature). More...
 
double convLength
 Data set normalization length conversion factor. More...
 
std::vector< size_t > memberIndex
 Vector containing indices of all member symmetry functions. More...
 
std::vector< double > scalingFactors
 Scaling factors of all member symmetry functions. More...
 
std::set< std::string > parametersCommon
 Set of common parameters IDs. More...
 
std::set< std::string > parametersMember
 Set of common parameters IDs. More...
 
std::vector< std::vector< std::size_t > > memberIndexPerElement
 Vector containing per-element indices of all member symmetry functions. More...
 
- Static Protected Attributes inherited from nnp::SymGrp
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

Radial symmetry function group (type 2)

\[ G^2_i = \sum_{j \neq i} \mathrm{e}^{-\eta(r_{ij} - r_\mathrm{s})^2} f_c(r_{ij}) \]

Common features:

  • element of central atom
  • element of neighbor atom
  • cutoff type
  • \(r_c\)
  • \(\alpha\)

Definition at line 46 of file SymGrpExpRad.h.

Constructor & Destructor Documentation

◆ SymGrpExpRad()

SymGrpExpRad::SymGrpExpRad ( ElementMap const &  elementMap)

Constructor, sets type = 2.

Definition at line 30 of file SymGrpExpRad.cpp.

30 :
32 e1(0)
33{
34 parametersCommon.insert("e1");
35
36 parametersMember.insert("eta");
37 parametersMember.insert("rs/rl");
38 parametersMember.insert("mindex");
39 parametersMember.insert("sfindex");
40}
SymGrpBaseCutoff(std::size_t type, ElementMap const &elementMap)
Constructor, sets type.
std::size_t e1
Element index of neighbor atom (common feature).
Definition: SymGrpExpRad.h:91
std::set< std::string > parametersCommon
Set of common parameters IDs.
Definition: SymGrp.h:120
ElementMap elementMap
Copy of element map.
Definition: SymGrp.h:108
std::set< std::string > parametersMember
Set of common parameters IDs.
Definition: SymGrp.h:122

References nnp::SymGrp::parametersCommon, and nnp::SymGrp::parametersMember.

Member Function Documentation

◆ operator==()

bool SymGrpExpRad::operator== ( SymGrp const &  rhs) const
virtual

Overload == operator.

Implements nnp::SymGrp.

Definition at line 42 of file SymGrpExpRad.cpp.

43{
44 if (ec != rhs.getEc() ) return false;
45 if (type != rhs.getType()) return false;
46 SymGrpExpRad const& c = dynamic_cast<SymGrpExpRad const&>(rhs);
47 if (cutoffType != c.cutoffType ) return false;
48 if (cutoffAlpha != c.cutoffAlpha) return false;
49 if (rc != c.rc ) return false;
50 if (e1 != c.e1 ) return false;
51 return true;
52}
double cutoffAlpha
Cutoff function parameter (common feature).
double rc
Cutoff radius (common feature).
CutoffFunction::CutoffType cutoffType
Cutoff type used by this symmetry function group (common feature).
Radial symmetry function group (type 2)
Definition: SymGrpExpRad.h:47
std::size_t type
Symmetry function type.
Definition: SymGrp.h:106
std::size_t ec
Element index of center atom (common feature).
Definition: SymGrp.h:112

References nnp::SymGrpBaseCutoff::cutoffAlpha, nnp::SymGrpBaseCutoff::cutoffType, e1, nnp::SymGrp::ec, nnp::SymGrp::getEc(), nnp::SymGrp::getType(), nnp::SymGrpBaseCutoff::rc, and nnp::SymGrp::type.

Here is the call graph for this function:

◆ operator<()

bool SymGrpExpRad::operator< ( SymGrp const &  rhs) const
virtual

Overload < operator.

Implements nnp::SymGrp.

Definition at line 54 of file SymGrpExpRad.cpp.

55{
56 if (ec < rhs.getEc() ) return true;
57 else if (ec > rhs.getEc() ) return false;
58 if (type < rhs.getType()) return true;
59 else if (type > rhs.getType()) return false;
60 SymGrpExpRad const& c = dynamic_cast<SymGrpExpRad const&>(rhs);
61 if (cutoffType < c.cutoffType ) return true;
62 else if (cutoffType > c.cutoffType ) return false;
63 if (cutoffAlpha < c.cutoffAlpha) return true;
64 else if (cutoffAlpha > c.cutoffAlpha) return false;
65 if (rc < c.rc ) return true;
66 else if (rc > c.rc ) return false;
67 if (e1 < c.e1 ) return true;
68 else if (e1 > c.e1 ) return false;
69 return false;
70}

References nnp::SymGrpBaseCutoff::cutoffAlpha, nnp::SymGrpBaseCutoff::cutoffType, e1, nnp::SymGrp::ec, nnp::SymGrp::getEc(), nnp::SymGrp::getType(), nnp::SymGrpBaseCutoff::rc, and nnp::SymGrp::type.

Here is the call graph for this function:

◆ addMember()

bool SymGrpExpRad::addMember ( SymFnc const *const  symmetryFunction)
virtual

Potentially add a member to group.

Parameters
[in]symmetryFunctionCandidate symmetry function.
Returns
If addition was successful.

If symmetry function is compatible with common feature list its pointer will be added to members.

Implements nnp::SymGrp.

Definition at line 72 of file SymGrpExpRad.cpp.

73{
74 if (symmetryFunction->getType() != type) return false;
75
76 SymFncExpRad const* sf =
77 dynamic_cast<SymFncExpRad const*>(symmetryFunction);
78
79 if (members.empty())
80 {
82 subtype = sf->getSubtype();
84 ec = sf->getEc();
85 rc = sf->getRc();
86 e1 = sf->getE1();
88
92 }
93
94 if (sf->getCutoffType() != cutoffType ) return false;
95 if (sf->getCutoffAlpha() != cutoffAlpha) return false;
96 if (sf->getEc() != ec ) return false;
97 if (sf->getRc() != rc ) return false;
98 if (sf->getE1() != e1 ) return false;
99 if (sf->getConvLength() != convLength )
100 {
101 throw runtime_error("ERROR: Unable to add symmetry function members "
102 "with different conversion factors.\n");
103 }
104
105 members.push_back(sf);
106
107 return true;
108}
void setCutoffParameter(double const alpha)
Set parameter for polynomial cutoff function (CT_POLY).
void setCutoffType(CutoffType const cutoffType)
Set cutoff type.
void setCutoffRadius(double const cutoffRadius)
Set cutoff radius.
std::string getSubtype() const
Get private subtype member variable.
double getCutoffAlpha() const
Get private cutoffAlpha member variable.
CutoffFunction::CutoffType getCutoffType() const
Get private cutoffType member variable.
Radial symmetry function (type 2)
Definition: SymFncExpRad.h:49
std::size_t getE1() const
Get private e1 member variable.
Definition: SymFncExpRad.h:145
double getConvLength() const
Get private convLength member variable.
Definition: SymFnc.h:364
double getRc() const
Get private rc member variable.
Definition: SymFnc.h:360
std::size_t getEc() const
Get private ec member variable.
Definition: SymFnc.h:356
std::string subtype
Subtype string (specifies cutoff type) (common feature).
CutoffFunction fc
Cutoff function used by this symmetry function group.
std::vector< SymFncExpRad const * > members
Vector of all group member pointers.
Definition: SymGrpExpRad.h:93
double convLength
Data set normalization length conversion factor.
Definition: SymGrp.h:114

References nnp::SymGrp::convLength, nnp::SymGrpBaseCutoff::cutoffAlpha, nnp::SymGrpBaseCutoff::cutoffType, e1, nnp::SymGrp::ec, nnp::SymGrpBaseCutoff::fc, nnp::SymFnc::getConvLength(), nnp::SymFncBaseCutoff::getCutoffAlpha(), nnp::SymFncBaseCutoff::getCutoffType(), nnp::SymFncExpRad::getE1(), nnp::SymFnc::getEc(), nnp::SymFnc::getRc(), nnp::SymFncBaseCutoff::getSubtype(), nnp::SymFnc::getType(), members, nnp::SymGrpBaseCutoff::rc, nnp::CutoffFunction::setCutoffParameter(), nnp::CutoffFunction::setCutoffRadius(), nnp::CutoffFunction::setCutoffType(), nnp::SymGrpBaseCutoff::subtype, and nnp::SymGrp::type.

Here is the call graph for this function:

◆ sortMembers()

void SymGrpExpRad::sortMembers ( )
virtual

Sort member symmetry functions.

Also allocate and precalculate additional stuff.

Implements nnp::SymGrp.

Definition at line 110 of file SymGrpExpRad.cpp.

111{
112 sort(members.begin(),
113 members.end(),
114 comparePointerTargets<SymFncExpRad const>);
115
116 for (size_t i = 0; i < members.size(); i++)
117 {
118 memberIndex.push_back(members[i]->getIndex());
119 eta.push_back(members[i]->getEta());
120 rs.push_back(members[i]->getRs());
121 memberIndexPerElement.push_back(members[i]->getIndexPerElement());
122 }
123
124 return;
125}
std::vector< double > rs
Vector containing values of all member symmetry functions.
Definition: SymGrpExpRad.h:97
std::vector< double > eta
Vector containing values of all member symmetry functions.
Definition: SymGrpExpRad.h:95
std::vector< size_t > memberIndex
Vector containing indices of all member symmetry functions.
Definition: SymGrp.h:116
std::vector< std::vector< std::size_t > > memberIndexPerElement
Vector containing per-element indices of all member symmetry functions.
Definition: SymGrp.h:124
std::size_t getIndex() const
Get private index member variable.
Definition: SymGrp.h:184

References eta, nnp::SymGrp::getIndex(), nnp::SymGrp::memberIndex, nnp::SymGrp::memberIndexPerElement, members, and rs.

Here is the call graph for this function:

◆ setScalingFactors()

void SymGrpExpRad::setScalingFactors ( )
virtual

Fill scalingFactors with values from member symmetry functions.

Implements nnp::SymGrp.

Definition at line 127 of file SymGrpExpRad.cpp.

128{
129 scalingFactors.resize(members.size(), 0.0);
130 for (size_t i = 0; i < members.size(); i++)
131 {
132 scalingFactors.at(i) = members[i]->getScalingFactor();
133 }
134
135 return;
136}
std::vector< double > scalingFactors
Scaling factors of all member symmetry functions.
Definition: SymGrp.h:118

References members, and nnp::SymGrp::scalingFactors.

◆ calculate()

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

Calculate all symmetry functions of this group for one atom.

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

Implements nnp::SymGrp.

Definition at line 144 of file SymGrpExpRad.cpp.

145{
146#ifndef N2P2_NO_SF_CACHE
147 // Can use cache indices of any member because this group is defined via
148 // identical symmetry function type, neighbors and cutoff functions.
149 auto cacheIndices = members.at(0)->getCacheIndices();
150 bool unique = true;
151 size_t c0 = 0;
152 size_t c1 = 0;
153 if (cacheIndices.at(e1).size() > 0)
154 {
155 unique = false;
156 c0 = cacheIndices.at(e1).at(0);
157 c1 = cacheIndices.at(e1).at(1);
158 }
159#endif
160 double* result = new double[members.size()];
161 for (size_t k = 0; k < members.size(); ++k)
162 {
163 result[k] = 0.0;
164 }
165
166 for (size_t j = 0; j < atom.getStoredMinNumNeighbors(rc); ++j)
167 {
168 Atom::Neighbor& n = atom.neighbors[j];
169 if (e1 == n.element && n.d < rc)
170 {
171 // Energy calculation.
172 double const rij = n.d;
173
174 // Calculate cutoff function and derivative.
175 double pfc;
176 double pdfc;
177#ifndef N2P2_NO_SF_CACHE
178 if (unique) fc.fdf(rij, pfc, pdfc);
179 else
180 {
181 double& cfc = n.cache[c0];
182 double& cdfc = n.cache[c1];
183 if (cfc < 0) fc.fdf(rij, cfc, cdfc);
184 pfc = cfc;
185 pdfc = cdfc;
186 }
187#else
188 fc.fdf(rij, pfc, pdfc);
189#endif
190 double const* const d1 = n.dr.r;
191 for (size_t k = 0; k < members.size(); ++k)
192 {
193 double pexp = exp(-eta[k] * (rij - rs[k]) * (rij - rs[k]));
194 result[k] += pexp * pfc;
195 // Force calculation.
196 if (!derivatives) continue;
197 double const p1 = scalingFactors[k] * (pdfc - 2.0 * eta[k]
198 * (rij - rs[k]) * pfc) * pexp / rij;
199 // SIMPLE EXPRESSIONS:
200 //Vec3D const dij = p1 * atom.neighbors[j].dr;
201 double const p1drijx = p1 * d1[0];
202 double const p1drijy = p1 * d1[1];
203 double const p1drijz = p1 * d1[2];
204
205 // Save force contributions in Atom storage.
206#ifndef N2P2_FULL_SFD_MEMORY
207 size_t ki = memberIndex[k];
208#else
209 size_t const ki = memberIndex[k];
210#endif
211 // SIMPLE EXPRESSIONS:
212 //atom.dGdr[ki] += dij;
213 //atom.neighbors[j].dGdr[ki] -= dij;
214
215 double* dGdr = atom.dGdr[ki].r;
216 dGdr[0] += p1drijx;
217 dGdr[1] += p1drijy;
218 dGdr[2] += p1drijz;
219
220#ifndef N2P2_FULL_SFD_MEMORY
221 ki = memberIndexPerElement[k][e1];
222#endif
223 dGdr = n.dGdr[ki].r;
224 dGdr[0] -= p1drijx;
225 dGdr[1] -= p1drijy;
226 dGdr[2] -= p1drijz;
227 }
228 }
229 }
230
231 for (size_t k = 0; k < members.size(); ++k)
232 {
233 atom.G[memberIndex[k]] = members[k]->scale(result[k]);
234 }
235
236 delete[] result;
237
238 return;
239}
void fdf(double r, double &fc, double &dfc) const
Calculate cutoff function and derivative .
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::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< 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
double r[3]
cartesian coordinates.
Definition: Vec3D.h:32

References nnp::Atom::Neighbor::cache, nnp::Atom::Neighbor::d, nnp::Atom::Neighbor::dGdr, nnp::Atom::dGdr, nnp::Atom::Neighbor::dr, e1, nnp::Atom::Neighbor::element, eta, nnp::SymGrpBaseCutoff::fc, nnp::CutoffFunction::fdf(), nnp::Atom::G, nnp::Atom::getStoredMinNumNeighbors(), nnp::SymGrp::memberIndex, nnp::SymGrp::memberIndexPerElement, members, nnp::Atom::neighbors, nnp::Vec3D::r, nnp::SymGrpBaseCutoff::rc, rs, and nnp::SymGrp::scalingFactors.

Here is the call graph for this function:

◆ parameterLines()

vector< string > SymGrpExpRad::parameterLines ( ) const
virtual

Give symmetry function group parameters on multiple lines.

Returns
Vector of string containing symmetry function parameters lines.

Implements nnp::SymGrp.

Definition at line 241 of file SymGrpExpRad.cpp.

242{
243 vector<string> v;
244
245 v.push_back(strpr(getPrintFormatCommon().c_str(),
246 index + 1,
247 elementMap[ec].c_str(),
248 type,
249 subtype.c_str(),
250 elementMap[e1].c_str(),
251 rc / convLength,
252 cutoffAlpha));
253
254 for (size_t i = 0; i < members.size(); ++i)
255 {
256 v.push_back(strpr(getPrintFormatMember().c_str(),
257 members[i]->getEta() * convLength * convLength,
258 members[i]->getRs() / convLength,
259 members[i]->getLineNumber() + 1,
260 i + 1,
261 members[i]->getIndex() + 1));
262 }
263
264 return v;
265}
std::size_t index
Symmetry function group index.
Definition: SymGrp.h:110
std::string getPrintFormatCommon() const
Get common parameter line format string.
Definition: SymGrp.cpp:97
std::string getPrintFormatMember() const
Get member parameter line format string.
Definition: SymGrp.cpp:130
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90

References nnp::SymGrp::convLength, nnp::SymGrpBaseCutoff::cutoffAlpha, e1, nnp::SymGrp::ec, nnp::SymGrp::elementMap, nnp::SymGrp::getIndex(), nnp::SymGrp::getPrintFormatCommon(), nnp::SymGrp::getPrintFormatMember(), nnp::SymGrp::index, members, nnp::SymGrpBaseCutoff::rc, nnp::strpr(), nnp::SymGrpBaseCutoff::subtype, and nnp::SymGrp::type.

Here is the call graph for this function:

Member Data Documentation

◆ e1

std::size_t nnp::SymGrpExpRad::e1
private

Element index of neighbor atom (common feature).

Definition at line 91 of file SymGrpExpRad.h.

Referenced by addMember(), calculate(), operator<(), operator==(), and parameterLines().

◆ members

std::vector<SymFncExpRad const*> nnp::SymGrpExpRad::members
private

Vector of all group member pointers.

Definition at line 93 of file SymGrpExpRad.h.

Referenced by addMember(), calculate(), parameterLines(), setScalingFactors(), and sortMembers().

◆ eta

std::vector<double> nnp::SymGrpExpRad::eta
private

Vector containing values of all member symmetry functions.

Definition at line 95 of file SymGrpExpRad.h.

Referenced by calculate(), and sortMembers().

◆ rs

std::vector<double> nnp::SymGrpExpRad::rs
private

Vector containing values of all member symmetry functions.

Definition at line 97 of file SymGrpExpRad.h.

Referenced by calculate(), and sortMembers().


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