n2p2 - A neural network potential package
Element.h
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef ELEMENT_H
18#define ELEMENT_H
19
20#include "CutoffFunction.h"
21#include "ElementMap.h"
22#include "NeuralNetwork.h"
23#include "SymFnc.h"
24#include "SymFncStatistics.h"
25#include <cstddef> // std::size_t
26#include <map> // std::map
27#include <string> // std::string
28#include <utility> // std::pair
29#include <vector> // std::vector
30
31namespace nnp
32{
33
34struct Atom;
35class SymGrp;
36
39{
40public:
41
42#ifndef N2P2_NO_SF_CACHE
45 {
47 std::size_t element;
49 std::string identifier;
51 std::vector<std::size_t> indices;
52 };
53#endif
54
60 Element(std::size_t const index, ElementMap const& elementMap);
65 virtual ~Element();
74 void setHardness(double hardness);
77 void setQsigma(double qsigma);
80 std::size_t getIndex() const;
83 std::size_t getAtomicNumber() const;
86 double getAtomicEnergyOffset() const;
89 double getHardness() const;
92 double getQsigma() const;
95 std::string getSymbol() const;
102 std::string const& parameters,
103 std::size_t const& lineNumber);
109 double convLength);
115 std::vector<std::string> infoSymmetryFunctionParameters() const;
118 std::vector<std::string> infoSymmetryFunction(std::size_t index) const;
121 std::vector<std::string> infoSymmetryFunctionScaling() const;
130 std::vector<std::string> infoSymmetryFunctionGroups() const;
137 CutoffFunction::CutoffType const cutoffType,
138 double const cutoffAlpha);
143 void setScalingNone() const;
152 void setScaling(
153 SymFnc::ScalingType scalingType,
154 std::vector<std::string> const& statisticsLine,
155 double minS,
156 double maxS) const;
161 std::size_t numSymmetryFunctions() const;
167 std::size_t getMinNeighbors() const;
172 double getMinCutoffRadius() const;
177 double getMaxCutoffRadius() const;
182 void getCutoffRadii(std::vector<double>& cutoffs) const;
187 std::vector<
188 std::size_t> const& getSymmetryFunctionNumTable() const;
193 std::vector<std::vector<
194 std::size_t>> const& getSymmetryFunctionTable() const;
202 Atom& atom,
203 bool const derivatives) const;
211 Atom& atom,
212 bool const derivatives) const;
222 Atom const& atom);
229 SymFnc const& getSymmetryFunction(std::size_t index) const;
230#ifndef N2P2_NO_SF_CACHE
236 void setCacheIndices(
237 std::vector<
238 std::vector<SFCacheList>> cacheLists);
243 std::vector<std::size_t> getCacheSizes() const;
244#endif
245
247 std::map<std::string, NeuralNetwork> neuralNetworks;
250
251protected:
255 std::size_t index;
257 std::size_t atomicNumber;
261 double hardness;
263 double qsigma;
265 std::string symbol;
267 std::vector<std::size_t> symmetryFunctionNumTable;
269 std::vector<std::vector<std::size_t>> symmetryFunctionTable;
270#ifndef N2P2_NO_SF_CACHE
272 std::vector<std::vector<SFCacheList>> cacheLists;
273#endif
275 std::vector<SymFnc*> symmetryFunctions;
277 std::vector<SymGrp*> symmetryFunctionGroups;
278};
279
281// Inlined function definitions //
283
284inline void Element::setAtomicEnergyOffset(double atomicEnergyOffset)
285{
286 this->atomicEnergyOffset = atomicEnergyOffset;
287
288 return;
289}
290
291inline void Element::setHardness(double hardness)
292{
293 this->hardness = hardness;
294
295 return;
296}
297
298inline void Element::setQsigma(double qsigma)
299{
300 this->qsigma = qsigma;
301
302 return;
303}
304
305inline size_t Element::getIndex() const
306{
307 return index;
308}
309
310inline size_t Element::getAtomicNumber() const
311{
312 return atomicNumber;
313}
314
316{
317 return atomicEnergyOffset;
318}
319
320inline double Element::getHardness() const
321{
322 return hardness;
323}
324
325inline double Element::getQsigma() const
326{
327 return qsigma;
328}
329
330inline std::string Element::getSymbol() const
331{
332 return symbol;
333}
334
335inline std::vector<std::size_t> const&
337{
339}
340
341inline std::vector<std::vector<std::size_t>> const&
343{
345}
346
347inline
348std::vector<std::string> Element::infoSymmetryFunction(std::size_t index) const
349{
350 return symmetryFunctions.at(index)->parameterInfo();
351}
352
353inline size_t Element::numSymmetryFunctions() const
354{
355 return symmetryFunctions.size();
356}
357
359 std::size_t index) const
360{
361 return *(symmetryFunctions.at(index));
362}
363
364}
365
366#endif
CutoffType
List of available cutoff function types.
Contains element map.
Definition: ElementMap.h:30
Contains element-specific data.
Definition: Element.h:39
void getCutoffRadii(std::vector< double > &cutoffs) const
Get all different cutoff radii belonging to this element.
Definition: Element.cpp:427
void calculateSymmetryFunctions(Atom &atom, bool const derivatives) const
Calculate symmetry functions.
Definition: Element.cpp:436
void setCutoffFunction(CutoffFunction::CutoffType const cutoffType, double const cutoffAlpha)
Set cutoff function for all symmetry functions.
Definition: Element.cpp:328
std::vector< std::string > infoSymmetryFunctionParameters() const
Print symmetry function parameter value information.
Definition: Element.cpp:168
ElementMap elementMap
Copy of element map.
Definition: Element.h:253
virtual ~Element()
Destructor.
Definition: Element.cpp:67
void setAtomicEnergyOffset(double atomicEnergyOffset)
Set atomicEnergyOffset.
Definition: Element.h:284
void calculateSymmetryFunctionGroups(Atom &atom, bool const derivatives) const
Calculate symmetry functions via groups.
Definition: Element.cpp:449
std::vector< std::size_t > getCacheSizes() const
Get cache sizes for each neighbor atom element.
Definition: Element.cpp:563
SymFncStatistics statistics
Symmetry function statistics.
Definition: Element.h:249
void sortSymmetryFunctions()
Sort all symmetry function.
Definition: Element.cpp:154
double getAtomicEnergyOffset() const
Get atomicEnergyOffset.
Definition: Element.h:315
std::vector< SymFnc * > symmetryFunctions
Vector of pointers to symmetry functions.
Definition: Element.h:275
std::vector< std::string > infoSymmetryFunctionGroups() const
Print symmetry function group info.
Definition: Element.cpp:313
void setupSymmetryFunctionMemory()
Extract relevant symmetry function combinations for derivative memory.
Definition: Element.cpp:289
std::vector< std::string > infoSymmetryFunctionScaling() const
Print symmetry function scaling information.
Definition: Element.cpp:181
double getMinCutoffRadius() const
Get minimum cutoff radius of all symmetry functions.
Definition: Element.cpp:397
std::vector< std::vector< SFCacheList > > cacheLists
Symmetry function cache lists.
Definition: Element.h:272
void setupSymmetryFunctionGroups()
Set up symmetry function groups.
Definition: Element.cpp:194
void addSymmetryFunction(std::string const &parameters, std::size_t const &lineNumber)
Add one symmetry function.
Definition: Element.cpp:82
std::size_t getIndex() const
Get index.
Definition: Element.h:305
Element(std::size_t const index, ElementMap const &elementMap)
Constructor using index.
void setCacheIndices(std::vector< std::vector< SFCacheList > > cacheLists)
Set cache indices for all symmetry functions of this element.
Definition: Element.cpp:544
std::size_t updateSymmetryFunctionStatistics(Atom const &atom)
Update symmetry function statistics.
Definition: Element.cpp:462
std::size_t index
Global index of this element.
Definition: Element.h:255
double qsigma
Gaussian width of charge distribution.
Definition: Element.h:263
void setScaling(SymFnc::ScalingType scalingType, std::vector< std::string > const &statisticsLine, double minS, double maxS) const
Set scaling of all symmetry functions.
Definition: Element.cpp:364
std::vector< std::vector< std::size_t > > symmetryFunctionTable
List of symmetry function indices relevant for each neighbor element.
Definition: Element.h:269
SymFnc const & getSymmetryFunction(std::size_t index) const
Get symmetry function instance.
Definition: Element.h:358
std::string symbol
Element symbol.
Definition: Element.h:265
std::vector< std::vector< std::size_t > > const & getSymmetryFunctionTable() const
Get symmetry function element relevance table.
Definition: Element.h:342
double getQsigma() const
Get qsigma.
Definition: Element.h:325
std::string getSymbol() const
Get symbol.
Definition: Element.h:330
double atomicEnergyOffset
Offset energy for every atom of this element.
Definition: Element.h:259
double hardness
Atomic hardness for global charge equilibration.
Definition: Element.h:261
Element()
Default constructor.
Definition: Element.h:57
std::size_t getMinNeighbors() const
Get maximum of required minimum number of neighbors for all symmetry functions for this element.
Definition: Element.cpp:384
void setQsigma(double qsigma)
Set qsigma.
Definition: Element.h:298
std::vector< std::string > infoSymmetryFunction(std::size_t index) const
Print symmetry function parameter names and values.
Definition: Element.h:348
void setHardness(double hardness)
Set hardness.
Definition: Element.h:291
std::vector< SymGrp * > symmetryFunctionGroups
Vector of pointers to symmetry function groups.
Definition: Element.h:277
std::vector< std::size_t > symmetryFunctionNumTable
Number of relevant symmetry functions for each neighbor element.
Definition: Element.h:267
double getMaxCutoffRadius() const
Get maximum cutoff radius of all symmetry functions.
Definition: Element.cpp:414
void clearSymmetryFunctions()
Clear all symmetry functions and groups.
Definition: Element.cpp:72
void setScalingNone() const
Set no scaling of symmetry function.
Definition: Element.cpp:344
std::map< std::string, NeuralNetwork > neuralNetworks
Neural networks for this element.
Definition: Element.h:247
double getHardness() const
Get hardness.
Definition: Element.h:320
std::size_t numSymmetryFunctions() const
Get number of symmetry functions.
Definition: Element.h:353
void changeLengthUnitSymmetryFunctions(double convLength)
Change length unit for all symmetry functions.
Definition: Element.cpp:143
std::vector< std::size_t > const & getSymmetryFunctionNumTable() const
Get number of relevant symmetry functions per element.
Definition: Element.h:336
std::size_t atomicNumber
Atomic number of this element.
Definition: Element.h:257
std::size_t getAtomicNumber() const
Get atomicNumber.
Definition: Element.h:310
Symmetry function base class.
Definition: SymFnc.h:40
ScalingType
List of available scaling types.
Definition: SymFnc.h:44
Definition: Atom.h:29
Storage for a single atom.
Definition: Atom.h:33
List of symmetry functions corresponding to one cache identifier.
Definition: Element.h:45
std::size_t element
Neighbor element index.
Definition: Element.h:47
std::string identifier
Cache identifier string.
Definition: Element.h:49
std::vector< std::size_t > indices
Symmetry function indices for this cache.
Definition: Element.h:51