366 {
367 long effectiveMaxIter = max_iterations_override;
368 QUILL_LOG_DEBUG(
369 log,
"Saddle point search started from reactant with energy {} eV.",
371
372 int optStatus;
373 bool firstIteration = true;
374 const char *forceLabel =
375 params.optimizer_options().convergence_metric_label.c_str();
376
377 if (
params.saddle_search_options().minmode_method ==
379 QUILL_LOG_DEBUG(
380 log,
"================= Using the GP Dimer Library =================");
383 QUILL_LOG_DEBUG(
log,
"GPR eigenvalue: {}",
387 }
389 QUILL_LOG_DEBUG(
log,
"[MinModeSaddleSearch] eigenvalue not negative");
391 }
393 params.saddle_search_options().zero_mode_abort_curvature) {
394 QUILL_LOG_DEBUG(
log,
"Zero mode eigenvalue: {}",
397 }
400 } else {
401
402 if (
params.saddle_search_options().minmode_method ==
405 "[Dimer] {:9s} {:9s} {:10s} {:18s} {:9s} "
406 "{:7s} {:6s} {:4s} {:5s}\n",
407 "Step", "Step Size", "Delta E", forceLabel, "Curvature",
408 "Torque", "Angle", "Rots", "Align");
409 }
else if (
params.saddle_search_options().minmode_method ==
411 QUILL_LOG_INFO(
413 "[Lanczos] {:9s} {:9s} {:10s} {:18s} {:9s} {:10s} {:7s} {:5s}\n",
414 "Step", "Step Size", "Delta E", forceLabel, "Curvature", "Rel Change",
415 "Angle", "Iters");
416 }
else if (
params.saddle_search_options().minmode_method ==
419 "[GPRDimer] {:9s} {:9s} {:10s} {:18s} {:9s} "
420 " {:7s} {:6s} {:4s}\n",
421 "Step", "Step Size", "Delta E", forceLabel, "Curvature",
422 "Torque", "Angle", "Rots");
423 }
424
425 std::string climbLabel = "climb";
426 std::string climbDatFilename = "climb.dat";
427
429
430 auto objf = std::make_shared<MinModeObjectiveFunction>(
432 auto write_climb_frame = [&](uint64_t frameIndex, bool append,
433 double stepSize, double de, double conv,
434 double eigenval, double torque, double angle,
435 long rotations) {
436 eonc::io::ConFrameMetadata metadata;
439 metadata.
scalars.push_back({
"step_size", stepSize});
440 metadata.
scalars.push_back({
"delta_e", de});
441 metadata.
scalars.push_back({
"convergence", conv});
442 metadata.
scalars.push_back({
"eigenvalue", eigenval});
443 metadata.
scalars.push_back({
"torque", torque});
444 metadata.
scalars.push_back({
"angle", angle});
445 metadata.
scalars.push_back({
"rotations",
static_cast<double>(rotations)});
448 }
449 if (
params.debug_options().write_movies) {
451 matter->matter2con(climbLabel, append, &metadata))) {
452 QUILL_LOG_WARNING(
log,
"Failed to write climb movie frame {}",
453 climbLabel);
454 }
458 }
459
460 if (
params.debug_options().write_deprecated_outs) {
461 std::ofstream climbDat(climbDatFilename,
462 append ? (std::ios::binary | std::ios::app)
463 : std::ios::binary);
464 if (climbDat) {
465 if (!append) {
466 climbDat << "iteration\tstep_size\tdelta_e\tconvergence"
467 "\teigenvalue\ttorque\tangle\trotations\n";
468 }
469 climbDat << std::format("{}\t{:.7e}\t{:.6f}\t{:.5e}\t{:.6f}"
470 "\t{:.6f}\t{:.4f}\t{}\n",
471 frameIndex, stepSize, de, conv, eigenval,
472 torque, angle, rotations);
473 }
474 }
475 };
477 write_climb_frame(0, false, 0.0, 0.0, objf->getConvergence(),
479 0);
480 }
481 if (
params.saddle_search_options().nonnegative_displacement_abort) {
482 objf->getGradient();
484 QUILL_LOG_DEBUG(
log,
"Nonnegative eigenvalue: {}",
488 }
489 }
490
493
494
495
496 const double stockMove =
params.optimizer_options().max_move;
497 double translationCap = stockMove;
498 int wallStalls = 0;
499 int wallEvents = 0;
500 int reseeds = 0;
501 int probeForceCalls = 0;
502 auto probedEnergy = [&]() {
503 const long beforeCalls =
matter->getForceCalls();
504 const double energy = objf->getEnergy();
505 probeForceCalls +=
506 static_cast<int>(
matter->getForceCalls() - beforeCalls);
507 return energy;
508 };
509 auto pullUnderEnergy = [&](const VectorXd &before) -> bool {
510 const double limit =
params.saddle_search_options().max_energy;
511 const VectorXd after = objf->getPositions();
512 const VectorXd delta = objf->difference(after, before);
513 double alpha = 0.5;
514 bool found = false;
515 for (int probe = 0; probe < kMaxEnergyHalvings; ++probe) {
517 kMaxEnergyMotionFloor) {
518 break;
519 }
520 objf->setPositions(before + alpha * delta);
522 found = true;
523 break;
524 }
525 alpha *= 0.5;
526 }
527 auto freshMode = [&]() {
529 if (reseeds % 2 == 1) {
530 seed = -seed;
531 }
532 objf->reseedMode(seed);
533 ++reseeds;
534 };
535 if (found) {
536 wallStalls = 0;
537 ++wallEvents;
539 translationCap =
540 std::min(stockMove, std::max(accepted, kMaxEnergyStepFloor));
541 if (alpha < kMaxEnergyReseedAlpha) {
542 freshMode();
543 QUILL_LOG_DEBUG(
545 "[MinMode] energy above max_energy {:.4f}, shortened "
546 "the translation to {:.3e} and re-initialised the mode",
547 limit, accepted);
548 } else {
550 "[MinMode] energy above max_energy {:.4f}, shortened "
551 "the translation to {:.3e}",
552 limit, accepted);
553 }
554 if (wallEvents >= kMaxEnergyWallEvents) {
556 "[MinMode] {} crossings of max_energy {:.4f}, "
557 "ending the search",
558 wallEvents, limit);
559 return false;
560 }
561 return true;
562 }
563 objf->setPositions(before);
565 return false;
566 }
567 ++wallEvents;
568 ++wallStalls;
569 translationCap = std::min(
570 stockMove, std::max(translationCap * 0.5, kMaxEnergyStepFloor));
571 freshMode();
573 "[MinMode] translation stays above max_energy {:.4f}, "
574 "restored the centre and re-initialised the mode",
575 limit);
576 if (wallEvents >= kMaxEnergyWallEvents) {
578 "[MinMode] {} crossings of max_energy {:.4f}, "
579 "ending the search",
580 wallEvents, limit);
581 return false;
582 }
583 return wallStalls < kMaxEnergyStalls;
584 };
585
586 while (!objf->isConverged() ||
iteration == 0) {
587 matter->pollCancel(
"saddle");
588
589 if (!firstIteration) {
590
591 if (
params.saddle_search_options().nonlocal_count_abort != 0) {
593 initialPosition -
matter->getPositions(),
594 params.saddle_search_options().nonlocal_distance_abort);
595 if (nm >=
params.saddle_search_options().nonlocal_count_abort) {
597 break;
598 }
599 }
600
602 params.saddle_search_options().zero_mode_abort_curvature) {
603 QUILL_LOG_DEBUG(
log,
"Zero mode eigenvalue: {}",
606 break;
607 }
608 }
609 firstIteration = false;
610
613 break;
614 }
615
616 const VectorXd posBefore = objf->getPositions();
618
619 try {
620 if (
params.saddle_search_options().confine_positive.bowl_breakout &&
623 optStatus = optim->step(-translationCap);
624 } else {
625 optStatus = optim->step(translationCap);
626 }
627 } catch (const eonc::DimerModeRestoredException &) {
628 QUILL_LOG_DEBUG(
629 log,
"Dimer restored to best state. Checking convergence...");
631 break;
632 } catch (const eonc::DimerModeLostException &) {
633 QUILL_LOG_WARNING(
log,
"Dimer lost mode completely. Aborting.");
635 break;
636 }
637
638 if (optStatus < 0) {
640 break;
641 }
642
644 const double energyLimit =
params.saddle_search_options().max_energy;
645 if (de > energyLimit) {
646 const bool kept = pullUnderEnergy(posBefore);
647 if (kept) {
648 optim->onTranslationPulledBack();
649 }
652
653
655 break;
656 }
658 } else if (translationCap < stockMove) {
659 translationCap =
660 std::min(stockMove, translationCap * kMaxEnergyCapRegrowth);
661 wallStalls = 0;
662 }
663
664
665 if (
params.saddle_search_options().remove_rotation) {
667 }
668 double stepSize = (
matter->pbc(
matter->getPositions() - pos)).norm();
669
671
672
677 double conv = objf->getConvergence();
678
679 if (
params.saddle_search_options().minmode_method ==
681 QUILL_LOG_DEBUG(
683 "[Lanczos] {:9} {:9.6f} {:10.4f} {:18.5e} {:9.4f} {:10.6f} "
684 "{:7.3f} {:5}\n",
685 iteration, stepSize, de, conv, eigenval, torque, angle, rotations);
686 } else {
687 QUILL_LOG_DEBUG(
689 "[Dimer] {:9} {:9.7f} {:10.4f} {:18.5e} {:9.4f} {:7.3f} "
690 " {:6.3f} {:4}\n",
691 iteration, stepSize, de, conv, eigenval, torque, angle, rotations);
692 }
693
695 write_climb_frame(
static_cast<uint64_t
>(
iteration),
true, stepSize, de,
696 conv, eigenval, torque, angle, rotations);
697 }
698
699 if (
params.main_options().checkpoint) {
701 matter->matter2con(
"displacement_cp.con",
false))) {
702 QUILL_LOG_WARNING(
log,
"Failed to write displacement_cp.con");
703 }
706 }
707
709 QUILL_LOG_DEBUG(
log,
"[MinModeSaddleSearch] reached a known saddle");
711 break;
712 }
713
714
716 if (!dimer->rotationDidConverge) {
720 QUILL_LOG_DEBUG(
log,
"Dimer restored to valid state. C_tau={:.4f}",
721 dimer->getEigenvalue());
722 }
723 break;
724 }
725 }
726 }
727
728
729
733 }
734
735
736
737 const bool climbConverged = objf->isConverged();
738 const int statusBeforeGuard =
status;
741 QUILL_LOG_WARNING(
log,
"[MinModeSaddleSearch] objective not converged; "
742 "refusing STATUS_GOOD");
743 }
744
745 long refineForceCalls = 0;
746 if (
params.saddle_search_options().prfo_refine.enabled &&
750 refineForceCalls = refined.forceCalls;
751 if (!refined.restored) {
752
754 }
755 }
756
758 QUILL_LOG_DEBUG(
log,
"[MinModeSaddleSearch] eigenvalue not negative");
760 }
763 probeForceCalls + refineForceCalls);
764 }
765
767}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
static const char MINMODE_GPRDIMER[]
static const char MINMODE_DIMER[]
static const char MINMODE_LANCZOS[]
AtomMatrix getEigenvector()
bool atKnownSaddle() const
bool retain_climb_frames_
static constexpr int finalizeClimbStatus(int climbStatus, bool objectiveConverged) noexcept
Issue #20 policy: never leave climb as STATUS_GOOD when the climb objective is still unconverged (unf...
long numAtomsMoved(const AtomMatrix v1, double cutoff)
double maxAtomMotionV(const VectorXd v1)
void rotationRemove(const AtomMatrix r1, std::shared_ptr< Matter > m2)
std::unique_ptr< Optimizer > mkOptim(std::shared_ptr< ObjectiveFunction > a_objf, OptType a_otype, const Parameters &a_params)
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
void eigenmodeCompute(LowestEigenmode &s, std::shared_ptr< Matter > matter, AtomMatrix direction)
PrfoRefineResult prfoRefineSaddle(Matter &, const AtomMatrix &, double, const Parameters &)
Partitioned rational function optimization (P-RFO) of a first-order saddle in the rgsaddle Sella orde...
long eigenmodeTotalForceCalls(LowestEigenmode &s)
long eigenmodeStatsRotations(LowestEigenmode &s)
long eigenmodeTotalIterations(LowestEigenmode &s)
double eigenmodeStatsTorque(LowestEigenmode &s)
double eigenmodeStatsAngle(LowestEigenmode &s)