Virtual run; used solely for dynamic dispatch.
24 {
25 std::string posInFilename("pos.con");
26 std::string posOutFilename("min.con");
27
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");
32 } else {
33 QUILL_LOG_DEBUG(
log,
"[Minimization] No checkpoint files found");
34 }
35 }
36
37 std::vector<std::string> returnFiles;
38 returnFiles.push_back(posOutFilename);
39
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);
44 }
45
46 QUILL_LOG_DEBUG(
log,
"\nBeginning minimization of {}", posInFilename);
47
48 bool converged;
49 try {
50 converged =
51 pos->relax(
false,
params.debug_options.write_movies,
52 params.main_options.checkpoint,
"minimization",
"pos");
53 if (converged) {
55 QUILL_LOG_DEBUG(
log,
"Minimization converged within tolerence");
56 } else {
58 QUILL_LOG_DEBUG(
log,
"Minimization did not converge to tolerence!"
59 "Maybe try to increase max_iterations?");
60 }
61 } catch (int e) {
62 if (e == 100) {
64 } else {
65 throw e;
66 }
67 }
68
69 QUILL_LOG_DEBUG(
log,
"Saving result to {}", posOutFilename);
71 QUILL_LOG_ERROR(
log,
"Failed to write {}", posOutFilename);
72 }
74 QUILL_LOG_DEBUG(
log,
"Final Energy: {}", pos->getPotentialEnergy());
75 }
76
77 std::filesystem::path resultsFilename("results.dat");
78 returnFiles.push_back(resultsFilename.string());
79
80 std::ofstream fileResults(resultsFilename, std::ios::binary);
81
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)));
87 return returnFiles;
88 }
89
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";
98
100 fileResults << std::format("{:.12e} potential_energy\n",
101 pos->getPotentialEnergy());
102 }
103
104
105 if (!fileResults.good()) {
106 std::cerr << "Error writing to file " << resultsFilename
107 << ": May be incomplete." << std::endl;
108
109 }
110
111 return returnFiles;
112}
std::shared_ptr< Potential > pot
constexpr bool io_ok(IoStatus s) noexcept