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

Radial symmetry function with compact support (type 20) More...

#include <SymGrpCompRad.h>

Inheritance diagram for nnp::SymGrpCompRad:
Collaboration diagram for nnp::SymGrpCompRad:

Public Member Functions

 SymGrpCompRad (ElementMap const &elementMap)
 Constructor, sets type = 20. 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::SymGrpBaseComp
double getRmin () const
 Getter for rmin. More...
 
double getRmax () const
 Getter for rmax. 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< SymFncCompRad const * > members
 Vector of all group member pointers. More...
 
std::vector< double > mrl
 Member rl. More...
 
std::vector< double > mrc
 Member rc. More...
 
std::vector< std::vector< std::size_t > > mci
 Member cache indices for actual neighbor element. 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::SymGrpBaseComp
 SymGrpBaseComp (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::SymGrpBaseComp
double rmin
 Minimum radius within group. More...
 
double rmax
 Maximum radius within group. 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 with compact support (type 20)

\[ G^{20}_i = \sum_{\substack{j \neq i}} C(r_{ij}, r_l, r_c), \]

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

Common features:

  • element of central atom
  • element of neighbor atom

Definition at line 47 of file SymGrpCompRad.h.

Constructor & Destructor Documentation

◆ SymGrpCompRad()

SymGrpCompRad::SymGrpCompRad ( ElementMap const &  elementMap)

Constructor, sets type = 20.

Definition at line 31 of file SymGrpCompRad.cpp.

32 :
34 e1(0)
35{
36 parametersCommon.insert("e1");
37}
SymGrpBaseComp(std::size_t type, ElementMap const &elementMap)
Constructor, sets type.
std::size_t e1
Element index of neighbor atom (common feature).
Definition: SymGrpCompRad.h:92
std::set< std::string > parametersCommon
Set of common parameters IDs.
Definition: SymGrp.h:120
ElementMap elementMap
Copy of element map.
Definition: SymGrp.h:108

References nnp::SymGrp::parametersCommon.

Member Function Documentation

◆ operator==()

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

Overload == operator.

Implements nnp::SymGrp.

Definition at line 39 of file SymGrpCompRad.cpp.

40{
41 if (ec != rhs.getEc() ) return false;
42 if (type != rhs.getType()) return false;
43 SymGrpCompRad const& c = dynamic_cast<SymGrpCompRad const&>(rhs);
44 if (e1 != c.e1) return false;
45 return true;
46}
Radial symmetry function with compact support (type 20)
Definition: SymGrpCompRad.h:48
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 e1, nnp::SymGrp::ec, nnp::SymGrp::getEc(), nnp::SymGrp::getType(), and nnp::SymGrp::type.

Here is the call graph for this function:

◆ operator<()

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

Overload < operator.

Implements nnp::SymGrp.

Definition at line 48 of file SymGrpCompRad.cpp.

49{
50 if (ec < rhs.getEc() ) return true;
51 else if (ec > rhs.getEc() ) return false;
52 if (type < rhs.getType()) return true;
53 else if (type > rhs.getType()) return false;
54 SymGrpCompRad const& c = dynamic_cast<SymGrpCompRad const&>(rhs);
55 if (e1 < c.e1) return true;
56 else if (e1 > c.e1) return false;
57 return false;
58}

References e1, nnp::SymGrp::ec, nnp::SymGrp::getEc(), nnp::SymGrp::getType(), and nnp::SymGrp::type.

Here is the call graph for this function:

◆ addMember()

bool SymGrpCompRad::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 60 of file SymGrpCompRad.cpp.

61{
62 if (symmetryFunction->getType() != type) return false;
63
64 SymFncCompRad const* sf =
65 dynamic_cast<SymFncCompRad const*>(symmetryFunction);
66
67 if (members.empty())
68 {
69 ec = sf->getEc();
70 e1 = sf->getE1();
72 }
73
74 if (sf->getEc() != ec ) return false;
75 if (sf->getE1() != e1 ) return false;
76 if (sf->getConvLength() != convLength )
77 {
78 throw runtime_error("ERROR: Unable to add symmetry function members "
79 "with different conversion factors.\n");
80 }
81
82 if (sf->getRl() <= 0.0) rmin = 0.0;
83 else rmin = min( rmin, sf->getRl() );
84 rmax = max( rmax, sf->getRc() );
85
86 members.push_back(sf);
87
88 return true;
89}
double getRl() const
Get private rl member variable.
Radial symmetry function with compact support (type 20)
Definition: SymFncCompRad.h:56
std::size_t getE1() const
Get private e1 member variable.
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
double rmin
Minimum radius within group.
double rmax
Maximum radius within group.
std::vector< SymFncCompRad const * > members
Vector of all group member pointers.
Definition: SymGrpCompRad.h:94
double convLength
Data set normalization length conversion factor.
Definition: SymGrp.h:114

References nnp::SymGrp::convLength, e1, nnp::SymGrp::ec, nnp::SymFnc::getConvLength(), nnp::SymFncCompRad::getE1(), nnp::SymFnc::getEc(), nnp::SymFnc::getRc(), nnp::SymFncBaseComp::getRl(), nnp::SymFnc::getType(), members, nnp::SymGrpBaseComp::rmax, nnp::SymGrpBaseComp::rmin, and nnp::SymGrp::type.

Here is the call graph for this function:

◆ sortMembers()

void SymGrpCompRad::sortMembers ( )
virtual

Sort member symmetry functions.

Also allocate and precalculate additional stuff.

Implements nnp::SymGrp.

Definition at line 91 of file SymGrpCompRad.cpp.

92{
93 sort(members.begin(),
94 members.end(),
95 comparePointerTargets<SymFncCompRad const>);
96
97 for (size_t i = 0; i < members.size(); i++)
98 {
99 memberIndex.push_back(members[i]->getIndex());
100 memberIndexPerElement.push_back(members[i]->getIndexPerElement());
101 }
102
103 mrl.resize(members.size(), 0.0);
104 mrc.resize(members.size(), 0.0);
105 for (size_t i = 0; i < members.size(); i++)
106 {
107 mrl.at(i) = members[i]->getRl();
108 mrc.at(i) = members[i]->getRc();
109 }
110
111#ifndef N2P2_NO_SF_CACHE
112 mci.resize(members.size());
113 for (size_t k = 0; k < members.size(); ++k)
114 {
115 mci.at(k) = members.at(k)->getCacheIndices()[e1];
116 }
117#endif
118
119 return;
120}
std::vector< double > mrc
Member rc.
Definition: SymGrpCompRad.h:98
std::vector< double > mrl
Member rl.
Definition: SymGrpCompRad.h:96
std::vector< std::vector< std::size_t > > mci
Member cache indices for actual neighbor element.
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 e1, nnp::SymGrp::getIndex(), mci, nnp::SymGrp::memberIndex, nnp::SymGrp::memberIndexPerElement, members, mrc, and mrl.

Here is the call graph for this function:

◆ setScalingFactors()

void SymGrpCompRad::setScalingFactors ( )
virtual

Fill scalingFactors with values from member symmetry functions.

Implements nnp::SymGrp.

Definition at line 122 of file SymGrpCompRad.cpp.

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

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

◆ calculate()

void SymGrpCompRad::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 139 of file SymGrpCompRad.cpp.

140{
141 double* result = new double[members.size()];
142 for (size_t k = 0; k < members.size(); ++k)
143 {
144 result[k] = 0.0;
145 }
146
147 for (size_t j = 0; j < atom.numNeighbors; ++j)
148 {
149 Atom::Neighbor& n = atom.neighbors[j];
150 double const rij = n.d;
151 if (e1 == n.element && rij < rmax && rij > rmin)
152 {
153 // Energy calculation.
154 double const* const d1 = n.dr.r;
155 for (size_t k = 0; k < members.size(); ++k)
156 {
157 SymFncCompRad const& sf = *(members[k]);
158 if (rij <= mrl[k] || rij >= mrc[k]) continue;
159 double rad;
160 double drad;
161#ifndef N2P2_NO_SF_CACHE
162 if (mci[k].size() == 0) sf.getCompactOnly(rij, rad, drad);
163 else
164 {
165 double& crad = n.cache[mci[k][0]];
166 double& cdrad = n.cache[mci[k][1]];
167 if (crad < 0) sf.getCompactOnly(rij, crad, cdrad);
168 rad = crad;
169 drad = cdrad;
170 }
171#else
172 sf.getCompactOnly(rij, rad, drad);
173#endif
174 result[k] += rad;
175
176 // Force calculation.
177 if (!derivatives || drad == 0.0) continue;
178 drad *= scalingFactors[k] / rij;
179 // SIMPLE EXPRESSIONS:
180 //Vec3D const dij = p1 * atom.neighbors[j].dr;
181 double const p1drijx = drad * d1[0];
182 double const p1drijy = drad * d1[1];
183 double const p1drijz = drad * d1[2];
184
185 // Save force contributions in Atom storage.
186#ifndef N2P2_FULL_SFD_MEMORY
187 size_t ki = memberIndex[k];
188#else
189 size_t const ki = memberIndex[k];
190#endif
191 // SIMPLE EXPRESSIONS:
192 //atom.dGdr[ki] += dij;
193 //atom.neighbors[j].dGdr[ki] -= dij;
194
195 double* dGdr = atom.dGdr[ki].r;
196 dGdr[0] += p1drijx;
197 dGdr[1] += p1drijy;
198 dGdr[2] += p1drijz;
199
200#ifndef N2P2_FULL_SFD_MEMORY
201 ki = memberIndexPerElement[k][e1];
202#endif
203 dGdr = n.dGdr[ki].r;
204 dGdr[0] -= p1drijx;
205 dGdr[1] -= p1drijy;
206 dGdr[2] -= p1drijz;
207 }
208 }
209 }
210
211 for (size_t k = 0; k < members.size(); ++k)
212 {
213 atom.G[memberIndex[k]] = members[k]->scale(result[k]);
214 }
215
216 delete[] result;
217
218 return;
219}
void getCompactOnly(double const x, double &fx, double &dfx) const
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::Atom::Neighbor::cache, nnp::Atom::Neighbor::d, nnp::Atom::Neighbor::dGdr, nnp::Atom::dGdr, nnp::Atom::Neighbor::dr, e1, nnp::Atom::Neighbor::element, nnp::Atom::G, nnp::SymFncCompRad::getCompactOnly(), mci, nnp::SymGrp::memberIndex, nnp::SymGrp::memberIndexPerElement, members, mrc, mrl, nnp::Atom::neighbors, nnp::Atom::numNeighbors, nnp::Vec3D::r, nnp::SymGrpBaseComp::rmin, and nnp::SymGrp::scalingFactors.

Here is the call graph for this function:

◆ parameterLines()

vector< string > SymGrpCompRad::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 221 of file SymGrpCompRad.cpp.

222{
223 vector<string> v;
224
225 v.push_back(strpr(getPrintFormatCommon().c_str(),
226 index + 1,
227 elementMap[ec].c_str(),
228 type,
229 elementMap[e1].c_str(),
231 rmax / convLength));
232
233 for (size_t i = 0; i < members.size(); ++i)
234 {
235 v.push_back(strpr(getPrintFormatMember().c_str(),
236 members[i]->getSubtype().c_str(),
237 members[i]->getRl() / convLength,
238 members[i]->getRc() / convLength,
239 members[i]->getLineNumber() + 1,
240 i + 1,
241 members[i]->getIndex() + 1));
242 }
243
244 return v;
245}
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, e1, nnp::SymGrp::ec, nnp::SymGrp::elementMap, nnp::SymGrp::getIndex(), nnp::SymGrp::getPrintFormatCommon(), nnp::SymGrp::getPrintFormatMember(), nnp::SymGrp::index, members, nnp::SymGrpBaseComp::rmax, nnp::SymGrpBaseComp::rmin, nnp::strpr(), and nnp::SymGrp::type.

Here is the call graph for this function:

Member Data Documentation

◆ e1

std::size_t nnp::SymGrpCompRad::e1
private

Element index of neighbor atom (common feature).

Definition at line 92 of file SymGrpCompRad.h.

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

◆ members

std::vector<SymFncCompRad const*> nnp::SymGrpCompRad::members
private

Vector of all group member pointers.

Definition at line 94 of file SymGrpCompRad.h.

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

◆ mrl

std::vector<double> nnp::SymGrpCompRad::mrl
private

Member rl.

Definition at line 96 of file SymGrpCompRad.h.

Referenced by calculate(), and sortMembers().

◆ mrc

std::vector<double> nnp::SymGrpCompRad::mrc
private

Member rc.

Definition at line 98 of file SymGrpCompRad.h.

Referenced by calculate(), and sortMembers().

◆ mci

std::vector<std::vector<std::size_t> > nnp::SymGrpCompRad::mci
private

Member cache indices for actual neighbor element.

Definition at line 101 of file SymGrpCompRad.h.

Referenced by calculate(), and sortMembers().


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