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

#include <BasinHoppingSaddleSearch.h>

Inheritance diagram for eonc::BasinHoppingSaddleSearch:

Public Member Functions

 BasinHoppingSaddleSearch (std::shared_ptr< Matter > reactant, std::shared_ptr< Matter > displacement, std::shared_ptr< Potential > potPassed, const Parameters &parametersPassed)
 ~BasinHoppingSaddleSearch ()=default
int run (void)
double getEigenvalue ()
AtomMatrix getEigenvector ()
std::string_view describeStatus (int code) const override
int getStatus () const override
Public Member Functions inherited from eonc::SaddleSearchMethod
 SaddleSearchMethod (std::shared_ptr< Potential > potPassed, const Parameters &paramsPassed)
virtual ~SaddleSearchMethod ()
virtual int getIterationCount () const
virtual int getForceCalls () const

Static Public Member Functions

static AtomMatrix initialDimerDirection (const Matter &image, const AtomMatrix &prev, const AtomMatrix &next)
static double metropolisProbability (double de, double kB, double temperature)
 Quenched Metropolis weight for energy change de.
static int highestEnergyInteriorImage (const std::vector< std::shared_ptr< Matter > > &path, long numImages)
 Highest-energy interior bead.

Public Attributes

double eigenvalue {0.0}
AtomMatrix eigenvector
std::shared_ptr< Matter > reactant
std::shared_ptr< Matter > saddle
std::shared_ptr< Matter > product
int status {0}

Private Attributes

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 22 of file BasinHoppingSaddleSearch.h.

Constructor & Destructor Documentation

◆ BasinHoppingSaddleSearch()

eonc::BasinHoppingSaddleSearch::BasinHoppingSaddleSearch ( std::shared_ptr< Matter > reactant,
std::shared_ptr< Matter > displacement,
std::shared_ptr< Potential > potPassed,
const Parameters & parametersPassed )
inline

Definition at line 24 of file BasinHoppingSaddleSearch.h.

28 : SaddleSearchMethod(potPassed, parametersPassed),
29 reactant{std::make_shared<Matter>(*reactant)}, saddle{displacement} {
30 eigenvector.resize(reactant->numberOfAtoms(), 3);
31 eigenvector.setZero();
32 }
SaddleSearchMethod(std::shared_ptr< Potential > potPassed, const Parameters &paramsPassed)

◆ ~BasinHoppingSaddleSearch()

eonc::BasinHoppingSaddleSearch::~BasinHoppingSaddleSearch ( )
default

Member Function Documentation

◆ describeStatus()

std::string_view eonc::BasinHoppingSaddleSearch::describeStatus ( int code) const
inlineoverridevirtual

Implements eonc::SaddleSearchMethod.

Definition at line 56 of file BasinHoppingSaddleSearch.h.

56 {
57 // Code 1 is the Metropolis rejection, not MinMode STATUS_INIT.
58 if (code == 1) {
59 return "Basin hop rejected";
60 }
62 }
static constexpr std::string_view statusMessage(int status)
Human-readable message for a status code.

◆ getEigenvalue()

double eonc::BasinHoppingSaddleSearch::getEigenvalue ( )
virtual

◆ getEigenvector()

AtomMatrix eonc::BasinHoppingSaddleSearch::getEigenvector ( )
virtual

Implements eonc::SaddleSearchMethod.

Definition at line 112 of file BasinHoppingSaddleSearch.cpp.

112{ return eigenvector; }

◆ getStatus()

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

Reimplemented from eonc::SaddleSearchMethod.

Definition at line 63 of file BasinHoppingSaddleSearch.h.

◆ highestEnergyInteriorImage()

int eonc::BasinHoppingSaddleSearch::highestEnergyInteriorImage ( const std::vector< std::shared_ptr< Matter > > & path,
long numImages )
staticnodiscard

Highest-energy interior bead.

Interiors are indices 1..numImages. Returns 0 when numImages < 1 so the caller does not read path[-1].

Definition at line 20 of file BasinHoppingSaddleSearch.cpp.

21 {
22 double emax = -1e100;
23 int highest = 0;
24 for (long i = 1; i <= numImages; i++) {
25 double etest = path[static_cast<size_t>(i)]->getPotentialEnergy();
26 QUILL_LOG_DEBUG(eonc::log::get(), "i: {} Etest: {:.1f}", i, etest);
27 if (etest > emax) {
28 emax = etest;
29 highest = static_cast<int>(i);
30 }
31 }
32 return highest;
33}
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:44

◆ initialDimerDirection()

AtomMatrix eonc::BasinHoppingSaddleSearch::initialDimerDirection ( const Matter & image,
const AtomMatrix & prev,
const AtomMatrix & next )
inlinestaticnodiscard

Definition at line 38 of file BasinHoppingSaddleSearch.h.

39 {
40 return image.pbc(next - prev) / 2.0;
41 }

◆ metropolisProbability()

double eonc::BasinHoppingSaddleSearch::metropolisProbability ( double de,
double kB,
double temperature )
static

Quenched Metropolis weight for energy change de.

Divides by kB * temperature only for an uphill hop when both are positive. Non-positive temperature or kB refuses that hop.

Definition at line 99 of file BasinHoppingSaddleSearch.cpp.

100 {
101 if (!(de > 0.0)) {
102 return 1.0;
103 }
104 if (!(temperature > 0.0) || !(kB > 0.0)) {
105 return 0.0;
106 }
107 return std::exp(-de / (kB * temperature));
108}

◆ run()

int eonc::BasinHoppingSaddleSearch::run ( void )
virtual

Implements eonc::SaddleSearchMethod.

Definition at line 35 of file BasinHoppingSaddleSearch.cpp.

35 {
36 // minimize "saddle"
37 saddle->relax(false, true, false, "displacementmin");
38 product = std::make_shared<Matter>(pot, params);
39 *product = *saddle;
40 // Metropolis on the quenched energies: exp(-de/(kB*T)).
41 // Divide only for an uphill hop at positive temperature. T <= 0 rejects
42 // that hop (zero-temperature limit) and must not trap or flip the sign.
43 double eproduct, ereactant, de;
44 eproduct = product->getPotentialEnergy();
45 ereactant = reactant->getPotentialEnergy();
46 de = eproduct - ereactant;
47 double kB = params.constants().kB;
48 double Temperature = params.main_options().temperature;
49 double p = metropolisProbability(de, kB, Temperature);
50 double r = eonc::rng::random();
51 if (de > 0.0 && r > p) { // reject
52 status = 1;
53 return status;
54 }
55 // NEB reactant to minimized "saddle"
56 NudgedElasticBand neb(reactant, product, params, pot);
57 if (!eonc::io::io_ok(
58 neb.path[0]->matter2con("neb_initial_band.con", false))) {
59 QUILL_LOG_WARNING(log, "Failed to write neb_initial_band.con");
60 }
61 // Reactant is frame 0. Interiors are 1..numImages, including the last.
62 for (int j = 1; j <= neb.numImages; j++) {
63 if (!eonc::io::io_ok(
64 neb.path[j]->matter2con("neb_initial_band.con", true))) {
65 QUILL_LOG_WARNING(log, "Failed to append neb_initial_band frame");
66 }
67 }
68 neb.compute();
69 // Interior images only. Endpoints are fixed, and a band with no interior
70 // image has no highest image; one image already has both neighbours.
71 if (neb.numImages < 1) {
72 QUILL_LOG_WARNING(log, "No interior NEB image for basin hopping");
74 return status;
75 }
76 int HighestImage = highestEnergyInteriorImage(neb.path, neb.numImages);
77 if (HighestImage < 1) {
78 QUILL_LOG_WARNING(log, "No interior NEB image for basin hopping");
80 return status;
81 }
82 // do dimer
83 // Calculate initial direction
84 AtomMatrix r_1 = neb.path[HighestImage - 1]->getPositions();
85 AtomMatrix r_3 = neb.path[HighestImage + 1]->getPositions();
86 AtomMatrix direction =
87 initialDimerDirection(*neb.path[HighestImage], r_1, r_3);
88 MinModeSaddleSearch dim(neb.path[HighestImage], direction.normalized(),
89 ereactant, params, pot);
90 // ProcessSearchJob treats STATUS_GOOD as a saddle. The climb's own
91 // status is that decision; discarding it records a failed climb as found.
92 status = dim.run();
93 *saddle = *neb.path[HighestImage];
94 eigenvalue = dim.getEigenvalue();
95 eigenvector = dim.getEigenvector();
96 return status;
97}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
static double metropolisProbability(double de, double kB, double temperature)
Quenched Metropolis weight for energy change de.
static AtomMatrix initialDimerDirection(const Matter &image, const AtomMatrix &prev, const AtomMatrix &next)
static int highestEnergyInteriorImage(const std::vector< std::shared_ptr< Matter > > &path, long numImages)
Highest-energy interior bead.
std::shared_ptr< Potential > pot
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
double random(long newSeed=0)

Member Data Documentation

◆ eigenvalue

double eonc::BasinHoppingSaddleSearch::eigenvalue {0.0}

Definition at line 65 of file BasinHoppingSaddleSearch.h.

65{0.0};

◆ eigenvector

AtomMatrix eonc::BasinHoppingSaddleSearch::eigenvector

Definition at line 66 of file BasinHoppingSaddleSearch.h.

◆ log

eonc::log::Scoped eonc::BasinHoppingSaddleSearch::log
private

Definition at line 75 of file BasinHoppingSaddleSearch.h.

◆ product

std::shared_ptr<Matter> eonc::BasinHoppingSaddleSearch::product

Definition at line 70 of file BasinHoppingSaddleSearch.h.

◆ reactant

std::shared_ptr<Matter> eonc::BasinHoppingSaddleSearch::reactant

Definition at line 68 of file BasinHoppingSaddleSearch.h.

◆ saddle

std::shared_ptr<Matter> eonc::BasinHoppingSaddleSearch::saddle

Definition at line 69 of file BasinHoppingSaddleSearch.h.

◆ status

int eonc::BasinHoppingSaddleSearch::status {0}

Definition at line 72 of file BasinHoppingSaddleSearch.h.

72{0};

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