Loading...
Searching...
No Matches
IRCDriver.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/*
6 * IRCDriver.h -- mass-weighted Intrinsic Reaction Coordinate driver.
7 *
8 * The step is rgsaddle's IRC session: rgsaddle_irc_create, rgsaddle_irc_step,
9 * rgsaddle_irc_set_direction and rgsaddle_irc_set_lengths, through
10 * gpr::neb::RgsaddleClient. Both IRCMethod values select
11 * RGSADDLE_IRC_MOROKUMA. MorokumaExtended sets RGSADDLE_IRC_ADAPTIVE so the
12 * library grows or halves the corrector length. The kick length is
13 * initial_displacement and is not the corrector length. A library without
14 * rgsaddle_irc_set_lengths throws. There is no local stepper.
15 *
16 * The saddle Hessian is read only to choose the imaginary mode passed as
17 * rgsaddle's launch direction. hessian_sketch_rank > 0 ignores that matrix
18 * and launches with rgsaddle_irc_create_from_surface (Lanczos on the
19 * gradient). The path sample stored for each step is that step's first
20 * surface evaluation. The kick sample is the geometry after the launch
21 * displacement; a small force there is still the saddle neighborhood,
22 * and the branch does not stop on it. A later step that is already
23 * inside conv_tol comes back from the library without moving, and that
24 * sample ends the branch. When the library then accepts a different
25 * geometry whose mass-weighted force is inside conv_tol, that geometry
26 * is stored too and the branch stops. A converged library status does
27 * not by itself end the branch.
28 *
29 * Coordinates: the library mass-weights Cartesian positions. Returned
30 * geometries are plain Cartesians.
31 *
32 * References:
33 * - Ishida-Morokuma-Komornicki 1977 -- predictor-corrector IRC
34 * - Page-McIver 1988 -- reaction-path Hamiltonian, MW coordinates
35 */
36
37#ifndef GPR_IRC_IRCDRIVER_H_
38#define GPR_IRC_IRCDRIVER_H_
39
40#include <Eigen/Dense>
41#include <cstdint>
42#include <functional>
43#include <vector>
44
45namespace gpr {
46namespace irc {
47
48enum class IRCMethod {
49 Morokuma, // rgsaddle Morokuma, fixed corrector length step_size
50 MorokumaExtended, // same step; rgsaddle adapts the length
51};
52
58
59struct IRCOptions {
62 // Mass-weighted Morokuma corrector length (sqrt(amu) * A).
63 double step_size = 0.1;
64 // Bounds for MorokumaExtended. The library clamps the next length here.
65 double max_step = 0.3;
66 double min_step = 0.01;
67 // Stop when ||M^{-1/2} g||_2 falls to this value. The same number is
68 // rgsaddle's RGSADDLE_FORCE_MW_L2 tolerance.
69 double conv_tol = 0.01;
70 // Hard cap on IRC steps per direction.
71 int max_steps = 200;
72 // Mass-weighted kick length. Independent of step_size.
74 // 1-indexed imaginary mode of the supplied Hessian. The Lanczos launch
75 // (hessian_sketch_rank > 0) has only the lowest mode.
77 // Above 0, launch from rgsaddle_irc_create_from_surface instead of the
78 // supplied Hessian. The seed is a splitmix64 Box-Muller draw from
79 // sketch_seed (0 maps to 1), mass-weighted like the surface, then
80 // projected off rigid translations. A non-periodic system of three or
81 // more atoms also drops rotations. hv_eps is the library's Lanczos
82 // finite-difference step. The rank is not a mode index. A returned
83 // mode whose curvature is not negative is rejected.
85 double hv_eps = 1e-3;
86 uint64_t sketch_seed = 1;
87 // Energy and gradient of the saddle sample. Later samples always store
88 // the values rgsaddle asked the surface for.
89 bool record_energy = true;
90};
91
92struct IRCStep {
93 Eigen::VectorXd positions; // plain Cartesians, length 3N
94 Eigen::VectorXd gradient; // plain Cartesians, length 3N
95 double energy = 0.0;
96 double g_norm = 0.0; // |g_mw|, mass-weighted
97 double cumulative_arc = 0.0; // arc length in mass-weighted coords
98};
99
100struct IRCBranch {
101 std::vector<IRCStep> path; // includes the saddle as path[0]
102 bool converged = false;
104 double final_energy = 0.0;
105};
106
111
112// Gradient functor: (positions) -> (energy, gradient).
113// Both vectors are length 3N in plain Cartesian.
115 std::function<std::pair<double, Eigen::VectorXd>(const Eigen::VectorXd&)>;
116
118public:
119 IRCDriver(GradientFn gradient_fn,
120 Eigen::VectorXd masses, // length N (amu)
121 IRCOptions options = {});
122
123 // Trace the IRC from the saddle. The Hessian is plain Cartesians,
124 // eV/A^2, size 3N x 3N. It is used only when hessian_sketch_rank is 0.
125 IRCResult run(const Eigen::VectorXd& saddle_positions,
126 const Eigen::MatrixXd& saddle_hessian);
127
128private:
129 GradientFn gradient_fn_;
130 Eigen::VectorXd masses_; // length N
131 Eigen::VectorXd sqrt_masses_; // length 3N (repeated)
132 IRCOptions options_;
133};
134
135} // namespace irc
136} // namespace gpr
137
138#endif // GPR_IRC_IRCDRIVER_H_
IRCDriver(GradientFn gradient_fn, Eigen::VectorXd masses, IRCOptions options={})
IRCResult run(const Eigen::VectorXd &saddle_positions, const Eigen::MatrixXd &saddle_hessian)
Intrinsic reaction coordinate drivers in mass-weighted coordinates.
Definition IRCDriver.cpp:20
std::function< std::pair< double, Eigen::VectorXd >(const Eigen::VectorXd &)> GradientFn
Definition IRCDriver.h:114
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
std::vector< IRCStep > path
Definition IRCDriver.h:101
IRCDirection direction
Definition IRCDriver.h:61
double initial_displacement
Definition IRCDriver.h:73
Eigen::VectorXd gradient
Definition IRCDriver.h:94
Eigen::VectorXd positions
Definition IRCDriver.h:93
double cumulative_arc
Definition IRCDriver.h:97