30int main(
int argc,
char* argv[])
32 bool structureInfo =
false;
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";
47 structureInfo = (bool)atoi(argv[1]);
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)
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)
79 prediction.
log <<
strpr(
"%10zu %2s %16.8E\n",
84 prediction.
log <<
strpr(
"NNP total charge: %16.8E (ref: %16.8E)\n",
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)
92 prediction.
log <<
strpr(
"%10zu %2s %16.8E %16.8E %16.8E\n",
100 prediction.
log <<
"-----------------------------------------"
101 "--------------------------------------\n";
102 prediction.
log <<
"Writing output files...\n";
103 prediction.
log <<
" - energy.out\n";
105 file.open(
"energy.out");
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 "
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).");
136 file <<
strpr(
"%10zu %10zu %24.16E %24.16E %24.16E %24.16E\n",
145 prediction.
log <<
" - nnatoms.out\n";
146 file.open(
"nnatoms.out");
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).");
179 for (vector<Atom>::const_iterator it = s.
atoms.begin();
180 it != s.
atoms.end(); ++it)
182 file <<
strpr(
"%10zu %10zu %3zu %24.16E %24.16E %24.16E %24.16E\n",
193 prediction.
log <<
" - nnforces.out\n";
194 file.open(
"nnforces.out");
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.");
229 for (vector<Atom>::const_iterator it = s.
atoms.begin();
230 it != s.
atoms.end(); ++it)
232 file <<
strpr(
"%10zu %10zu %24.16E %24.16E %24.16E %24.16E %24.16E "
245 prediction.
log <<
"Writing structure with NNP prediction "
246 "to \"output.data\".\n";
247 file.open(
"output.data");
253 prediction.
log <<
"Writing detailed structure information to "
254 "\"structure.out\".\n";
255 file.open(
"structure.out");
261 prediction.
log <<
"Finished.\n";
262 prediction.
log <<
"*****************************************"
263 "**************************************\n";
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.
int main(int argc, char *argv[])
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.