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";
67 prediction.
log <<
"-----------------------------------------"
68 "--------------------------------------\n";
69 prediction.
log <<
strpr(
"NNP total energy: %16.8E\n",
71 if (prediction.
getNnpType() == Mode::NNPType::HDNNP_4G)
72 {
73 prediction.
log <<
strpr(
"NNP electrostatic energy: %16.8E\n",
75 prediction.
log <<
"\n";
76 prediction.
log <<
"NNP charges:\n";
77 for (
auto const& a : s.
atoms)
78 {
79 prediction.
log <<
strpr(
"%10zu %2s %16.8E\n",
80 a.index + 1,
82 a.charge);
83 }
84 prediction.
log <<
strpr(
"NNP total charge: %16.8E (ref: %16.8E)\n",
86 }
87 prediction.
log <<
"\n";
88 prediction.
log <<
"NNP forces:\n";
89 for (vector<Atom>::const_iterator it = s.
atoms.begin();
90 it != s.
atoms.end(); ++it)
91 {
92 prediction.
log <<
strpr(
"%10zu %2s %16.8E %16.8E %16.8E\n",
93 it->index + 1,
95 it->element,
96 it->f[0],
97 it->f[1],
98 it->f[2]);
99 }
100 prediction.
log <<
"-----------------------------------------"
101 "--------------------------------------\n";
102 prediction.
log <<
"Writing output files...\n";
103 prediction.
log <<
" - energy.out\n";
104 ofstream file;
105 file.open("energy.out");
106
107
108 vector<string> title;
109 vector<string> colName;
110 vector<string> colInfo;
111 vector<size_t> colSize;
112 title.push_back("Energy comparison.");
113 colSize.push_back(10);
114 colName.push_back("conf");
115 colInfo.push_back("Configuration index (starting with 1).");
116 colSize.push_back(10);
117 colName.push_back("natoms");
118 colInfo.push_back("Number of atoms in configuration.");
119 colSize.push_back(24);
120 colName.push_back("Eref");
121 colInfo.push_back("Reference potential energy.");
122 colSize.push_back(24);
123 colName.push_back("Ennp");
124 colInfo.push_back("Potential energy predicted by NNP.");
125 colSize.push_back(24);
126 colName.push_back("Ediff");
127 colInfo.push_back("Difference in energy per atom between reference and "
128 "NNP prediction.");
129 colSize.push_back(24);
130 colName.push_back("E_offset");
131 colInfo.push_back("Sum of atomic offset energies "
132 "(included in column Ennp).");
135
136 file <<
strpr(
"%10zu %10zu %24.16E %24.16E %24.16E %24.16E\n",
143 file.close();
144
145 prediction.
log <<
" - nnatoms.out\n";
146 file.open("nnatoms.out");
147
148
149 title.clear();
150 colName.clear();
151 colInfo.clear();
152 colSize.clear();
153 title.push_back("Energy contributions calculated from NNP.");
154 colSize.push_back(10);
155 colName.push_back("conf");
156 colInfo.push_back("Configuration index (starting with 1).");
157 colSize.push_back(10);
158 colName.push_back("index");
159 colInfo.push_back("Atom index (starting with 1).");
160 colSize.push_back(3);
161 colName.push_back("Z");
162 colInfo.push_back("Nuclear charge of atom.");
163 colSize.push_back(24);
164 colName.push_back("Qref");
165 colInfo.push_back("Reference atomic charge.");
166 colSize.push_back(24);
167 colName.push_back("Qnnp");
168 colInfo.push_back("NNP atomic charge.");
169 colSize.push_back(24);
170 colName.push_back("Eref_atom");
171 colInfo.push_back("Reference atomic energy contribution.");
172 colSize.push_back(24);
173 colName.push_back("Ennp_atom");
174 colInfo.push_back("Atomic energy contribution (physical units, no mean "
175 "or offset energy added).");
178
179 for (vector<Atom>::const_iterator it = s.
atoms.begin();
180 it != s.
atoms.end(); ++it)
181 {
182 file <<
strpr(
"%10zu %10zu %3zu %24.16E %24.16E %24.16E %24.16E\n",
184 it->index + 1,
186 it->chargeRef,
187 it->charge,
188 0.0,
189 it->energy);
190 }
191 file.close();
192
193 prediction.
log <<
" - nnforces.out\n";
194 file.open("nnforces.out");
195
196
197 title.clear();
198 colName.clear();
199 colInfo.clear();
200 colSize.clear();
201 title.push_back("Atomic force comparison (ordered by atom index).");
202 colSize.push_back(10);
203 colName.push_back("conf");
204 colInfo.push_back("Configuration index (starting with 1).");
205 colSize.push_back(10);
206 colName.push_back("index");
207 colInfo.push_back("Atom index (starting with 1).");
208 colSize.push_back(24);
209 colName.push_back("fxRef");
210 colInfo.push_back("Reference force in x direction.");
211 colSize.push_back(24);
212 colName.push_back("fyRef");
213 colInfo.push_back("Reference force in y direction.");
214 colSize.push_back(24);
215 colName.push_back("fzRef");
216 colInfo.push_back("Reference force in z direction.");
217 colSize.push_back(24);
218 colName.push_back("fx");
219 colInfo.push_back("Force in x direction.");
220 colSize.push_back(24);
221 colName.push_back("fy");
222 colInfo.push_back("Force in y direction.");
223 colSize.push_back(24);
224 colName.push_back("fz");
225 colInfo.push_back("Force in z direction.");
228
229 for (vector<Atom>::const_iterator it = s.
atoms.begin();
230 it != s.
atoms.end(); ++it)
231 {
232 file <<
strpr(
"%10zu %10zu %24.16E %24.16E %24.16E %24.16E %24.16E "
233 "%24.16E\n",
235 it->index + 1,
236 it->fRef[0],
237 it->fRef[1],
238 it->fRef[2],
239 it->f[0],
240 it->f[1],
241 it->f[2]);
242 }
243 file.close();
244
245 prediction.
log <<
"Writing structure with NNP prediction "
246 "to \"output.data\".\n";
247 file.open("output.data");
249 file.close();
250
251 if (structureInfo)
252 {
253 prediction.
log <<
"Writing detailed structure information to "
254 "\"structure.out\".\n";
255 file.open("structure.out");
258 file.close();
259 }
260
261 prediction.
log <<
"Finished.\n";
262 prediction.
log <<
"*****************************************"
263 "**************************************\n";
265
266 return 0;
267}
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.
NNPType getNnpType() const
Getter for Mode::nnpType.
ElementMap elementMap
Global element map, populated by setupElementMap().
void logEwaldCutoffs()
Logs Ewald params whenever they change.
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 charge
Charge determined by neural network potential.
std::size_t index
Index number of this structure.
double chargeRef
Reference charge.
double energyElec
Electrostatics part of the potential energy predicted by NNP.
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.