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

#include <MinModeSaddleSearch.h>

Inheritance diagram for eonc::MinModeSaddleSearch:

Public Types

enum  Status : int {
  STATUS_GOOD , STATUS_INIT , STATUS_BAD_NO_CONVEX , STATUS_BAD_HIGH_ENERGY ,
  STATUS_BAD_MAX_CONCAVE_ITERATIONS , STATUS_BAD_MAX_ITERATIONS , STATUS_BAD_NOT_CONNECTED , STATUS_BAD_PREFACTOR ,
  STATUS_BAD_HIGH_BARRIER , STATUS_BAD_MINIMA , STATUS_FAILED_PREFACTOR , STATUS_POTENTIAL_FAILED ,
  STATUS_NONNEGATIVE_ABORT , STATUS_NONLOCAL_ABORT , STATUS_NEGATIVE_BARRIER , STATUS_BAD_MD_TRAJECTORY_TOO_SHORT ,
  STATUS_BAD_NO_NEGATIVE_MODE_AT_SADDLE , STATUS_BAD_NO_BARRIER , STATUS_ZEROMODE_ABORT , STATUS_OPTIMIZER_ERROR ,
  STATUS_DIMER_LOST_MODE , STATUS_DIMER_RESTORED_BEST , STATUS_KNOWN_SADDLE = 23
}

Public Member Functions

 MinModeSaddleSearch (std::shared_ptr< Matter > matterPassed, AtomMatrix modePassed, double reactantEnergyPassed, const Parameters &parametersPassed, std::shared_ptr< Potential > potPassed)
 ~MinModeSaddleSearch ()=default
 MinModeSaddleSearch (const MinModeSaddleSearch &)=delete
MinModeSaddleSearch & operator= (const MinModeSaddleSearch &)=delete
 MinModeSaddleSearch (MinModeSaddleSearch &&) noexcept=default
MinModeSaddleSearch & operator= (MinModeSaddleSearch &&) noexcept=default
AtomMatrix getEigenvector ()
double getEigenvalue ()
std::string_view describeStatus (int status) const override
int getStatus () const override
int getIterationCount () const override
int getForceCalls () const override
int run () override
int run (long max_iterations_override)
int runRetainFrames (long max_iterations_override=-1)
 Like run(), but also retain climb ConFrames in memory (same stamps as write_movies climb CON).
const std::vector< readcon::ConFrame > & climbFrames () const
void clearClimbFrames ()
void setKnownSaddles (std::vector< AtomMatrix > positions, std::vector< double > energies)
 Saddles the server already holds for this state (positions, energies).
std::vector< readcon::ConFrame > takeClimbFrames ()
Public Member Functions inherited from eonc::SaddleSearchMethod
 SaddleSearchMethod (std::shared_ptr< Potential > potPassed, const Parameters &paramsPassed)
virtual ~SaddleSearchMethod ()

Static Public Member Functions

static constexpr std::string_view statusMessage (int status)
 Human-readable message for a status code.
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 (unfeasible systems must not look like success).

Public Attributes

int forcecalls {0}
int iteration {0}
int status {0}

Private Member Functions

bool atKnownSaddle () const

Private Attributes

std::vector< readcon::ConFrame > climb_frames_
bool retain_climb_frames_ {false}
AtomMatrix mode
AtomMatrix initialTangent_
std::shared_ptr< Matter > matter
std::shared_ptr< EigenmodeStrategy > minModeMethod
double reactantEnergy
std::vector< AtomMatrix > knownSaddlePositions_
std::vector< double > knownSaddleEnergies_
eonc::log::Scoped log

Additional Inherited Members

Protected Attributes inherited from eonc::SaddleSearchMethod
std::shared_ptr< Potential > pot
const Parameters & params

Detailed Description

Definition at line 26 of file MinModeSaddleSearch.h.

Member Enumeration Documentation

◆ Status

Enumerator
STATUS_GOOD 
STATUS_INIT 
STATUS_BAD_NO_CONVEX 
STATUS_BAD_HIGH_ENERGY 
STATUS_BAD_MAX_CONCAVE_ITERATIONS 
STATUS_BAD_MAX_ITERATIONS 
STATUS_BAD_NOT_CONNECTED 
STATUS_BAD_PREFACTOR 
STATUS_BAD_HIGH_BARRIER 
STATUS_BAD_MINIMA 
STATUS_FAILED_PREFACTOR 
STATUS_POTENTIAL_FAILED 
STATUS_NONNEGATIVE_ABORT 
STATUS_NONLOCAL_ABORT 
STATUS_NEGATIVE_BARRIER 
STATUS_BAD_MD_TRAJECTORY_TOO_SHORT 
STATUS_BAD_NO_NEGATIVE_MODE_AT_SADDLE 
STATUS_BAD_NO_BARRIER 
STATUS_ZEROMODE_ABORT 
STATUS_OPTIMIZER_ERROR 
STATUS_DIMER_LOST_MODE 
STATUS_DIMER_RESTORED_BEST 
STATUS_KNOWN_SADDLE 

Definition at line 29 of file MinModeSaddleSearch.h.

29 : int {
30 // DO NOT CHANGE THE ORDER OF THIS LIST
31 STATUS_GOOD, // 0
32 STATUS_INIT, // 1
53 // 22 is ARTnSaddleSearch::STATUS_BAD_ARTN_ERROR
55 };

Constructor & Destructor Documentation

◆ MinModeSaddleSearch() [1/3]

eonc::MinModeSaddleSearch::MinModeSaddleSearch ( std::shared_ptr< Matter > matterPassed,
AtomMatrix modePassed,
double reactantEnergyPassed,
const Parameters & parametersPassed,
std::shared_ptr< Potential > potPassed )

Definition at line 325 of file MinModeSaddleSearch.cpp.

330 : SaddleSearchMethod(potPassed, parametersPassed),
331 matter{matterPassed} {
333 params.optimizer_options().convergence_metric, "[MinModeSaddleSearch]");
335 reactantEnergy = reactantEnergyPassed;
336 mode = modePassed;
337 initialTangent_ = modePassed;
339 iteration = 0;
340
342
343 // Set reference mode for ImprovedDimer (prevents mode switching)
344 if (auto *dimer = eonc::asImprovedDimer(*minModeMethod)) {
345 VectorXd refVec = VectorXd::Map(mode.data(), 3 * matter->numberOfAtoms());
346 refVec = refVec.array() * matter->getFreeV().array();
347 dimer->setReferenceMode(refVec);
348 }
349}
std::shared_ptr< Matter > matter
std::shared_ptr< EigenmodeStrategy > minModeMethod
std::shared_ptr< Potential > pot
SaddleSearchMethod(std::shared_ptr< Potential > potPassed, const Parameters &paramsPassed)
void requireKnownConvergenceMetric(std::string_view metric, std::string_view context)
Throws std::invalid_argument naming context when metric is unrecognized.
std::shared_ptr< LowestEigenmode > buildEigenmodeStrategy(std::shared_ptr< Matter > matter, const Parameters &params, std::shared_ptr< Potential > pot)
ImprovedDimer * asImprovedDimer(LowestEigenmode &s)
void requirePrfoRefine(const Parameters &params)
Does nothing unless [Saddle Search] prfo_refine is on.

◆ ~MinModeSaddleSearch()

eonc::MinModeSaddleSearch::~MinModeSaddleSearch ( )
default

◆ MinModeSaddleSearch() [2/3]

eonc::MinModeSaddleSearch::MinModeSaddleSearch ( const MinModeSaddleSearch & )
delete

◆ MinModeSaddleSearch() [3/3]

eonc::MinModeSaddleSearch::MinModeSaddleSearch ( MinModeSaddleSearch && )
defaultnoexcept

Member Function Documentation

◆ atKnownSaddle()

bool eonc::MinModeSaddleSearch::atKnownSaddle ( ) const
nodiscardprivate

Definition at line 779 of file MinModeSaddleSearch.cpp.

779 {
780 if (knownSaddleEnergies_.empty() ||
782 return false;
783 }
784 const double energy = matter->getPotentialEnergy();
785 const double eps = params.structure_comparison_options().energy_difference;
786 for (size_t k = 0; k < knownSaddleEnergies_.size(); ++k) {
787 if (std::abs(energy - knownSaddleEnergies_[k]) > eps) {
788 continue;
789 }
790 Matter known(*matter);
791 known.setPositions(knownSaddlePositions_[k]);
792 if (known.compare(*matter)) {
793 return true;
794 }
795 }
796 return false;
797}
std::vector< double > knownSaddleEnergies_
std::vector< AtomMatrix > knownSaddlePositions_
constexpr double eps
Definition SafeMath.h:19
double eigenmodeGetEigenvalue(LowestEigenmode &s)

◆ clearClimbFrames()

void eonc::MinModeSaddleSearch::clearClimbFrames ( )
inline

Definition at line 134 of file MinModeSaddleSearch.h.

134{ climb_frames_.clear(); }
std::vector< readcon::ConFrame > climb_frames_

◆ climbFrames()

const std::vector< readcon::ConFrame > & eonc::MinModeSaddleSearch::climbFrames ( ) const
inlinenodiscard

Definition at line 131 of file MinModeSaddleSearch.h.

131 {
132 return climb_frames_;
133 }

◆ describeStatus()

std::string_view eonc::MinModeSaddleSearch::describeStatus ( int status) const
inlineoverridevirtual

Implements eonc::SaddleSearchMethod.

Definition at line 114 of file MinModeSaddleSearch.h.

114 {
115 return statusMessage(status);
116 }
static constexpr std::string_view statusMessage(int status)
Human-readable message for a status code.

◆ finalizeClimbStatus()

constexpr int eonc::MinModeSaddleSearch::finalizeClimbStatus ( int climbStatus,
bool objectiveConverged )
inlinestaticnodiscardconstexprnoexcept

Issue #20 policy: never leave climb as STATUS_GOOD when the climb objective is still unconverged (unfeasible systems must not look like success).

Used by run(); unit-tested so deleting this rule fails CI.

Definition at line 95 of file MinModeSaddleSearch.h.

95 {
96 if (climbStatus == STATUS_GOOD && !objectiveConverged) {
98 }
99 return climbStatus;
100 }

◆ getEigenvalue()

double eonc::MinModeSaddleSearch::getEigenvalue ( )
virtual

Implements eonc::SaddleSearchMethod.

Definition at line 799 of file MinModeSaddleSearch.cpp.

799 {
801}

◆ getEigenvector()

AtomMatrix eonc::MinModeSaddleSearch::getEigenvector ( )
virtual

Implements eonc::SaddleSearchMethod.

Definition at line 803 of file MinModeSaddleSearch.cpp.

803 {
805}
AtomMatrix eigenmodeGetEigenvector(LowestEigenmode &s)

◆ getForceCalls()

int eonc::MinModeSaddleSearch::getForceCalls ( ) const
inlineoverridevirtual

Reimplemented from eonc::SaddleSearchMethod.

Definition at line 119 of file MinModeSaddleSearch.h.

◆ getIterationCount()

int eonc::MinModeSaddleSearch::getIterationCount ( ) const
inlineoverridevirtual

Reimplemented from eonc::SaddleSearchMethod.

Definition at line 118 of file MinModeSaddleSearch.h.

118{ return iteration; }

◆ getStatus()

int eonc::MinModeSaddleSearch::getStatus ( ) const
inlineoverridevirtual

Reimplemented from eonc::SaddleSearchMethod.

Definition at line 117 of file MinModeSaddleSearch.h.

117{ return status; }

◆ operator=() [1/2]

MinModeSaddleSearch & eonc::MinModeSaddleSearch::operator= ( const MinModeSaddleSearch & )
delete

◆ operator=() [2/2]

MinModeSaddleSearch & eonc::MinModeSaddleSearch::operator= ( MinModeSaddleSearch && )
defaultnoexcept

◆ run() [1/2]

int eonc::MinModeSaddleSearch::run ( void )
overridevirtual

Implements eonc::SaddleSearchMethod.

Definition at line 351 of file MinModeSaddleSearch.cpp.

351 {
352 return run(params.saddle_search_options().max_iterations);
353}

◆ run() [2/2]

int eonc::MinModeSaddleSearch::run ( long max_iterations_override)

Definition at line 366 of file MinModeSaddleSearch.cpp.

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: {}",
386 return status;
387 }
388 if (getEigenvalue() > 0.0 && status == STATUS_GOOD) {
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 ==
404 QUILL_LOG_INFO(log,
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(
412 log,
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 ==
418 QUILL_LOG_INFO(log,
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
428 AtomMatrix initialPosition = matter->getPositions();
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;
437 metadata.frame_index = frameIndex;
438 metadata.energy = matter->getPotentialEnergy();
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)});
447 climb_frames_.push_back(eonc::io::matterToConFrame(*matter, &metadata));
448 }
449 if (params.debug_options().write_movies) {
450 if (!eonc::io::io_ok(
451 matter->matter2con(climbLabel, append, &metadata))) {
452 QUILL_LOG_WARNING(log, "Failed to write climb movie frame {}",
453 climbLabel);
454 }
455 eonc::helpers::saveMode(std::format("mode_{:03}.dat", frameIndex),
456 matter,
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 };
476 if (params.debug_options().write_movies || retain_climb_frames_) {
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: {}",
487 return status;
488 }
489 }
490
492 objf, params.optimizer_options().method, params);
493
494 // Stock max_move stays the cap until a translation crosses max_energy.
495 // A search that never crosses it takes the same steps as before.
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) {
516 if (eonc::geometry::maxAtomMotionV(alpha * delta) <
517 kMaxEnergyMotionFloor) {
518 break;
519 }
520 objf->setPositions(before + alpha * delta);
521 if (probedEnergy() - reactantEnergy <= limit) {
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;
538 const double accepted = eonc::geometry::maxAtomMotionV(alpha * delta);
539 translationCap =
540 std::min(stockMove, std::max(accepted, kMaxEnergyStepFloor));
541 if (alpha < kMaxEnergyReseedAlpha) {
542 freshMode();
543 QUILL_LOG_DEBUG(
544 log,
545 "[MinMode] energy above max_energy {:.4f}, shortened "
546 "the translation to {:.3e} and re-initialised the mode",
547 limit, accepted);
548 } else {
549 QUILL_LOG_DEBUG(log,
550 "[MinMode] energy above max_energy {:.4f}, shortened "
551 "the translation to {:.3e}",
552 limit, accepted);
553 }
554 if (wallEvents >= kMaxEnergyWallEvents) {
555 QUILL_LOG_DEBUG(log,
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);
564 if (probedEnergy() - reactantEnergy > limit) {
565 return false;
566 }
567 ++wallEvents;
568 ++wallStalls;
569 translationCap = std::min(
570 stockMove, std::max(translationCap * 0.5, kMaxEnergyStepFloor));
571 freshMode();
572 QUILL_LOG_DEBUG(log,
573 "[MinMode] translation stays above max_energy {:.4f}, "
574 "restored the centre and re-initialised the mode",
575 limit);
576 if (wallEvents >= kMaxEnergyWallEvents) {
577 QUILL_LOG_DEBUG(log,
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
611 if (iteration >= effectiveMaxIter) {
613 break;
614 }
615
616 const VectorXd posBefore = objf->getPositions();
617 AtomMatrix pos = matter->getPositions();
618
619 try {
620 if (params.saddle_search_options().confine_positive.bowl_breakout &&
622 params.optimizer_options().method == OptType::CG) {
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...");
630 status = objf->isConverged() ? STATUS_GOOD : STATUS_DIMER_RESTORED_BEST;
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
643 double de = objf->getEnergy() - reactantEnergy;
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 }
650 if (!kept || objf->getEnergy() - reactantEnergy > energyLimit) {
652 // Count the attempt so a first-step abort does not fall through
653 // to the iteration == 0 mode estimate below.
654 ++iteration;
655 break;
656 }
657 de = objf->getEnergy() - reactantEnergy;
658 } else if (translationCap < stockMove) {
659 translationCap =
660 std::min(stockMove, translationCap * kMaxEnergyCapRegrowth);
661 wallStalls = 0;
662 }
663
664 // Melander, Laasonen, Jonsson, JCTC 11(3), 1055-1062, 2015
665 if (params.saddle_search_options().remove_rotation) {
667 }
668 double stepSize = (matter->pbc(matter->getPositions() - pos)).norm();
669
670 iteration++;
671
672 // Logging
677 double conv = objf->getConvergence();
678
679 if (params.saddle_search_options().minmode_method ==
681 QUILL_LOG_DEBUG(
682 log,
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(
688 log,
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
694 if (params.debug_options().write_movies || retain_climb_frames_) {
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) {
700 if (!eonc::io::io_ok(
701 matter->matter2con("displacement_cp.con", false))) {
702 QUILL_LOG_WARNING(log, "Failed to write displacement_cp.con");
703 }
704 eonc::helpers::saveMode("mode_cp.dat", matter,
706 }
707
708 if (atKnownSaddle()) {
709 QUILL_LOG_DEBUG(log, "[MinModeSaddleSearch] reached a known saddle");
711 break;
712 }
713
714 // Check ImprovedDimer mode convergence
715 if (auto *dimer = eonc::asImprovedDimer(*minModeMethod)) {
716 if (!dimer->rotationDidConverge) {
717 status = (dimer->getEigenvalue() < 0.0) ? STATUS_DIMER_RESTORED_BEST
720 QUILL_LOG_DEBUG(log, "Dimer restored to valid state. C_tau={:.4f}",
721 dimer->getEigenvalue());
722 }
723 break;
724 }
725 }
726 }
727
728 // A rejected or restored mode already carries the curvature needed by
729 // the caller; solving it again would discard that handoff state.
730 if (iteration == 0 && status != STATUS_DIMER_LOST_MODE &&
733 }
734
735 // Never report STATUS_GOOD when the climb objective is unconverged
736 // (issue #20: unfeasible systems must not look like success).
737 const bool climbConverged = objf->isConverged();
738 const int statusBeforeGuard = status;
739 status = finalizeClimbStatus(status, climbConverged);
740 if (statusBeforeGuard == STATUS_GOOD && status != STATUS_GOOD) {
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 &&
747 status == STATUS_GOOD && getEigenvalue() < 0.0) {
748 const auto refined = eonc::prfoRefineSaddle(*matter, getEigenvector(),
750 refineForceCalls = refined.forceCalls;
751 if (!refined.restored) {
752 // The mode at the refined point, for mode.dat and the sign test.
754 }
755 }
756
757 if (getEigenvalue() > 0.0 && status == STATUS_GOOD) {
758 QUILL_LOG_DEBUG(log, "[MinModeSaddleSearch] eigenvalue not negative");
760 }
761 forcecalls =
763 probeForceCalls + refineForceCalls);
764 }
765
766 return status;
767}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
static const char MINMODE_GPRDIMER[]
static const char MINMODE_DIMER[]
static const char MINMODE_LANCZOS[]
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)
Definition Optimizer.cpp:55
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
Definition ConFileIO.h:38
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)
std::optional< uint64_t > frame_index
Definition ConFileIO.h:72
std::vector< ConMetadataValue > scalars
Definition ConFileIO.h:79
std::optional< double > energy
Definition ConFileIO.h:73

◆ runRetainFrames()

int eonc::MinModeSaddleSearch::runRetainFrames ( long max_iterations_override = -1)

Like run(), but also retain climb ConFrames in memory (same stamps as write_movies climb CON).

Does not require write_movies on disk.

Definition at line 355 of file MinModeSaddleSearch.cpp.

355 {
357 climb_frames_.clear();
358 const long maxIter = max_iterations_override < 0
359 ? params.saddle_search_options().max_iterations
360 : max_iterations_override;
361 const int st = run(maxIter);
362 retain_climb_frames_ = false;
363 return st;
364}

◆ setKnownSaddles()

void eonc::MinModeSaddleSearch::setKnownSaddles ( std::vector< AtomMatrix > positions,
std::vector< double > energies )

Saddles the server already holds for this state (positions, energies).

A climb point with negative curvature that matches one under the structure comparison ends the search with STATUS_KNOWN_SADDLE.

Definition at line 769 of file MinModeSaddleSearch.cpp.

770 {
771 if (positions.size() != energies.size()) {
772 throw std::invalid_argument(
773 "MinModeSaddleSearch::setKnownSaddles: size mismatch");
774 }
775 knownSaddlePositions_ = std::move(positions);
776 knownSaddleEnergies_ = std::move(energies);
777}

◆ statusMessage()

constexpr std::string_view eonc::MinModeSaddleSearch::statusMessage ( int status)
inlinestaticconstexpr

Human-readable message for a status code.

Definition at line 58 of file MinModeSaddleSearch.h.

58 {
59 constexpr std::string_view msgs[] = {
60 "Success", // 0
61 "Initialized", // 1
62 "Initial displacement unable to reach convex region", // 2
63 "Barrier too high", // 3
64 "Too many iterations in concave region", // 4
65 "Too many iterations", // 5
66 "Saddle is not connected to initial state", // 6
67 "Prefactors not within window", // 7
68 "Energy barrier not within window", // 8
69 "Minimizations from saddle did not converge", // 9
70 "Hessian calculation failed", // 10
71 "Potential evaluation failed", // 11
72 "Nonnegative initial mode, aborting", // 12
73 "Nonlocal abort", // 13
74 "Negative barrier detected", // 14
75 "No reaction found during MD trajectory", // 15
76 "Converged to stationary point with zero negative modes", // 16
77 "No forward barrier found along minimized band", // 17
78 "Zero mode abort", // 18
79 "Optimizer error", // 19
80 "Dimer lost mode", // 20
81 "Dimer restored best", // 21
82 };
84 return "Climb reached a known saddle";
85 if (status >= 0 &&
86 status < static_cast<int>(sizeof(msgs) / sizeof(msgs[0])))
87 return msgs[status];
88 return "Unknown status";
89 }

◆ takeClimbFrames()

std::vector< readcon::ConFrame > eonc::MinModeSaddleSearch::takeClimbFrames ( )
inlinenodiscard

Definition at line 141 of file MinModeSaddleSearch.h.

141 {
142 return std::move(climb_frames_);
143 }

Member Data Documentation

◆ climb_frames_

std::vector<readcon::ConFrame> eonc::MinModeSaddleSearch::climb_frames_
private

Definition at line 146 of file MinModeSaddleSearch.h.

◆ forcecalls

int eonc::MinModeSaddleSearch::forcecalls {0}

Definition at line 127 of file MinModeSaddleSearch.h.

127{0};

◆ initialTangent_

AtomMatrix eonc::MinModeSaddleSearch::initialTangent_
private

Definition at line 149 of file MinModeSaddleSearch.h.

◆ iteration

int eonc::MinModeSaddleSearch::iteration {0}

Definition at line 128 of file MinModeSaddleSearch.h.

128{0};

◆ knownSaddleEnergies_

std::vector<double> eonc::MinModeSaddleSearch::knownSaddleEnergies_
private

Definition at line 155 of file MinModeSaddleSearch.h.

◆ knownSaddlePositions_

std::vector<AtomMatrix> eonc::MinModeSaddleSearch::knownSaddlePositions_
private

Definition at line 154 of file MinModeSaddleSearch.h.

◆ log

eonc::log::Scoped eonc::MinModeSaddleSearch::log
private

Definition at line 157 of file MinModeSaddleSearch.h.

◆ matter

std::shared_ptr<Matter> eonc::MinModeSaddleSearch::matter
private

Definition at line 150 of file MinModeSaddleSearch.h.

◆ minModeMethod

std::shared_ptr<EigenmodeStrategy> eonc::MinModeSaddleSearch::minModeMethod
private

Definition at line 152 of file MinModeSaddleSearch.h.

◆ mode

AtomMatrix eonc::MinModeSaddleSearch::mode
private

Definition at line 148 of file MinModeSaddleSearch.h.

◆ reactantEnergy

double eonc::MinModeSaddleSearch::reactantEnergy
private

Definition at line 153 of file MinModeSaddleSearch.h.

◆ retain_climb_frames_

bool eonc::MinModeSaddleSearch::retain_climb_frames_ {false}
private

Definition at line 147 of file MinModeSaddleSearch.h.

147{false};

◆ status

int eonc::MinModeSaddleSearch::status {0}

Definition at line 129 of file MinModeSaddleSearch.h.

129{0};

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