n2p2 - A neural network potential package
Loading...
Searching...
No Matches
nnp::SymGrpCompRadWeighted Class Reference

Weighted radial symmetry function with compact support (type 23) More...

#include <SymGrpCompRadWeighted.h>

Inheritance diagram for nnp::SymGrpCompRadWeighted:
Collaboration diagram for nnp::SymGrpCompRadWeighted:

Public Member Functions

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

Private Attributes

std::vector< SymFncCompRadWeighted const * > members
 Vector of all group member pointers.
 
std::vector< double > mrl
 Member rl.
 
std::vector< double > mrc
 Member rc.
 

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.
 
- Protected Member Functions inherited from nnp::SymGrp
 SymGrp (std::size_t type, ElementMap const &elementMap)
 Constructor, sets type.
 
std::string getPrintFormatCommon () const
 Get common parameter line format string.
 
std::string getPrintFormatMember () const
 Get member parameter line format string.
 
- Static Protected Member Functions inherited from nnp::SymGrp
static PrintFormat const initializePrintFormat ()
 Initialize static print format map for all possible parameters.
 
static PrintOrder const initializePrintOrder ()
 Initialize static print order vector for all possible parameters.
 
- Protected Attributes inherited from nnp::SymGrpBaseComp
double rmin
 Minimum radius within group.
 
double rmax
 Maximum radius within group.
 
- Protected Attributes inherited from nnp::SymGrp
std::size_t type
 Symmetry function type.
 
ElementMap elementMap
 Copy of element map.
 
std::size_t index
 Symmetry function group index.
 
std::size_t ec
 Element index of center atom (common feature).
 
double convLength
 Data set normalization length conversion factor.
 
std::vector< size_t > memberIndex
 Vector containing indices of all member symmetry functions.
 
std::vector< double > scalingFactors
 Scaling factors of all member symmetry functions.
 
std::set< std::string > parametersCommon
 Set of common parameters IDs.
 
std::set< std::string > parametersMember
 Set of common parameters IDs.
 
std::vector< std::vector< std::size_t > > memberIndexPerElement
 Vector containing per-element indices of all member symmetry functions.
 
- Static Protected Attributes inherited from nnp::SymGrp
static PrintFormat const printFormat = initializePrintFormat()
 Map of parameter format strings and empty strings.
 
static PrintOrder const printOrder = initializePrintOrder()
 Vector of parameters in order of printing.
 

Detailed Description

Weighted radial symmetry function with compact support (type 23)

\[G^{23}_i = \sum_{\substack{j \neq i}} Z_j 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]\). \(Z_j\) is defined as the atomic number of the neighbor atom \(j\).

Common features:

  • element of central atom

Definition at line 48 of file SymGrpCompRadWeighted.h.

Constructor & Destructor Documentation

◆ SymGrpCompRadWeighted()

SymGrpCompRadWeighted::SymGrpCompRadWeighted ( ElementMap const & elementMap)

Constructor, sets type = 23.

Definition at line 31 of file SymGrpCompRadWeighted.cpp.

32 :
34{
35}
SymGrpBaseComp(std::size_t type, ElementMap const &elementMap)
Constructor, sets type.
ElementMap elementMap
Copy of element map.
Definition SymGrp.h:108

References nnp::SymGrp::elementMap, and nnp::SymGrpBaseComp::SymGrpBaseComp().

Here is the call graph for this function:

Member Function Documentation

◆ operator==()

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

Overload == operator.

Implements nnp::SymGrp.

Definition at line 37 of file SymGrpCompRadWeighted.cpp.

38{
39 if (ec != rhs.getEc() ) return false;
40 if (type != rhs.getType()) return false;
41 return true;
42}
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::SymGrp::ec, nnp::SymGrp::getEc(), nnp::SymGrp::getType(), and nnp::SymGrp::type.

Here is the call graph for this function:

◆ operator<()

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

Overload < operator.

Implements nnp::SymGrp.

Definition at line 44 of file SymGrpCompRadWeighted.cpp.

45{
46 if (ec < rhs.getEc() ) return true;
47 else if (ec > rhs.getEc() ) return false;
48 if (type < rhs.getType()) return true;
49 else if (type > rhs.getType()) return false;
50 return false;
51}

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

Here is the call graph for this function:

◆ addMember()

bool SymGrpCompRadWeighted::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 53 of file SymGrpCompRadWeighted.cpp.

54{
55 if (symmetryFunction->getType() != type) return false;
56
57 SymFncCompRadWeighted const* sf =
58 dynamic_cast<SymFncCompRadWeighted const*>(symmetryFunction);
59
60 if (members.empty())
61 {
62 ec = sf->getEc();
64 }
65
66 if (sf->getEc() != ec ) return false;
67 if (sf->getConvLength() != convLength )
68 {
69 throw runtime_error("ERROR: Unable to add symmetry function members "
70 "with different conversion factors.\n");
71 }
72
73 if (sf->getRl() <= 0.0) rmin = 0.0;
74 else rmin = min( rmin, sf->getRl() );
75 rmax = max( rmax, sf->getRc() );
76
77 members.push_back(sf);
78
79 return true;
80}
double getRl() const
Get private rl 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< SymFncCompRadWeighted 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::SymGrp::ec, nnp::SymFnc::getConvLength(), 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 SymGrpCompRadWeighted::sortMembers ( )
virtual

Sort member symmetry functions.

Also allocate and precalculate additional stuff.

Implements nnp::SymGrp.

Definition at line 82 of file SymGrpCompRadWeighted.cpp.

83{
84 sort(members.begin(),
85 members.end(),
87
88 for (size_t i = 0; i < members.size(); i++)
89 {
90 memberIndex.push_back(members[i]->getIndex());
91 memberIndexPerElement.push_back(members[i]->getIndexPerElement());
92 }
93
94 mrl.resize(members.size(), 0.0);
95 mrc.resize(members.size(), 0.0);
96 for (size_t i = 0; i < members.size(); i++)
97 {
98 mrl.at(i) = members[i]->getRl();
99 mrc.at(i) = members[i]->getRc();
100 }
101
102 return;
103}
std::vector< double > mrc
Member rc.
std::vector< double > mrl
Member rl.
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
bool comparePointerTargets(T *lhs, T *rhs)
Compare pointer targets.
Definition utility.h:194

References nnp::comparePointerTargets(), nnp::SymGrp::getIndex(), nnp::SymGrp::memberIndex, nnp::SymGrp::memberIndexPerElement, members, mrc, and mrl.

Here is the call graph for this function:

◆ setScalingFactors()

void SymGrpCompRadWeighted::setScalingFactors ( )
virtual

Fill scalingFactors with values from member symmetry functions.

Implements nnp::SymGrp.

Definition at line 105 of file SymGrpCompRadWeighted.cpp.

106{
107 scalingFactors.resize(members.size(), 0.0);
108 for (size_t i = 0; i < members.size(); i++)
109 {
110 scalingFactors.at(i) = members[i]->getScalingFactor();
111 }
112
113 return;
114}
std::vector< double > scalingFactors
Scaling factors of all member symmetry functions.
Definition SymGrp.h:118

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

◆ calculate()

void SymGrpCompRadWeighted::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 122 of file SymGrpCompRadWeighted.cpp.

123{
124 double* result = new double[members.size()];
125 for (size_t k = 0; k < members.size(); ++k)
126 {
127 result[k] = 0.0;
128 }
129
130 for (size_t j = 0; j < atom.numNeighbors; ++j)
131 {
132 Atom::Neighbor& n = atom.neighbors[j];
133 double const rij = n.d;
134 if (rij < rmax && rij > rmin)
135 {
136 // Energy calculation.
137 double const* const d1 = n.dr.r;
138 size_t const ne = n.element;
139 for (size_t k = 0; k < members.size(); ++k)
140 {
141 SymFncCompRadWeighted const& sf = *(members[k]);
142 if (rij <= mrl[k] || rij >= mrc[k]) continue;
143 double rad;
144 double drad;
145#ifndef N2P2_NO_SF_CACHE
146 auto ci = sf.getCacheIndices();
147 if (ci[ne].size() == 0) sf.getCompactOnly(rij, rad, drad);
148 else
149 {
150 double& crad = n.cache[ci[ne][0]];
151 double& cdrad = n.cache[ci[ne][1]];
152 if (crad < 0) sf.getCompactOnly(rij, crad, cdrad);
153 rad = crad;
154 drad = cdrad;
155 }
156#else
157 sf.getCompactOnly(rij, rad, drad);
158#endif
159 result[k] += elementMap.atomicNumber(ne) * rad;
160
161 // Force calculation.
162 if (!derivatives || drad == 0.0) continue;
163 drad *= elementMap.atomicNumber(ne) * scalingFactors[k] / rij;
164 // SIMPLE EXPRESSIONS:
165 //Vec3D const dij = p1 * atom.neighbors[j].dr;
166 double const p1drijx = drad * d1[0];
167 double const p1drijy = drad * d1[1];
168 double const p1drijz = drad * d1[2];
169
170 // Save force contributions in Atom storage.
171#ifndef N2P2_FULL_SFD_MEMORY
172 size_t ki = memberIndex[k];
173#else
174 size_t const ki = memberIndex[k];
175#endif
176 // SIMPLE EXPRESSIONS:
177 //atom.dGdr[ki] += dij;
178 //atom.neighbors[j].dGdr[ki] -= dij;
179
180 double* dGdr = atom.dGdr[ki].r;
181 dGdr[0] += p1drijx;
182 dGdr[1] += p1drijy;
183 dGdr[2] += p1drijz;
184
185#ifndef N2P2_FULL_SFD_MEMORY
186 ki = memberIndexPerElement[k][ne];
187#endif
188 dGdr = n.dGdr[ki].r;
189 dGdr[0] -= p1drijx;
190 dGdr[1] -= p1drijy;
191 dGdr[2] -= p1drijz;
192 }
193 }
194 }
195
196 for (size_t k = 0; k < members.size(); ++k)
197 {
198 atom.G[memberIndex[k]] = members[k]->scale(result[k]);
199 }
200
201 delete[] result;
202
203 return;
204}
void getCompactOnly(double const x, double &fx, double &dfx) const
std::vector< std::vector< std::size_t > > getCacheIndices() const
Getter for cacheIndices.
Definition SymFnc.h:396
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::dGdr, nnp::Atom::Neighbor::dGdr, nnp::Atom::Neighbor::dr, nnp::Atom::Neighbor::element, nnp::SymGrp::elementMap, nnp::Atom::G, nnp::SymFnc::getCacheIndices(), nnp::SymFncCompRadWeighted::getCompactOnly(), 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 > SymGrpCompRadWeighted::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 206 of file SymGrpCompRadWeighted.cpp.

207{
208 vector<string> v;
209
210 v.push_back(strpr(getPrintFormatCommon().c_str(),
211 index + 1,
212 elementMap[ec].c_str(),
213 type,
215 rmax / convLength));
216
217 for (size_t i = 0; i < members.size(); ++i)
218 {
219 v.push_back(strpr(getPrintFormatMember().c_str(),
220 members[i]->getSubtype().c_str(),
221 members[i]->getRl() / convLength,
222 members[i]->getRc() / convLength,
223 members[i]->getLineNumber() + 1,
224 i + 1,
225 members[i]->getIndex() + 1));
226 }
227
228 return v;
229}
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::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

◆ members

std::vector<SymFncCompRadWeighted const*> nnp::SymGrpCompRadWeighted::members
private

Vector of all group member pointers.

Definition at line 93 of file SymGrpCompRadWeighted.h.

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

◆ mrl

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

Member rl.

Definition at line 95 of file SymGrpCompRadWeighted.h.

Referenced by calculate(), and sortMembers().

◆ mrc

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

Member rc.

Definition at line 97 of file SymGrpCompRadWeighted.h.

Referenced by calculate(), and sortMembers().


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