Loading...
Searching...
No Matches
RgSellaMin.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
5#ifndef GPR_NEB_RG_SELLA_MIN_H_
6#define GPR_NEB_RG_SELLA_MIN_H_
7
8#include <cstdint>
9#include <vector>
10
11#include "RgsaddleClient.h"
12
13namespace gpr {
14namespace neb {
15
19public:
20 RgSellaMin() = default;
22 {
23 release();
24 }
25 RgSellaMin(const RgSellaMin&) = delete;
26 RgSellaMin& operator=(const RgSellaMin&) = delete;
27
28 bool bind(RgsaddleClient& client, int64_t n_atoms, const double* position,
29 const double* masses, double force_tol, int32_t force_gate = 2)
30 {
31 if (!client.loaded() || n_atoms < 1 || position == nullptr ||
32 masses == nullptr) {
33 return false;
34 }
35 release();
36 if (force_gate < RGSADDLE_FORCE_L2 ||
37 force_gate > RGSADDLE_FORCE_MAX_ATOM) {
38 return false;
39 }
40 rgsaddle_sella_min_config_t cfg{};
41 cfg.version.major = RGSADDLE_ABI_MAJOR;
42 cfg.version.minor = 0;
43 cfg.delta = 0.1;
44 cfg.force_tol = force_tol > 0.0 ? force_tol : 1e-3;
45 cfg.force_gate = static_cast<rgsaddle_force_gate_t>(force_gate);
46 sess_ = client.sellaMinCreate(&cfg, n_atoms, position, masses);
47 if (sess_ == nullptr) return false;
48 client_ = &client;
49 n_atoms_ = n_atoms;
50 pos_.assign(static_cast<std::size_t>(3 * n_atoms), 0.0);
51 return true;
52 }
53
54 bool step(rgsaddle_surface_fn surface, void* user,
55 rgsaddle_report_t& report)
56 {
57 if (client_ == nullptr || sess_ == nullptr || surface == nullptr)
58 return false;
59 return client_->sellaMinStep(sess_, surface, user, &report) == 0;
60 }
61
62 bool position(double* out)
63 {
64 if (client_ == nullptr || sess_ == nullptr || out == nullptr)
65 return false;
66 return client_->sellaMinPosition(sess_, out) == 0;
67 }
68
69 [[nodiscard]] int64_t nAtoms() const noexcept
70 {
71 return n_atoms_;
72 }
73
74private:
75 void release()
76 {
77 if (client_ != nullptr && sess_ != nullptr)
78 client_->sellaMinFree(sess_);
79 sess_ = nullptr;
80 client_ = nullptr;
81 }
82
83 RgsaddleClient* client_ = nullptr;
84 RgsaddleClient::SellaMin sess_ = nullptr;
85 int64_t n_atoms_ = 0;
86 std::vector<double> pos_;
87};
88
89} // namespace neb
90} // namespace gpr
91
92#endif
bool bind(RgsaddleClient &client, int64_t n_atoms, const double *position, const double *masses, double force_tol, int32_t force_gate=2)
Definition RgSellaMin.h:28
RgSellaMin & operator=(const RgSellaMin &)=delete
bool position(double *out)
Definition RgSellaMin.h:62
int64_t nAtoms() const noexcept
Definition RgSellaMin.h:69
RgSellaMin(const RgSellaMin &)=delete
bool step(rgsaddle_surface_fn surface, void *user, rgsaddle_report_t &report)
Definition RgSellaMin.h:54
RgsaddleSellaMin * SellaMin
bool loaded() const noexcept
SellaMin sellaMinCreate(const rgsaddle_sella_min_config_t *cfg, int64_t n_atoms, const double *position, const double *masses)
void sellaMinFree(SellaMin sess)
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
eon_relax_band_t eon_relax_surface_fn surface
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.
Definition Macros.h:16