n2p2 - A neural network potential package
SymFncBaseComp.cpp
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3// Copyright (C) 2020 Martin P. Bircher
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18#include "SymFncBaseComp.h"
19#include "utility.h"
20#include <string>
21
22using namespace std;
23using namespace nnp;
24
25vector<string> SymFncBaseComp::parameterInfo() const
26{
27 vector<string> v = SymFnc::parameterInfo();
28 string s;
29 size_t w = sfinfoWidth;
30
31 s = "subtype";
32 v.push_back(strpr((pad(s, w) + "%s" ).c_str(), subtype.c_str()));
33 s = "rl";
34 v.push_back(strpr((pad(s, w) + "%14.8E").c_str(), rl / convLength));
35
36 return v;
37}
38
40{
41 if (subtype.size() < 1 || subtype.size() > 3)
42 {
43 throw runtime_error(strpr("ERROR: Invalid compact function type "
44 "specification: \"%s\".\n",
45 subtype.c_str()));
46 }
47
48 using CFT = CoreFunction::Type;
49 // Check for polynomials.
50 if (subtype.front() == 'p')
51 {
52 if (subtype.at(1) == '1') cr.setCoreFunction(CFT::POLY1);
53 else if (subtype.at(1) == '2') cr.setCoreFunction(CFT::POLY2);
54 else if (subtype.at(1) == '3') cr.setCoreFunction(CFT::POLY3);
55 else if (subtype.at(1) == '4') cr.setCoreFunction(CFT::POLY4);
56 else
57 {
58 throw runtime_error(strpr("ERROR: Invalid polynom type: \"%s\".\n",
59 subtype.c_str()));
60 }
61 if (subtype.size() == 3)
62 {
63 if (subtype.at(2) == 'a')
64 {
65#ifndef N2P2_NO_ASYM_POLY
66 asymmetric = true;
67 cr.setAsymmetric(true);
68#else
69 throw runtime_error("ERROR: Compiled without support for "
70 "asymmetric polynomial symmetry functions "
71 "(-DN2P2_NO_ASYM_POLY).\n");
72#endif
73 }
74 else
75 {
76 throw runtime_error(strpr("ERROR: Invalid polynom specifier: "
77 "\"%s\".\n", subtype.c_str()));
78 }
79 }
80 }
81 else if (subtype.front() == 'e')
82 {
83 cr.setCoreFunction(CFT::EXP);
84 }
85 else
86 {
87 throw runtime_error(strpr("ERROR: Unknown compact SF type: \"%s\".\n",
88 subtype.c_str()));
89 }
90
91 return;
92}
93
95 ElementMap const& elementMap) :
96 SymFnc(type, elementMap),
97 asymmetric(false),
98 rl (0.0 ),
99 subtype ("" )
100{
101 // Add compact-related parameter IDs to set.
102 parameters.insert("rs/rl");
103 parameters.insert("subtype");
104}
void setCoreFunction(CoreFunction::Type const type)
Set type.
void setAsymmetric(bool asymmetric)
Set asymmetric property in core function.
Type
List of available function types.
Definition: CoreFunction.h:31
Contains element map.
Definition: ElementMap.h:30
double rl
Lower bound of compact function, .
CompactFunction cr
Compact function for radial part.
bool asymmetric
If asymmetric version of polynomials should be used.
std::string subtype
Subtype string (specifies e.g. polynom type).
void setCompactFunction(std::string subtype)
Set radial compact function.
SymFncBaseComp(std::size_t type, ElementMap const &)
Constructor, initializes type.
Symmetry function base class.
Definition: SymFnc.h:40
double convLength
Data set normalization length conversion factor.
Definition: SymFnc.h:296
std::set< std::string > parameters
Set with symmetry function parameter IDs (lookup for printing).
Definition: SymFnc.h:300
static std::size_t const sfinfoWidth
Width of the SFINFO parameter description field (see parameterInfo()).
Definition: SymFnc.h:309
virtual std::vector< std::string > parameterInfo() const
Get description with parameter names and values.
Definition: SymFnc.cpp:32
Definition: Atom.h:28
string pad(string const &input, size_t num, char fill, bool right)
Definition: utility.cpp:79
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90