25 std::string posInFilename(
"pos.con");
26 std::string posOutFilename(
"min.con");
28 if (
params.main_options.checkpoint) {
29 if (std::filesystem::exists(
"pos_cp.con")) {
30 posInFilename =
"pos_cp.con";
31 QUILL_LOG_DEBUG(
log,
"[Minimization] Resuming from checkpoint");
33 QUILL_LOG_DEBUG(
log,
"[Minimization] No checkpoint files found");
37 std::vector<std::string> returnFiles;
38 returnFiles.push_back(posOutFilename);
40 auto pos = std::make_shared<Matter>(
pot,
params);
42 QUILL_LOG_CRITICAL(
log,
"Failed to load {}", posInFilename);
43 throw std::runtime_error(
"failed to load " + posInFilename);
46 QUILL_LOG_DEBUG(
log,
"\nBeginning minimization of {}", posInFilename);
51 pos->relax(
false,
params.debug_options.write_movies,
52 params.main_options.checkpoint,
"minimization",
"pos");
55 QUILL_LOG_DEBUG(
log,
"Minimization converged within tolerence");
58 QUILL_LOG_DEBUG(
log,
"Minimization did not converge to tolerence!"
59 "Maybe try to increase max_iterations?");
69 QUILL_LOG_DEBUG(
log,
"Saving result to {}", posOutFilename);
71 QUILL_LOG_ERROR(
log,
"Failed to write {}", posOutFilename);
74 QUILL_LOG_DEBUG(
log,
"Final Energy: {}", pos->getPotentialEnergy());
77 std::filesystem::path resultsFilename(
"results.dat");
78 returnFiles.push_back(resultsFilename.string());
80 std::ofstream fileResults(resultsFilename, std::ios::binary);
82 if (!fileResults.is_open()) {
83 std::cerr <<
"Error opening file " << resultsFilename <<
": "
84 << std::strerror(errno) << std::endl;
85 throw std::runtime_error(
"Failed to open results file: " +
86 std::string(std::strerror(errno)));
90 fileResults << static_cast<int>(
status) <<
" termination_reason\n";
91 fileResults << magic_enum::enum_name<RunStatus>(
status)
92 <<
" termination_reason_text\n";
93 fileResults <<
"minimization job_type\n";
94 fileResults << magic_enum::enum_name<PotType>(
95 params.potential_options.potential)
96 <<
" potential_type\n";
97 fileResults << this->
pot->forceCallCounter.load() <<
" total_force_calls\n";
100 fileResults << std::format(
"{:.12e} potential_energy\n",
101 pos->getPotentialEnergy());
105 if (!fileResults.good()) {
106 std::cerr <<
"Error writing to file " << resultsFilename
107 <<
": May be incomplete." << std::endl;