45void loadKnownSaddles(
const std::string &path,
const Matter &reference,
47 std::ifstream in(path);
51 long count = 0, nFree = 0;
52 if (!(in >> count >> nFree) || count < 0 ||
54 throw std::runtime_error(path +
": header does not match pos.con");
56 std::vector<long> freeIndex;
59 freeIndex.push_back(i);
62 std::vector<AtomMatrix> positions;
63 std::vector<double> energies;
64 positions.reserve(
static_cast<size_t>(count));
65 energies.reserve(
static_cast<size_t>(count));
66 for (
long k = 0; k < count; ++k) {
69 bool ok =
static_cast<bool>(in >> energy);
70 for (
long j = 0; ok && j < nFree; ++j) {
71 const long i = freeIndex[
static_cast<size_t>(j)];
72 ok =
static_cast<bool>(in >> pos(i, 0) >> pos(i, 1) >> pos(i, 2));
75 throw std::runtime_error(path +
": truncated saddle record");
77 energies.push_back(energy);
78 positions.push_back(std::move(pos));
86 if (
params.saddle_search_options().method ==
"min_mode") {
90 std::string displacementFilename(
"displacement.con");
91 std::string modeFilename(
"direction.dat");
94 if (
params.saddle_search_options().method ==
"min_mode" ||
95 params.saddle_search_options().method ==
"basin_hopping" ||
96 params.saddle_search_options().method ==
"bgsd") {
98 }
else if (
params.saddle_search_options().method ==
"dynamics") {
103 std::shared_ptr<Potential> min2Pot =
pot;
104 if (
pot->needsPerImageInstance() &&
params.main_options().parallel) {
108 min2 = std::make_shared<Matter>(min2Pot,
params);
112 throw std::runtime_error(
"failed to load " + reactantFilename);
115 if (
params.process_search_options().minimize_first) {
116 QUILL_LOG_DEBUG(
log,
"Minimizing initial structure\n");
117 fctmp =
initial->getPotentialCalls();
120 QUILL_LOG_DEBUG(
log,
"Initial minimization took {} fcalls",
121 initial->getPotentialCalls() - fctmp);
128 if (
params.saddle_search_options().method ==
"min_mode" ||
129 params.saddle_search_options().method ==
"basin_hopping" ||
130 params.saddle_search_options().method ==
"bgsd") {
131 if (
params.saddle_search_options().displace_type ==
137 params.saddle_search_options().displace_magnitude)) {
139 displacementFilename, modeFilename);
140 throw std::runtime_error(
"failed to load " + displacementFilename);
156 min2->setPotential(min2Pot);
158 const bool useARTnAsMinMode =
159 params.saddle_search_options().method ==
"min_mode" &&
160 params.saddle_search_options().minmode_method ==
"artn";
162 if (
params.saddle_search_options().method ==
"min_mode") {
163 if (
params.saddle_search_options().displace_type ==
165 std::filesystem::exists(modeFilename)) {
171 if (useARTnAsMinMode) {
177 auto minMode = std::make_unique<MinModeSaddleSearch>(
179 if (
params.process_search_options().known_saddles) {
180 loadKnownSaddles(
"known_saddles.dat", *
initial, *minMode);
185 }
else if (
params.saddle_search_options().method ==
"artn") {
189 if (
params.saddle_search_options().displace_type ==
191 std::filesystem::exists(modeFilename)) {
198 }
else if (
params.saddle_search_options().method ==
"basin_hopping") {
201 }
else if (
params.saddle_search_options().method ==
"dynamics") {
203 }
else if (
params.saddle_search_options().method ==
"bgsd") {
204 saddleSearch = std::make_unique<BiasedGradientSquaredDescent>(
213 if (
params.saddle_search_options().method ==
"artn") {
214 throw std::runtime_error(
215 "saddle_search.method=artn requires a build with ARTn support "
216 "(reconfigure with -Dwith_artn=true)");
218 if (useARTnAsMinMode) {
219 throw std::runtime_error(
220 "saddle_search.minmode_method=artn requires a build with ARTn "
221 "support (reconfigure with -Dwith_artn=true)");
226 throw std::runtime_error(
"unknown saddle_search.method");
233std::shared_ptr<Matter>
236 throw std::runtime_error(
"ProcessSearchJob::runFromMatter: null Matter");
240 std::shared_ptr<Potential> min2Pot =
pot;
241 if (
pot->needsPerImageInstance() &&
params.main_options().parallel) {
247 min2 = std::make_shared<Matter>(min2Pot,
params);
255 min2->setPotential(min2Pot);
256 if (
params.saddle_search_options().method ==
"min_mode") {
259 }
else if (
params.saddle_search_options().method ==
"basin_hopping") {
262 }
else if (
params.saddle_search_options().method ==
"dynamics") {
264 }
else if (
params.saddle_search_options().method ==
"bgsd") {
265 saddleSearch = std::make_unique<BiasedGradientSquaredDescent>(
268 throw std::runtime_error(
269 "ProcessSearchJob::runFromMatter: unsupported saddle_search.method");
276 throw std::runtime_error(
"unknown saddle_search.method");
294 if (
params.saddle_search_options().method ==
"min_mode" &&
295 params.saddle_search_options().minmode_method ==
298 }
else if (
params.saddle_search_options().method ==
"artn") {
303 EONC_LOG_DEBUG(
"Got {} calls in the saddle search, with previous {}",
315 const auto min1Pot =
min1->getPotential();
316 const auto min2Pot =
min2->getPotential();
318 min1->setPotential(min1Pot);
322 params.process_search_options().minimization_offset;
323 min1->setPositions(displacedPos);
326 min2->setPotential(min2Pot);
329 params.process_search_options().minimization_offset;
330 min2->setPositions(displacedPos);
335 QUILL_LOG_DEBUG(
log,
"Starting Minimization 1 & 2");
336 bool converged1{
false}, converged2{
false};
337 long fc1_before =
min1->getPotentialCalls();
338 long fc2_before =
min2->getPotentialCalls();
343 (
pot->needsPerImageInstance() &&
344 min1->getPotential().get() !=
min2->getPotential().get());
345 if (
params.main_options().parallel && canParallel) {
349 std::exception_ptr t1Error;
352 converged1 =
min1->relax(
false,
params.debug_options().write_movies,
355 t1Error = std::current_exception();
359 converged2 =
min2->relax(
false,
params.debug_options().write_movies,
367 std::rethrow_exception(t1Error);
370 min1->relax(
false,
params.debug_options().write_movies,
false,
"min1");
372 min2->relax(
false,
params.debug_options().write_movies,
false,
"min2");
375 if (
min1->getPotential().get() ==
min2->getPotential().get()) {
379 (
min2->getPotentialCalls() - fc2_before);
381 QUILL_LOG_DEBUG(
log,
"Min1: {} fcalls, Min2: {} fcalls",
382 min1->getPotentialCalls() - fc1_before,
383 min2->getPotentialCalls() - fc2_before);
385 if (!converged1 || !converged2) {
406 params.structure_comparison_options().distance_difference;
407 auto countMoved = [&](
const Matter &m) {
409 for (
long i = 0; i <
initial->numberOfAtoms(); ++i) {
411 ->
pbc(
initial->getPositions().row(i) - m.getPositions().row(i))
419 "initial != min1: {} of {} atoms past the {} A tolerance "
420 "for min1 ({} for min2); largest separation {} A",
427 QUILL_LOG_DEBUG(
log,
"both minima are the initial state");
431 if (!
params.process_search_options().minimize_first) {
447 if (!
params.prefactor_options().default_value) {
456 if (prefStatus == -1) {
461 if ((pref1 >
params.prefactor_options().max_value) ||
462 (pref1 <
params.prefactor_options().min_value)) {
466 if ((pref2 >
params.prefactor_options().max_value) ||
467 (pref2 <
params.prefactor_options().min_value)) {
482 std::string resultsFilename(
"results.dat");
485 const bool dynamics =
params.saddle_search_options().method ==
"dynamics";
486 double simTime = 0.0;
490 simTime = ds.
time *
params.constants().timeUnit;
491 mdTemp =
params.saddle_search_options().dynamics.temperature;
493 const double disp =
params.saddle_search_options().method ==
"min_mode"
497 status, std::string(
saddleSearch->describeStatus(status)),
498 params.potential_options().potential,
params.main_options().randomSeed,
502 dynamics, simTime, mdTemp);
507 env.writeResultsDat(resultsFilename);
509 std::string reactantFilename(
"reactant.con");
512 QUILL_LOG_ERROR(
log,
"Failed to write {}", reactantFilename);
515 std::string modeFilename(
"mode.dat");
519 std::string saddleFilename(
"saddle.con");
522 QUILL_LOG_ERROR(
log,
"Failed to write {}", saddleFilename);
525 std::string productFilename(
"product.con");
528 QUILL_LOG_ERROR(
log,
"Failed to write {}", productFilename);
535 QUILL_LOG_DEBUG(
log,
"[Saddle Search] {}", msg);
537 QUILL_LOG_ERROR(
log,
"[Saddle Search] {}", msg);
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
#define EONC_LOG_DEBUG(...)
#define EONC_LOG_ERROR(...)
#define EONC_LOG_CRITICAL(...)
The optimizer class is used to serve as an abstract class for all optimizers, as well as to call an o...
Finds possible escape mecahnisms from a state.
const AtomMatrix & getPositions() const
long int numberOfAtoms() const
long int numberOfFreeAtoms() const
int getFixed(long int atom) const
1 if every Cartesian axis of the atom is fixed, else 0.
void setKnownSaddles(std::vector< AtomMatrix > positions, std::vector< double > energies)
Saddles the server already holds for this state (positions, energies).
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 compare(const Matter &matter, bool indistinguishable=false)
@ STATUS_NEGATIVE_BARRIER
@ STATUS_FAILED_PREFACTOR
@ STATUS_BAD_NOT_CONNECTED
@ STATUS_BAD_HIGH_BARRIER
std::shared_ptr< Matter > displacement
Configuration used during the saddle point search.
size_t fCallsPrefactors
Force calls to find the prefactors.
size_t fCallsMin
Force calls to minimize.
std::shared_ptr< Matter > min1
First minimum from the saddle.
std::vector< std::string > returnFiles
Container for the results of the run.
double prefactorsValues[2]
void printEndState(int status)
Logs the run status and makes sure the run was successful.
std::shared_ptr< Matter > min2
Second minimum from the saddle.
std::shared_ptr< Matter > saddle
Configuration used during the saddle point search.
std::vector< std::string > run(void) override
Kicks off the Process Search.
std::shared_ptr< Matter > initial
Initial configuration.
std::unique_ptr< SaddleSearchMethod > saddleSearch
Pulled from parameters.
size_t fCallsSaddle
Force calls to find the saddle.
void saveData(int status)
Writes the results from the run to file.
std::shared_ptr< Matter > runFromMatter(std::shared_ptr< Matter > seed)
In-process entry: seed reactant Matter, no pos.con.
std::shared_ptr< Matter > runPrepared()
int doProcessSearch(void)
Runs the correct saddle search; also checks if the run was successful.
int getPrefactors(const Parameters ¶meters, Matter *min1, Matter *saddle, Matter *min2, double &pref1, double &pref2)
bool applyClientDisplacement(Matter &target, const Matter &initial, const Parameters ¶ms, AtomMatrix *modeOut)
std::string getRelevantFile(std::string filename)
std::shared_ptr< Potential > makeImagePotential(const Potential &pot, const Parameters ¶ms)
A separate instance of pot for one image of a band, dimer or pair of minimizations: a clone when the ...
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.
readcon::ConFrame matterToConFrame(Matter &m, const ConFrameMetadata *metadata)
Build a single stamped ConFrame from Matter (same builder as matter2con).
constexpr bool io_ok(IoStatus s) noexcept
RAII resource manager for the ARTn C library with global synchronization.
bool potAllowsSharedInstance(const P &p) noexcept
JobResultProvenance provenanceForJob(const Parameters ¶ms)
Optimizer backend, engine identity, rgpot pin, and xts ABI from a job.
void requirePrfoRefine(const Parameters ¶ms)
Does nothing unless [Saddle Search] prfo_refine is on.
static JobResultEnvelope fromProcessSearch(int status, std::string statusText, PotType pot, std::int64_t seed, std::uint64_t fMin, std::uint64_t fSaddle, std::uint64_t fPref, double eSaddle, double eReactant, double eProduct, double barrierFwd, double barrierRev, double displacement, double prefFwd, double prefRev, bool dynamics, double simTime, double mdTemp)