28{
29 double threshold;
30 string pruneMode;
31
32 if (!(argc == 3 || argc == 4))
33 {
34 cout << "USAGE: " << argv[0] << " <mode> <threshold> <<sensmode>>\n"
35 << " <mode> ........ Use scaling data \"range\" or "
36 "sensitivity analysis data \"sensitivity\".\n"
37 << " <threshold> ... Prune symmetry function lines in "
38 "settings file below this threshold.\n"
39 << " <sensmode> .... If <mode> is sensitivity, select mean "
40 "square average or maximum sensitivity (msa/max).\n"
41 << " Execute in directory with these NNP files present:\n"
42 << " - input.nn (NNP settings)\n"
43 << " - sensitivity.???.out (Data for sensitivity mode).\n";
44 return 1;
45 }
46
47 pruneMode = argv[1];
48 if (! (pruneMode == "range" || pruneMode == "sensitivity"))
49 {
50 throw invalid_argument("ERROR: Unknown pruning mode.\n");
51 }
52 threshold = atof(argv[2]);
53
61 if (pruneMode == "range")
62 {
64 }
65
67 mode.
log <<
"*** PRUNE SYMMETRY FUNCTIONS ************"
68 "**************************************\n";
70
71 vector<size_t> prune;
72 if (pruneMode == "range")
73 {
74 mode.
log <<
"Pruning symmetry functions according to their range.\n";
75 mode.
log <<
strpr(
"Symmetry function threshold for pruning |Gmax - "
76 "Gmin| < %10.2E\n", threshold);
78 mode.
log <<
strpr(
"Number of symmetry functions to be pruned: %zu\n",
79 prune.size());
81 mode.
log <<
"Pruned settings file written to: output-prune-range.nn\n";
82 }
83 else if (pruneMode == "sensitivity")
84 {
85 if (argc != 4)
86 {
87 throw invalid_argument("ERROR: Please select sensitivity mode.\n");
88 }
89 string sensMode = argv[3];
90 size_t column = 0;
91 if (sensMode == "msa")
92 {
93 column = 1;
94 mode.
log <<
strpr(
"Pruning symmetry functions below mean square "
95 "average sensitivity threshold: %10.2E.\n",
96 threshold);
97 }
98 else if (sensMode == "max")
99 {
100 column = 2;
101 mode.
log <<
strpr(
"Pruning symmetry functions below maximum "
102 "sensitivity threshold: %10.2E.\n",
103 threshold);
104 }
105 else
106 {
107 throw invalid_argument("ERROR: Unknown sensitivity mode.\n");
108 }
109 vector<vector<double> > sensitivity;
112 sensitivity.resize(numElements);
113 for (size_t i = 0; i < numElements; ++i)
114 {
115 ifstream sensFile;
116 string sensFileName =
strpr(
"sensitivity.%03d.out",
118 sensFile.open(sensFileName.c_str());
119 string line;
120 vector<string> lines;
121 while (getline(sensFile, line))
122 {
123 if (line.at(0) != '#')
124 {
125 lines.push_back(line);
126 }
127 }
128 if (lines.size() != numSymmetryFunctions.at(i))
129 {
130 throw range_error(
strpr(
"ERROR: Inconsistent sensistivity"
131 " data file \"%s\".\n",
132 sensFileName.c_str()));
133 }
134 for (size_t j = 0; j < numSymmetryFunctions.at(i); ++j)
135 {
137 double s = atof(
split.at(column).c_str());
138 sensitivity.at(i).push_back(s);
139 }
140 sensFile.close();
141 }
143 mode.
log <<
strpr(
"Number of symmetry functions to be pruned: %zu\n",
144 prune.size());
146 mode.
log <<
"Pruned settings file written to: "
147 "output-prune-sensitivity.nn\n";
148 }
149
150 mode.
log <<
"*****************************************"
151 "**************************************\n";
153
154 return 0;
155}
std::size_t atomicNumber(std::size_t index) const
Get atomic number from element index.
void registerStreamPointer(std::ofstream *const &streamPointer)
Register new C++ ofstream pointer.
Base class for all NNP applications.
ElementMap elementMap
Global element map, populated by setupElementMap().
void initialize()
Write welcome message with version information.
std::size_t getNumElements() const
Getter for Mode::numElements.
void setupGeneric(std::string const &nnpDir="", bool skipNormalize=false, bool initialHardness=false)
Combine multiple setup routines and provide a basic NNP setup.
std::vector< std::size_t > pruneSymmetryFunctionsRange(double threshold)
Prune symmetry functions according to their range and write settings file.
void writePrunedSettingsFile(std::vector< std::size_t > prune, std::string fileName="output.nn") const
Copy settings file but comment out lines provided.
virtual void setupSymmetryFunctionScaling(std::string const &fileName="scaling.data")
Set up symmetry function scaling from file.
std::vector< std::size_t > getNumSymmetryFunctions() const
Get number of symmetry functions per element.
void loadSettingsFile(std::string const &fileName="input.nn")
Open settings file and load all keywords into memory.
std::vector< std::size_t > pruneSymmetryFunctionsSensitivity(double threshold, std::vector< std::vector< double > > sensitivity)
Prune symmetry functions with sensitivity analysis data.
string strpr(const char *format,...)
String version of printf function.
vector< string > split(string const &input, char delimiter)
Split string at each delimiter.
string reduce(string const &line, string const &whitespace, string const &fill)
Replace multiple whitespaces with fill.