Loading...
Searching...
No Matches
eonc::PrefactorJob Class Reference

#include <PrefactorJob.h>

Inheritance diagram for eonc::PrefactorJob:

Public Member Functions

 PrefactorJob (std::unique_ptr< Parameters > parameters, Runtime &rt)
 ~PrefactorJob ()=default
std::vector< std::string > run () override
 Virtual run; used solely for dynamic dispatch.
Public Member Functions inherited from eonc::Job
void adoptRuntime (std::unique_ptr< Runtime > rt)
 Take ownership of a Runtime previously passed as Runtime&.
 Job (std::unique_ptr< Parameters > parameters, Runtime &rt)
 Borrow: caller keeps Runtime alive (CLI stack / Python Session).
 Job (std::unique_ptr< Parameters > parameters, std::unique_ptr< Runtime > rt)
 Own a Runtime (one-shot makeJob / rvalue).
 Job (std::unique_ptr< Parameters > parameters)
 Own a default-constructed Runtime.
 Job (std::shared_ptr< Potential > potPassed, const Parameters &parameters)
virtual ~Job ()=default
JobType getType ()
PotRegistry & pots () noexcept
void releasePotential ()
 Drop the Potential so on_destroyed is recorded before Runtime dies.

Static Public Attributes

static constexpr std::string_view PREFACTOR_REACTANT {"reactant"}
static constexpr std::string_view PREFACTOR_SADDLE {"saddle"}
static constexpr std::string_view PREFACTOR_PRODUCT {"product"}

Additional Inherited Members

Protected Attributes inherited from eonc::Job
JobType jtype
Parameters params
std::unique_ptr< Runtime > owned_runtime_
 Non-null when this Job owns the composition root (one-shot makeJob).
Runtime * runtime_
 Always valid: either owned_runtime_.get() or a caller-owned Runtime.
std::shared_ptr< Potential > pot

Detailed Description

Definition at line 21 of file PrefactorJob.h.

Constructor & Destructor Documentation

◆ PrefactorJob()

eonc::PrefactorJob::PrefactorJob ( std::unique_ptr< Parameters > parameters,
Runtime & rt )
inline

Definition at line 23 of file PrefactorJob.h.

24 : Job(std::move(parameters), rt) {}
Job(std::unique_ptr< Parameters > parameters, Runtime &rt)
Borrow: caller keeps Runtime alive (CLI stack / Python Session).
Definition Job.h:76

◆ ~PrefactorJob()

eonc::PrefactorJob::~PrefactorJob ( )
default

Member Function Documentation

◆ run()

std::vector< std::string > eonc::PrefactorJob::run ( )
overridevirtual

Virtual run; used solely for dynamic dispatch.

Implements eonc::Job.

Definition at line 32 of file PrefactorJob.cpp.

32 {
33 std::vector<std::string> returnFiles;
34 VectorXd freqs;
35
36 std::string reactantFilename = eonc::helpers::getRelevantFile("reactant.con");
37 std::string saddleFilename = eonc::helpers::getRelevantFile("saddle.con");
38 std::string productFilename = eonc::helpers::getRelevantFile("product.con");
39
40 auto reactant = std::make_unique<Matter>(pot, params);
41 auto saddle = std::make_unique<Matter>(pot, params);
42 auto product = std::make_unique<Matter>(pot, params);
43
44 if (!eonc::io::io_ok(reactant->con2matter(reactantFilename)) ||
45 !eonc::io::io_ok(saddle->con2matter(saddleFilename)) ||
46 !eonc::io::io_ok(product->con2matter(productFilename))) {
47 EONC_LOG_CRITICAL("Failed to load reactant/saddle/product for prefactor");
48 throw std::runtime_error("failed to load prefactor geometries");
49 }
50 double pref1 = 0.0, pref2 = 0.0;
51 const int prefStatus = eonc::Prefactor::getPrefactors(
52 params, reactant.get(), saddle.get(), product.get(), pref1, pref2);
53
54 VectorXi atoms;
55 if (params.prefactor_options().all_free_atoms) {
56 std::string matterFilename;
57 if (params.prefactor_options().configuration ==
59 matterFilename = reactantFilename;
60 } else if (params.prefactor_options().configuration ==
62 matterFilename = saddleFilename;
63 } else if (params.prefactor_options().configuration ==
65 matterFilename = productFilename;
66 }
67 if (!eonc::io::io_ok(reactant->con2matter(matterFilename)) ||
68 !eonc::io::io_ok(saddle->con2matter(matterFilename)) ||
69 !eonc::io::io_ok(product->con2matter(matterFilename))) {
70 EONC_LOG_CRITICAL("Failed to reload {} for all-free-atoms prefactor",
71 matterFilename);
72 throw std::runtime_error("failed to load prefactor configuration");
73 }
74
75 atoms = eonc::Prefactor::allFreeAtoms(reactant.get());
76 } else {
77 if (!eonc::io::io_ok(reactant->con2matter(reactantFilename)) ||
78 !eonc::io::io_ok(saddle->con2matter(saddleFilename)) ||
79 !eonc::io::io_ok(product->con2matter(productFilename))) {
81 "Failed to reload reactant/saddle/product for prefactor");
82 throw std::runtime_error("failed to load prefactor geometries");
83 }
84
85 atoms = eonc::Prefactor::movedAtoms(params, reactant.get(), saddle.get(),
86 product.get());
87 }
88 bool failed = (prefStatus == -1) || (atoms.rows() == 0);
89
90 if (!failed) {
91 if (params.prefactor_options().configuration ==
93 Hessian hessian(params, reactant.get());
94 freqs = hessian.getFreqs(reactant.get(), atoms);
95 } else if (params.prefactor_options().configuration ==
97 Hessian hessian(params, saddle.get());
98 freqs = hessian.getFreqs(saddle.get(), atoms);
99 } else if (params.prefactor_options().configuration ==
101 Hessian hessian(params, product.get());
102 freqs = hessian.getFreqs(product.get(), atoms);
103 }
104 }
105
106 if (!failed) {
107 failed = freqs.size() != 3 * atoms.rows();
108 }
109
110 std::string results_file("results.dat");
111 std::string freq_file("freq.dat");
112 returnFiles.push_back(results_file);
113 returnFiles.push_back(freq_file);
114
115 std::ofstream outFreq(freq_file, std::ios::binary);
116
119 params.potential_options().potential,
120 PotRegistry::get().total_force_calls(), false, 0.0);
121 env.job_type = "prefactor";
122 env.tags.emplace_back("good", failed ? "false" : "true");
123 env.extras.emplace_back("force_calls", static_cast<double>(env.force_calls));
124 if (!failed) {
125 env.extras.emplace_back("prefactor_reactant_to_product", pref1);
126 env.extras.emplace_back("prefactor_product_to_reactant", pref2);
127 }
128 env.writeResultsDat(results_file);
129
130 if (outFreq && !failed) {
131 for (int i = 0; i < freqs.size(); i++) {
132 if (0. < freqs[i]) {
133 outFreq << std::format("{:f}\n",
134 std::sqrt(freqs[i]) /
135 (2 * eonc::helpers::pi * 10.18e-15));
136 } else {
137 outFreq << std::format("{:f}\n",
138 -std::sqrt(-freqs[i]) /
139 (2 * eonc::helpers::pi * 10.18e-15));
140 }
141 }
142 }
143
144 if (std::filesystem::exists("freqs.dat")) {
145 returnFiles.push_back("freqs.dat");
146 }
147 if (std::filesystem::exists("hessian.dat")) {
148 returnFiles.push_back("hessian.dat");
149 }
150
151 return returnFiles;
152}
#define EONC_LOG_CRITICAL(...)
Definition EonLogger.h:267
std::shared_ptr< Potential > pot
Definition Job.h:63
Parameters params
Definition Job.h:58
static PotRegistry & get() noexcept
Process-lifetime singleton.
size_t total_force_calls() const noexcept
static constexpr std::string_view PREFACTOR_PRODUCT
static constexpr std::string_view PREFACTOR_SADDLE
static constexpr std::string_view PREFACTOR_REACTANT
VectorXi allFreeAtoms(Matter *matter)
VectorXi movedAtoms(const Parameters &parameters, Matter *min1, Matter *saddle, Matter *min2)
int getPrefactors(const Parameters &parameters, Matter *min1, Matter *saddle, Matter *min2, double &pref1, double &pref2)
Definition Prefactor.cpp:24
std::string getRelevantFile(std::string filename)
constexpr double pi
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
static JobResultEnvelope fromMinimization(RunStatus status, PotType pot, std::uint64_t fcalls, bool hasE, double energy)
Definition JobResult.h:101

Member Data Documentation

◆ PREFACTOR_PRODUCT

std::string_view eonc::PrefactorJob::PREFACTOR_PRODUCT {"product"}
staticconstexpr

Definition at line 29 of file PrefactorJob.h.

29{"product"};

◆ PREFACTOR_REACTANT

std::string_view eonc::PrefactorJob::PREFACTOR_REACTANT {"reactant"}
staticconstexpr

Definition at line 27 of file PrefactorJob.h.

27{"reactant"};

◆ PREFACTOR_SADDLE

std::string_view eonc::PrefactorJob::PREFACTOR_SADDLE {"saddle"}
staticconstexpr

Definition at line 28 of file PrefactorJob.h.

28{"saddle"};

The documentation for this class was generated from the following files: