Loading...
Searching...
No Matches
RgMinMode.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_MIN_MODE_H_
6#define GPR_NEB_RG_MIN_MODE_H_
7
8#include <cstdint>
9
10#include "RgsaddleClient.h"
11
12namespace gpr {
13namespace neb {
14
17class RgMinMode {
18public:
19 enum class Kind { Dimer = 0, Lanczos = 1 };
20
23 static constexpr Kind kOciBurstKind = Kind::Dimer;
24
26 static Kind indexTestKind(const char* name)
27 {
28 if (name != nullptr && name[0] == 'd' && name[1] == 'i' &&
29 name[2] == 'm' && name[3] == 'e' && name[4] == 'r' &&
30 name[5] == '\0') {
31 return Kind::Dimer;
32 }
33 return Kind::Lanczos;
34 }
35
36 RgMinMode() = default;
38 {
39 release();
40 }
41 RgMinMode(const RgMinMode&) = delete;
42 RgMinMode& operator=(const RgMinMode&) = delete;
43
44 bool bind(RgsaddleClient& client, int64_t n_atoms, const double* position,
45 const double* mode, double force_tol, Kind kind = Kind::Dimer,
46 int32_t force_gate = 2, int32_t max_rotations = 16,
47 double rotation_tol = 1e-3)
48 {
49 if (!client.hasMinMode() || n_atoms < 1 || position == nullptr ||
50 mode == nullptr) {
51 return false;
52 }
53 release();
54 if (force_gate < RGSADDLE_FORCE_L2 ||
55 force_gate > RGSADDLE_FORCE_MAX_ATOM) {
56 return false;
57 }
58 rgsaddle_minmode_config_t cfg{};
59 cfg.version.major = RGSADDLE_ABI_MAJOR;
60 cfg.version.minor = 0;
61 cfg.kind = kind == Kind::Lanczos ? 1 : 0;
62 cfg.method = 0;
63 cfg.dr = 0.01;
64 cfg.rotation_tol = rotation_tol;
65 cfg.max_rotations = max_rotations;
66 cfg.krylov_dim = 8;
67 cfg.force_tol = force_tol > 0.0 ? force_tol : 1e-3;
68 cfg.max_move = 0.1;
69 sess_ = client.minModeCreate(&cfg, n_atoms, position, mode);
70 if (sess_ == nullptr) return false;
71 if (client.minModeSetForceGate(
72 sess_, static_cast<rgsaddle_force_gate_t>(force_gate)) !=
73 RGSADDLE_OK) {
74 client.minModeFree(sess_);
75 sess_ = nullptr;
76 return false;
77 }
78 client_ = &client;
79 n_atoms_ = n_atoms;
80 return true;
81 }
82
83 bool step(rgsaddle_surface_fn surface, void* user,
84 rgsaddle_report_t& report)
85 {
86 if (client_ == nullptr || sess_ == nullptr || surface == nullptr)
87 return false;
88 return client_->minModeStep(sess_, surface, user, &report) == 0;
89 }
90
91 bool position(double* out)
92 {
93 if (client_ == nullptr || sess_ == nullptr || out == nullptr)
94 return false;
95 return client_->minModePosition(sess_, out) == 0;
96 }
97
98 [[nodiscard]] int64_t nAtoms() const noexcept
99 {
100 return n_atoms_;
101 }
102
103private:
104 void release()
105 {
106 if (client_ != nullptr && sess_ != nullptr) client_->minModeFree(sess_);
107 sess_ = nullptr;
108 client_ = nullptr;
109 }
110
111 RgsaddleClient* client_ = nullptr;
112 RgsaddleClient::MinMode sess_ = nullptr;
113 int64_t n_atoms_ = 0;
114};
115
116} // namespace neb
117} // namespace gpr
118
119#endif
bool step(rgsaddle_surface_fn surface, void *user, rgsaddle_report_t &report)
Definition RgMinMode.h:83
static Kind indexTestKind(const char *name)
gprn --index-test token. Unrecognised names are Lanczos.
Definition RgMinMode.h:26
RgMinMode & operator=(const RgMinMode &)=delete
bool bind(RgsaddleClient &client, int64_t n_atoms, const double *position, const double *mode, double force_tol, Kind kind=Kind::Dimer, int32_t force_gate=2, int32_t max_rotations=16, double rotation_tol=1e-3)
Definition RgMinMode.h:44
RgMinMode(const RgMinMode &)=delete
int64_t nAtoms() const noexcept
Definition RgMinMode.h:98
static constexpr Kind kOciBurstKind
Definition RgMinMode.h:23
bool position(double *out)
Definition RgMinMode.h:91
RgsaddleMinMode * MinMode
bool hasMinMode() const noexcept
int minModeSetForceGate(MinMode sess, rgsaddle_force_gate_t gate)
MinMode minModeCreate(const rgsaddle_minmode_config_t *cfg, int64_t n_atoms, const double *position, const double *mode)
void minModeFree(MinMode 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