Loading...
Searching...
No Matches
BasinHoppingSaddleSearch.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
15#include <cmath>
16#include <cstddef>
17
18namespace eonc {
19
21 const std::vector<std::shared_ptr<Matter>> &path, long numImages) {
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}
34
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"
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];
96 return status;
97}
98
100 double temperature) {
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}
109
111
113
114} // namespace eonc
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
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:44
double random(long newSeed=0)
RAII resource manager for the ARTn C library with global synchronization.