5#ifndef GPR_NEB_RG_EON_NEB_ENGINE_H_
6#define GPR_NEB_RG_EON_NEB_ENGINE_H_
24class RgEonNebEngine final :
public BandRelaxationEngine {
26 RgEonNebEngine() =
default;
27 ~RgEonNebEngine()
override =
default;
29 RgEonNebEngine(
const RgEonNebEngine&) =
delete;
30 RgEonNebEngine& operator=(
const RgEonNebEngine&) =
delete;
35 bool bind(EonRelaxClient& client, eon_relax_band_t
band,
56 if (client_ !=
nullptr) client_->reset();
59 bool step(GlobalLBFGSObjective& objective,
double max_move,
60 std::optional<double> = std::nullopt)
override
62 if (client_ ==
nullptr || surface_ ==
nullptr)
return false;
63 const Eigen::VectorXd before = objective.
positions();
64 if (before.size() != interior_dof_)
return false;
65 packInteriors(before);
66 eon_relax_outcome_t
out{};
67 const int rc = client_->step(band_, surface_, user_,
out);
69 Eigen::VectorXd after = unpackInteriors();
70 if (!after.allFinite() || after.size() != before.size()) {
71 packInteriors(before);
76 const Eigen::VectorXd limited =
77 clipAtomMaxmove(before, after, max_move);
78 if ((limited - after).cwiseAbs().maxCoeff() > 0.0) {
83 const Eigen::VectorXd next =
84 objective.stepPositions(before, after - before);
85 if (!next.allFinite() || next.size() != before.size()) {
86 packInteriors(before);
91 if ((next - after).cwiseAbs().maxCoeff() > 0.0) {
94 objective.setPositions(next);
95 if (!objective.refresh(
false)) {
96 packInteriors(before);
97 objective.setPositions(before);
102 last_status_ =
out.status;
103 last_max_force_ =
out.max_force;
107 void rebuildSketchedH0(
108 const std::function<Eigen::VectorXd(
const Eigen::VectorXd&)>&,
112 void setCurvatureExclusion(Eigen::Index, Eigen::Index)
noexcept override { }
113 [[nodiscard]]
int iteration()
const override
117 [[nodiscard]]
int historySize()
const override
121 [[nodiscard]]
double lastCurvatureDot()
const override
125 [[nodiscard]]
double lastCurvatureScale()
const override
129 [[nodiscard]]
int lastStatus() const noexcept
133 [[nodiscard]]
double lastMaxForce() const noexcept
135 return last_max_force_;
139 void packInteriors(
const Eigen::VectorXd& interiors)
141 const Eigen::Index stride = 3 * band_.
n_atoms;
142 Eigen::Map<Eigen::VectorXd>(band_.positions + stride, interior_dof_) =
146 [[nodiscard]] Eigen::VectorXd unpackInteriors()
const
148 const Eigen::Index stride = 3 * band_.n_atoms;
149 return Eigen::Map<const Eigen::VectorXd>(band_.positions + stride,
156 [[nodiscard]] Eigen::VectorXd clipAtomMaxmove(
const Eigen::VectorXd& before,
157 const Eigen::VectorXd& after,
158 double max_move)
const
160 Eigen::VectorXd clipped = after;
161 const Eigen::Index n_atoms = band_.n_atoms;
162 if (n_atoms <= 0 || max_move <= 0.0)
return clipped;
163 const Eigen::Index n_images = interior_dof_ / (3 * n_atoms);
164 for (Eigen::Index im = 0; im < n_images; ++im) {
165 for (Eigen::Index a = 0; a < n_atoms; ++a) {
166 const Eigen::Index off = (im * n_atoms + a) * 3;
167 const Eigen::Vector3d d =
168 after.segment<3>(off) - before.segment<3>(off);
169 const double n = d.norm();
171 clipped.segment<3>(off) =
172 before.segment<3>(off) + d * (max_move / n);
178 EonRelaxClient* client_ =
nullptr;
179 eon_relax_band_t band_{};
181 void* user_ =
nullptr;
182 Eigen::Index interior_dof_ = 0;
184 int last_status_ = 0;
185 double last_max_force_ = 0.0;
GP-accelerated NEB: AIE and OIE variants.
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
eon_relax_band_t eon_relax_surface_fn surface
int(* eon_relax_surface_fn)(void *user, eon_relax_surface_request_t *req)
eon_relax_band_t eon_relax_surface_fn void * user
The nudged elastic band: path, GP-NEB driver, configuration and result, acquisition,...
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
const int32_t * atomic_nrs