Compute a harmonic rate prefactor¶
Harmonic transition-state theory gives the rate prefactor in the Vineyard form
where \(\omega_i^2\) are the eigenvalues of the mass-weighted Hessian with
the rigid translations and rotations projected out, and the saddle product
runs over its real modes. gpridge computes \(\ln\nu\) in two halves, one per
stationary point: ln_sum is \(\sum_i \ln\nu_i\) over the real modes, and
\(\ln\nu =\) ln_sum (minimum) \(-\) ln_sum (saddle).
Status: implemented (C ABI 1.20) in C, C++, Fortran, Python, R, Julia and Rust.
Choose how a half gets its Hessian¶
Mode |
Hessian |
Oracle calls |
|---|---|---|
|
the GP posterior-mean Hessian |
none |
|
the GP Hessian, corrected direction by direction by the oracle |
2 per measured direction |
|
the full central-difference Hessian of the oracle |
\(2N\) for \(N\) coordinates |
The refined mode starts from the posterior mean. It measures the oracle
Hessian action along the mode whose estimated \(\ln\nu\) spread is largest,
and stops when one more direction moves ln_sum by less than tolerance
and no unmeasured mode’s spread exceeds it. The spread comes from the GP
curvature variance. It is a probabilistic estimate, not a bound. The
measured mode is the reference that the refined mode is tested against.
A half reports which Hessian it used (source), whether it converged, its
own oracle calls, which directions were measured and its status. A
saddle half without exactly one negative mode, or a minimum with one, has
status GPR_HTST_WRONG_INDEX. gpr_htst_ln_prefactor refuses such a half
with GPR_ERR_INVALID_ARG instead of returning a number. A half that could
not be formed is GPR_HTST_UNAVAILABLE. Nothing falls back silently.
Read the halves of a search¶
Prefactors of a search are opt-in. gpr_neb_search*, including the local
and periodic bands, and gpr_minimize leave the stored halves empty until
gpr_request_prefactor (or request_prefactor) opts this thread in. Set
options.enabled = 1 on that call. NULL does so and selects the
surrogate. Without the call, gpr_search_prefactor returns
GPR_ERR_UNSUPPORTED.
The reactant and product of a band are minima and its climbing image is
the saddle; the minimizer’s result is the reactant. The surrogate is built
from the search’s own evaluations, so an opted-in surrogate search costs
exactly as many oracle calls as before. At each stationary point it fits a
local GP on up to 40 nearest search evaluations, diagonalizes the
\(d \times d\) posterior-mean Hessian (\(O(d^3)\)), and evaluates the
curvature-variance stencil along each vibrational mode. ln_sum_std is
the root-sum-square, over the positive modes with a component outside the
measured directions, of \(\sqrt{v_i} / (2\lambda_i)\): the standard
deviation of \(\ln\nu_i\) from the mode’s diagonal curvature variance
\(v_i\). Covariance between modes is not included. A later call selects the
refined or measured mode, or turns the request off with enabled = 0. A
NEB search that ran the index certificate (gpr_neb_request_index_certificate) uses its
measured stencil Hessian for the saddle half, at no extra call
(GPR_HTST_SOURCE_STENCIL). A half that cannot be formed is stored with
status GPR_HTST_UNAVAILABLE and a message. The search does not drop the
request or substitute another mode.
The program minimizes a Lennard-Jones trimer twice: once with the surrogate request and once with the refined one. It then measures the full Hessian at the same point for reference. The extra oracle calls of the refined half reach the callback but not the search’s own count.
#include <gpr/capi/gpridge_c.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
typedef struct {
gpr_lj_params_t lj;
int calls;
} counted_t;
static void oracle(int n, const double *x, double *e, double *g, void *data)
{
counted_t *c = (counted_t *)data;
c->calls++;
gpr_oracle_lj(n, x, e, g, &c->lj);
}
static gpr_htst_half_t fresh(void)
{
gpr_htst_half_t half;
memset(&half, 0, sizeof half);
half.struct_size = sizeof half;
return half;
}
int main(void)
{
const double x0[9] = {0.0, 0.0, 0.0, 1.15, 0.0, 0.0, 0.5, 0.95, 0.05};
double x[9], e, g[9];
int converged = 0, calls = 0;
counted_t c = {{3, 1.0, 1.0}, 0};
gpr_atoms_t atoms = gpr_atoms_create_simple(3);
gpr_minimize_config_t config = gpr_minimize_config_defaults();
gpr_htst_options_t options = gpr_htst_options_defaults();
gpr_htst_half_t surrogate = fresh(), refined = fresh(), measured = fresh();
config.max_iter = 60;
config.conv_tol = 1e-4;
/* Search prefactors are opt-in. NULL requests the cheap surrogate mode. */
gpr_request_prefactor(NULL, NULL, 0);
if (gpr_minimize(oracle, &c, x0, 9, atoms, &config, x, &e, g, &converged,
&calls) != GPR_SUCCESS ||
gpr_search_prefactor(GPR_HTST_REACTANT, &surrogate, NULL, NULL, 0) !=
GPR_SUCCESS)
return 1;
printf("surrogate: %d search calls, %d callback calls, surrogate ln_sum "
"%.4f\n",
calls, c.calls, surrogate.ln_sum);
options.mode = GPR_HTST_REFINED;
gpr_request_prefactor(&options, NULL, 0);
c.calls = 0;
gpr_minimize(oracle, &c, x0, 9, atoms, &config, x, &e, g, &converged,
&calls);
gpr_request_prefactor(NULL, NULL, 0);
gpr_search_prefactor(GPR_HTST_REACTANT, &refined, NULL, NULL, 0);
printf("refined: %d search calls, %d callback calls, ln_sum %.4f "
"(+- %.1e, %d directions)\n",
calls, c.calls, refined.ln_sum, refined.ln_sum_std,
refined.n_measured);
options.mode = GPR_HTST_MEASURED;
c.calls = 0;
gpr_htst_half(NULL, oracle, &c, &options, NULL, 0, x, 9, GPR_HTST_MINIMUM,
NULL, NULL, &measured);
printf("measured: %d calls, ln_sum %.4f, %d modes\n", c.calls,
measured.ln_sum, measured.n_modes);
if (fabs(refined.ln_sum - measured.ln_sum) < 1e-2)
printf("refined agrees with measured\n");
gpr_atoms_destroy(atoms);
return 0;
}
The numbers are in native units: unit masses and \(\varepsilon = \sigma =
1\). Pass one mass per atom and set omega_scale to
GPR_HTST_OMEGA_EV_ANGSTROM_AMU for frequencies in Hz from eV, Angstrom and
amu. Each half records the omega_scale it was computed with, and
gpr_htst_ln_prefactor returns GPR_ERR_UNIT_MISMATCH for two halves whose
scales differ, since their ln_sum are in different units.
Build a prefactor from two halves¶
gpr_htst_half_from_hessian takes a Hessian the caller already has, for
instance from an instanton code, and gpr_htst_half measures or refines one
at a point. In Python the same calls are htst_half_from_hessian,
htst_half and htst_ln_prefactor:
import math
import numpy as np
from gpridge import HtstKind, HtstOptions, htst_half_from_hessian, htst_ln_prefactor
options = HtstOptions()
options.project_translation = False
options.project_rotation = False
x = np.zeros(3)
minimum = htst_half_from_hessian(np.diag([1.0, 3.0, 5.0]), x, HtstKind.MINIMUM, options)
saddle = htst_half_from_hessian(np.diag([-2.0, 3.0, 5.0]), x, HtstKind.SADDLE, options)
ln_nu, ln_nu_std = htst_ln_prefactor(minimum, saddle)
assert abs(ln_nu - math.log(1.0 / (2.0 * math.pi))) < 1e-12
print(f"ln nu = {ln_nu:.6f}, saddle |nu| = {saddle.imaginary_frequency:.6f}")
After a Python search that called request_prefactor,
search_prefactor(HtstPoint.REACTANT) returns the half. gp_neb and
run_ocineb store halves only after that call, and they need an
atoms_config to fit the surrogate. Without one, or without the request,
search_prefactor raises UnsupportedError.
Supply an exact Hessian or HVP callback when conditioning at a fixed point¶
When an exact Hessian or Hessian-vector-product (HVP) operator is already
known at a stationary point, pass it to gpr_model_condition_fixed_hessian
(in C) or via hessian / hvp on condition_fixed (in Python, C++,
Fortran, R, Julia and Rust). The library validates the shape, finiteness and
symmetry of the supplied Hessian or HVP operator before mutating the model:
an invalid shape, non-finite entry or asymmetric operator fails immediately
with GPR_ERR_INVALID_ARG (InvalidArgumentError in Python) and leaves the
model and outputs untouched, with no silent fallback to GP curvature. An HVP
callback that raises in Python, R or Julia is an oracle failure instead
(OracleError in Python, GPR_ERR_ORACLE in R and Julia) with the same
untouched model; Python chains the raised exception as its cause. When
valid, a subsequent gpr_htst_half / htst_half at that fixed point uses
the exact Hessian in the Vineyard prefactor instead of GP curvature, at zero
additional oracle calls (GPR_HTST_SOURCE_CONDITIONED):
import numpy as np
import gpridge
from gpridge import HtstKind, HtstSource, htst_half, htst_half_from_hessian, potential_lj
r_min = 2.0 ** (1.0 / 6.0)
pts = np.array([[0.0, 0.0, 0.0, r_min + 0.03 * (i - 3), 0.01 * i, 0.0] for i in range(7)])
rows = [potential_lj(p, 2) for p in pts]
obs = gpridge.Observation()
obs.R = pts
obs.E = np.array([[e] for e, _ in rows])
obs.G = np.array([g for _, g in rows])
cfg = gpridge.AtomsConfiguration()
cfg.positions = np.zeros((1, 6))
cfg.is_frozen = np.zeros((1, 2), dtype=np.uint8)
cfg.id = np.arange(2, dtype=np.uint32).reshape(1, 2)
cfg.atomic_nrs = np.ones((1, 2), dtype=np.int32)
gpridge.initialize_atoms_config(cfg, np.zeros(2, dtype=np.uint32), cfg.positions.copy(), -1.0, 1)
params = gpridge.default_gpr_parameters()
params["max_iter"] = 25
params["report_level"] = 0
gp = gpridge.GaussianProcessRegression()
gp.initialize(params, cfg)
gp.set_hyperparameters(obs, cfg)
gp.optimize(obs)
x0 = np.array([0.0, 0.0, 0.0, r_min, 0.0, 0.0])
e0, g0 = potential_lj(x0, 2)
added = gpridge.Observation()
added.R = x0[None, :]
added.E = np.array([[e0]])
added.G = g0[None, :]
k = 72.0 / (r_min * r_min)
h_exact = np.zeros((6, 6))
h_exact[0, 0] = h_exact[3, 3] = k
h_exact[0, 3] = h_exact[3, 0] = -k
gp.condition_fixed(obs, added, x0[None, :], hessian=h_exact)
half = htst_half(x0, HtstKind.MINIMUM, model=gp)
ref = htst_half_from_hessian(h_exact, x0, HtstKind.MINIMUM)
assert half.source == HtstSource.CONDITIONED and half.oracle_calls == 0
assert abs(half.ln_sum - ref.ln_sum) < 1e-12
Use the posterior derivatives directly¶
The halves are built on batched derivatives of a trained model’s posterior, which are available on their own:
Need |
C function |
|---|---|
Exact posterior-mean Hessians at \(B\) points |
|
Hessian-vector products |
|
Covariance of \(v^\top H w\) |
|
Variance of \(\mathrm{tr}(A\,\delta H)\) |
|
Energy and gradient variance |
|
Add oracle rows without a refit |
|
They work in the units of the training data, apply no mass weighting and
project rigid motions only when project_rigid is set. Set
max_energy_std to fail closed outside the training support with
GPR_ERR_OUT_OF_SUPPORT. The report then carries the largest posterior
standard deviation. Python names the same calls as methods of
GaussianProcessRegression (mean_hessian_batch and so on) and raises
OutOfSupportError with the report attached.
See also¶
C function reference for every argument and status.
C reference for the shared rules.