n2p2 - A neural network potential package
SymGrp.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//
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#include "SymGrp.h"
18#include "utility.h"
19
20using namespace std;
21using namespace nnp;
22
23SymGrp::PrintFormat const SymGrp::printFormat = initializePrintFormat();
24
25SymGrp::PrintOrder const SymGrp::printOrder = initializePrintOrder();
26
27SymGrp::SymGrp(size_t type, ElementMap const& elementMap) :
28 type (type ),
29 elementMap (elementMap),
30 index (0 ),
31 ec (0 ),
32 convLength (1.0 )
33{
34 // Add standard common parameter IDs to set.
35 parametersCommon.insert("index");
36 parametersCommon.insert("type");
37 parametersCommon.insert("ec");
38
39 // Add standard member parameter IDs to set.
40 parametersMember.insert("lineNumber");
41 parametersMember.insert("mindex");
42 parametersMember.insert("sfindex");
43}
44
46{
47 PrintFormat pf;
48
49 pf["index"] = make_pair("%4zu" , string(4, ' '));
50 pf["ec"] = make_pair("%2s" , string(2, ' '));
51 pf["type"] = make_pair("%2zu" , string(2, ' '));
52 pf["subtype"] = make_pair("%4s" , string(4, ' '));
53 pf["e1"] = make_pair("%2s" , string(2, ' '));
54 pf["e2"] = make_pair("%2s" , string(2, ' '));
55 pf["eta"] = make_pair("%9.3E" , string(9, ' '));
56 pf["rs/rl"] = make_pair("%10.3E", string(10, ' '));
57 pf["rc"] = make_pair("%10.3E", string(10, ' '));
58 pf["angleLeft"] = make_pair("%6.1f" , string(6, ' '));
59 pf["angleRight"] = make_pair("%6.1f" , string(6, ' '));
60 pf["lambda"] = make_pair("%2.0f" , string(2, ' '));
61 pf["zeta"] = make_pair("%4.1f" , string(4, ' '));
62 pf["alpha"] = make_pair("%4.2f" , string(4, ' '));
63 pf["lineNumber"] = make_pair("%5zu" , string(5, ' '));
64 pf["mindex"] = make_pair("%4zu" , string(4, ' '));
65 pf["sfindex"] = make_pair("%4zu" , string(4, ' '));
66 pf["calcexp"] = make_pair("%1d" , string(1, ' '));
67
68 return pf;
69}
70
72{
73 vector<string> po;
74
75 po.push_back("index" );
76 po.push_back("ec" );
77 po.push_back("type" );
78 po.push_back("subtype" );
79 po.push_back("e1" );
80 po.push_back("e2" );
81 po.push_back("eta" );
82 po.push_back("rs/rl" );
83 po.push_back("rc" );
84 po.push_back("angleLeft" );
85 po.push_back("angleRight");
86 po.push_back("lambda" );
87 po.push_back("zeta" );
88 po.push_back("alpha" );
89 po.push_back("lineNumber");
90 po.push_back("mindex" );
91 po.push_back("sfindex" );
92 po.push_back("calcexp" );
93
94 return po;
95}
96
98{
99 string s;
100
101 for (PrintOrder::const_iterator it = printOrder.begin();
102 it != printOrder.end(); ++it)
103 {
104 // If common parameter is present add format string.
105 if (parametersCommon.find(*it) != parametersCommon.end())
106 {
107 s += safeFind(printFormat, (*it)).first + ' ';
108 }
109 // Else if member parameter is present add star marker.
110 else if (parametersMember.find(*it) != parametersMember.end())
111 {
112 string t = safeFind(printFormat, (*it)).second;
113 if (t.size () > 0) t.resize (t.size () - 1);
114 t += '*';
115 s += t + ' ';
116 }
117 // Else add just enough empty spaces.
118 else
119 {
120 s += safeFind(printFormat, (*it)).second + ' ';
121 }
122 }
123 // Remove extra space at the end.
124 if (s.size () > 0) s.resize (s.size () - 1);
125 s += '\n';
126
127 return s;
128}
129
131{
132 string s;
133
134 for (PrintOrder::const_iterator it = printOrder.begin();
135 it != printOrder.end(); ++it)
136 {
137 // If common parameter is present add format string.
138 if (parametersMember.find(*it) != parametersMember.end())
139 {
140 s += safeFind(printFormat, (*it)).first + ' ';
141 }
142 // Else if member parameter is present add star marker.
143 else if (parametersCommon.find(*it) != parametersCommon.end())
144 {
145 string t = safeFind(printFormat, (*it)).second;
146 if (t.size () > 0) t.resize (t.size () - 1);
147 t += '-';
148 s += t + ' ';
149 }
150 // Else add just enough empty spaces.
151 else
152 {
153 s += safeFind(printFormat, (*it)).second + ' ';
154 }
155 }
156 // Remove extra space at the end.
157 if (s.size () > 0) s.resize (s.size () - 1);
158 s += '\n';
159
160 return s;
161}
Contains element map.
Definition: ElementMap.h:30
static PrintFormat const printFormat
Map of parameter format strings and empty strings.
Definition: SymGrp.h:126
static PrintFormat const initializePrintFormat()
Initialize static print format map for all possible parameters.
Definition: SymGrp.cpp:45
std::string getPrintFormatCommon() const
Get common parameter line format string.
Definition: SymGrp.cpp:97
std::map< std::string, std::pair< std::string, std::string > > PrintFormat
Definition: SymGrp.h:103
std::set< std::string > parametersCommon
Set of common parameters IDs.
Definition: SymGrp.h:120
std::vector< std::string > PrintOrder
Definition: SymGrp.h:104
std::string getPrintFormatMember() const
Get member parameter line format string.
Definition: SymGrp.cpp:130
std::set< std::string > parametersMember
Set of common parameters IDs.
Definition: SymGrp.h:122
static PrintOrder const printOrder
Vector of parameters in order of printing.
Definition: SymGrp.h:128
static PrintOrder const initializePrintOrder()
Initialize static print order vector for all possible parameters.
Definition: SymGrp.cpp:71
Definition: Atom.h:29
V const & safeFind(std::map< K, V > const &stdMap, typename std::map< K, V >::key_type const &key)
Safely access map entry.
Definition: utility.h:144