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
60 [[nodiscard]] bool solidState() const noexcept { return solidState_; }
61 [[nodiscard]] double solidJacobian() const noexcept { return solidJacobian_; }
62 [[nodiscard]] const Matrix3d &cellForce(long image) const {
63 return projectedCellForce.at(static_cast<size_t>(image));
64 }
65 void updateForces(bool ci_active);
67 void setCIEnabled(bool enabled) { ci_enabled_ = enabled; }
68 double convergenceForce(void);
69 void findExtrema(void);
70 void printImageData(bool writeToFile = false, size_t idx = 0);
71
74 [[nodiscard]] std::vector<readcon::ConFrame>
75 pathFrames(std::optional<size_t> bandIndex = std::nullopt);
76
77 std::vector<std::shared_ptr<EigenmodeStrategy>> eigenmode_solvers;
78
79 int atoms{0};
81 // Reactant energy at construction. Zoom moves path[0] to the start of its
82 // window, so reported energies are measured from this value instead.
83 double reactantEnergy{0.0};
84 std::vector<std::shared_ptr<Matter>> path; // NEB images
85 std::vector<std::shared_ptr<AtomMatrix>> tangent;
86 std::vector<std::shared_ptr<AtomMatrix>> projectedForce;
87 std::vector<double> extremumEnergy;
88 std::vector<double> extremumPosition;
89 std::vector<double> extremumCurvature;
90
91 std::size_t maxEnergyImage{0};
94 false};
95 double ksp{0.0};
96 double k_u{0.0}; // Upper-bound value for the spring constant
97 double k_l{0.0}; // Lower-bound value for the spring constant
98 double E_ref; // Reference energy chosen to be equal to the max energy of the
99 // reactant or product energy minimum
100
101private:
102 bool ci_enabled_{false}; // runtime CI state, set by compute()
103 double baseline_force{-1.0};
105 std::shared_ptr<Potential> pot;
108
109 // Cached strategies (constant across iterations)
112 bool solidState_{false};
113 double solidJacobian_{1.0};
114 std::vector<Matrix3d> projectedCellForce;
115 void prepareSolidState();
116 void projectSolidState(bool ci_active);
117};
118
120public:
122 const Parameters &parametersPassed)
123 : ObjectiveFunction(parametersPassed), neb{nebPassed} {}
124 // This is the odd one out, doesn't take a Matter so we null it
125
127
128 VectorXd getGradient(bool fdstep = false);
129 double getEnergy();
130 void setPositions(const VectorXd &x);
131 VectorXd getPositions();
132 int degreesOfFreedom();
133 bool isConverged();
134 bool isUncertain();
135 double getConvergence();
136 VectorXd difference(const VectorXd &a, const VectorXd &b);
137 // The band residual rotates with its tangent and is not a PES gradient.
138 bool supportsFiniteDifferenceCurvature() const override { return false; }
140
141private:
143};
144
145} // 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)
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
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_
std::vector< std::shared_ptr< AtomMatrix > > projectedForce
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:171