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 std::size_t getIndex() const;
77 std::size_t getAtomicNumber() const;
80 double getAtomicEnergyOffset() const;
83 std::string getSymbol() const;
90 std::string const& parameters,
91 std::size_t const& lineNumber);
97 double convLength);
103 std::vector<std::string> infoSymmetryFunctionParameters() const;
106 std::vector<std::string> infoSymmetryFunction(std::size_t index) const;
109 std::vector<std::string> infoSymmetryFunctionScaling() const;
118 std::vector<std::string> infoSymmetryFunctionGroups() const;
125 CutoffFunction::CutoffType const cutoffType,
126 double const cutoffAlpha);
131 void setScalingNone() const;
140 void setScaling(
141 SymFnc::ScalingType scalingType,
142 std::vector<std::string> const& statisticsLine,
143 double minS,
144 double maxS) const;
149 std::size_t numSymmetryFunctions() const;
155 std::size_t getMinNeighbors() const;
160 double getMinCutoffRadius() const;
165 double getMaxCutoffRadius() const;
170 std::vector<
171 std::size_t> const& getSymmetryFunctionNumTable() const;
176 std::vector<std::vector<
177 std::size_t>> const& getSymmetryFunctionTable() const;
185 Atom& atom,
186 bool const derivatives) const;
194 Atom& atom,
195 bool const derivatives) const;
205 Atom const& atom);
212 SymFnc const& getSymmetryFunction(std::size_t index) const;
213#ifndef N2P2_NO_SF_CACHE
219 void setCacheIndices(
220 std::vector<
221 std::vector<SFCacheList>> cacheLists);
226 std::vector<std::size_t> getCacheSizes() const;
227#endif
228
230 std::map<std::string, NeuralNetwork> neuralNetworks;
233
234protected:
238 std::size_t index;
240 std::size_t atomicNumber;
244 std::string symbol;
246 std::vector<std::size_t> symmetryFunctionNumTable;
248 std::vector<std::vector<std::size_t>> symmetryFunctionTable;
249#ifndef N2P2_NO_SF_CACHE
251 std::vector<std::vector<SFCacheList>> cacheLists;
252#endif
254 std::vector<SymFnc*> symmetryFunctions;
256 std::vector<SymGrp*> symmetryFunctionGroups;
257};
258
260// Inlined function definitions //
262
263inline void Element::setAtomicEnergyOffset(double atomicEnergyOffset)
264{
265 this->atomicEnergyOffset = atomicEnergyOffset;
266
267 return;
268}
269
270inline size_t Element::getIndex() const
271{
272 return index;
273}
274
275inline size_t Element::getAtomicNumber() const
276{
277 return atomicNumber;
278}
279
281{
282 return atomicEnergyOffset;
283}
284
285inline std::string Element::getSymbol() const
286{
287 return symbol;
288}
289
290inline std::vector<std::size_t> const&
292{
294}
295
296inline std::vector<std::vector<std::size_t>> const&
298{
300}
301
302inline
303std::vector<std::string> Element::infoSymmetryFunction(std::size_t index) const
304{
305 return symmetryFunctions.at(index)->parameterInfo();
306}
307
308inline size_t Element::numSymmetryFunctions() const
309{
310 return symmetryFunctions.size();
311}
312
314 std::size_t index) const
315{
316 return *(symmetryFunctions.at(index));
317}
318
319}
320
321#endif
CutoffType
List of available cutoff function types.
Contains element map.
Definition: ElementMap.h:30
Contains element-specific data.
Definition: Element.h:39
void calculateSymmetryFunctions(Atom &atom, bool const derivatives) const
Calculate symmetry functions.
Definition: Element.cpp:425
void setCutoffFunction(CutoffFunction::CutoffType const cutoffType, double const cutoffAlpha)
Set cutoff function for all symmetry functions.
Definition: Element.cpp:326
std::vector< std::string > infoSymmetryFunctionParameters() const
Print symmetry function parameter value information.
Definition: Element.cpp:166
ElementMap elementMap
Copy of element map.
Definition: Element.h:236
virtual ~Element()
Destructor.
Definition: Element.cpp:65
void setAtomicEnergyOffset(double atomicEnergyOffset)
Set atomicEnergyOffset.
Definition: Element.h:263
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:232
void sortSymmetryFunctions()
Sort all symmetry function.
Definition: Element.cpp:152
double getAtomicEnergyOffset() const
Get atomicEnergyOffset.
Definition: Element.h:280
std::vector< SymFnc * > symmetryFunctions
Vector of pointers to symmetry functions.
Definition: Element.h:254
std::vector< std::string > infoSymmetryFunctionGroups() const
Print symmetry function group info.
Definition: Element.cpp:311
void setupSymmetryFunctionMemory()
Extract relevant symmetry function combinations for derivative memory.
Definition: Element.cpp:287
std::vector< std::string > infoSymmetryFunctionScaling() const
Print symmetry function scaling information.
Definition: Element.cpp:179
double getMinCutoffRadius() const
Get minimum cutoff radius of all symmetry functions.
Definition: Element.cpp:395
std::vector< std::vector< SFCacheList > > cacheLists
Symmetry function cache lists.
Definition: Element.h:251
void setupSymmetryFunctionGroups()
Set up symmetry function groups.
Definition: Element.cpp:192
void addSymmetryFunction(std::string const &parameters, std::size_t const &lineNumber)
Add one symmetry function.
Definition: Element.cpp:80
std::size_t getIndex() const
Get index.
Definition: Element.h:270
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:238
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:362
std::vector< std::vector< std::size_t > > symmetryFunctionTable
List of symmetry function indices relevant for each neighbor element.
Definition: Element.h:248
SymFnc const & getSymmetryFunction(std::size_t index) const
Get symmetry function instance.
Definition: Element.h:313
std::string symbol
Element symbol.
Definition: Element.h:244
std::vector< std::vector< std::size_t > > const & getSymmetryFunctionTable() const
Get symmetry function element relevance table.
Definition: Element.h:297
std::string getSymbol() const
Get symbol.
Definition: Element.h:285
double atomicEnergyOffset
Offset energy for every atom of this element.
Definition: Element.h:242
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:382
std::vector< std::string > infoSymmetryFunction(std::size_t index) const
Print symmetry function parameter names and values.
Definition: Element.h:303
std::vector< SymGrp * > symmetryFunctionGroups
Vector of pointers to symmetry function groups.
Definition: Element.h:256
std::vector< std::size_t > symmetryFunctionNumTable
Number of relevant symmetry functions for each neighbor element.
Definition: Element.h:246
double getMaxCutoffRadius() const
Get maximum cutoff radius of all symmetry functions.
Definition: Element.cpp:412
void clearSymmetryFunctions()
Clear all symmetry functions and groups.
Definition: Element.cpp:70
void setScalingNone() const
Set no scaling of symmetry function.
Definition: Element.cpp:342
std::map< std::string, NeuralNetwork > neuralNetworks
Neural networks for this element.
Definition: Element.h:230
std::size_t numSymmetryFunctions() const
Get number of symmetry functions.
Definition: Element.h:308
void changeLengthUnitSymmetryFunctions(double convLength)
Change length unit for all symmetry functions.
Definition: Element.cpp:141
std::vector< std::size_t > const & getSymmetryFunctionNumTable() const
Get number of relevant symmetry functions per element.
Definition: Element.h:291
std::size_t atomicNumber
Atomic number of this element.
Definition: Element.h:240
std::size_t getAtomicNumber() const
Get atomicNumber.
Definition: Element.h:275
Symmetry function base class.
Definition: SymFnc.h:40
ScalingType
List of available scaling types.
Definition: SymFnc.h:44
Definition: Atom.h:28
Storage for a single atom.
Definition: Atom.h:32
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