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

Declaration of the Saddle Search job. More...

#include <SaddleSearchJob.h>

Inheritance diagram for eonc::SaddleSearchJob:

Public Member Functions

 SaddleSearchJob (std::unique_ptr< Parameters > parameters, Runtime &rt)
 Saddle Search job constructor.
 ~SaddleSearchJob (void)=default
 Saddle Search Job Deconstructor.
std::vector< std::string > run (void) override
 Kicks off the Saddle Search.
std::shared_ptr< Matter > runFromMatter (std::shared_ptr< Matter > seed)
 In-process entry: seed reactant Matter, no pos.con.
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.

Private Member Functions

std::shared_ptr< Matter > runPrepared (const AtomMatrix &mode)
int doSaddleSearch ()
 Runs the correct saddle search; also checks if the run was successful.
void printEndState (int status)
 Logs the run status and makes sure the run was successful.
void saveData (int status)
 Writes the results from the run to file.

Private Attributes

std::vector< std::string > returnFiles
 Container for the results of the run.
std::unique_ptr< SaddleSearchMethod > saddleSearch
 Initializes a ref SaddleSearchMethod (base class for polymorphism).
std::shared_ptr< Matter > initial
 Initial configuration.
std::shared_ptr< Matter > saddle
 Configuration used during the saddle point search.
std::shared_ptr< Matter > displacement
 Configuration used during the saddle point search.
int fCallsSaddle
 Force calls to find the saddle.
eonc::log::Scoped log

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

Declaration of the Saddle Search job.

Definition at line 45 of file SaddleSearchJob.h.

Constructor & Destructor Documentation

◆ SaddleSearchJob()

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

Saddle Search job constructor.

Parameters
*paramsdefined by the config.init file

Definition at line 51 of file SaddleSearchJob.h.

52 : Job(std::move(parameters), rt),
53 fCallsSaddle{0} {}
Job(std::unique_ptr< Parameters > parameters, Runtime &rt)
Borrow: caller keeps Runtime alive (CLI stack / Python Session).
Definition Job.h:76
int fCallsSaddle
Force calls to find the saddle.

◆ ~SaddleSearchJob()

eonc::SaddleSearchJob::~SaddleSearchJob ( void )
default

Saddle Search Job Deconstructor.

Member Function Documentation

◆ doSaddleSearch()

int eonc::SaddleSearchJob::doSaddleSearch ( )
private

Runs the correct saddle search; also checks if the run was successful.

Definition at line 139 of file SaddleSearchJob.cpp.

139 {
140 long status;
141 int f1{0};
142 f1 = this->pot->forceCallCounter;
143 try {
144 status = saddleSearch->run();
145 } catch (int e) {
146 if (e == 100) {
148 } else {
149 QUILL_LOG_ERROR(log, "unknown exception: {}", e);
150 throw e;
151 }
152 } catch (const std::exception &e) {
153 QUILL_LOG_ERROR(log, "Saddle search potential failed: {}", e.what());
155 }
156
157 if (params.saddle_search_options().method == "min_mode" &&
158 params.saddle_search_options().minmode_method ==
160 fCallsSaddle = saddleSearch->getForceCalls();
161 } else if (params.saddle_search_options().method == "artn") {
162 fCallsSaddle = saddleSearch->getForceCalls();
163 } else {
164 fCallsSaddle += this->pot->forceCallCounter - f1;
165 }
166
167 return status;
168}
std::shared_ptr< Potential > pot
Definition Job.h:63
Parameters params
Definition Job.h:58
static const char MINMODE_GPRDIMER[]
std::unique_ptr< SaddleSearchMethod > saddleSearch
Initializes a ref SaddleSearchMethod (base class for polymorphism).
eonc::log::Scoped log

◆ printEndState()

void eonc::SaddleSearchJob::printEndState ( int status)
private

Logs the run status and makes sure the run was successful.

Definition at line 209 of file SaddleSearchJob.cpp.

209 {
210 auto msg = saddleSearch->describeStatus(status);
211 if (status == MinModeSaddleSearch::STATUS_GOOD) {
212 QUILL_LOG_DEBUG(log, "[Saddle Search] {}", msg);
213 } else {
214 QUILL_LOG_WARNING(log, "[Saddle Search] {}", msg);
215 }
216}

◆ run()

std::vector< std::string > eonc::SaddleSearchJob::run ( void )
overridevirtual

Kicks off the Saddle Search.

Implements eonc::Job.

Definition at line 29 of file SaddleSearchJob.cpp.

29 {
30 std::string reactantFilename = eonc::helpers::getRelevantFile("pos.con");
31 std::string displacementFilename("displacement.con");
32 std::string modeFilename("direction.dat");
33
34 if (params.main_options().checkpoint) {
35 if (std::filesystem::exists("displacement_cp.con") &&
36 std::filesystem::exists("mode_cp.dat")) {
37 displacementFilename = "displacement_cp.con";
38 modeFilename = "mode_cp.dat";
39 QUILL_LOG_DEBUG(log, "Resuming from checkpoint");
40 } else {
41 QUILL_LOG_DEBUG(log, "No checkpoint files found");
42 }
43 }
44
45 initial = std::make_shared<Matter>(pot, params);
46 displacement = std::make_shared<Matter>(pot, params);
47 saddle = std::make_shared<Matter>(pot, params);
48
49 if (!eonc::io::io_ok(initial->con2matter(reactantFilename))) {
50 EONC_LOG_CRITICAL("Failed to load {}", reactantFilename);
51 throw std::runtime_error("failed to load " + reactantFilename);
52 }
53
54 const bool standaloneARTn = params.saddle_search_options().method == "artn";
55
56 AtomMatrix mode = AtomMatrix::Zero(initial->numberOfAtoms(), 3);
57 if (!standaloneARTn && params.saddle_search_options().displace_type ==
59 // Load displacement.con, or synthesize from pos.con + direction.dat (#79).
61 *saddle, *initial, displacementFilename, modeFilename,
62 params.saddle_search_options().displace_magnitude)) {
63 EONC_LOG_CRITICAL("Failed to load {} (and no usable {})",
64 displacementFilename, modeFilename);
65 throw std::runtime_error("missing displacement.con and direction.dat");
66 }
67 if (std::filesystem::exists(modeFilename)) {
68 mode = eonc::helpers::loadMode(modeFilename, initial->numberOfAtoms());
69 }
70 } else if (!standaloneARTn && eonc::helpers::applyClientDisplacement(
71 *saddle, *initial, params, &mode)) {
72 // listed_atoms / random / last_atom / least_coordinated / not_fcc_hcp
73 } else {
74 *saddle = *initial;
75 }
76
77 if (standaloneARTn && std::filesystem::exists(modeFilename)) {
78 mode = eonc::helpers::loadMode(modeFilename, initial->numberOfAtoms());
79 }
80
81 (void)runPrepared(mode);
82 return returnFiles;
83}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
#define EONC_LOG_CRITICAL(...)
Definition EonLogger.h:267
std::vector< std::string > returnFiles
Container for the results of the run.
std::shared_ptr< Matter > saddle
Configuration used during the saddle point search.
std::shared_ptr< Matter > displacement
Configuration used during the saddle point search.
std::shared_ptr< Matter > initial
Initial configuration.
std::shared_ptr< Matter > runPrepared(const AtomMatrix &mode)
const char DISP_LOAD[]
Definition EpiCenters.h:20
bool applyClientDisplacement(Matter &target, const Matter &initial, const Parameters &params, AtomMatrix *modeOut)
std::string getRelevantFile(std::string filename)
bool loadOrSynthesizeDisplacement(Matter &target, const Matter &initial, const std::string &displacementPath, const std::string &modePath, double scale)
AtomMatrix loadMode(FILE *modeFile, int nAtoms)
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38

◆ runFromMatter()

std::shared_ptr< Matter > eonc::SaddleSearchJob::runFromMatter ( std::shared_ptr< Matter > seed)

In-process entry: seed reactant Matter, no pos.con.

Definition at line 86 of file SaddleSearchJob.cpp.

86 {
87 if (!seed) {
88 throw std::runtime_error("SaddleSearchJob::runFromMatter: null Matter");
89 }
90 initial = seed;
91 initial->setPotential(pot);
92 displacement = std::make_shared<Matter>(pot, params);
93 saddle = std::make_shared<Matter>(pot, params);
94 AtomMatrix mode = AtomMatrix::Zero(initial->numberOfAtoms(), 3);
96 &mode)) {
97 *saddle = *initial;
98 }
100 return runPrepared(mode);
101}

◆ runPrepared()

std::shared_ptr< Matter > eonc::SaddleSearchJob::runPrepared ( const AtomMatrix & mode)
private

Definition at line 103 of file SaddleSearchJob.cpp.

103 {
104 const bool useStandaloneARTn =
105 params.saddle_search_options().method == "artn";
106 const bool useARTnAsMinMode =
107 params.saddle_search_options().method == "min_mode" &&
108 params.saddle_search_options().minmode_method == "artn";
109
110#ifdef WITH_ARTN
111 if (useStandaloneARTn || useARTnAsMinMode) {
113 std::make_unique<ARTnSaddleSearch>(saddle, pot, mode, params);
114 } else
115#endif
116 {
117#ifndef WITH_ARTN
118 if (useStandaloneARTn) {
119 throw std::runtime_error(
120 "saddle_search.method=artn requires a build with ARTn support");
121 }
122 if (useARTnAsMinMode) {
123 throw std::runtime_error(
124 "saddle_search.minmode_method=artn requires a build with ARTn "
125 "support");
126 }
127#endif
128 saddleSearch = std::make_unique<MinModeSaddleSearch>(
129 saddle, mode, initial->getPotentialEnergy(), params, pot);
130 }
131
132 int status = doSaddleSearch();
133 printEndState(status);
134 saveData(status);
135
136 return saddle;
137}
int doSaddleSearch()
Runs the correct saddle search; also checks if the run was successful.
void saveData(int status)
Writes the results from the run to file.
void printEndState(int status)
Logs the run status and makes sure the run was successful.

◆ saveData()

void eonc::SaddleSearchJob::saveData ( int status)
private

Writes the results from the run to file.

Definition at line 170 of file SaddleSearchJob.cpp.

170 {
171 std::string resultsFilename("results.dat");
172 returnFiles.push_back(resultsFilename);
173
174 std::ofstream out(resultsFilename, std::ios::binary);
175 if (out) {
176 out << std::format("{} termination_reason\n", status);
177 out << std::format("{} termination_reason_text\n",
178 saddleSearch->describeStatus(status));
179 out << "saddle_search job_type\n";
180 out << std::format("{} random_seed\n", params.main_options().randomSeed);
181 out << std::format(
182 "{} potential_type\n",
183 magic_enum::enum_name<PotType>(params.potential_options().potential));
184 out << std::format("{} total_force_calls\n",
185 this->pot->forceCallCounter.load());
186 out << std::format("{} force_calls_saddle\n", fCallsSaddle);
187 out << std::format("{} iterations\n", saddleSearch->getIterationCount());
189 out << std::format("{:f} potential_energy_saddle\n",
190 saddle->getPotentialEnergy());
191 out << std::format("{:f} final_eigenvalue\n",
192 saddleSearch->getEigenvalue());
193 }
194 out << std::format("{:f} potential_energy_reactant\n",
195 initial->getPotentialEnergy());
196 }
197
198 std::string modeFilename("mode.dat");
199 returnFiles.push_back(modeFilename);
200 eonc::helpers::saveMode(modeFilename, saddle, saddleSearch->getEigenvector());
201
202 std::string saddleFilename("saddle.con");
203 returnFiles.push_back(saddleFilename);
204 if (!eonc::io::io_ok(saddle->matter2con(saddleFilename))) {
205 QUILL_LOG_ERROR(log, "Failed to write {}", saddleFilename);
206 }
207}
void saveMode(FILE *modeFile, std::shared_ptr< Matter > matter, AtomMatrix mode)
Write a mode; constrained axes are emitted as 0.

Member Data Documentation

◆ displacement

std::shared_ptr<Matter> eonc::SaddleSearchJob::displacement
private

Configuration used during the saddle point search.

Definition at line 80 of file SaddleSearchJob.h.

◆ fCallsSaddle

int eonc::SaddleSearchJob::fCallsSaddle
private

Force calls to find the saddle.

Definition at line 83 of file SaddleSearchJob.h.

◆ initial

std::shared_ptr<Matter> eonc::SaddleSearchJob::initial
private

Initial configuration.

Definition at line 76 of file SaddleSearchJob.h.

◆ log

eonc::log::Scoped eonc::SaddleSearchJob::log
private

Definition at line 85 of file SaddleSearchJob.h.

◆ returnFiles

std::vector<std::string> eonc::SaddleSearchJob::returnFiles
private

Container for the results of the run.

Definition at line 71 of file SaddleSearchJob.h.

◆ saddle

std::shared_ptr<Matter> eonc::SaddleSearchJob::saddle
private

Configuration used during the saddle point search.

Definition at line 78 of file SaddleSearchJob.h.

◆ saddleSearch

std::unique_ptr<SaddleSearchMethod> eonc::SaddleSearchJob::saddleSearch
private

Initializes a ref SaddleSearchMethod (base class for polymorphism).

Definition at line 74 of file SaddleSearchJob.h.


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