n2p2 - A neural network potential package
SymFnc.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 SYMFNC_H
18#define SYMFNC_H
19
20#include "ElementMap.h"
21#include <cstddef> // std::size_t
22#include <map> // std::map
23#include <set> // std::set
24#include <string> // std::string
25#include <utility> // std::pair
26#include <vector> // std::vector
27
28namespace nnp
29{
30
31struct Atom;
32class SymFncStatistics;
33
39class SymFnc
40{
41public:
44 {
65 };
66
69 virtual ~SymFnc() {};
72 virtual bool operator==(SymFnc const& rhs) const = 0;
75 virtual bool operator<(SymFnc const& rhs) const = 0;
78 bool operator!=(SymFnc const& rhs) const;
81 bool operator>(SymFnc const& rhs) const;
84 bool operator<=(SymFnc const& rhs) const;
87 bool operator>=(SymFnc const& rhs) const;
93 virtual void setParameters(std::string const& parameterString) = 0;
105 virtual void changeLengthUnit(double convLength) = 0;
110 virtual std::string getSettingsLine() const = 0;
117 virtual void calculate(Atom& atom,
118 bool const derivatives) const = 0;
123 virtual std::string parameterLine() const = 0;
128 virtual std::vector<std::string>
129 parameterInfo() const;
139 std::string statisticsLine,
140 double Smin,
141 double Smax);
147 double scale(double value) const;
153 double unscale(double value) const;
156 std::size_t getType() const;
159 std::size_t getIndex() const;
162 std::size_t getLineNumber() const;
165 std::size_t getEc() const;
168 std::size_t getMinNeighbors() const;
171 double getRc() const;
174 double getGmin() const;
177 double getGmax() const;
180 double getScalingFactor() const;
183 double getConvLength() const;
186 std::set<
187 std::string> getParameters() const;
190 std::vector<
191 std::size_t> getIndexPerElement() const;
196 void setIndex(std::size_t index);
202 void setIndexPerElement(std::size_t elementIndex,
203 std::size_t index);
208 void setLineNumber(std::size_t lineNumber);
213 std::string scalingLine() const;
223 virtual double calculateRadialPart(double distance) const = 0;
233 virtual double calculateAngularPart(double angle) const = 0;
240 virtual bool checkRelevantElement(std::size_t index) const = 0;
241#ifndef N2P2_NO_SF_CACHE
247 virtual std::vector<
248 std::string> getCacheIdentifiers() const;
255 void addCacheIndex(std::size_t element,
256 std::size_t cacheIndex,
257 std::string cacheIdentifier);
259 std::vector<std::vector<
260 std::size_t>> getCacheIndices() const;
261#endif
262
263protected:
264 typedef std::map<std::string,
265 std::pair<std::string, std::string> > PrintFormat;
266 typedef std::vector<std::string> PrintOrder;
268 std::size_t type;
272 std::size_t index;
274 std::size_t lineNumber;
276 std::size_t ec;
278 std::size_t minNeighbors;
280 double Smin;
282 double Smax;
284 double Gmin;
286 double Gmax;
288 double Gmean;
290 double Gsigma;
292 double rc;
300 std::set<std::string> parameters;
302 std::vector<std::size_t> indexPerElement;
303#ifndef N2P2_NO_SF_CACHE
305 std::vector<
306 std::vector<std::size_t>> cacheIndices;
307#endif
309 static std::size_t const sfinfoWidth;
313 static PrintOrder const printOrder;
314
317 SymFnc(std::size_t type, ElementMap const&);
320 static PrintFormat const initializePrintFormat();
323 static PrintOrder const initializePrintOrder();
328 std::string getPrintFormat() const;
329};
330
332// Inlined function definitions //
334
335inline bool SymFnc::operator!=(SymFnc const& rhs) const
336{
337 return !((*this) == rhs);
338}
339
340inline bool SymFnc::operator>(SymFnc const& rhs) const
341{
342 return rhs < (*this);
343}
344
345inline bool SymFnc::operator<=(SymFnc const& rhs) const
346{
347 return !((*this) > rhs);
348}
349
350inline bool SymFnc::operator>=(SymFnc const& rhs) const
351{
352 return !((*this) < rhs);
353}
354
355inline std::size_t SymFnc::getType() const { return type; }
356inline std::size_t SymFnc::getEc() const { return ec; }
357inline std::size_t SymFnc::getIndex() const { return index; }
358inline std::size_t SymFnc::getLineNumber() const { return lineNumber; }
359inline std::size_t SymFnc::getMinNeighbors() const { return minNeighbors; }
360inline double SymFnc::getRc() const { return rc; }
361inline double SymFnc::getGmin() const { return Gmin; }
362inline double SymFnc::getGmax() const { return Gmax; }
363inline double SymFnc::getScalingFactor() const { return scalingFactor; }
364inline double SymFnc::getConvLength() const { return convLength; }
365
366inline void SymFnc::setIndex(std::size_t index)
367{
368 this->index = index;
369 return;
370}
371
372inline void SymFnc::setLineNumber(std::size_t lineNumber)
373{
374 this->lineNumber = lineNumber;
375 return;
376}
377
378inline std::set<std::string> SymFnc::getParameters() const
379{
380 return parameters;
381}
382
383inline std::vector<std::size_t> SymFnc::getIndexPerElement() const
384{
385 return indexPerElement;
386}
387
388inline void SymFnc::setIndexPerElement(std::size_t elementIndex,
389 std::size_t index)
390{
391 indexPerElement.at(elementIndex) = index;
392 return;
393}
394
395#ifndef N2P2_NO_SF_CACHE
396inline std::vector<std::vector<std::size_t>> SymFnc::getCacheIndices() const
397{
398 return cacheIndices;
399}
400#endif
401
402}
403
404#endif
Contains element map.
Definition: ElementMap.h:30
Symmetry function base class.
Definition: SymFnc.h:40
ScalingType
List of available scaling types.
Definition: SymFnc.h:44
@ ST_NONE
Definition: SymFnc.h:47
@ ST_SCALESIGMA
Definition: SymFnc.h:64
@ ST_SCALECENTER
Definition: SymFnc.h:60
@ ST_CENTER
Definition: SymFnc.h:55
@ ST_SCALE
Definition: SymFnc.h:52
virtual std::string parameterLine() const =0
Give symmetry function parameters in one line.
void setIndex(std::size_t index)
Set private index member variable.
Definition: SymFnc.h:366
double getGmin() const
Get private Gmin member variable.
Definition: SymFnc.h:361
virtual bool checkRelevantElement(std::size_t index) const =0
Check whether symmetry function is relevant for given element.
virtual void calculate(Atom &atom, bool const derivatives) const =0
Calculate symmetry function for one atom.
double convLength
Data set normalization length conversion factor.
Definition: SymFnc.h:296
virtual bool operator<(SymFnc const &rhs) const =0
Overload < operator.
static PrintFormat const printFormat
Map of parameter format strings and empty strings.
Definition: SymFnc.h:311
std::map< std::string, std::pair< std::string, std::string > > PrintFormat
Definition: SymFnc.h:265
void addCacheIndex(std::size_t element, std::size_t cacheIndex, std::string cacheIdentifier)
Add one cache index for given neighbor element and check identifier.
Definition: SymFnc.cpp:106
double Gmean
Mean unscaled symmetry function value.
Definition: SymFnc.h:288
double getConvLength() const
Get private convLength member variable.
Definition: SymFnc.h:364
bool operator>(SymFnc const &rhs) const
Overload > operator.
Definition: SymFnc.h:340
bool operator>=(SymFnc const &rhs) const
Overload >= operator.
Definition: SymFnc.h:350
std::size_t type
Symmetry function type.
Definition: SymFnc.h:268
virtual ~SymFnc()
Virtual destructor.
Definition: SymFnc.h:69
void setIndexPerElement(std::size_t elementIndex, std::size_t index)
Set private indexPerElement member variable.
Definition: SymFnc.h:388
double getGmax() const
Get private Gmax member variable.
Definition: SymFnc.h:362
std::vector< std::size_t > getIndexPerElement() const
Get private indexPerElement member variable.
Definition: SymFnc.h:383
virtual double calculateRadialPart(double distance) const =0
Calculate (partial) symmetry function value for one given distance.
virtual std::vector< std::string > getCacheIdentifiers() const
Get unique cache identifiers.
Definition: SymFnc.cpp:101
double Gmax
Maximum unscaled symmetry function value.
Definition: SymFnc.h:286
std::size_t getIndex() const
Get private index member variable.
Definition: SymFnc.h:357
std::set< std::string > parameters
Set with symmetry function parameter IDs (lookup for printing).
Definition: SymFnc.h:300
double getRc() const
Get private rc member variable.
Definition: SymFnc.h:360
virtual double calculateAngularPart(double angle) const =0
Calculate (partial) symmetry function value for one given angle.
void setLineNumber(std::size_t lineNumber)
Set line number.
Definition: SymFnc.h:372
bool operator!=(SymFnc const &rhs) const
Overload != operator.
Definition: SymFnc.h:335
static PrintOrder const printOrder
Vector of parameters in order of printing.
Definition: SymFnc.h:313
std::size_t index
Symmetry function index (per element).
Definition: SymFnc.h:272
double scalingFactor
Scaling factor.
Definition: SymFnc.h:294
std::size_t getType() const
Get private type member variable.
Definition: SymFnc.h:355
ScalingType scalingType
Symmetry function scaling type used by this symmetry function.
Definition: SymFnc.h:298
double rc
Cutoff radius .
Definition: SymFnc.h:292
void setScalingType(ScalingType scalingType, std::string statisticsLine, double Smin, double Smax)
Set symmetry function scaling type.
Definition: SymFnc.cpp:52
std::vector< std::string > PrintOrder
Definition: SymFnc.h:266
std::vector< std::vector< std::size_t > > cacheIndices
Cache indices for each element.
Definition: SymFnc.h:306
std::set< std::string > getParameters() const
Get private parameters member variable.
Definition: SymFnc.h:378
SymFnc(std::size_t type, ElementMap const &)
Constructor, initializes type.
Definition: SymFnc.cpp:135
double Smin
Minimum for scaling range.
Definition: SymFnc.h:280
double getScalingFactor() const
Get private scalingFactor member variable.
Definition: SymFnc.h:363
std::vector< std::vector< std::size_t > > getCacheIndices() const
Getter for cacheIndices.
Definition: SymFnc.h:396
double unscale(double value) const
Undo symmetry function scaling and/or centering.
Definition: SymFnc.cpp:197
std::size_t getLineNumber() const
Get private lineNumber member variable.
Definition: SymFnc.h:358
ElementMap elementMap
Copy of element map.
Definition: SymFnc.h:270
double Smax
Maximum for scaling range.
Definition: SymFnc.h:282
double scale(double value) const
Apply symmetry function scaling and/or centering.
Definition: SymFnc.cpp:169
std::size_t getEc() const
Get private ec member variable.
Definition: SymFnc.h:356
virtual void setParameters(std::string const &parameterString)=0
Set parameters.
double Gsigma
Sigma of unscaled symmetry function values.
Definition: SymFnc.h:290
double Gmin
Minimum unscaled symmetry function value.
Definition: SymFnc.h:284
std::vector< std::size_t > indexPerElement
Per-element index for derivative memory in Atom::Neighbor::dGdr arrays.
Definition: SymFnc.h:302
std::size_t ec
Element index of center atom.
Definition: SymFnc.h:276
static std::size_t const sfinfoWidth
Width of the SFINFO parameter description field (see parameterInfo()).
Definition: SymFnc.h:309
static PrintFormat const initializePrintFormat()
Initialize static print format map for all possible parameters.
Definition: SymFnc.cpp:239
std::size_t minNeighbors
Minimum number of neighbors required.
Definition: SymFnc.h:278
virtual bool operator==(SymFnc const &rhs) const =0
Overload == operator.
virtual std::string getSettingsLine() const =0
Get settings file line from currently set parameters.
std::string scalingLine() const
Get string with scaling information.
Definition: SymFnc.cpp:225
std::size_t lineNumber
Line number.
Definition: SymFnc.h:274
std::string getPrintFormat() const
Generate format string for symmetry function parameter printing.
Definition: SymFnc.cpp:285
virtual std::vector< std::string > parameterInfo() const
Get description with parameter names and values.
Definition: SymFnc.cpp:32
bool operator<=(SymFnc const &rhs) const
Overload <= operator.
Definition: SymFnc.h:345
std::size_t getMinNeighbors() const
Get private minNeighbors member variable.
Definition: SymFnc.h:359
virtual void changeLengthUnit(double convLength)=0
Change length unit.
static PrintOrder const initializePrintOrder()
Initialize static print order vector for all possible parameters.
Definition: SymFnc.cpp:262
Definition: Atom.h:29
Storage for a single atom.
Definition: Atom.h:33