Loading...
Searching...
No Matches
NudgedElasticBand.h
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*/
12#pragma once
13
14#include <filesystem>
15
16#include "Eigen.h"
17#include "EonLogger.h"
18
19#include "EigenmodeStrategy.h"
20#include "HelperFunctions.h"
21#include "Matter.h"
22#include "NEBProjection.h"
23#include "NEBTangent.h"
24#include "ObjectiveFunction.h"
25#include "Parameters.h"
26
27#include <optional>
28#include <readcon-core.hpp>
29#include <vector>
30
31namespace eonc::neb {
33}
34
35namespace eonc {
36
37// NEB method for determining a minimum energy path between two matter objects
40
41public:
49 NudgedElasticBand(std::shared_ptr<Matter> initialPassed,
50 std::shared_ptr<Matter> finalPassed,
51 const Parameters &parametersPassed,
52 std::shared_ptr<Potential> potPassed);
53 NudgedElasticBand(std::vector<Matter> initPath,
54 const Parameters &parametersPassed,
55 std::shared_ptr<Potential> potPassed);
56 ~NudgedElasticBand() = default;
57
61 [[nodiscard]] long lastIteration() const noexcept { return iteration_; }
62 [[nodiscard]] bool solidState() const noexcept { return solidState_; }
63 [[nodiscard]] double solidJacobian() const noexcept { return solidJacobian_; }
64 [[nodiscard]] const Matrix3d &cellForce(long image) const {
65 return projectedCellForce.at(static_cast<size_t>(image));
66 }
67 // An explicit projection does not change the runtime CI flag.
68 void updateForces(bool ci_active);
70 void setCIEnabled(bool enabled) {
71 if (ci_enabled_ != enabled) {
72 ci_enabled_ = enabled;
73 // CI changes the projection while physical force caches remain valid.
75 }
76 }
77 double convergenceForce(void);
83 void adoptSessionProjection(long ciIndex);
84 void findExtrema(void);
85 void printImageData(bool writeToFile = false, size_t idx = 0);
86
89 [[nodiscard]] std::vector<readcon::ConFrame>
90 pathFrames(std::optional<size_t> bandIndex = std::nullopt);
91
92 std::vector<std::shared_ptr<EigenmodeStrategy>> eigenmode_solvers;
93
97 [[nodiscard]] long imageOwner(std::size_t i) const noexcept {
98 const auto idx = static_cast<long>(i);
99 if (idx == 0)
100 return numImages;
101 return idx == numImages + 1 ? numImages + 1 : idx - 1;
102 }
103
104 int atoms{0};
106 // Reactant energy at construction. Zoom moves path[0] to the start of its
107 // window, so reported energies are measured from this value instead.
108 double reactantEnergy{0.0};
109 std::vector<std::shared_ptr<Matter>> path; // NEB images
110 std::vector<std::shared_ptr<AtomMatrix>> tangent;
111 std::vector<std::shared_ptr<AtomMatrix>> projectedForce;
112 std::vector<double> extremumEnergy;
113 std::vector<double> extremumPosition;
114 std::vector<double> extremumCurvature;
115
116 std::size_t maxEnergyImage{0};
117 // Geometry or runtime CI state differs from the cached band projection.
120 false};
121 double ksp{0.0};
122 double k_u{0.0}; // Upper-bound value for the spring constant
123 double k_l{0.0}; // Lower-bound value for the spring constant
124 double E_ref; // Reference energy chosen to be equal to the max energy of the
125 // reactant or product energy minimum
126
127private:
128 bool ci_enabled_{false}; // runtime CI state, set by compute()
129 double baseline_force{-1.0};
131 std::shared_ptr<Potential> pot;
133 long iteration_{0};
135
136 // Cached strategies (constant across iterations)
139 bool solidState_{false};
140 double solidJacobian_{1.0};
141 std::vector<Matrix3d> projectedCellForce;
142 void prepareSolidState();
143 void projectSolidState(bool ci_active);
144};
145
147public:
149 const Parameters &parametersPassed)
150 : ObjectiveFunction(parametersPassed), neb{nebPassed} {}
151 // This is the odd one out, doesn't take a Matter so we null it
152
154
155 VectorXd getGradient(bool fdstep = false);
156 double getEnergy();
157 void setPositions(const VectorXd &x);
158 VectorXd getPositions();
159 int degreesOfFreedom();
160 bool isConverged();
161 bool isUncertain();
162 double getConvergence();
163 VectorXd difference(const VectorXd &a, const VectorXd &b);
164 // One mass per free atom on each interior image, in band order.
165 VectorXd getMasses() const override;
166 // The band residual rotates with its tangent and is not a PES gradient.
167 bool supportsFiniteDifferenceCurvature() const override { return false; }
168 // getEnergy() sums the image energies; the springs are not in it and the
169 // climbing image moves up it.
170 bool gradientMatchesEnergy() const override { return false; }
171 bool reuseDisplacementCurvature() const override { return true; }
173
174private:
176};
177
178} // namespace eonc
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Definition Eigen.h:35
VectorXd getGradient(bool fdstep=false)
NudgedElasticBand::NEBStatus status
bool supportsFiniteDifferenceCurvature() const override
VectorXd difference(const VectorXd &a, const VectorXd &b)
bool gradientMatchesEnergy() const override
bool reuseDisplacementCurvature() const override
VectorXd getMasses() const override
NEBObjectiveFunction(NudgedElasticBand *nebPassed, const Parameters &parametersPassed)
void setPositions(const VectorXd &x)
NudgedElasticBand::NEBStatus compute(void)
NudgedElasticBand(std::shared_ptr< Matter > initialPassed, std::shared_ptr< Matter > finalPassed, const Parameters &parametersPassed, std::shared_ptr< Potential > potPassed)
std::vector< double > extremumEnergy
std::vector< std::shared_ptr< AtomMatrix > > tangent
void printImageData(bool writeToFile=false, size_t idx=0)
std::vector< std::shared_ptr< Matter > > path
bool perImagePotentials_
Whether per-image potential instances exist.
double solidJacobian() const noexcept
long lastIteration() const noexcept
Iteration count from the last compute(). Zero before compute() runs.
std::vector< double > extremumPosition
std::vector< std::shared_ptr< EigenmodeStrategy > > eigenmode_solvers
void projectSolidState(bool ci_active)
std::vector< readcon::ConFrame > pathFrames(std::optional< size_t > bandIndex=std::nullopt)
In-memory ConFrames with the same NEB stamps as writePathCon / neb.con.
const Matrix3d & cellForce(long image) const
neb::TangentStrategy tangentStrat_
void adoptSessionProjection(long ciIndex)
Host bookkeeping for a band whose projected force came from the rgsaddle session: the highest interio...
std::vector< std::shared_ptr< AtomMatrix > > projectedForce
long imageOwner(std::size_t i) const noexcept
The identity band image i carries in a batch (forceBatchOwned): interior image i is i - 1,...
void setCIEnabled(bool enabled)
std::shared_ptr< Potential > pot
NudgedElasticBand::NEBStatus getStatus()
neb::ProjectionStrategy projectionStrat_
std::vector< double > extremumCurvature
bool solidState() const noexcept
std::vector< Matrix3d > projectedCellForce
ObjectiveFunction(const Parameters &paramsPassed)
std::variant< PlainEB, NEB_Projection, DNEB_Projection > ProjectionStrategy
std::variant< SimpleTangent, ImprovedTangent > TangentStrategy
Definition NEBTangent.h:38
RAII resource manager for the ARTn C library with global synchronization.
RAII helper for class-scoped logging.
Definition EonLogger.h:238