31{
32 bool structureInfo = false;
33
34 if (argc != 2)
35 {
36 cout << "USAGE: " << argv[0] << " <info>\n"
37 << " <info> ... Write structure information for debugging "
38 "to \"structure.out (0/1)\".\n"
39 << " Execute in directory with these NNP files present:\n"
40 << " - input.data (structure file)\n"
41 << " - input.nn (NNP settings)\n"
42 << " - scaling.data (symmetry function scaling data)\n"
43 << " - \"weights.%%03d.data\" (weights files)\n";
44 return 1;
45 }
46
47 structureInfo = (bool)atoi(argv[1]);
48
50 logFile.open(
"nnp-predict.log");
54 prediction.
log <<
"\n";
55 prediction.
log <<
"*** PREDICTION **************************"
56 "**************************************\n";
57 prediction.
log <<
"\n";
58 prediction.
log <<
"Reading structure file...\n";
61 prediction.
log <<
strpr(
"Structure contains %d atoms (%d elements).\n",
63 prediction.
log <<
"Calculating NNP prediction...\n";
65 prediction.
log <<
"\n";
66 prediction.
log <<
"-----------------------------------------"
67 "--------------------------------------\n";
68 prediction.
log <<
strpr(
"NNP energy: %16.8E\n",
70 prediction.
log <<
"\n";
71 prediction.
log <<
"NNP forces:\n";
72 for (vector<Atom>::const_iterator it = s.
atoms.begin();
73 it != s.
atoms.end(); ++it)
74 {
75 prediction.
log <<
strpr(
"%10zu %2s %16.8E %16.8E %16.8E\n",
76 it->index + 1,
78 it->element,
79 it->f[0],
80 it->f[1],
81 it->f[2]);
82 }
83 prediction.
log <<
"-----------------------------------------"
84 "--------------------------------------\n";
85 prediction.
log <<
"Writing output files...\n";
86 prediction.
log <<
" - energy.out\n";
87 ofstream file;
88 file.open("energy.out");
89
90
91 vector<string> title;
92 vector<string> colName;
93 vector<string> colInfo;
94 vector<size_t> colSize;
95 title.push_back("Energy comparison.");
96 colSize.push_back(16);
97 colName.push_back("Ennp");
98 colInfo.push_back("Potential energy predicted by NNP.");
99 colSize.push_back(16);
100 colName.push_back("Eref");
101 colInfo.push_back("Reference potential energy.");
102 colSize.push_back(16);
103 colName.push_back("Ediff");
104 colInfo.push_back("Difference between reference and NNP prediction.");
105 colSize.push_back(16);
106 colName.push_back("E_offset");
107 colInfo.push_back("Sum of atomic offset energies "
108 "(included in column Ennp).");
111
112 file <<
strpr(
"%16.8E %16.8E %16.8E %16.8E\n",
117 file.close();
118
119 prediction.
log <<
" - nnatoms.out\n";
120 file.open("nnatoms.out");
121
122
123 title.clear();
124 colName.clear();
125 colInfo.clear();
126 colSize.clear();
127 title.push_back("Energy contributions calculated from NNP.");
128 colSize.push_back(10);
129 colName.push_back("index");
130 colInfo.push_back("Atom index.");
131 colSize.push_back(2);
132 colName.push_back("e");
133 colInfo.push_back("Element of atom.");
134 colSize.push_back(16);
135 colName.push_back("charge");
136 colInfo.push_back("Atomic charge (not used).");
137 colSize.push_back(16);
138 colName.push_back("Ennp_atom");
139 colInfo.push_back("Atomic energy contribution (physical units, no mean "
140 "or offset energy added).");
143
144 for (vector<Atom>::const_iterator it = s.
atoms.begin();
145 it != s.
atoms.end(); ++it)
146 {
147 file <<
strpr(
"%10d %2s %16.8E %16.8E\n",
148 it->index,
150 it->charge,
151 it->energy);
152 }
153 file.close();
154
155 prediction.
log <<
" - nnforces.out\n";
156 file.open("nnforces.out");
157
158
159 title.clear();
160 colName.clear();
161 colInfo.clear();
162 colSize.clear();
163 title.push_back("Atomic force comparison (ordered by atom index).");
164 colSize.push_back(16);
165 colName.push_back("fx");
166 colInfo.push_back("Force in x direction.");
167 colSize.push_back(16);
168 colName.push_back("fy");
169 colInfo.push_back("Force in y direction.");
170 colSize.push_back(16);
171 colName.push_back("fz");
172 colInfo.push_back("Force in z direction.");
173 colSize.push_back(16);
174 colName.push_back("fxRef");
175 colInfo.push_back("Reference force in x direction.");
176 colSize.push_back(16);
177 colName.push_back("fyRef");
178 colInfo.push_back("Reference force in y direction.");
179 colSize.push_back(16);
180 colName.push_back("fzRef");
181 colInfo.push_back("Reference force in z direction.");
182 colSize.push_back(16);
183 colName.push_back("fxDiff");
184 colInfo.push_back("Difference between reference and NNP force in x dir.");
185 colSize.push_back(16);
186 colName.push_back("fyDiff");
187 colInfo.push_back("Difference between reference and NNP force in y dir.");
188 colSize.push_back(16);
189 colName.push_back("fzDiff");
190 colInfo.push_back("Difference between reference and NNP force in z dir.");
193
194 for (vector<Atom>::const_iterator it = s.
atoms.begin();
195 it != s.
atoms.end(); ++it)
196 {
197 file <<
strpr(
"%16.8E %16.8E %16.8E %16.8E %16.8E "
198 "%16.8E %16.8E %16.8E %16.8E\n",
199 it->f[0],
200 it->f[1],
201 it->f[2],
202 it->fRef[0],
203 it->fRef[1],
204 it->fRef[2],
205 it->fRef[0] - it->f[0],
206 it->fRef[1] - it->f[1],
207 it->fRef[2] - it->f[2]);
208 }
209 file.close();
210
211 prediction.
log <<
"Writing structure with NNP prediction "
212 "to \"output.data\".\n";
213 file.open("output.data");
215 file.close();
216
217 if (structureInfo)
218 {
219 prediction.
log <<
"Writing detailed structure information to "
220 "\"structure.out\".\n";
221 file.open("structure.out");
224 file.close();
225 }
226
227 prediction.
log <<
"Finished.\n";
228 prediction.
log <<
"*****************************************"
229 "**************************************\n";
231
232 return 0;
233}
void registerStreamPointer(std::ofstream *const &streamPointer)
Register new C++ ofstream pointer.
ElementMap elementMap
Global element map, populated by setupElementMap().
double getEnergyOffset(Structure const &structure) const
Get atomic energy offset for given structure.
void readStructureFromFile(std::string const &fileName="input.data")
string strpr(const char *format,...)
String version of printf function.
vector< string > createFileHeader(vector< string > const &title, vector< size_t > const &colSize, vector< string > const &colName, vector< string > const &colInfo, char const &commentChar)
void appendLinesToFile(ofstream &file, vector< string > const lines)
Append multiple lines of strings to open file stream.
Storage for one atomic configuration.
void writeToFile(std::string const fileName="output.data", bool const ref=true, bool const append=false) const
Write configuration to file.
double energy
Potential energy determined by neural network.
double energyRef
Reference potential energy.
std::size_t numAtoms
Total number of atoms present in this structure.
std::size_t numElements
Global number of elements (all structures).
std::vector< Atom > atoms
Vector of all atoms in this structure.
std::vector< std::string > info() const
Get structure information as a vector of strings.