32 if (
params.saddle_search_options().method ==
"min_mode") {
36 std::string displacementFilename(
"displacement.con");
37 std::string modeFilename(
"direction.dat");
39 if (
params.main_options().checkpoint) {
40 if (std::filesystem::exists(
"displacement_cp.con") &&
41 std::filesystem::exists(
"mode_cp.dat")) {
42 displacementFilename =
"displacement_cp.con";
43 modeFilename =
"mode_cp.dat";
44 QUILL_LOG_DEBUG(
log,
"Resuming from checkpoint");
46 QUILL_LOG_DEBUG(
log,
"No checkpoint files found");
56 throw std::runtime_error(
"failed to load " + reactantFilename);
59 const bool standaloneARTn =
params.saddle_search_options().method ==
"artn";
62 if (!standaloneARTn &&
params.saddle_search_options().displace_type ==
67 params.saddle_search_options().displace_magnitude)) {
69 displacementFilename, modeFilename);
70 throw std::runtime_error(
"missing displacement.con and direction.dat");
72 if (std::filesystem::exists(modeFilename)) {
82 if (standaloneARTn && std::filesystem::exists(modeFilename)) {
90std::shared_ptr<Matter>
93 throw std::runtime_error(
"SaddleSearchJob::runFromMatter: null Matter");
109 const auto &ircOpts =
params.saddle_search_options().irc;
112 throw std::runtime_error(
"[Saddle Search] irc_after needs eOn built with "
113 "-Dwith_rgsaddle=true against rgsaddle C ABI "
114 "minor 14 or newer");
116 if (!(ircOpts.step_size > 0.0) || !(ircOpts.converged_force > 0.0) ||
117 ircOpts.max_steps < 1) {
118 throw std::invalid_argument(
"[Saddle Search] irc_step_size and "
119 "irc_converged_force must be positive and "
120 "irc_max_steps at least 1");
123 const bool useStandaloneARTn =
124 params.saddle_search_options().method ==
"artn";
125 const bool useARTnAsMinMode =
126 params.saddle_search_options().method ==
"min_mode" &&
127 params.saddle_search_options().minmode_method ==
"artn";
130 if (useStandaloneARTn || useARTnAsMinMode) {
137 if (useStandaloneARTn) {
138 throw std::runtime_error(
139 "saddle_search.method=artn requires a build with ARTn support");
141 if (useARTnAsMinMode) {
142 throw std::runtime_error(
143 "saddle_search.minmode_method=artn requires a build with ARTn "
157 QUILL_LOG_WARNING(
log,
158 "[Saddle Search] IRC skipped: lowest eigenvalue "
159 "{:f} is not negative",
171 const size_t potBefore = this->
pot->forceCallCounter;
178 QUILL_LOG_ERROR(
log,
"unknown exception: {}", e);
181 }
catch (
const std::exception &e) {
182 QUILL_LOG_ERROR(
log,
"Saddle search potential failed: {}", e.what());
186 if (
params.saddle_search_options().method ==
"min_mode" &&
187 params.saddle_search_options().minmode_method ==
190 }
else if (
params.saddle_search_options().method ==
"artn") {
202 std::string resultsFilename(
"results.dat");
205 std::ofstream out(resultsFilename, std::ios::binary);
207 out << std::format(
"{} termination_reason\n", status);
208 out << std::format(
"{} termination_reason_text\n",
210 out <<
"saddle_search job_type\n";
211 out << std::format(
"{} random_seed\n",
params.main_options().randomSeed);
213 "{} potential_type\n",
214 magic_enum::enum_name<PotType>(
params.potential_options().potential));
215 out << std::format(
"{} total_force_calls\n",
217 out << std::format(
"{} force_calls_saddle\n",
fCallsSaddle);
218 out << std::format(
"{} iterations\n",
saddleSearch->getIterationCount());
220 out << std::format(
"{:f} potential_energy_saddle\n",
221 saddle->getPotentialEnergy());
222 out << std::format(
"{:f} final_eigenvalue\n",
225 out << std::format(
"{:f} potential_energy_reactant\n",
226 initial->getPotentialEnergy());
228 out << std::format(
"{} irc_branches_at_minimum\n",
irc.branchesAtMinimum);
229 out << std::format(
"{} irc_ends_relaxed\n",
int{
irc.endsRelaxed});
230 out << std::format(
"{} irc_connects_reactant\n",
231 int{
irc.connectsReactant});
232 out << std::format(
"{} force_calls_irc\n",
irc.forceCalls);
233 out << std::format(
"{} force_calls_irc_minimization\n",
235 out << std::format(
"{:f} potential_energy_irc_min1\n",
irc.energies[0]);
236 out << std::format(
"{:f} potential_energy_irc_min2\n",
irc.energies[1]);
240 std::string modeFilename(
"mode.dat");
244 std::string saddleFilename(
"saddle.con");
247 QUILL_LOG_ERROR(
log,
"Failed to write {}", saddleFilename);
253 const size_t before =
pot->forceCallCounter;
257 }
catch (
const std::exception &e) {
258 irc.forceCalls =
pot->forceCallCounter - before;
259 QUILL_LOG_ERROR(
log,
"[Saddle Search] IRC failed: {}", e.what());
262 irc.forceCalls =
pot->forceCallCounter - before;
263 irc.branchesAtMinimum =
274 std::vector<Point> points;
279 const size_t saddleIndex = points.size();
281 const double saddleEnergy =
saddle->getPotentialEnergy();
282 points.push_back({&saddlePos, saddleEnergy,
saddle->maxForce()});
287 std::vector<double> arc(points.size(), 0.0);
288 for (
size_t i = 1; i < points.size(); ++i) {
290 arc[i - 1] +
saddle->pbc(*points[i].pos - *points[i - 1].pos).norm();
293 std::ofstream dat(
"irc.dat", std::ios::binary);
294 dat << std::format(
"{:>3s} {:>12s} {:>12s} {:>12s}\n",
"img",
"rxn_coord",
295 "energy",
"max_force");
296 for (
size_t i = 0; i < points.size(); ++i) {
299 meta.
energy = points[i].energy;
301 QUILL_LOG_ERROR(
log,
"Failed to write irc.con");
303 dat << std::format(
"{:>3} {:>12.6f} {:>12.6f} {:>12.6f}\n", i,
304 arc[i] - arc[saddleIndex],
305 points[i].energy - saddleEnergy, points[i].maxForce);
310 const size_t minBefore =
pot->forceCallCounter;
311 irc.endsRelaxed =
true;
313 for (
int k = 0; k < 2; ++k) {
315 if (!branches[k]->positions.empty()) {
318 irc.endsRelaxed = end.
relax(
true) &&
irc.endsRelaxed;
321 irc.connectsReactant =
irc.connectsReactant || reactant.compare(end);
322 const std::string name = std::format(
"irc_min{}.con", k + 1);
325 QUILL_LOG_ERROR(
log,
"Failed to write {}", name);
328 irc.forceCallsMin =
pot->forceCallCounter - minBefore;
330 "[Saddle Search] IRC: {} of 2 branches at a minimum, {} force "
331 "calls, {} more to relax the ends",
332 irc.branchesAtMinimum,
irc.forceCalls,
irc.forceCallsMin);
338 QUILL_LOG_DEBUG(
log,
"[Saddle Search] {}", msg);
340 QUILL_LOG_WARNING(
log,
"[Saddle Search] {}", msg);
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
#define EONC_LOG_CRITICAL(...)
Finds transition states by finding saddle points on the potential energy surface.
size_t potRegistryForceCalls() const noexcept
Force calls charged to pot's registry.
std::shared_ptr< Potential > pot
Set when one Potential is shared across Matters, images, or a caller.
static const char MINMODE_GPRDIMER[]
bool relax(bool quiet=false, bool writeMovie=false, bool checkpoint=false, std::string prefixMovie=std::string(), std::string prefixCheckpoint=std::string(), bool retainMovieFrames=false)
void setPositions(const AtomMatrix &pos)
double getPotentialEnergy() const
io::IoStatus matter2con(std::string filename, bool append=false, const io::ConFrameMetadata *metadata=nullptr)
@ STATUS_POTENTIAL_FAILED
std::unique_ptr< SaddleSearchMethod > saddleSearch
Initializes a ref SaddleSearchMethod (base class for polymorphism).
std::vector< std::string > returnFiles
Container for the results of the run.
std::shared_ptr< Matter > runFromMatter(std::shared_ptr< Matter > seed)
In-process entry: seed reactant Matter, no pos.con.
std::shared_ptr< Matter > saddle
Configuration used during the saddle point search.
std::vector< std::string > run(void) override
Kicks off the Saddle Search.
int doSaddleSearch()
Runs the correct saddle search; also checks if the run was successful.
int fCallsSaddle
Force calls to find the saddle.
struct eonc::SaddleSearchJob::IrcSummary irc
std::shared_ptr< Matter > displacement
Configuration used during the saddle point search.
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.
std::shared_ptr< Matter > initial
Initial configuration.
std::shared_ptr< Matter > runPrepared(const AtomMatrix &mode)
bool applyClientDisplacement(Matter &target, const Matter &initial, const Parameters ¶ms, 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)
void saveMode(FILE *modeFile, std::shared_ptr< Matter > matter, AtomMatrix mode)
Write a mode; constrained axes are emitted as 0.
constexpr bool io_ok(IoStatus s) noexcept
RAII resource manager for the ARTn C library with global synchronization.
IrcPath followIrc(const Matter &saddle, const AtomMatrix &mode, const Parameters ¶ms)
Follows the rgsaddle IRC from a converged saddle along both signs of its lowest mode.
bool ircAvailable()
True when this build can run followIrc: linked to rgsaddle at C ABI minor 14 or newer,...
void requirePrfoRefine(const Parameters ¶ms)
Does nothing unless [Saddle Search] prfo_refine is on.
Accepted points of one branch of the intrinsic reaction coordinate (IRC), in order away from the sadd...
std::vector< AtomMatrix > positions
std::vector< double > maxForces
std::vector< double > energies
Both branches of the IRC.