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

Weighted radial symmetry function group (type 12) More...

#include <SymGrpExpRadWeighted.h>

Inheritance diagram for nnp::SymGrpExpRadWeighted:
Collaboration diagram for nnp::SymGrpExpRadWeighted:

Public Member Functions

 SymGrpExpRadWeighted (ElementMap const &elementMap)
 Constructor, sets type = 12. 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::vector< SymFncExpRadWeighted 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

Weighted radial symmetry function group (type 12)

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

Common features:

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

Definition at line 45 of file SymGrpExpRadWeighted.h.

Constructor & Destructor Documentation

◆ SymGrpExpRadWeighted()

SymGrpExpRadWeighted::SymGrpExpRadWeighted ( ElementMap const &  elementMap)

Constructor, sets type = 12.

Definition at line 30 of file SymGrpExpRadWeighted.cpp.

30 :
32{
33 parametersMember.insert("eta");
34 parametersMember.insert("rs/rl");
35 parametersMember.insert("mindex");
36 parametersMember.insert("sfindex");
37}
SymGrpBaseCutoff(std::size_t type, ElementMap const &elementMap)
Constructor, sets type.
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::parametersMember.

Member Function Documentation

◆ operator==()

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

Overload == operator.

Implements nnp::SymGrp.

Definition at line 39 of file SymGrpExpRadWeighted.cpp.

40{
41 if (ec != rhs.getEc() ) return false;
42 if (type != rhs.getType()) return false;
43 SymGrpExpRadWeighted const& c =
44 dynamic_cast<SymGrpExpRadWeighted const&>(rhs);
45 if (cutoffType != c.cutoffType ) return false;
46 if (cutoffAlpha != c.cutoffAlpha) return false;
47 if (rc != c.rc ) return false;
48 return true;
49}
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).
Weighted radial symmetry function group (type 12)
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, 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 SymGrpExpRadWeighted::operator< ( SymGrp const &  rhs) const
virtual

Overload < operator.

Implements nnp::SymGrp.

Definition at line 51 of file SymGrpExpRadWeighted.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 SymGrpExpRadWeighted const& c =
58 dynamic_cast<SymGrpExpRadWeighted const&>(rhs);
59 if (cutoffType < c.cutoffType ) return true;
60 else if (cutoffType > c.cutoffType ) return false;
61 if (cutoffAlpha < c.cutoffAlpha) return true;
62 else if (cutoffAlpha > c.cutoffAlpha) return false;
63 if (rc < c.rc ) return true;
64 else if (rc > c.rc ) return false;
65 return false;
66}

References nnp::SymGrpBaseCutoff::cutoffAlpha, nnp::SymGrpBaseCutoff::cutoffType, 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 SymGrpExpRadWeighted::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 68 of file SymGrpExpRadWeighted.cpp.

69{
70 if (symmetryFunction->getType() != type) return false;
71
72 SymFncExpRadWeighted const* sf =
73 dynamic_cast<SymFncExpRadWeighted const*>(symmetryFunction);
74
75 if (members.empty())
76 {
78 subtype = sf->getSubtype();
80 ec = sf->getEc();
81 rc = sf->getRc();
83
87 }
88
89 if (sf->getCutoffType() != cutoffType ) return false;
90 if (sf->getCutoffAlpha() != cutoffAlpha) return false;
91 if (sf->getEc() != ec ) return false;
92 if (sf->getRc() != rc ) return false;
93 if (sf->getConvLength() != convLength )
94 {
95 throw runtime_error("ERROR: Unable to add symmetry function members "
96 "with different conversion factors.\n");
97 }
98
99 members.push_back(sf);
100
101 return true;
102}
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.
Weighted radial symmetry function (type 12)
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< SymFncExpRadWeighted const * > members
Vector of all group member pointers.
double convLength
Data set normalization length conversion factor.
Definition: SymGrp.h:114

References nnp::SymGrp::convLength, nnp::SymGrpBaseCutoff::cutoffAlpha, nnp::SymGrpBaseCutoff::cutoffType, nnp::SymGrp::ec, nnp::SymGrpBaseCutoff::fc, nnp::SymFnc::getConvLength(), nnp::SymFncBaseCutoff::getCutoffAlpha(), nnp::SymFncBaseCutoff::getCutoffType(), 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 SymGrpExpRadWeighted::sortMembers ( )
virtual

Sort member symmetry functions.

Also allocate and precalculate additional stuff.

Implements nnp::SymGrp.

Definition at line 104 of file SymGrpExpRadWeighted.cpp.

105{
106 sort(members.begin(),
107 members.end(),
108 comparePointerTargets<SymFncExpRadWeighted const>);
109
110 for (size_t i = 0; i < members.size(); i++)
111 {
112 memberIndex.push_back(members[i]->getIndex());
113 eta.push_back(members[i]->getEta());
114 rs.push_back(members[i]->getRs());
115 memberIndexPerElement.push_back(members[i]->getIndexPerElement());
116 }
117
118 return;
119}
std::vector< double > eta
Vector containing values of all member symmetry functions.
std::vector< double > rs
Vector containing values of all member symmetry functions.
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 SymGrpExpRadWeighted::setScalingFactors ( )
virtual

Fill scalingFactors with values from member symmetry functions.

Implements nnp::SymGrp.

Definition at line 121 of file SymGrpExpRadWeighted.cpp.

122{
123 scalingFactors.resize(members.size(), 0.0);
124 for (size_t i = 0; i < members.size(); i++)
125 {
126 scalingFactors.at(i) = members[i]->getScalingFactor();
127 }
128
129 return;
130}
std::vector< double > scalingFactors
Scaling factors of all member symmetry functions.
Definition: SymGrp.h:118

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

◆ calculate()

void SymGrpExpRadWeighted::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 138 of file SymGrpExpRadWeighted.cpp.

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

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

Here is the call graph for this function:

◆ parameterLines()

vector< string > SymGrpExpRadWeighted::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 228 of file SymGrpExpRadWeighted.cpp.

229{
230 vector<string> v;
231
232 v.push_back(strpr(getPrintFormatCommon().c_str(),
233 index + 1,
234 elementMap[ec].c_str(),
235 type,
236 subtype.c_str(),
237 rc / convLength,
238 cutoffAlpha));
239
240 for (size_t i = 0; i < members.size(); ++i)
241 {
242 v.push_back(strpr(getPrintFormatMember().c_str(),
243 members[i]->getEta() * convLength * convLength,
244 members[i]->getRs() / convLength,
245 members[i]->getLineNumber() + 1,
246 i + 1,
247 members[i]->getIndex() + 1));
248 }
249
250 return v;
251}
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, 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

◆ members

std::vector<SymFncExpRadWeighted const*> nnp::SymGrpExpRadWeighted::members
private

Vector of all group member pointers.

Definition at line 90 of file SymGrpExpRadWeighted.h.

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

◆ eta

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

Vector containing values of all member symmetry functions.

Definition at line 92 of file SymGrpExpRadWeighted.h.

Referenced by calculate(), and sortMembers().

◆ rs

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

Vector containing values of all member symmetry functions.

Definition at line 94 of file SymGrpExpRadWeighted.h.

Referenced by calculate(), and sortMembers().


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