Loading...
Searching...
No Matches
eonc::tunneling Namespace Reference

Classes

struct  BandWall
 One well's outer wall: increasing mass-weighted distances outward from the minimum along the reaction path, and the energies there on the scale of the band's profile. More...
struct  BandWalls
class  CyclicBlockBath
 Exact factorization of diag(E_j) plus the cyclic primitive spring matrix. More...
class  DerivativeRbfModel
 Gaussian derivative interpolant with an explicit quadratic baseline. More...
class  EnergyBias
 delta sigma(xi) between two minima, xi = (q - start) . More...
class  HarmonicReferenceAction
 Exact nonnegative harmonic-reference links in mass-weighted coordinates. More...
struct  Instanton
struct  InstantonOptions
struct  Levels
 The two lowest levels of a one-dimensional double well, in eV. More...
struct  PhysicalBathModel
struct  PhysicalQuadraticBath
 V(q,b)=V_fixed(q)+source(q)^T b+b^T E(q)b/2. More...
class  Profile
 Energy along the path, interpolated as a monotone cubic (Fritsch and Carlson), flat at both ends because the ends of a band are minima. More...
class  QuadraticBath
 Exact Gaussian elimination of a stable physical mass-weighted harmonic bath. More...
struct  RateInstanton
struct  RateInstantonOptions
struct  RbfEvaluation
struct  RingChannel
 Where a ring sits against the saddle it was seeded from, in mass-weighted coordinates. More...
class  RingPolymerPotential
 One structure whose coordinates are the beads of a closed ring. More...
struct  RingRigidBodies
 The atoms behind a ring's mass-weighted coordinates, for its rigid motions: sqrt(m) per atom, the Cartesian positions q is measured from (3 per atom; the reactant minimum, q = 0, for the rotational ratio), and which rotations are free. More...
struct  RingSeed
 Closed ring of beads samples of path whose imaginary-time period is betaHbar. More...
struct  RingSpectrum
 Spectrum of a closed ring's Hessian without forming it. More...
struct  RotationZeroModes
struct  Splitting

Typedefs

using BatchPotential
 V (eV) and dV/dq (eV / (amu^0.5 Angstrom)) at every point of q, all in one call so a potential can spread the beads over its calculators.
using OwnedBatchPotential
 Explicit electronic-state owners for each evaluated geometry.
using BeadHessian = std::function<MatrixXd(long j, const VectorXd &q)>
 The mass-weighted Hessian d2V/dq2 at interior bead j (1..P-1).
using RingBeadHessian = std::function<MatrixXd(long j, const VectorXd &q)>
 The mass-weighted Hessian d2V/dq2 at ring bead j (0..N-1).

Functions

double massWeightedDistance (const Matter &a, const Matter &b)
 sqrt(sum_i m_i |b_i - a_i|^2) under the minimum image of a's cell.
std::vector< double > massWeightedPath (const std::vector< std::shared_ptr< Matter > > &band)
 Cumulative mass-weighted arc length at each image of a band.
double wellCurvature (const Profile &p, bool leftEnd)
 d2V/ds2 at one end of the path, in eV / (amu Angstrom^2), from a least squares fit of a s^2 + b s^3 to the points within half the barrier above that end.
std::array< double, 2 > wellFit (const Profile &p, bool leftEnd)
 {a, b} of that fit, s measured inward from the end: wellCurvature is 2 a.
double hbarOmega (double curvature)
 hbar omega in eV for a mass-weighted curvature.
double wkbAction (const Profile &p, double energy, int points=4001)
 (1/hbar) integral sqrt(2 (V(s) - E)) ds over the path where V > E.
Splitting wkbSplitting (const Profile &p, double hwReactant, double hwProduct)
 delta0 = (hbar omega / pi) exp(-S) with the Landau and Lifshitz prefactor.
std::vector< VectorXd > ringFromPath (const std::vector< VectorXd > &path, const std::vector< double > &energies, double betaHbar, long beads, RingSeed *seed)
double wkbLogRateAlongPath (const Profile &profile, double beta, double hwReactant)
 ln(k), k in 1/time, for the one-dimensional thermal rate along profile.
Profile bandProfile (const std::vector< std::shared_ptr< Matter > > &band, double referenceEnergy)
 The energy of a band against its mass-weighted arc length, measured from referenceEnergy.
Splitting bandSplitting (const std::vector< std::shared_ptr< Matter > > &band, double referenceEnergy)
 The splitting of a converged band, with the well frequencies from the band's curvature at each end.
bool singleBarrier (const Profile &p)
 Whether a profile is one double well: its images rise to exactly one maximum between the two ends.
Levels dvrLevels (const std::function< double(double)> &v, double sReactant, double sProduct, double sTop, double hwReactant, double hwProduct)
 The levels of -hbar^2/2 d2/ds2 + V(s) at unit mass on a mass-weighted path coordinate s, with V defined past both minima: fourth-order central differences on a uniform grid from kDvrPadLengths oscillator lengths before the reactant minimum to as far past the product's.
Levels bandLevels (const Profile &p, const BandWalls *walls=nullptr)
 dvrLevels on a band: the profile between the images, and past each end the well's fit a s^2 + b s^3 continued, never softer than its parabola.
BandWalls bandWalls (const std::vector< std::shared_ptr< Matter > > &band, double referenceEnergy, long points)
 The walls of both ends of a band, after Khomenko et al.
double pathOmega (const MatrixXd &hessStart, const MatrixXd &hessEnd, const VectorXd &start, const VectorXd &end)
 omega along the straight line between the minima from the curvature of each well there, the larger of the two; in 1 / time.
Instanton optimizeInstanton (const VectorXd &start, const VectorXd &end, double betaHbar, std::vector< VectorXd > guess, const BatchPotential &potential, const InstantonOptions &options)
 Minimises the action from guess (P + 1 beads, ends at the minima, or empty for a tanh kink along the straight line).
void instantonSplitting (Instanton &inst, const BeadHessian &hessian, const MatrixXd &hessStart, const MatrixXd &hessEnd)
 Fills delta0, zeroMode and modeSeparation from the bead Hessians and the Hessians of the two minima.
double zeroPointDifference (const MatrixXd &hessStart, const MatrixXd &hessEnd, long rigidModes)
 Harmonic zero-point energy of the end minimum minus that of the start, in eV: (hbar / 2) times the difference of the sums of the vibrational frequencies of the two mass-weighted Hessians.
double crossoverTemperature (const MatrixXd &hessSaddle)
 T_c = hbar omega_b / (2 pi kB) from the mass-weighted Hessian at the saddle, in K; throws when the Hessian has no negative eigenvalue.
void addFrictionBath (const std::vector< VectorXd > &q, double &u, std::vector< VectorXd > &grad, const std::vector< double > &eta)
 Position-independent (one eta) or bead-wise friction on a closed ring.
RingSpectrum ringSpectrum (const std::vector< MatrixXd > &beadHessians, double c, const std::vector< VectorXd > &tau)
 The ring Hessian of bead Hessians beadHessians (d2V/dq2 at each of the N beads) and spring constant c, with the normalised direction tau (N beads) lifted by c and taken out again through the determinant lemma det(J + c tau tau^T) = (c + lambda_0) det' J, exact when J tau = lambda_0 tau.
double cyclicRingLogAbsDet (double c, const std::vector< MatrixXd > &diag)
 log|det| of the cyclic block-tridiagonal ring Hessian.
std::vector< VectorXd > cyclicRingSolve (double c, const std::vector< MatrixXd > &diag, const std::vector< VectorXd > &rhs)
 Solves that same cyclic ring Hessian.
RateInstanton optimizeRateInstanton (const VectorXd &saddle, const MatrixXd &hessSaddle, double beta, std::vector< VectorXd > guess, const BatchPotential &potential, const RateInstantonOptions &options)
 Finds the rate instanton at inverse temperature beta (1 / eV).
double logRotationalRatio (const std::vector< VectorXd > &beads, const RingRigidBodies &bodies)
 ln of the classical rotational partition function of beads over that of as many copies of the reference (q = 0), for the free rotations: half the log of the ratio of the products of their principal moments, the inertia of every bead's atoms about the beads' common centre of mass, which is the Gram matrix of the ring's rotation generators.
double closedRingPotential (const std::vector< VectorXd > &beads, double spring, const BatchPotential &potential, const std::vector< double > &discretization={})
 U_N of a closed ring.
void instantonRate (RateInstanton &inst, const RingBeadHessian &hessian, const MatrixXd &hessReactant, double vReactant, const MatrixXd &hessSaddle=MatrixXd(), double vSaddle=0.0, long rigidModes=0, long denseLimit=4096, const RingRigidBodies &rigidBodies={})
 Fills the rate from the bead Hessians, the reactant minimum's Hessian and energy, and optionally the saddle's Hessian and energy for the classical comparison (pass an empty matrix to skip it).
RotationZeroModes rotationZeroModes (const MatrixXd &hess, const MatrixXd &generators, double fraction)
void bofillKeepingInertia (MatrixXd &h, const VectorXd &dq, const VectorXd &dg, long allowedNegatives)
 The Bofill update of a bead block (Powell symmetric Broyden and SR1 mixed by the angle between the secant residual and the step), then any negative eigenvalues beyond allowedNegatives, the count the block's last exact (finite-difference) version had, mirrored to their absolute value.
RingChannel ringChannel (const std::vector< VectorXd > &beads, const VectorXd &saddle, const VectorXd &mode)
 The channel test above for a ring of beads, a saddle and its unstable mode (normalised inside).
double parabolicFactor (double temperature, double crossover)
 (pi T_c / T) / sin(pi T_c / T).
double harmonicTstLogRate (const MatrixXd &hessReactant, const MatrixXd &hessSaddle, double beta, double barrier, long rigidModes)
 ln(k) for classical harmonic transition-state theory, k in 1/time.
double quantumHarmonicTstLogRate (const MatrixXd &hessReactant, const MatrixXd &hessSaddle, double beta, double barrier, long rigidModes)
 ln(k) for quantum harmonic transition-state theory, k in 1/time: (1 / (2 pi beta hbar)) prod_r 2 sinh(beta hbar omega_r / 2) / prod'_s 2 sinh(beta hbar omega_s / 2) exp(-beta barrier), the zero-point and quantised partition functions of every bound mode; the saddle's unstable mode leaves the product.
std::vector< AtomMatrix > readRateRingSeed (const std::string &filename, const Matter &reference, long beads)
 Read closed-ring geometry on the reference's ordered physical coordinates.
MatrixXd readReferenceHessian (const std::string &filename, const Matter &reference, long dimension)
 Read a mass-weighted reference matrix bound to filename + ".con".

Variables

constexpr double kHbar = 0.06465415129579072
 hbar in eV^0.5 amu^0.5 Angstrom, correctly rounded from the exact SI values (h = 6.62607015e-34 J s, e = 1.602176634e-19 C) and the CODATA 2022 dalton, 1.66053906892e-27 kg.
constexpr double kBoltzmann = 8.617333262145177e-5
 Boltzmann constant in eV / K, correctly rounded from the exact 1.380649e-23 J / K.
constexpr long kDvrPointsPerLength = 20
 Grid points per oscillator length hbar / sqrt(hbar omega) of the stiffer well.
constexpr double kDvrPadLengths = 7.0
 Oscillator lengths the grid reaches past each minimum.
constexpr long kDvrMaxPoints = 1500
 Largest grid; a longer path takes a coarser spacing.
constexpr double kTimeUnitSeconds = 1.0180505717871193e-14
 One unit of time, sqrt(amu Angstrom^2 / eV), in seconds.
constexpr double kRotationZeroFraction = 0.1
 Which rotations of a structure are zero modes of its mass-weighted Hessian.

Typedef Documentation

◆ BatchPotential

Initial value:
std::function<void(const std::vector<VectorXd> &q, std::vector<double> &v,
std::vector<VectorXd> &grad)>

V (eV) and dV/dq (eV / (amu^0.5 Angstrom)) at every point of q, all in one call so a potential can spread the beads over its calculators.

Definition at line 238 of file Tunneling.h.

◆ BeadHessian

using eonc::tunneling::BeadHessian = std::function<MatrixXd(long j, const VectorXd &q)>

The mass-weighted Hessian d2V/dq2 at interior bead j (1..P-1).

Definition at line 248 of file Tunneling.h.

◆ OwnedBatchPotential

Initial value:
std::function<void(
const std::vector<VectorXd> &q, std::vector<double> &v,
std::vector<VectorXd> &grad, const std::vector<long> &owners)>

Explicit electronic-state owners for each evaluated geometry.

Definition at line 243 of file Tunneling.h.

◆ RingBeadHessian

using eonc::tunneling::RingBeadHessian = std::function<MatrixXd(long j, const VectorXd &q)>

The mass-weighted Hessian d2V/dq2 at ring bead j (0..N-1).

Definition at line 616 of file Tunneling.h.

Function Documentation

◆ addFrictionBath()

void eonc::tunneling::addFrictionBath ( const std::vector< VectorXd > & q,
double & u,
std::vector< VectorXd > & grad,
const std::vector< double > & eta )

Position-independent (one eta) or bead-wise friction on a closed ring.

Empty or all-zero eta leaves u and grad unchanged. A negative eta is refused. J. Chem. Phys. 156, 194106 (2022).

Definition at line 1339 of file Tunneling.cpp.

1341 {
1342 const size_t n = q.size();
1343 if (n < 2 || eta.empty() || grad.size() != n) {
1344 return;
1345 }
1346 std::vector<double> s(n, eta.size() == 1 ? eta[0] : 0.0);
1347 if (eta.size() == n) {
1348 s = eta;
1349 } else if (eta.size() != 1) {
1350 throw std::invalid_argument(
1351 "addFrictionBath: eta is one value or one per bead");
1352 }
1353 for (double value : s) {
1354 if (!(value >= 0.0)) {
1355 throw std::invalid_argument("addFrictionBath: eta must be non-negative");
1356 }
1357 }
1358 const long f = q[0].size();
1359 std::vector<double> root(n);
1360 for (size_t j = 0; j < n; ++j) {
1361 root[j] = std::sqrt(s[j]);
1362 }
1363 std::vector<VectorXd> g(n, VectorXd::Zero(f));
1364 std::vector<double> mid(n, 0.0);
1365 for (size_t j = 1; j < n; ++j) {
1366 mid[j] = 0.5 * (root[j - 1] + root[j]);
1367 g[j] = g[j - 1] + mid[j] * (q[j] - q[j - 1]);
1368 }
1369 std::vector<VectorXd> dUdg(n, VectorXd::Zero(f));
1370 const double scale = 1.0 / std::sqrt(static_cast<double>(n));
1371 for (size_t k = 1; k < n; ++k) {
1372 const double omega =
1373 2.0 * std::abs(std::sin(std::numbers::pi * static_cast<double>(k) /
1374 static_cast<double>(n)));
1375 VectorXd real = VectorXd::Zero(f);
1376 VectorXd imag = VectorXd::Zero(f);
1377 for (size_t j = 0; j < n; ++j) {
1378 const double ang = -2.0 * std::numbers::pi * static_cast<double>(k * j) /
1379 static_cast<double>(n);
1380 real += std::cos(ang) * g[j];
1381 imag += std::sin(ang) * g[j];
1382 }
1383 real *= scale;
1384 imag *= scale;
1385 u += 0.5 * omega * (real.squaredNorm() + imag.squaredNorm());
1386 for (size_t j = 0; j < n; ++j) {
1387 const double ang = -2.0 * std::numbers::pi * static_cast<double>(k * j) /
1388 static_cast<double>(n);
1389 dUdg[j] += omega * scale * (std::cos(ang) * real + std::sin(ang) * imag);
1390 }
1391 }
1392 for (size_t j = n - 1; j >= 1; --j) {
1393 dUdg[j - 1] += dUdg[j];
1394 if (j == 1) {
1395 break;
1396 }
1397 }
1398 for (size_t j = 1; j < n; ++j) {
1399 grad[j] += mid[j] * dUdg[j];
1400 grad[j - 1] -= mid[j] * dUdg[j];
1401 }
1402}

◆ bandLevels()

Levels eonc::tunneling::bandLevels ( const Profile & p,
const BandWalls * walls = nullptr )

dvrLevels on a band: the profile between the images, and past each end the well's fit a s^2 + b s^3 continued, never softer than its parabola.

A sampled wall adds the residual of its samples against that fit, a cubic spline flat at the minimum and straight past the last sample.

Definition at line 689 of file Tunneling.cpp.

689 {
690 const std::array<double, 2> fitR = wellFit(p, true);
691 const std::array<double, 2> fitP = wellFit(p, false);
692 const double hwR = hbarOmega(2.0 * fitR[0]);
693 const double hwP = hbarOmega(2.0 * fitP[0]);
694 const double s0 = p.s().front();
695 const double s1 = p.s().back();
696 double sTop = s0;
697 double vTop = -std::numeric_limits<double>::infinity();
698 constexpr int grid = 4000;
699 for (int k = 0; k <= grid; ++k) {
700 const double sk = s0 + (s1 - s0) * static_cast<double>(k) / grid;
701 if (p(sk) > vTop) {
702 vTop = p(sk);
703 sTop = sk;
704 }
705 }
706 // Past each end the well's fit, its parabola or its cubic, whichever is
707 // stiffer. A sampled wall adds the residual of its samples, a spline flat
708 // at the minimum: the fit already bends like the potential where the
709 // ground state lives, so the residual is small there and smooth beyond.
710 auto model = [](double u, const std::array<double, 2> &fit) {
711 return std::max(fit[0] * u * u - fit[1] * u * u * u, fit[0] * u * u);
712 };
713 auto residual = [&](const BandWall *wall, const std::array<double, 2> &fit,
714 double floor) -> std::optional<FlatStartSpline> {
715 if (wall == nullptr || wall->distance.empty()) {
716 return std::nullopt;
717 }
718 if (wall->distance.size() != wall->energy.size()) {
719 throw std::invalid_argument("a wall needs one energy per distance");
720 }
721 std::vector<double> x{0.0};
722 std::vector<double> y{0.0};
723 for (size_t k = 0; k < wall->distance.size(); ++k) {
724 x.push_back(wall->distance[k]);
725 y.push_back(wall->energy[k] - floor - model(wall->distance[k], fit));
726 }
727 return FlatStartSpline(std::move(x), std::move(y));
728 };
729 const std::optional<FlatStartSpline> wallR =
730 residual(walls ? &walls->reactant : nullptr, fitR, p.v().front());
731 const std::optional<FlatStartSpline> wallP =
732 residual(walls ? &walls->product : nullptr, fitP, p.v().back());
733 auto outer = [&](double u, const std::array<double, 2> &fit, double floor,
734 const std::optional<FlatStartSpline> &wall) {
735 return floor + model(u, fit) + (wall ? (*wall)(u) : 0.0);
736 };
737 auto v = [&](double s) {
738 if (s < s0) {
739 return outer(s0 - s, fitR, p.v().front(), wallR);
740 }
741 if (s > s1) {
742 return outer(s - s1, fitP, p.v().back(), wallP);
743 }
744 return p(s);
745 };
746 return dvrLevels(v, s0, s1, sTop, hwR, hwP);
747}
const std::vector< double > & v() const
Definition Tunneling.h:61
const std::vector< double > & s() const
Definition Tunneling.h:60
Levels dvrLevels(const std::function< double(double)> &v, double sReactant, double sProduct, double sTop, double hwReactant, double hwProduct)
The levels of -hbar^2/2 d2/ds2 + V(s) at unit mass on a mass-weighted path coordinate s,...
std::array< double, 2 > wellFit(const Profile &p, bool leftEnd)
{a, b} of that fit, s measured inward from the end: wellCurvature is 2 a.
double hbarOmega(double curvature)
hbar omega in eV for a mass-weighted curvature.
One well's outer wall: increasing mass-weighted distances outward from the minimum along the reaction...
Definition Tunneling.h:150

◆ bandProfile()

Profile eonc::tunneling::bandProfile ( const std::vector< std::shared_ptr< Matter > > & band,
double referenceEnergy )

The energy of a band against its mass-weighted arc length, measured from referenceEnergy.

Definition at line 540 of file Tunneling.cpp.

541 {
542 std::vector<double> v;
543 v.reserve(band.size());
544 for (const auto &image : band) {
545 v.push_back(image->getPotentialEnergy() - referenceEnergy);
546 }
547 return Profile(massWeightedPath(band), std::move(v));
548}
std::vector< double > massWeightedPath(const std::vector< std::shared_ptr< Matter > > &band)
Cumulative mass-weighted arc length at each image of a band.
Definition Tunneling.cpp:79

◆ bandSplitting()

Splitting eonc::tunneling::bandSplitting ( const std::vector< std::shared_ptr< Matter > > & band,
double referenceEnergy )

The splitting of a converged band, with the well frequencies from the band's curvature at each end.

Definition at line 550 of file Tunneling.cpp.

551 {
552 const Profile p = bandProfile(band, referenceEnergy);
553 return wkbSplitting(p, hbarOmega(wellCurvature(p, true)),
554 hbarOmega(wellCurvature(p, false)));
555}
Energy along the path, interpolated as a monotone cubic (Fritsch and Carlson), flat at both ends beca...
Definition Tunneling.h:56
Splitting wkbSplitting(const Profile &p, double hwReactant, double hwProduct)
delta0 = (hbar omega / pi) exp(-S) with the Landau and Lifshitz prefactor.
double wellCurvature(const Profile &p, bool leftEnd)
d2V/ds2 at one end of the path, in eV / (amu Angstrom^2), from a least squares fit of a s^2 + b s^3 t...
Profile bandProfile(const std::vector< std::shared_ptr< Matter > > &band, double referenceEnergy)
The energy of a band against its mass-weighted arc length, measured from referenceEnergy.

◆ bandWalls()

BandWalls eonc::tunneling::bandWalls ( const std::vector< std::shared_ptr< Matter > > & band,
double referenceEnergy,
long points )

The walls of both ends of a band, after Khomenko et al.

(PRL 124, 225901 (2020), SI): the potential at points distances past each minimum, along the band's end segment continued outward, out to kDvrPadLengths oscillator lengths of that well. Each point is one force call.

Definition at line 749 of file Tunneling.cpp.

750 {
751 if (band.size() < 3 || points < 1) {
752 throw std::invalid_argument(
753 "bandWalls: a band of three images or more and a point per wall");
754 }
755 const Profile p = bandProfile(band, referenceEnergy);
756 auto wall = [&](const Matter &end, const Matter &next, double a) {
757 const double ell = kHbar / std::sqrt(hbarOmega(2.0 * a));
758 const AtomMatrix step = end.pbc(end.getPositions() - next.getPositions());
759 const auto mass = end.getMasses();
760 double norm2 = 0.0;
761 for (long i = 0; i < end.numberOfAtoms(); ++i) {
762 norm2 += mass(i) * step.row(i).squaredNorm();
763 }
764 if (!(norm2 > 0.0)) {
765 throw std::invalid_argument("bandWalls: an end segment has no length");
766 }
767 // One unit of mass-weighted length along the end segment, outward.
768 const AtomMatrix direction = step / std::sqrt(norm2);
769 BandWall out;
770 Matter probe(end);
771 for (long k = 1; k <= points; ++k) {
772 const double u = kDvrPadLengths * ell * static_cast<double>(k) /
773 static_cast<double>(points);
774 probe.setPositions(end.getPositions() + u * direction);
775 out.distance.push_back(u);
776 out.energy.push_back(probe.getPotentialEnergy() - referenceEnergy);
777 }
778 return out;
779 };
780 BandWalls out;
781 out.reactant = wall(*band.front(), *band[1], wellFit(p, true)[0]);
782 out.product =
783 wall(*band.back(), *band[band.size() - 2], wellFit(p, false)[0]);
784 return out;
785}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
const AtomMatrix & getPositions() const
Definition Matter.cpp:378
long int numberOfAtoms() const
Definition Matter.cpp:343
AtomMatrix pbc(const AtomMatrix &diff) const
Definition Matter.cpp:943
Eigen::Matrix< double, Eigen::Dynamic, 1 > getMasses() const
Definition Matter.cpp:846
constexpr double kDvrPadLengths
Oscillator lengths the grid reaches past each minimum.
Definition Tunneling.h:135
constexpr double kHbar
hbar in eV^0.5 amu^0.5 Angstrom, correctly rounded from the exact SI values (h = 6....
Definition Tunneling.h:39

◆ bofillKeepingInertia()

void eonc::tunneling::bofillKeepingInertia ( MatrixXd & h,
const VectorXd & dq,
const VectorXd & dg,
long allowedNegatives )

The Bofill update of a bead block (Powell symmetric Broyden and SR1 mixed by the angle between the secant residual and the step), then any negative eigenvalues beyond allowedNegatives, the count the block's last exact (finite-difference) version had, mirrored to their absolute value.

A negative count applies the plain update.

Definition at line 5213 of file Tunneling.cpp.

5214 {
5215 inertiaKeepingUpdate(h, dq, dg, allowedNegatives);
5216}

◆ closedRingPotential()

double eonc::tunneling::closedRingPotential ( const std::vector< VectorXd > & beads,
double spring,
const BatchPotential & potential,
const std::vector< double > & discretization = {} )

U_N of a closed ring.

An empty discretization is the uniform spring. Otherwise one positive weight per bead divides the spring that leaves that bead.

Definition at line 4431 of file Tunneling.cpp.

4433 {
4434 if (beads.size() < 2 || !(spring > 0.0)) {
4435 throw std::invalid_argument(
4436 "closedRingPotential: need two beads and a positive spring");
4437 }
4438 return evaluateRing(beads, spring, potential, 0.0, {}, discretization).u;
4439}

◆ crossoverTemperature()

double eonc::tunneling::crossoverTemperature ( const MatrixXd & hessSaddle)

T_c = hbar omega_b / (2 pi kB) from the mass-weighted Hessian at the saddle, in K; throws when the Hessian has no negative eigenvalue.

Definition at line 1317 of file Tunneling.cpp.

1317 {
1318 const Eigen::SelfAdjointEigenSolver<MatrixXd> es(
1319 0.5 * (hessSaddle + hessSaddle.transpose()));
1320 const double lambda = es.eigenvalues()(0);
1321 if (!(lambda < 0.0)) {
1322 throw std::invalid_argument(
1323 "crossoverTemperature: the saddle Hessian has no negative eigenvalue");
1324 }
1325 return kHbar * std::sqrt(-lambda) / (2.0 * std::numbers::pi * kBoltzmann);
1326}
constexpr double kBoltzmann
Boltzmann constant in eV / K, correctly rounded from the exact 1.380649e-23 J / K.
Definition Tunneling.h:43

◆ cyclicRingLogAbsDet()

double eonc::tunneling::cyclicRingLogAbsDet ( double c,
const std::vector< MatrixXd > & diag )

log|det| of the cyclic block-tridiagonal ring Hessian.

Each diag[j] already contains the bead Hessian plus 2 c I, and the neighbour coupling is -c I, including the corner that closes the ring. A singular ring, one whose closing pivot falls to 1e-12 of the corner's scale, returns -infinity. Throws when the open chain is singular.

Definition at line 2083 of file Tunneling.cpp.

2083 {
2084 requireCyclicBlocks(c, diag, "cyclicRingLogAbsDet");
2085 return CyclicFactor(c, diag).logAbs;
2086}

◆ cyclicRingSolve()

std::vector< VectorXd > eonc::tunneling::cyclicRingSolve ( double c,
const std::vector< MatrixXd > & diag,
const std::vector< VectorXd > & rhs )

Solves that same cyclic ring Hessian.

Throws when the ring is singular or the right-hand side does not match the blocks.

Definition at line 2088 of file Tunneling.cpp.

2090 {
2091 requireCyclicBlocks(c, diag, "cyclicRingSolve");
2092 if (static_cast<long>(rhs.size()) != static_cast<long>(diag.size())) {
2093 throw std::invalid_argument(
2094 "cyclicRingSolve: one right-hand side per bead");
2095 }
2096 for (const auto &row : rhs) {
2097 if (row.size() != diag.front().rows()) {
2098 throw std::invalid_argument(
2099 "cyclicRingSolve: the right-hand side does not match the blocks");
2100 }
2101 }
2102 return CyclicFactor(c, diag).solve(rhs);
2103}

◆ dvrLevels()

Levels eonc::tunneling::dvrLevels ( const std::function< double(double)> & v,
double sReactant,
double sProduct,
double sTop,
double hwReactant,
double hwProduct )

The levels of -hbar^2/2 d2/ds2 + V(s) at unit mass on a mass-weighted path coordinate s, with V defined past both minima: fourth-order central differences on a uniform grid from kDvrPadLengths oscillator lengths before the reactant minimum to as far past the product's.

Definition at line 574 of file Tunneling.cpp.

576 {
577 if (!(hwReactant > 0.0) || !(hwProduct > 0.0) || !(sProduct > sReactant)) {
578 throw std::invalid_argument(
579 "dvrLevels: two wells with positive hbar omega along an increasing "
580 "path");
581 }
582 const double ellR = kHbar / std::sqrt(hwReactant);
583 const double ellP = kHbar / std::sqrt(hwProduct);
584 const double lo = sReactant - kDvrPadLengths * ellR;
585 const double hi = sProduct + kDvrPadLengths * ellP;
586 const long n = std::clamp<long>(
587 static_cast<long>(
588 std::ceil((hi - lo) * kDvrPointsPerLength / std::min(ellR, ellP))) +
589 1,
590 64, kDvrMaxPoints);
591 const double h = (hi - lo) / static_cast<double>(n - 1);
592 const double c = kHbar * kHbar / (2.0 * h * h);
593 MatrixXd hmat = MatrixXd::Zero(n, n);
594 for (long i = 0; i < n; ++i) {
595 hmat(i, i) = v(lo + static_cast<double>(i) * h) + 2.5 * c;
596 if (i + 1 < n) {
597 hmat(i, i + 1) = hmat(i + 1, i) = -4.0 * c / 3.0;
598 }
599 if (i + 2 < n) {
600 hmat(i, i + 2) = hmat(i + 2, i) = c / 12.0;
601 }
602 }
603 const Eigen::SelfAdjointEigenSolver<MatrixXd> es(hmat);
604 // The overlaps of the two lowest states on the reactant side; their
605 // leading eigenvector is the rotation onto the reactant-localised state.
606 Eigen::Matrix2d side = Eigen::Matrix2d::Zero();
607 for (long i = 0; i < n && lo + static_cast<double>(i) * h < sTop; ++i) {
608 const double a = es.eigenvectors()(i, 0);
609 const double b = es.eigenvectors()(i, 1);
610 side(0, 0) += a * a;
611 side(0, 1) += a * b;
612 side(1, 1) += b * b;
613 }
614 side(1, 0) = side(0, 1);
615 const Eigen::SelfAdjointEigenSolver<Eigen::Matrix2d> rotation(side);
616 const double cosine = rotation.eigenvectors()(0, 1);
617 const double sine = rotation.eigenvectors()(1, 1);
618 Levels out;
619 out.gap = es.eigenvalues()(1) - es.eigenvalues()(0);
620 out.asymmetry = out.gap * (cosine * cosine - sine * sine);
621 out.delta0 = 2.0 * out.gap * std::abs(cosine * sine);
622 return out;
623}
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, eOnStorageOrder > MatrixXd
Definition Eigen.h:33
constexpr long kDvrMaxPoints
Largest grid; a longer path takes a coarser spacing.
Definition Tunneling.h:137
constexpr long kDvrPointsPerLength
Grid points per oscillator length hbar / sqrt(hbar omega) of the stiffer well.
Definition Tunneling.h:133
The two lowest levels of a one-dimensional double well, in eV.
Definition Tunneling.h:124

◆ harmonicTstLogRate()

double eonc::tunneling::harmonicTstLogRate ( const MatrixXd & hessReactant,
const MatrixXd & hessSaddle,
double beta,
double barrier,
long rigidModes )

ln(k) for classical harmonic transition-state theory, k in 1/time.

rigidModes eigenvalues nearest zero are omitted at each Hessian. The saddle's most negative eigenvalue is the barrier mode and leaves the product. Throws std::invalid_argument when another reactant or saddle eigenvalue off the rigid modes is not positive: the reactant is then no minimum, or the saddle not of first order.

Definition at line 5352 of file Tunneling.cpp.

5354 {
5355 const HarmonicSpectrum spectrum =
5356 harmonicSpectrum(hessReactant, hessSaddle, beta, barrier, rigidModes);
5357 const VectorXd &lr = spectrum.reactant;
5358 const VectorXd &ls = spectrum.saddle;
5359 double logRatio = 0.0;
5360 for (long m = 0; m < lr.size(); ++m) {
5361 if (!spectrum.rigidReactant[static_cast<size_t>(m)]) {
5362 logRatio += 0.5 * std::log(lr(m));
5363 }
5364 }
5365 // Eigenvalue 0 is the unstable mode, the most negative.
5366 for (long m = 1; m < ls.size(); ++m) {
5367 if (!spectrum.rigidSaddle[static_cast<size_t>(m)]) {
5368 logRatio -= 0.5 * std::log(ls(m));
5369 }
5370 }
5371 return finiteHarmonicLogRate(logRatio - std::log(2.0 * std::numbers::pi) -
5372 beta * barrier);
5373}

◆ hbarOmega()

double eonc::tunneling::hbarOmega ( double curvature)

hbar omega in eV for a mass-weighted curvature.

Definition at line 174 of file Tunneling.cpp.

174 {
175 if (!(curvature > 0.0)) {
176 throw std::invalid_argument("a well needs a positive curvature");
177 }
178 return kHbar * std::sqrt(curvature);
179}

◆ instantonRate()

void eonc::tunneling::instantonRate ( RateInstanton & inst,
const RingBeadHessian & hessian,
const MatrixXd & hessReactant,
double vReactant,
const MatrixXd & hessSaddle = MatrixXd(),
double vSaddle = 0.0,
long rigidModes = 0,
long denseLimit = 4096,
const RingRigidBodies & rigidBodies = {} )

Fills the rate from the bead Hessians, the reactant minimum's Hessian and energy, and optionally the saddle's Hessian and energy for the classical comparison (pass an empty matrix to skip it).

rigidModes is the count of rigid-body zero modes to omit: the translations, plus a rotation only when the reactant Hessian leaves it null (a free cluster has them, a crystal does not, and an atom held fixed has none). They leave the centroid factors. The translational partition functions of reactant and instanton cancel; the rotational ones do not, since the ring's moments of inertia are not the reactant's. With rigidBodies given and a rotation free, k Z_r carries their ratio, logRotationalRatio of the beads (Richardson's moments averaged over the ring), and the classical comparison that of rigidBodies.saddle; without it both are left out. On the ring the omitted directions are its null vectors: with rigidBodies given, the translations and rotations of the beads themselves about the ring's centre of mass (a rotation moves each bead differently), otherwise the reactant Hessian's null vectors copied to every bead, which are exact only for a coordinate every bead shares. The bead Hessians must then keep their rotational part: projecting a rotation out of a bead that is not stationary removes the curvature that balances its springs.

Up to denseLimit ring degrees of freedom, and for any negative limit, the determinant, the negative-mode count and the lowest eigenvalue come from the dense eigenvalues of the lifted ring Hessian, and a block-chain determinant that disagrees with them throws. Beyond that, and for a limit of 0, the block chain gives the determinant and the inertia, and a Lanczos run on ring products the lowest eigenvalue.

Definition at line 4805 of file Tunneling.cpp.

4808 {
4809 const long N = static_cast<long>(inst.beads.size());
4810 if (N < 4 || !(inst.betaN > 0.0)) {
4811 throw std::invalid_argument("instantonRate: no optimised ring");
4812 }
4813 const long f = inst.beads.front().size();
4814 if (rigidModes < 0 || rigidModes > f) {
4815 throw std::invalid_argument(
4816 "instantonRate: rigidModes exceeds the degrees of freedom");
4817 }
4818 const double bnh = inst.betaN * kHbar;
4819 const double c = 1.0 / (bnh * bnh);
4820 const MatrixXd eye = MatrixXd::Identity(f, f);
4821 const std::vector<double> *linkWeight =
4822 inst.discretization.empty() ? nullptr : &inst.discretization;
4823
4824 std::vector<MatrixXd> hBead(static_cast<size_t>(N));
4825 for (long j = 0; j < N; ++j) {
4826 const MatrixXd h = hessian(j, inst.beads[static_cast<size_t>(j)]);
4827 if (h.rows() != f || h.cols() != f) {
4828 throw std::runtime_error("instantonRate: bead Hessian size");
4829 }
4830 const double hTolerance = 64.0 * std::numeric_limits<double>::epsilon() *
4831 f * h.cwiseAbs().maxCoeff();
4832 if (!h.allFinite() ||
4833 (h - h.transpose()).cwiseAbs().maxCoeff() > hTolerance) {
4834 throw std::runtime_error(
4835 "instantonRate: asymmetric physical bead Hessian");
4836 }
4837 hBead[static_cast<size_t>(j)] = 0.5 * (h + h.transpose());
4838 }
4839 const std::vector<MatrixXd> diag = ringDiagonal(hBead, c, false, linkWeight);
4840
4841 if (inst.physicalBath) {
4842 if (rigidModes || !inst.discretization.empty() || !inst.bathEta.empty())
4843 throw std::invalid_argument(
4844 "physical bath fluctuations require retained coordinates and uniform "
4845 "links without scalar friction");
4846 physicalBathFluctuations(inst, hBead, hessReactant, vReactant, c);
4847 return;
4848 }
4849
4850 if (hessReactant.rows() != f || hessReactant.cols() != f ||
4851 !hessReactant.allFinite()) {
4852 throw std::runtime_error("instantonRate: invalid reactant Hessian");
4853 }
4854 const double reactantTolerance = 64.0 *
4855 std::numeric_limits<double>::epsilon() * f *
4856 hessReactant.cwiseAbs().maxCoeff();
4857 if ((hessReactant - hessReactant.transpose()).cwiseAbs().maxCoeff() >
4858 reactantTolerance) {
4859 throw std::runtime_error("instantonRate: asymmetric reactant Hessian");
4860 }
4861 const Eigen::SelfAdjointEigenSolver<MatrixXd> er(
4862 0.5 * (hessReactant + hessReactant.transpose()));
4863 if (er.info() != Eigen::Success || !er.eigenvalues().allFinite()) {
4864 throw std::runtime_error("instantonRate: reactant eigensolver failed");
4865 }
4866 const VectorXd &lr = er.eigenvalues();
4867 const std::vector<bool> rigidR = nearestZero(lr, rigidModes);
4868 MatrixXd nullBasis(f, 0);
4869 // The rigid vectors leave the product whether or not every bead Hessian
4870 // annihilates them exactly; a finite-difference Hessian never does, and
4871 // the reactant side drops the same modes at k = 0.
4872 for (long m = 0; m < lr.size(); ++m) {
4873 if (!rigidR[static_cast<size_t>(m)]) {
4874 continue;
4875 }
4876 nullBasis.conservativeResize(f, nullBasis.cols() + 1);
4877 nullBasis.col(nullBasis.cols() - 1) = er.eigenvectors().col(m);
4878 }
4879 if (rigidModes >= f) {
4880 throw std::runtime_error("instantonRate: every direction is a rigid mode");
4881 }
4882 // det' through the block chain: the cyclic zero mode and the rigid null
4883 // vectors leave the product by the determinant lemma, the inertia comes
4884 // from the Schur complements, and the N f by N f matrix is never formed.
4885 std::vector<VectorXd> cycle = beadVelocities(inst.beads, linkWeight);
4886 const double cycleNorm = dot(cycle, cycle);
4887 if (!(cycleNorm > 0.0)) {
4888 throw std::runtime_error(
4889 "instantonRate: the beads coincide, so the ring has collapsed");
4890 }
4891 scale(cycle, 1.0 / std::sqrt(cycleNorm));
4892 // The rigid null vectors, orthonormal.
4893 std::vector<std::vector<VectorXd>> rigid;
4894 if (!rigidBodies.sqrtMasses.empty()) {
4895 // The ring's own rigid motions; the lemma needs an orthonormal basis of
4896 // the null space, not the generators themselves.
4897 rigid = ringRigidBasis(inst.beads, rigidBodies.sqrtMasses,
4898 rigidBodies.reference, rigidBodies.rotations);
4899 if (static_cast<long>(rigid.size()) != nullBasis.cols()) {
4900 throw std::runtime_error("instantonRate: the ring has " +
4901 std::to_string(rigid.size()) +
4902 " rigid motions and the reactant " +
4903 std::to_string(nullBasis.cols()));
4904 }
4905 } else {
4906 for (long r = 0; r < nullBasis.cols(); ++r) {
4907 rigid.emplace_back(
4908 static_cast<size_t>(N),
4909 (nullBasis.col(r) / std::sqrt(static_cast<double>(N))).eval());
4910 }
4911 }
4912 for (double eta : inst.bathEta) {
4913 if (!(eta >= 0.0) || !std::isfinite(eta)) {
4914 throw std::invalid_argument(
4915 "instantonRate: bath eta must be finite and nonnegative");
4916 }
4917 }
4918 const bool weightedLinks =
4919 std::any_of(inst.discretization.begin(), inst.discretization.end(),
4920 [](double weight) { return weight != 1.0; });
4921 if (weightedLinks || std::any_of(inst.bathEta.begin(), inst.bathEta.end(),
4922 [](double eta) { return eta > 0.0; })) {
4923 bathFluctuations(inst, hBead, rigid, lr, rigidR, vReactant, c);
4924 if (hessSaddle.size() > 0) {
4926 hessReactant, hessSaddle, inst.beta, vSaddle - vReactant, rigidModes);
4927 if (rigidBodies.saddle.size() > 0) {
4928 inst.classicalLogRate +=
4929 logRotationalRatio({rigidBodies.saddle}, rigidBodies);
4930 }
4931 inst.classicalRate = std::exp(inst.classicalLogRate) / kTimeUnitSeconds;
4932 }
4933 return;
4934 }
4935 auto offRigid = [&](std::vector<VectorXd> &v) {
4936 for (const auto &u : rigid) {
4937 const double o = dot(u, v);
4938 for (long j = 0; j < N; ++j) {
4939 v[static_cast<size_t>(j)] -= o * u[static_cast<size_t>(j)];
4940 }
4941 }
4942 const double vn = std::sqrt(dot(v, v));
4943 if (!(vn > 1e-8)) {
4944 throw std::runtime_error(
4945 "instantonRate: a rigid motion of the ring lies along its cycle");
4946 }
4947 scale(v, 1.0 / vn);
4948 };
4949 offRigid(cycle);
4950 const long nDrop = 1 + nullBasis.cols();
4951
4952 // On a discrete ring the time shift is only nearly a symmetry, so the
4953 // central difference tau is not quite the eigenvector of J's near-zero
4954 // eigenvalue, and lifting tau would leave out cos^2 of their angle
4955 // times that eigenvalue rather than the eigenvalue itself. Inverse
4956 // iteration with the rigid modes lifted finds the eigenvector; tau stays
4957 // when the iteration fails or wanders off it.
4958 {
4959 const std::vector<double> rigidKappas(rigid.size(), c);
4960 const WoodburyRing lifted(c, diag, true, rigid, rigidKappas, false,
4961 linkWeight);
4962 std::vector<VectorXd> v = cycle;
4963 bool good = lifted.ok();
4964 for (int it = 0; good && it < 12; ++it) {
4965 std::vector<VectorXd> x = lifted.solve(v);
4966 for (const auto &b : x) {
4967 good = good && b.allFinite();
4968 }
4969 if (!good) {
4970 break;
4971 }
4972 offRigid(x);
4973 const double change = 1.0 - std::abs(dot(x, v));
4974 v = std::move(x);
4975 if (change < 1e-15) {
4976 break;
4977 }
4978 }
4979 if (good && std::abs(dot(v, cycle)) > 0.9) {
4980 cycle = std::move(v);
4981 }
4982 }
4983 // Each omitted direction is lifted by a spring-sized curvature c, far
4984 // above any physical near-zero eigenvalue, and the lift comes off the
4985 // log-determinant again: det(J + c u u^T) = (c + lambda) det' J for u the
4986 // eigenvector of lambda.
4987 std::vector<std::vector<VectorXd>> dropped{cycle};
4988 std::vector<double> kappas{c};
4989 for (auto &u : rigid) {
4990 dropped.push_back(std::move(u));
4991 kappas.push_back(c);
4992 }
4993 const WoodburyRing ring(c, diag, true, dropped, kappas, true, linkWeight);
4994 if (!ring.ok() || !std::isfinite(ring.logAbsDet())) {
4995 throw std::runtime_error(
4996 "instantonRate: the ring Hessian is singular and the zero mode was "
4997 "not removed with the rigid modes");
4998 }
4999 const auto phaseProduct = applyDiagonal(diag, c, true, cycle, linkWeight);
5000 inst.zeroEigenvalue = dot(cycle, phaseProduct);
5001 double phaseResidualSquared = 0.0, phaseOperatorBound = 0.0;
5002 for (long j = 0; j < N; ++j) {
5003 phaseResidualSquared +=
5004 (phaseProduct[j] - inst.zeroEigenvalue * cycle[j]).squaredNorm();
5005 const double offDiagonal =
5006 linkWeight ? c / (*linkWeight)[j] + c / (*linkWeight)[(j + N - 1) % N]
5007 : 2.0 * c;
5008 phaseOperatorBound =
5009 std::max(phaseOperatorBound,
5010 diag[j].cwiseAbs().rowwise().sum().maxCoeff() + offDiagonal);
5011 }
5012 inst.phaseEigenResidual = std::sqrt(phaseResidualSquared);
5013 const double phaseRoundoff = 64.0 * std::numeric_limits<double>::epsilon() *
5014 N * f * phaseOperatorBound;
5015 inst.phaseZeroVerified = std::abs(inst.zeroEigenvalue) <= phaseRoundoff &&
5016 inst.phaseEigenResidual <= phaseRoundoff;
5017 inst.negativeModes = ring.negative();
5018 double logAbsDet = ring.logAbsDet();
5019 const long dim = N * f;
5020 if (denseLimit < 0 || dim <= denseLimit) {
5021 // The lifted ring Hessian, dense: its eigenvalues give the determinant,
5022 // the inertia and the lowest mode directly, and check the block chain.
5023 ColMajorXd full = ColMajorXd::Zero(dim, dim);
5024 for (long j = 0; j < N; ++j) {
5025 full.block(j * f, j * f, f, f) = diag[static_cast<size_t>(j)];
5026 const long k = (j + 1) % N;
5027 full.block(j * f, k * f, f, f) -= c * eye;
5028 full.block(k * f, j * f, f, f) -= c * eye;
5029 }
5030 for (size_t d = 0; d < dropped.size(); ++d) {
5031 VectorXd u(dim);
5032 for (long j = 0; j < N; ++j) {
5033 u.segment(j * f, f) = dropped[d][static_cast<size_t>(j)];
5034 }
5035 full += kappas[d] * u * u.transpose();
5036 }
5037 const Eigen::SelfAdjointEigenSolver<ColMajorXd> es(full,
5038 Eigen::EigenvaluesOnly);
5039 const VectorXd lam = es.eigenvalues();
5040 const double inertiaTol = 64.0 * std::numeric_limits<double>::epsilon() *
5041 dim * lam.cwiseAbs().maxCoeff();
5042 double dense = 0.0, scaleSum = 0.0;
5043 long negative = 0;
5044 for (long i = 0; i < dim; ++i) {
5045 const double l = std::abs(lam(i));
5046 dense += std::log(l);
5047 scaleSum += std::abs(std::log(l));
5048 negative += lam(i) < -inertiaTol ? 1 : 0;
5049 }
5050 if (!(std::abs(dense - logAbsDet) <= 1e-6 * std::max(1.0, scaleSum))) {
5051 throw std::runtime_error(
5052 "instantonRate: the block-chain determinant disagrees with the "
5053 "dense ring Hessian");
5054 }
5055 logAbsDet = dense;
5056 inst.negativeEigenvalue = std::min(0.0, lam(0));
5057 inst.negativeModes = negative;
5058 } else {
5059 // The lowest ring eigenvalue, for the report, from products alone.
5060 auto applyFull = [&](const std::vector<VectorXd> &vec) {
5061 return applyDiagonal(diag, c, true, vec, linkWeight);
5062 };
5063 const long steps = std::min(dim, static_cast<long>(60));
5064 std::vector<VectorXd> start = cycle;
5065 std::uint64_t h = 0x9E3779B97F4A7C15ULL;
5066 for (auto &bead : start) {
5067 for (long a2 = 0; a2 < bead.size(); ++a2) {
5068 h ^= h << 13;
5069 h ^= h >> 7;
5070 h ^= h << 17;
5071 bead(a2) += 0.1 * (static_cast<double>(h >> 11) * 0x1.0p-53 - 0.5);
5072 }
5073 }
5074 const std::vector<RingMode> modes =
5075 lowestRingModes(applyFull, std::move(start), steps);
5076 inst.negativeEigenvalue = 0.0;
5077 for (const auto &mode : modes) {
5078 if (mode.theta < inst.negativeEigenvalue &&
5079 std::abs(dot(mode.vector, cycle)) < 0.5) {
5080 inst.negativeEigenvalue = mode.theta;
5081 }
5082 }
5083 // Only resolved eigenpairs inside the matrix roundoff scale can
5084 // account for numerical zeros outside the declared lifted directions.
5085 double operatorBound = 2.0 * c;
5086 for (const auto &block : diag) {
5087 operatorBound = std::max(
5088 operatorBound, block.cwiseAbs().rowwise().sum().maxCoeff() + 2.0 * c);
5089 }
5090 const double inertiaTol =
5091 64.0 * std::numeric_limits<double>::epsilon() * dim * operatorBound;
5092 long numericalZeros = 0;
5093 for (const auto &mode : modes) {
5094 bool lifted = false;
5095 for (const auto &direction : dropped) {
5096 lifted = lifted || std::abs(dot(mode.vector, direction)) > 0.5;
5097 }
5098 if (!lifted && mode.theta < 0.0 && std::abs(mode.theta) <= inertiaTol &&
5099 mode.residual <= inertiaTol) {
5100 ++numericalZeros;
5101 }
5102 }
5103 inst.negativeModes = std::max(0L, inst.negativeModes - numericalZeros);
5104 }
5105 // Along an eigenvector the lift adds c to its eigenvalue, so it comes off
5106 // as c + lambda_0 for the cycle (lambda_0 is not zero on a discrete ring)
5107 // and as c for the exact rigid zeros.
5108 const double logDetPrime = logAbsDet -
5109 std::log(std::abs(c + inst.zeroEigenvalue)) -
5110 static_cast<double>(nDrop - 1) * std::log(c);
5111 const double logProd =
5112 static_cast<double>(N * f - nDrop) * std::log(bnh) + 0.5 * logDetPrime;
5113
5114 inst.logRateTimesZr = -std::log(bnh) +
5115 0.5 * std::log(inst.bN / (2.0 * std::numbers::pi *
5116 inst.betaN * kHbar * kHbar)) -
5117 logProd - inst.betaN * inst.ringPotential;
5118 inst.logRotationRatio = logRotationalRatio(inst.beads, rigidBodies);
5119 inst.logRateTimesZr += inst.logRotationRatio;
5120
5121 for (long m = 0; m < lr.size(); ++m) {
5122 if (!rigidR[static_cast<size_t>(m)] && !(lr(m) > 0.0)) {
5123 throw std::runtime_error(
5124 "instantonRate: the reactant Hessian is not positive definite");
5125 }
5126 }
5127 // The rigid modes leave the centroid (k = 0) factor, as the ring's own
5128 // rigid modes leave its product; both carry them as free particles for
5129 // k > 0.
5130 double logZr = -inst.beta * vReactant;
5131 for (long k = 0; k < N; ++k) {
5132 const double sk = std::sin(std::numbers::pi * static_cast<double>(k) /
5133 static_cast<double>(N));
5134 for (long m = 0; m < lr.size(); ++m) {
5135 if (k == 0 && rigidR[static_cast<size_t>(m)]) {
5136 continue;
5137 }
5138 const double l = rigidR[static_cast<size_t>(m)] ? 0.0 : lr(m);
5139 logZr -= std::log(bnh) + 0.5 * std::log(l + 4.0 * c * sk * sk);
5140 }
5141 }
5142 inst.logZr = logZr;
5143 inst.rateValid = inst.converged && inst.negativeModes == 1;
5144 inst.rateValidity = !inst.converged
5145 ? "unconverged_ring"
5146 : (inst.negativeModes == 1 ? "collective_coordinate"
5147 : "non_index_one_ring");
5148 inst.logRate = inst.logRateTimesZr - logZr;
5149 inst.rate = std::exp(inst.logRate) / kTimeUnitSeconds;
5150 inst.effectiveBarrier =
5151 -std::log(2.0 * std::numbers::pi * kHbar * inst.beta) / inst.beta -
5152 inst.logRate / inst.beta;
5153 // An unconverged index-one input retains its numerical prefactor
5154 // diagnostic; rateValid prevents its use as a stationary physical rate.
5155 if (inst.negativeModes != 1) {
5156 const double invalid = std::numeric_limits<double>::quiet_NaN();
5157 inst.logRateTimesZr = inst.logRate = inst.rate = inst.effectiveBarrier =
5158 invalid;
5159 }
5160
5161 if (hessSaddle.size() > 0) {
5163 hessReactant, hessSaddle, inst.beta, vSaddle - vReactant, rigidModes);
5164 if (rigidBodies.saddle.size() > 0) {
5165 inst.classicalLogRate +=
5166 logRotationalRatio({rigidBodies.saddle}, rigidBodies);
5167 }
5168 inst.classicalRate = std::exp(inst.classicalLogRate) / kTimeUnitSeconds;
5169 }
5170}
double squaredNorm(const Eigen::MatrixBase< A > &x)
double dot(const double *x, const double *y, std::size_t n)
Round-to-nearest-even value of the exact sum of x[i] * y[i].
double sum(const double *x, std::size_t n)
Round-to-nearest-even value of the exact sum of x[i].
constexpr double kTimeUnitSeconds
One unit of time, sqrt(amu Angstrom^2 / eV), in seconds.
Definition Tunneling.h:350
double logRotationalRatio(const std::vector< VectorXd > &beads, const RingRigidBodies &bodies)
ln of the classical rotational partition function of beads over that of as many copies of the referen...
double harmonicTstLogRate(const MatrixXd &hessReactant, const MatrixXd &hessSaddle, double beta, double barrier, long rigidModes)
ln(k) for classical harmonic transition-state theory, k in 1/time.
long negativeModes
eigenvalues below the zero mode
Definition Tunneling.h:524
double zeroEigenvalue
the eigenvalue left out
Definition Tunneling.h:523
bool rateValid
A physical rate requires a converged index-one stationary ring.
Definition Tunneling.h:519
double beta
1 / (kB T), 1 / eV
Definition Tunneling.h:497
std::shared_ptr< const PhysicalQuadraticBath > physicalBath
Definition Tunneling.h:494
std::vector< double > discretization
Empty keeps every spring equal. Otherwise one positive weight per bead.
Definition Tunneling.h:504
double bN
sum_j |q_{j+1} - q_j|^2, amu Angstrom^2
Definition Tunneling.h:502
std::vector< double > bathEta
Resolved fixed bath coefficients: empty, one value or one per bead.
Definition Tunneling.h:506
double logRotationRatio
ln of the ring's rotational partition function over the reactant's, included in logRateTimesZr; zero ...
Definition Tunneling.h:534
double logRate
ln k, k in 1 / time
Definition Tunneling.h:536
std::vector< VectorXd > beads
N beads, q_N = q_0 implied.
Definition Tunneling.h:495
double classicalRate
Classical harmonic transition-state theory at the same T, 1 / s, when the saddle Hessian was given; i...
Definition Tunneling.h:543
double logRateTimesZr
ln(k Z_r), k in 1 / time
Definition Tunneling.h:531
double negativeEigenvalue
of the ring Hessian, 1 / time^2
Definition Tunneling.h:522
double effectiveBarrier
-kB T ln(2 pi hbar beta k): the barrier an Eyring rate would need, eV.
Definition Tunneling.h:539
std::array< bool, 3 > rotations
Definition Tunneling.h:627
std::vector< double > sqrtMasses
Definition Tunneling.h:625

◆ instantonSplitting()

void eonc::tunneling::instantonSplitting ( Instanton & inst,
const BeadHessian & hessian,
const MatrixXd & hessStart,
const MatrixXd & hessEnd )

Fills delta0, zeroMode and modeSeparation from the bead Hessians and the Hessians of the two minima.

Definition at line 1180 of file Tunneling.cpp.

1181 {
1182 const long P = static_cast<long>(inst.path.size()) - 1;
1183 if (P < 4 || !(inst.dtau > 0.0)) {
1184 throw std::invalid_argument("instantonSplitting: no optimised path");
1185 }
1186 const double dtau = inst.dtau;
1187 const double c = 1.0 / dtau;
1188 const long n = inst.path.front().size();
1189 const MatrixXd spring = 2.0 * c * MatrixXd::Identity(n, n);
1190
1191 std::vector<MatrixXd> diag;
1192 diag.reserve(static_cast<size_t>(P - 1));
1193 for (long j = 1; j < P; ++j) {
1194 const MatrixXd h = hessian(j, inst.path[static_cast<size_t>(j)]);
1195 if (h.rows() != n || h.cols() != n) {
1196 throw std::runtime_error("instantonSplitting: bead Hessian size");
1197 }
1198 diag.push_back(spring + dtau * 0.5 * (h + h.transpose()));
1199 }
1200 // The inertia comes from the Schur blocks (Haynsworth), so a path with
1201 // two negative modes is not mistaken for a minimum by the determinant's
1202 // sign.
1203 const HaynsworthChain chain(c, diag, true);
1204
1205 auto wellLogDet = [&](const MatrixXd &h) {
1206 const std::vector<MatrixXd> d(static_cast<size_t>(P - 1),
1207 spring + dtau * 0.5 * (h + h.transpose()));
1208 const HaynsworthChain well(c, d, true);
1209 if (well.negative() > 0) {
1210 throw std::runtime_error(
1211 "instantonSplitting: a well Hessian is not positive definite");
1212 }
1213 return well.logAbsDet();
1214 };
1215 const double logDetWell = 0.5 * (wellLogDet(hessStart) + wellLogDet(hessEnd));
1216
1217 // The zero mode is the kink's translation in imaginary time, along the
1218 // discrete velocity v; det' J = det J (v^T J^-1 v) for v its eigenvector.
1219 std::vector<VectorXd> v(static_cast<size_t>(P - 1));
1220 for (long j = 1; j < P; ++j) {
1221 v[static_cast<size_t>(j - 1)] = inst.path[static_cast<size_t>(j + 1)] -
1222 inst.path[static_cast<size_t>(j - 1)];
1223 }
1224 scale(v, 1.0 / std::sqrt(dot(v, v)));
1225 const double vJv = dot(v, chain.solve(v));
1226 // A zero mode just below zero is one negative eigenvalue the prime
1227 // leaves out; any other negative eigenvalue is a second unstable mode.
1228 if (chain.negative() - (vJv < 0.0 ? 1 : 0) != 0) {
1229 throw std::runtime_error(
1230 "instantonSplitting: the path is not a minimum of the action "
1231 "(a negative mode besides the kink's translation)");
1232 }
1233 inst.zeroMode = 1.0 / vJv;
1234 const double logDetPrime = chain.logAbsDet() + std::log(std::abs(vJv));
1235
1236 // Next eigenvalue: inverse iteration orthogonal to v.
1237 std::vector<VectorXd> w(v.size());
1238 for (size_t k = 0; k < w.size(); ++k) {
1239 w[k].resize(n);
1240 for (long i = 0; i < n; ++i) {
1241 w[k](i) = std::sin(0.7 * static_cast<double>(k) +
1242 1.3 * static_cast<double>(i) + 0.1);
1243 }
1244 }
1245 double lambda1 = 0.0;
1246 for (int it = 0; it < 40; ++it) {
1247 const double proj = dot(v, w);
1248 for (size_t k = 0; k < w.size(); ++k) {
1249 w[k] -= proj * v[k];
1250 }
1251 scale(w, 1.0 / std::sqrt(dot(w, w)));
1252 std::vector<VectorXd> z = chain.solve(w);
1253 lambda1 = 1.0 / dot(w, z);
1254 w = std::move(z);
1255 }
1256 inst.modeSeparation = std::abs(lambda1 / inst.zeroMode);
1257
1258 inst.delta0 = 2.0 * kHbar *
1259 std::sqrt(inst.s0 / (2.0 * std::numbers::pi * kHbar * dtau)) *
1260 std::exp(0.5 * (logDetWell - logDetPrime) - inst.action);
1261}
double zeroMode
the eigenvalue det' leaves out
Definition Tunneling.h:257
double action
(S - S_well) / hbar
Definition Tunneling.h:255
double s0
integral of |dq/dtau|^2 dtau
Definition Tunneling.h:256
double modeSeparation
The second smallest eigenvalue of J over the zero mode's: small means the kink is not isolated in ima...
Definition Tunneling.h:267
double dtau
betaHbar / P
Definition Tunneling.h:254
double delta0
tunnelling splitting, eV
Definition Tunneling.h:258
std::vector< VectorXd > path
P + 1 beads, ends at the minima.
Definition Tunneling.h:251

◆ logRotationalRatio()

double eonc::tunneling::logRotationalRatio ( const std::vector< VectorXd > & beads,
const RingRigidBodies & bodies )

ln of the classical rotational partition function of beads over that of as many copies of the reference (q = 0), for the free rotations: half the log of the ratio of the products of their principal moments, the inertia of every bead's atoms about the beads' common centre of mass, which is the Gram matrix of the ring's rotation generators.

Moments below 1e-8 of the largest (a linear structure's axis) leave both products. Zero with empty masses or no free rotation; throws when the beads and the reference turn about different numbers of axes. With one bead it is the saddle's ratio sqrt(det I_saddle / det I_reactant) of harmonic TST for a free cluster.

Definition at line 4397 of file Tunneling.cpp.

4398 {
4399 const long nAtoms = static_cast<long>(bodies.sqrtMasses.size());
4400 const bool anyFree =
4401 bodies.rotations[0] || bodies.rotations[1] || bodies.rotations[2];
4402 if (nAtoms == 0 || !anyFree || beads.empty()) {
4403 return 0.0;
4404 }
4405 if (bodies.reference.size() != 3 * nAtoms) {
4406 throw std::invalid_argument(
4407 "logRotationalRatio: the reference needs three coordinates per atom");
4408 }
4409 for (const auto &q : beads) {
4410 if (q.size() != 3 * nAtoms) {
4411 throw std::invalid_argument(
4412 "logRotationalRatio: a bead needs three coordinates per atom");
4413 }
4414 }
4415 const std::vector<double> ring = rotationMoments(beads, bodies);
4416 const std::vector<double> reactant = rotationMoments(
4417 std::vector<VectorXd>(beads.size(), VectorXd::Zero(3 * nAtoms)), bodies);
4418 if (ring.size() != reactant.size()) {
4419 throw std::runtime_error("logRotationalRatio: the beads turn about " +
4420 std::to_string(ring.size()) +
4421 " axes and the reactant about " +
4422 std::to_string(reactant.size()));
4423 }
4424 double out = 0.0;
4425 for (size_t i = 0; i < ring.size(); ++i) {
4426 out += 0.5 * (std::log(ring[i]) - std::log(reactant[i]));
4427 }
4428 return out;
4429}
constexpr long reactant

◆ massWeightedDistance()

double eonc::tunneling::massWeightedDistance ( const Matter & a,
const Matter & b )

sqrt(sum_i m_i |b_i - a_i|^2) under the minimum image of a's cell.

Definition at line 61 of file Tunneling.cpp.

61 {
62 if (a.numberOfAtoms() != b.numberOfAtoms()) {
63 throw std::invalid_argument("the structures hold different atom counts");
64 }
65 const AtomMatrix dr = a.pbc(b.getPositions() - a.getPositions());
66 const auto mass = a.getMasses();
67 double sum = 0.0;
68 for (long i = 0; i < a.numberOfAtoms(); ++i) {
69 if (mass(i) <= 0.0) {
70 throw std::invalid_argument(
71 "every atom needs a positive mass for a mass-weighted path");
72 }
73 sum += mass(i) * dr.row(i).squaredNorm();
74 }
75 return std::sqrt(sum);
76}

◆ massWeightedPath()

std::vector< double > eonc::tunneling::massWeightedPath ( const std::vector< std::shared_ptr< Matter > > & band)

Cumulative mass-weighted arc length at each image of a band.

Definition at line 79 of file Tunneling.cpp.

79 {
80 std::vector<double> s{0.0};
81 s.reserve(band.size());
82 for (size_t i = 1; i < band.size(); ++i) {
83 s.push_back(s.back() + massWeightedDistance(*band[i - 1], *band[i]));
84 }
85 return s;
86}
double massWeightedDistance(const Matter &a, const Matter &b)
sqrt(sum_i m_i |b_i - a_i|^2) under the minimum image of a's cell.
Definition Tunneling.cpp:61

◆ optimizeInstanton()

Instanton eonc::tunneling::optimizeInstanton ( const VectorXd & start,
const VectorXd & end,
double betaHbar,
std::vector< VectorXd > guess,
const BatchPotential & potential,
const InstantonOptions & options )

Minimises the action from guess (P + 1 beads, ends at the minima, or empty for a tanh kink along the straight line).

Evaluates the interior beads once per iteration and line-search step.

Definition at line 1032 of file Tunneling.cpp.

1035 {
1036 const long P = options.beads;
1037 if (P < 4 || !(betaHbar > 0.0) || start.size() != end.size()) {
1038 throw std::invalid_argument("optimizeInstanton: need P >= 4, beta hbar > 0 "
1039 "and ends of one dimension");
1040 }
1041 Instanton inst;
1042 inst.betaHbar = betaHbar;
1043 inst.dtau = betaHbar / static_cast<double>(P);
1044 const double dtau = inst.dtau;
1045
1046 std::vector<double> vEnds;
1047 std::vector<VectorXd> gEnds;
1048 potential({start, end}, vEnds, gEnds);
1049 if (vEnds.size() != 2) {
1050 throw std::runtime_error("instanton: potential returned the wrong count");
1051 }
1052 inst.asymmetry = vEnds[1] - vEnds[0];
1053
1054 // Beads along the guess (or the straight line) on a tanh kink centred at
1055 // beta hbar / 2 whose width follows the harmonic decay of a well.
1056 if (guess.size() < 2) {
1057 guess = {start, end};
1058 }
1059 std::vector<double> cum(guess.size(), 0.0);
1060 for (size_t k = 1; k < guess.size(); ++k) {
1061 cum[k] = cum[k - 1] + (guess[k] - guess[k - 1]).norm();
1062 }
1063 if (!(cum.back() > 0.0)) {
1064 throw std::invalid_argument("optimizeInstanton: the two minima coincide");
1065 }
1066 const double width = betaHbar / (2.0 * options.betaHbarOmega);
1067 std::vector<VectorXd> x(static_cast<size_t>(P - 1));
1068 for (long j = 1; j < P; ++j) {
1069 const double tau = static_cast<double>(j) * dtau - 0.5 * betaHbar;
1070 const double f = 0.5 * (1.0 + std::tanh(tau / width));
1071 x[static_cast<size_t>(j - 1)] = alongPolyline(guess, cum, f);
1072 }
1073
1074 // L-BFGS with a backtracking Armijo line search.
1075 ActionEval cur =
1076 evaluateAction(x, start, end, vEnds[0], vEnds[1], dtau, potential);
1077 std::deque<std::pair<std::vector<VectorXd>, std::vector<VectorXd>>> pairs;
1078 for (long it = 0; it < options.maxIterations; ++it) {
1079 inst.iterations = it;
1080 if (largestBeadNorm(cur.grad) / dtau < options.forceTolerance) {
1081 inst.converged = true;
1082 break;
1083 }
1084 std::vector<VectorXd> q = cur.grad;
1085 std::vector<double> alpha(pairs.size());
1086 for (size_t i = pairs.size(); i-- > 0;) {
1087 const double rho = 1.0 / dot(pairs[i].second, pairs[i].first);
1088 alpha[i] = rho * dot(pairs[i].first, q);
1089 for (size_t k = 0; k < q.size(); ++k) {
1090 q[k] -= alpha[i] * pairs[i].second[k];
1091 }
1092 }
1093 // Without history, half the inverse spring stiffness 2 / dtau.
1094 double gamma = dtau / 4.0;
1095 if (!pairs.empty()) {
1096 gamma = dot(pairs.back().first, pairs.back().second) /
1097 dot(pairs.back().second, pairs.back().second);
1098 }
1099 scale(q, gamma);
1100 for (size_t i = 0; i < pairs.size(); ++i) {
1101 const double rho = 1.0 / dot(pairs[i].second, pairs[i].first);
1102 const double beta = rho * dot(pairs[i].second, q);
1103 for (size_t k = 0; k < q.size(); ++k) {
1104 q[k] += (alpha[i] - beta) * pairs[i].first[k];
1105 }
1106 }
1107 // q is now the inverse-Hessian estimate times the gradient; step -q.
1108 double slope = -dot(cur.grad, q);
1109 if (!(slope < 0.0)) {
1110 pairs.clear();
1111 q = cur.grad;
1112 scale(q, dtau / 4.0);
1113 slope = -dot(cur.grad, q);
1114 }
1115 double step = 1.0;
1116 ActionEval next;
1117 std::vector<VectorXd> trial(x.size());
1118 bool accepted = false;
1119 for (int ls = 0; ls < 30; ++ls) {
1120 for (size_t k = 0; k < x.size(); ++k) {
1121 trial[k] = x[k] - step * q[k];
1122 }
1123 next = evaluateAction(trial, start, end, vEnds[0], vEnds[1], dtau,
1124 potential);
1125 // Near the minimum the action changes by less than its round-off;
1126 // there a step that shrinks the gradient is progress too.
1127 const bool armijo = next.action <= cur.action + 1e-4 * step * slope;
1128 const bool flat = std::abs(next.action - cur.action) <=
1129 1e-13 * std::max(1.0, std::abs(cur.action));
1130 if (armijo ||
1131 (flat && largestBeadNorm(next.grad) < largestBeadNorm(cur.grad))) {
1132 accepted = true;
1133 break;
1134 }
1135 step *= 0.5;
1136 }
1137 if (!accepted) {
1138 break;
1139 }
1140 std::vector<VectorXd> sk(x.size()), yk(x.size());
1141 for (size_t k = 0; k < x.size(); ++k) {
1142 sk[k] = trial[k] - x[k];
1143 yk[k] = next.grad[k] - cur.grad[k];
1144 }
1145 if (dot(sk, yk) > 0.0) {
1146 pairs.emplace_back(std::move(sk), std::move(yk));
1147 if (static_cast<long>(pairs.size()) > options.memory) {
1148 pairs.pop_front();
1149 }
1150 }
1151 x = std::move(trial);
1152 cur = std::move(next);
1153 }
1154 if (!inst.converged &&
1155 largestBeadNorm(cur.grad) / dtau < options.forceTolerance) {
1156 inst.converged = true;
1157 }
1158
1159 inst.path.reserve(static_cast<size_t>(P + 1));
1160 inst.path.push_back(start);
1161 inst.path.insert(inst.path.end(), x.begin(), x.end());
1162 inst.path.push_back(end);
1163 inst.energies.reserve(static_cast<size_t>(P + 1));
1164 inst.energies.push_back(vEnds[0]);
1165 inst.energies.insert(inst.energies.end(), cur.v.begin(), cur.v.end());
1166 inst.energies.push_back(vEnds[1]);
1167 const double sWell = betaHbar * 0.5 * (vEnds[0] + vEnds[1]);
1168 inst.action = (cur.action - sWell) / kHbar;
1169 double s0 = 0.0;
1170 for (long j = 0; j < P; ++j) {
1171 s0 += (inst.path[static_cast<size_t>(j + 1)] -
1172 inst.path[static_cast<size_t>(j)])
1173 .squaredNorm();
1174 }
1175 inst.s0 = s0 / dtau;
1176 inst.symmetricEnough = std::abs(inst.asymmetry) * betaHbar / kHbar < 0.1;
1177 return inst;
1178}
double norm(const Eigen::MatrixBase< A > &x)
sqrt of the correctly rounded squared norm; IEEE sqrt is itself correctly rounded,...
long maxIterations
L-BFGS iterations.
Definition Tunneling.h:230
double forceTolerance
largest per-bead |dS/dq| / dtau, eV / (amu^0.5 Angstrom)
Definition Tunneling.h:231
long beads
P: segments from one minimum to the other.
Definition Tunneling.h:227
long memory
L-BFGS correction pairs.
Definition Tunneling.h:233
double betaHbarOmega
beta hbar omega of the stiffer end along the path; sets the imaginary time
Definition Tunneling.h:228

◆ optimizeRateInstanton()

RateInstanton eonc::tunneling::optimizeRateInstanton ( const VectorXd & saddle,
const MatrixXd & hessSaddle,
double beta,
std::vector< VectorXd > guess,
const BatchPotential & potential,
const RateInstantonOptions & options )

Finds the rate instanton at inverse temperature beta (1 / eV).

guess holds N beads, or is empty for a ring stretched along the saddle's unstable mode to where V has dropped by (1 - T / T_c) of the lower of the two barriers. At or below newtonLimit active coordinates the step is an index-1 Newton step on a Bofill Hessian, and below 0.75 T_c an empty guess cools from 0.85 T_c. Beyond that limit the step is the dimer in MinModeSaddleSearch on one ring structure. An even ring whose beads match under j -> N - j is evaluated from one turning point to the other and mirrored. saddle and hessSaddle are mass-weighted.

Definition at line 4151 of file Tunneling.cpp.

4155 {
4156 if (request.physicalBath) {
4157 request.physicalBath->validate(saddle.size());
4158 if (request.friction || !request.discretization.empty() ||
4159 !request.rigidSqrtMasses.empty())
4160 throw std::invalid_argument(
4161 "physical quadratic bath requires uniform links and a retained "
4162 "coordinate basis without rigid generators");
4163 }
4164 if (!(request.physicalHessianStep > 0.0) ||
4165 !std::isfinite(request.physicalHessianStep)) {
4166 throw std::invalid_argument("optimizeRateInstanton: physicalHessianStep "
4167 "must be finite and positive "
4168 "in sqrt(amu) Angstrom");
4169 }
4170 const long N = request.beads;
4171 if (N < 4 || !(beta > 0.0) || hessSaddle.rows() != saddle.size()) {
4172 throw std::invalid_argument(
4173 "optimizeRateInstanton: need N >= 4, beta > 0 and a saddle Hessian "
4174 "of the saddle's dimension");
4175 }
4176 RateInstantonOptions options = request;
4177 // A friction bath couples every bead to every other, which the Newton
4178 // step's block-tridiagonal model cannot hold; the dimer needs gradients
4179 // only, and the rate takes the bath's curvature from the dense ring.
4180 const std::vector<double> bath = frictionEta(options, N);
4181 if (!bath.empty() && !options.discretization.empty()) {
4182 throw std::invalid_argument(
4183 "optimizeRateInstanton: the friction bath's frequencies are those of "
4184 "the uniform ring, so it takes no link weights");
4185 }
4186 RateInstanton inst;
4187 inst.physicalBath = options.physicalBath;
4188 inst.discretization = options.discretization;
4189 inst.bathEta = frictionEta(options, options.beads);
4190 inst.beta = beta;
4191 inst.betaN = beta / static_cast<double>(N);
4192 inst.temperature = 1.0 / (kBoltzmann * beta);
4193 inst.crossover = crossoverTemperature(
4194 options.physicalBath
4195 ? MatrixXd(options.physicalBath->fullHessian(saddle, hessSaddle))
4196 : hessSaddle);
4197 if (!(inst.temperature < inst.crossover)) {
4198 throw std::invalid_argument(
4199 "optimizeRateInstanton: T is at or above the crossover temperature; "
4200 "the ring collapses onto the saddle and steepest descent needs the "
4201 "parabolic barrier correction, of which classical transition-state "
4202 "theory is only the one-bead limit");
4203 }
4204 bool mirror = options.halfRing && options.discretization.empty() &&
4205 !options.friction && !options.physicalBath && N % 2 == 0;
4206 if (mirror && static_cast<long>(guess.size()) == N) {
4207 const long mid = N / 2;
4208 for (long j = 1; j < mid && mirror; ++j) {
4209 if ((guess[static_cast<size_t>(j)] - guess[static_cast<size_t>(N - j)])
4210 .norm() > 1e-8) {
4211 mirror = false;
4212 }
4213 }
4214 }
4215 const long active = mirror ? (N / 2 + 1) : N;
4216 // The nonlocal bath uses the dense Newton operator. Larger rings
4217 // use the dimer backend, whose products include the complete bath.
4218 const bool denseBath =
4219 options.physicalBath || !frictionEta(options, N).empty();
4220 if (options.newtonLimit > 0 &&
4221 active * saddle.size() <= options.newtonLimit &&
4222 (!denseBath || active * saddle.size() <= kDenseRing)) {
4223 return optimizeRateByNewton(saddle, hessSaddle, beta, std::move(guess),
4224 potential, options);
4225 }
4226 if (!options.discretization.empty()) {
4227 throw std::invalid_argument(
4228 "optimizeRateInstanton: link weights take the Newton search; "
4229 "minimum-mode following keeps the uniform ring");
4230 }
4231 const double bnh = inst.betaN * kHbar;
4232 const double c = 1.0 / (bnh * bnh);
4233
4234 const ColMajorXd saddleCurvature = physicalStaticCurvature(
4235 0.5 * (hessSaddle + hessSaddle.transpose()), saddle, options);
4236 const Eigen::SelfAdjointEigenSolver<ColMajorXd> es(saddleCurvature);
4237 const VectorXd dir = es.eigenvectors().col(0);
4238
4239 if (static_cast<long>(guess.size()) != N) {
4240 std::vector<double> v0;
4241 std::vector<VectorXd> g0;
4242 potential({saddle}, v0, g0);
4243 const double vS = v0.at(0);
4244 // Scan in steps of a quarter of the length over which the barrier's
4245 // curvature drops V by kB T_c.
4246 const double h = 0.25 * std::sqrt(2.0 * kBoltzmann * inst.crossover /
4247 -es.eigenvalues()(0));
4248 const long pts = 200;
4249 const double dPlus = sideDrop(saddle, dir, vS, 1.0, h, pts, potential);
4250 const double dMinus = sideDrop(saddle, dir, vS, -1.0, h, pts, potential);
4251 const double dMin = std::min(dPlus, dMinus);
4252 const double drop =
4253 (1.0 - inst.temperature / inst.crossover) *
4254 (std::isfinite(dMin) ? dMin : kBoltzmann * inst.crossover);
4255 const double sPlus =
4256 turningDistance(saddle, dir, vS, drop, 1.0, h, pts, potential);
4257 const double sMinus =
4258 turningDistance(saddle, dir, vS, drop, -1.0, h, pts, potential);
4259 guess.resize(static_cast<size_t>(N));
4260 for (long j = 0; j < N; ++j) {
4261 const double ct =
4262 std::cos(2.0 * std::numbers::pi * static_cast<double>(j) /
4263 static_cast<double>(N));
4264 guess[static_cast<size_t>(j)] =
4265 saddle + dir * (ct >= 0.0 ? sPlus * ct : sMinus * ct);
4266 }
4267 }
4268
4269 // An even count whose beads already match under j -> N-j is the
4270 // out-and-back instanton. The shared dimer sees one half of that ring.
4271 const bool wantMirror = options.halfRing && !options.friction &&
4272 !options.physicalBath &&
4273 options.discretization.empty() && N % 2 == 0;
4274 std::vector<VectorXd> x = std::move(guess);
4275 bool fold = false;
4276 if (wantMirror) {
4277 fold = true;
4278 const long m = N / 2;
4279 for (long j = 1; j < m; ++j) {
4280 if ((x[static_cast<size_t>(j)] - x[static_cast<size_t>(N - j)]).norm() >
4281 1e-8) {
4282 fold = false;
4283 break;
4284 }
4285 }
4286 }
4287 if (fold) {
4288 const long m = N / 2;
4289 for (long j = 1; j < m; ++j) {
4290 const size_t a = static_cast<size_t>(j);
4291 const size_t b = static_cast<size_t>(N - j);
4292 const VectorXd mid = 0.5 * (x[a] + x[b]);
4293 x[a] = mid;
4294 x[b] = mid;
4295 }
4296 projectMonotonePrefix(x, m, dir);
4297 for (long j = 1; j < m; ++j) {
4298 x[static_cast<size_t>(N - j)] = x[static_cast<size_t>(j)];
4299 }
4300 }
4301 const double barrierCurvature = std::abs(es.eigenvalues()(0));
4302 const SearchedRing found =
4303 searchRingWithDimer(std::move(x), c, potential, options, dir, fold,
4304 inst.betaN, barrierCurvature);
4305 inst.beads = found.beads;
4306 inst.energies = found.energies;
4307 inst.ringPotential = found.ringPotential;
4308 inst.bN = found.bN;
4309 inst.iterations = found.iterations;
4310 inst.converged = found.converged;
4311 return inst;
4312}
constexpr long saddle
double crossoverTemperature(const MatrixXd &hessSaddle)
T_c = hbar omega_b / (2 pi kB) from the mass-weighted Hessian at the saddle, in K; throws when the He...

◆ parabolicFactor()

double eonc::tunneling::parabolicFactor ( double temperature,
double crossover )

(pi T_c / T) / sin(pi T_c / T).

Defined only above T_c. The factor diverges as T approaches T_c from above and tends to 1 at high T.

Definition at line 5261 of file Tunneling.cpp.

5261 {
5262 if (!(temperature > 0.0) || !(crossover > 0.0)) {
5263 throw std::invalid_argument(
5264 "parabolicFactor: temperature and crossover must be positive");
5265 }
5266 if (!(temperature > crossover)) {
5267 throw std::invalid_argument(
5268 "parabolicFactor: T is at or below the crossover; the factor "
5269 "diverges there");
5270 }
5271 // beta hbar omega_b / 2 = pi T_c / T, since T_c = hbar omega_b / (2 pi kB).
5272 const double phase = std::numbers::pi * crossover / temperature;
5273 const double s = std::sin(phase);
5274 if (!(s > 0.0)) {
5275 throw std::invalid_argument(
5276 "parabolicFactor: the sine of the barrier phase is not positive");
5277 }
5278 return phase / s;
5279}

◆ pathOmega()

double eonc::tunneling::pathOmega ( const MatrixXd & hessStart,
const MatrixXd & hessEnd,
const VectorXd & start,
const VectorXd & end )

omega along the straight line between the minima from the curvature of each well there, the larger of the two; in 1 / time.

Definition at line 1021 of file Tunneling.cpp.

1022 {
1023 const VectorXd d = (end - start).normalized();
1024 const double k = std::max(d.dot(hessStart * d), d.dot(hessEnd * d));
1025 if (!(k > 0.0)) {
1026 throw std::invalid_argument(
1027 "pathOmega: no positive curvature along the path at either minimum");
1028 }
1029 return std::sqrt(k);
1030}

◆ quantumHarmonicTstLogRate()

double eonc::tunneling::quantumHarmonicTstLogRate ( const MatrixXd & hessReactant,
const MatrixXd & hessSaddle,
double beta,
double barrier,
long rigidModes )

ln(k) for quantum harmonic transition-state theory, k in 1/time: (1 / (2 pi beta hbar)) prod_r 2 sinh(beta hbar omega_r / 2) / prod'_s 2 sinh(beta hbar omega_s / 2) exp(-beta barrier), the zero-point and quantised partition functions of every bound mode; the saddle's unstable mode leaves the product.

Times the parabolic factor it is the steepest-descent ring-polymer rate above T_c as N -> infinity. That factor diverges at T_c, as the instanton's fluctuation prefactor does from below, so neither rate holds near the crossover and the two do not join there. Its high-temperature limit is harmonicTstLogRate. Checks the Hessians as harmonicTstLogRate does.

Definition at line 5375 of file Tunneling.cpp.

5377 {
5378 const HarmonicSpectrum spectrum =
5379 harmonicSpectrum(hessReactant, hessSaddle, beta, barrier, rigidModes);
5380 const VectorXd &lr = spectrum.reactant;
5381 const VectorXd &ls = spectrum.saddle;
5382 const double bh = beta * kHbar;
5383 if (!(bh > 0.0) || !std::isfinite(bh)) {
5384 throw std::overflow_error(
5385 "harmonic TST: beta hbar is not finite and positive");
5386 }
5387 // ln(2 sinh(x / 2)) without overflow for large x, and without the
5388 // cancellation of 1 - exp(-x) for small x.
5389 auto logTwoSinhHalf = [bh](double omega) {
5390 if (omega > 1.0 && bh > std::numeric_limits<double>::max() / omega) {
5391 throw std::overflow_error("harmonic TST: beta hbar omega overflows");
5392 }
5393 const double x = bh * omega;
5394 if (!(x > 0.0)) {
5395 throw std::underflow_error("harmonic TST: beta hbar omega underflows");
5396 }
5397 return 0.5 * x + std::log(-std::expm1(-x));
5398 };
5399 double logRatio = 0.0;
5400 for (long m = 0; m < lr.size(); ++m) {
5401 if (!spectrum.rigidReactant[static_cast<size_t>(m)]) {
5402 logRatio += logTwoSinhHalf(std::sqrt(lr(m)));
5403 }
5404 }
5405 for (long m = 1; m < ls.size(); ++m) {
5406 if (!spectrum.rigidSaddle[static_cast<size_t>(m)]) {
5407 logRatio -= logTwoSinhHalf(std::sqrt(ls(m)));
5408 }
5409 }
5410 return finiteHarmonicLogRate(logRatio - std::log(2.0 * std::numbers::pi) -
5411 std::log(bh) - beta * barrier);
5412}

◆ readRateRingSeed()

std::vector< AtomMatrix > eonc::tunneling::readRateRingSeed ( const std::string & filename,
const Matter & reference,
long beads )
inline

Read closed-ring geometry on the reference's ordered physical coordinates.

Cached energies and forces do not participate in the seed.

Definition at line 20 of file RateRingSeed.h.

22 {
23 const auto frames = readcon::read_all_frames(filename);
24 if (beads < 4 || frames.size() != static_cast<size_t>(beads)) {
25 throw std::invalid_argument(
26 "instanton: initial_ring must contain exactly beads frames, without "
27 "a repeated closing frame");
28 }
29 std::vector<AtomMatrix> positions;
30 positions.reserve(frames.size());
31 for (const auto &frame : frames) {
32 Matter image(reference);
33 if (!io::io_ok(io::con2matter(image, frame))) {
34 throw std::runtime_error("instanton: cannot read ring seed " + filename);
35 }
36 auto mismatch = [&]() {
37 throw std::invalid_argument(
38 "instanton: ring seed differs in ordered species, IDs, masses, "
39 "cell, constraints or frozen coordinates");
40 };
41 if (image.numberOfAtoms() != reference.numberOfAtoms() ||
42 image.getPeriodic() != reference.getPeriodic() ||
43 !image.getCell().allFinite() || !reference.getCell().allFinite() ||
44 (image.getCell() - reference.getCell()).cwiseAbs().maxCoeff() > 1e-8) {
45 mismatch();
46 }
47 const AtomMatrix delta =
48 reference.pbc(image.getPositions() - reference.getPositions());
49 if (!delta.allFinite()) {
50 mismatch();
51 }
52 for (long atom = 0; atom < reference.numberOfAtoms(); ++atom) {
53 if (image.getAtomicNr(atom) != reference.getAtomicNr(atom) ||
54 image.getAtomIndex(atom) != reference.getAtomIndex(atom) ||
55 image.getFixedMask(atom) != reference.getFixedMask(atom) ||
56 image.getMass(atom) != reference.getMass(atom) ||
57 !std::isfinite(image.getMass(atom)) || !(image.getMass(atom) > 0.) ||
58 (reference.getFixed(atom) &&
59 delta.row(atom).cwiseAbs().maxCoeff() > 1e-8)) {
60 mismatch();
61 }
62 }
63 positions.push_back(image.getPositions());
64 }
65 return positions;
66}
bool getPeriodic() const noexcept
Definition Matter.h:338
Matrix3d getCell() const
Definition Matter.cpp:345
double getMass(long int atom) const
Definition Matter.cpp:548
long getAtomicNr(long int atom) const
Definition Matter.cpp:565
std::array< bool, 3 > getFixedMask(long int atom) const
Per-axis CON column-4 mask (bit0=x, bit1=y, bit2=z).
Definition Matter.cpp:590
std::int64_t getAtomIndex(long int atom) const
.con column-5 index (pre-grouping); public for I/O / bindings.
Definition Matter.cpp:959
int getFixed(long int atom) const
1 if every Cartesian axis of the atom is fixed, else 0.
Definition Matter.cpp:575
IoStatus con2matter(Matter &m, std::string filename)
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38

◆ readReferenceHessian()

MatrixXd eonc::tunneling::readReferenceHessian ( const std::string & filename,
const Matter & reference,
long dimension )
inline

Read a mass-weighted reference matrix bound to filename + ".con".

The caller verifies external-potential and finite-difference provenance.

Definition at line 22 of file ReferenceHessian.h.

23 {
24 if (dimension <= 0 || reference.numberOfAtoms() <= 0) {
25 throw std::invalid_argument(
26 "instanton: empty reference Hessian coordinates");
27 }
28 Matter recorded(reference);
29 if (!io::io_ok(recorded.con2matter(filename + ".con"))) {
30 throw std::runtime_error("instanton: cannot read Hessian geometry " +
31 filename + ".con");
32 }
33 auto mismatch = [&]() {
34 throw std::invalid_argument(
35 "instanton: Hessian reference geometry or mass metric differs: " +
36 filename);
37 };
38 if (recorded.numberOfAtoms() != reference.numberOfAtoms() ||
39 recorded.getPeriodic() != reference.getPeriodic() ||
40 !recorded.getCell().allFinite() || !reference.getCell().allFinite() ||
41 (recorded.getCell() - reference.getCell()).cwiseAbs().maxCoeff() > 1e-8) {
42 mismatch();
43 }
44 const AtomMatrix delta =
45 reference.pbc(recorded.getPositions() - reference.getPositions());
46 if (!delta.allFinite() || delta.cwiseAbs().maxCoeff() > 1e-8) {
47 mismatch();
48 }
49 long coordinates = 0;
50 for (long i = 0; i < reference.numberOfAtoms(); ++i) {
51 if (recorded.getAtomicNr(i) != reference.getAtomicNr(i) ||
52 recorded.getAtomIndex(i) != reference.getAtomIndex(i) ||
53 recorded.getFixedMask(i) != reference.getFixedMask(i) ||
54 recorded.getMass(i) != reference.getMass(i) ||
55 !(recorded.getMass(i) > 0.0) || !std::isfinite(recorded.getMass(i))) {
56 mismatch();
57 }
58 if (!reference.getFixed(i)) {
59 coordinates += 3;
60 }
61 }
62 if (dimension <= 0 || dimension != coordinates) {
63 throw std::invalid_argument(
64 "instanton: Hessian coordinate dimension differs: " + filename);
65 }
66 std::ifstream stream(filename);
67 MatrixXd matrix(dimension, dimension);
68 for (long i = 0; i < dimension; ++i) {
69 for (long j = 0; j < dimension; ++j) {
70 if (!(stream >> matrix(i, j)) || !std::isfinite(matrix(i, j))) {
71 throw std::runtime_error(
72 "instanton: incomplete or non-finite reference Hessian: " +
73 filename);
74 }
75 }
76 }
77 std::string extra;
78 if (stream >> extra) {
79 throw std::runtime_error("instanton: extra reference Hessian data: " +
80 filename);
81 }
82 const double scale = std::max(1.0, matrix.cwiseAbs().maxCoeff());
83 if ((matrix - matrix.transpose()).cwiseAbs().maxCoeff() >
84 128.0 * std::numeric_limits<double>::epsilon() * scale) {
85 throw std::invalid_argument("instanton: reference Hessian is asymmetric: " +
86 filename);
87 }
88 return (0.5 * (matrix + matrix.transpose())).eval();
89}

◆ ringChannel()

RingChannel eonc::tunneling::ringChannel ( const std::vector< VectorXd > & beads,
const VectorXd & saddle,
const VectorXd & mode )

The channel test above for a ring of beads, a saddle and its unstable mode (normalised inside).

Definition at line 5218 of file Tunneling.cpp.

5219 {
5220 RingChannel out;
5221 const double mn = mode.norm();
5222 if (beads.size() < 2 || !(mn > 0.0)) {
5223 return out;
5224 }
5225 const VectorXd n = mode / mn;
5226 const size_t nb = beads.size();
5227 std::vector<double> s(nb);
5228 size_t jLo = 0, jHi = 0;
5229 for (size_t j = 0; j < nb; ++j) {
5230 s[j] = (beads[j] - saddle).dot(n);
5231 if (s[j] < s[jLo]) {
5232 jLo = j;
5233 }
5234 if (s[j] > s[jHi]) {
5235 jHi = j;
5236 }
5237 }
5238 out.sMin = s[jLo];
5239 out.sMax = s[jHi];
5240 const VectorXd chord = beads[jHi] - beads[jLo];
5241 const double cn = chord.norm();
5242 out.chordOverlap = cn > 0.0 ? std::abs(chord.dot(n)) / cn : 0.0;
5243 bool crossed = false;
5244 for (size_t j = 0; j < nb; ++j) {
5245 const size_t k = (j + 1) % nb;
5246 if ((s[j] < 0.0) == (s[k] < 0.0)) {
5247 continue;
5248 }
5249 const double t = s[j] / (s[j] - s[k]);
5250 const VectorXd p = beads[j] + t * (beads[k] - beads[j]) - saddle;
5251 const VectorXd across = p - p.dot(n) * n;
5252 out.crossingOffset = std::max(out.crossingOffset, across.norm());
5253 crossed = true;
5254 }
5255 out.belongs = crossed && out.sMin < 0.0 && out.sMax > 0.0 &&
5256 out.chordOverlap >= 0.5 &&
5257 out.crossingOffset <= out.sMax - out.sMin;
5258 return out;
5259}
Where a ring sits against the saddle it was seeded from, in mass-weighted coordinates.
Definition Tunneling.h:566
bool belongs
Beads on both sides of the dividing plane, the chord within 60 degrees of the mode,...
Definition Tunneling.h:579
double sMin
least s over the beads, amu^0.5 Angstrom
Definition Tunneling.h:567
double chordOverlap
|cos| of the angle between the chord joining the turning points and the unstable mode.
Definition Tunneling.h:571
double crossingOffset
Largest distance from the saddle, across the mode, of a point where the ring crosses the dividing pla...
Definition Tunneling.h:574
double sMax
greatest s over the beads
Definition Tunneling.h:568

◆ ringFromPath()

std::vector< VectorXd > eonc::tunneling::ringFromPath ( const std::vector< VectorXd > & path,
const std::vector< double > & energies,
double betaHbar,
long beads,
RingSeed * seed )

Definition at line 304 of file Tunneling.cpp.

307 {
308 if (path.size() < 3 || path.size() != energies.size() || beads < 4 ||
309 !(betaHbar > 0.0)) {
310 throw std::invalid_argument(
311 "ringFromPath: a path of at least three points with energies, "
312 "N >= 4 and beta hbar > 0");
313 }
314 const long width = path.front().size();
315 for (const auto &q : path) {
316 if (q.size() != width) {
317 throw std::invalid_argument("ringFromPath: the path changes dimension");
318 }
319 }
320 const std::vector<double> s = arcLengths(path);
321 const Profile profile(s, energies);
322 double sTop = s.front();
323 double vTop = -std::numeric_limits<double>::infinity();
324 const int grid = 4000;
325 for (int k = 0; k <= grid; ++k) {
326 const double sk =
327 s.front() + (s.back() - s.front()) * static_cast<double>(k) / grid;
328 if (profile(sk) > vTop) {
329 vTop = profile(sk);
330 sTop = sk;
331 }
332 }
333 const double vLow = std::max(energies.front(), energies.back());
334 if (!(vTop > vLow)) {
335 throw std::invalid_argument("ringFromPath: the path has no barrier");
336 }
337 auto period = [&](double energy) {
338 const auto [sMinus, sPlus] = turningPoints(profile, sTop, energy);
339 return 2.0 * halfPeriod(profile, sMinus, sPlus, energy);
340 };
341 // The crossover along the path from a parabola through the three input
342 // points around the barrier top, not from the interpolant, whose slope is
343 // clamped to zero at the top node.
344 {
345 size_t top = 0;
346 for (size_t k = 1; k < energies.size(); ++k) {
347 if (energies[k] > energies[top]) {
348 top = k;
349 }
350 }
351 if (top == 0 || top + 1 == energies.size()) {
352 throw std::invalid_argument(
353 "ringFromPath: the barrier top is an end of the path");
354 }
355 const double h1 = s[top] - s[top - 1], h2 = s[top + 1] - s[top];
356 const double curvature =
357 2.0 *
358 (h1 * energies[top + 1] - (h1 + h2) * energies[top] +
359 h2 * energies[top - 1]) /
360 (h1 * h2 * (h1 + h2));
361 if (!(curvature < 0.0)) {
362 throw std::invalid_argument("ringFromPath: no curvature at the top");
363 }
364 const double tc = kHbar * std::sqrt(-curvature) / (2.0 * std::numbers::pi);
365 if (!(kHbar / betaHbar < tc)) {
366 throw std::invalid_argument(
367 "ringFromPath: the temperature is at or above the crossover along "
368 "this path");
369 }
370 }
371 // Orbit energies on a geometric grid above the lower end: the period
372 // grows only logarithmically as E approaches a well bottom. The period
373 // need not fall monotonically with E: a shoulder on the path, where V'
374 // nearly vanishes away from a well, makes it spike, and a bisection over
375 // the whole range then converges onto the spike for every beta hbar it
376 // spans. Every crossing of beta hbar on the grid is refined, and the
377 // one kept minimises theta(E) + beta E, theta = 2 x the WKB action: it
378 // dominates the steepest-descent integral the instanton evaluates.
379 const double span = vTop - vLow;
380 const double eBottom = vLow + 1e-14 * span;
381 // Geometric in the distance from the top over the upper half, where a
382 // flat-topped barrier keeps the crossing within a small fraction of the
383 // span, and geometric in the height above the lower end over the lower
384 // half, where the period diverges only logarithmically.
385 constexpr int kHalf = 200;
386 constexpr int kScan = 2 * kHalf + 1;
387 std::vector<double> levels(kScan + 1);
388 std::vector<double> gap(kScan + 1);
389 for (int k = 0; k <= kHalf; ++k) {
390 const double u = static_cast<double>(k) / kHalf;
391 levels[static_cast<size_t>(k)] =
392 vTop - span * std::pow(10.0, -9.0 + u * (9.0 + std::log10(0.5)));
393 levels[static_cast<size_t>(kScan - k)] =
394 vLow + span * std::pow(10.0, -14.0 + u * (14.0 + std::log10(0.5)));
395 }
396 for (int k = 0; k <= kScan; ++k) {
397 gap[static_cast<size_t>(k)] =
398 period(levels[static_cast<size_t>(k)]) - betaHbar;
399 }
400 const double beta = betaHbar / kHbar;
401 double energy = eBottom;
402 double best = std::numeric_limits<double>::infinity();
403 for (int k = 0; k < kScan; ++k) {
404 double a = levels[static_cast<size_t>(k)];
405 double b = levels[static_cast<size_t>(k + 1)];
406 double ga = gap[static_cast<size_t>(k)];
407 if ((ga > 0.0) == (gap[static_cast<size_t>(k + 1)] > 0.0)) {
408 continue;
409 }
410 for (int it = 0; it < 200 && std::abs(a - b) > 1e-15 * span; ++it) {
411 const double m = vLow + std::sqrt((a - vLow) * (b - vLow));
412 const double gm = period(m) - betaHbar;
413 if ((gm > 0.0) == (ga > 0.0)) {
414 a = m;
415 ga = gm;
416 } else {
417 b = m;
418 }
419 }
420 const double root = 0.5 * (a + b);
421 // A bracket around a jump of the turning point refines onto the jump,
422 // where the period is not beta hbar.
423 if (!(std::abs(period(root) - betaHbar) <= 1e-6 * betaHbar)) {
424 continue;
425 }
426 const double w = 2.0 * wkbAction(profile, root) + beta * root;
427 if (w < best) {
428 best = w;
429 energy = root;
430 }
431 }
432 // With no crossing the path does not reach a long enough orbit; the
433 // lowest one it holds is the start.
434 if (seed != nullptr) {
435 seed->energy = energy;
436 seed->period = period(energy);
437 seed->pathLow = vLow;
438 seed->reached = std::abs(seed->period - betaHbar) <= 1e-6 * betaHbar;
439 }
440 const auto [sMinus, sPlus] = turningPoints(profile, sTop, energy);
441 std::vector<double> tau;
442 std::vector<double> pos;
443 const double half = halfPeriod(profile, sMinus, sPlus, energy, &tau, &pos);
444 if (tau.size() < 2 || tau.size() != pos.size()) {
445 throw std::invalid_argument("ringFromPath: the orbit has no length");
446 }
447 // Bead j sits at imaginary time j * beta hbar / N on the way from the
448 // reactant-side turning point to the other side. The return repeats it.
449 std::vector<VectorXd> ring(static_cast<size_t>(beads), VectorXd::Zero(width));
450 for (long j = 0; j <= beads / 2; ++j) {
451 const double t =
452 std::min(half, half * 2.0 * static_cast<double>(j) / beads);
453 const auto it = std::upper_bound(tau.begin(), tau.end(), t);
454 const size_t k = std::clamp<size_t>(
455 static_cast<size_t>(std::distance(tau.begin(), it)), 1, tau.size() - 1);
456 const double seg = tau[k] - tau[k - 1];
457 const double w = seg > 0.0 ? (t - tau[k - 1]) / seg : 0.0;
458 const double sj =
459 pos[k - 1] + std::clamp(w, 0.0, 1.0) * (pos[k] - pos[k - 1]);
460 ring[static_cast<size_t>(j)] = atArcLength(path, s, sj);
461 if (j > 0 && j < beads - j) {
462 ring[static_cast<size_t>(beads - j)] = ring[static_cast<size_t>(j)];
463 }
464 }
465 return ring;
466}
double wkbAction(const Profile &p, double energy, int points)
(1/hbar) integral sqrt(2 (V(s) - E)) ds over the path where V > E.
double pathLow
the higher of the path's two end energies
Definition Tunneling.h:188

◆ ringSpectrum()

RingSpectrum eonc::tunneling::ringSpectrum ( const std::vector< MatrixXd > & beadHessians,
double c,
const std::vector< VectorXd > & tau )

The ring Hessian of bead Hessians beadHessians (d2V/dq2 at each of the N beads) and spring constant c, with the normalised direction tau (N beads) lifted by c and taken out again through the determinant lemma det(J + c tau tau^T) = (c + lambda_0) det' J, exact when J tau = lambda_0 tau.

Block LU of the open chain plus a low-rank correction for the closure and tau, O(N f^3).

Definition at line 2062 of file Tunneling.cpp.

2063 {
2064 if (beadHessians.empty() || beadHessians.size() != tau.size()) {
2065 throw std::invalid_argument(
2066 "ringSpectrum: N bead Hessians and N tau blocks");
2067 }
2068 const std::vector<MatrixXd> diag = ringDiagonal(beadHessians, c, false);
2069 // Lifted by the spring, as the rate lifts it: a unit lift would leave
2070 // ln|1 + lambda_0| in det', a unit-dependent amount.
2071 const WoodburyRing ring(c, diag, true, {tau}, {c}, true);
2072 if (!ring.ok()) {
2073 throw std::runtime_error("ringSpectrum: singular ring");
2074 }
2075 RingSpectrum out;
2076 out.zeroEigenvalue = dot(tau, applyDiagonal(diag, c, true, tau));
2077 out.logDetPrime =
2078 ring.logAbsDet() - std::log(std::abs(c + out.zeroEigenvalue));
2079 out.negativeModes = ring.negative();
2080 return out;
2081}
Spectrum of a closed ring's Hessian without forming it.
Definition Tunneling.h:474

◆ rotationZeroModes()

RotationZeroModes eonc::tunneling::rotationZeroModes ( const MatrixXd & hess,
const MatrixXd & generators,
double fraction )

Definition at line 5172 of file Tunneling.cpp.

5174 {
5176 const long n = hess.rows();
5177 if (hess.cols() != n || generators.rows() != n || generators.cols() != 6) {
5178 throw std::invalid_argument(
5179 "rotationZeroModes: need a square Hessian and six generators");
5180 }
5181 const ColMajorXd h = 0.5 * (hess + hess.transpose());
5182 const ColMajorXd g = generators;
5183 const Eigen::ColPivHouseholderQR<ColMajorXd> qr(g);
5184 const long rank = qr.rank();
5185 if (rank >= n) {
5186 return out;
5187 }
5188 const ColMajorXd q = qr.householderQ() * ColMajorXd::Identity(n, n);
5189 const ColMajorXd z = q.rightCols(n - rank);
5190 const ColMajorXd reduced = z.transpose() * h * z;
5191 const Eigen::SelfAdjointEigenSolver<ColMajorXd> es(
5192 0.5 * (reduced + reduced.transpose()), Eigen::EigenvaluesOnly);
5193 out.softestVibration = es.eigenvalues()(0);
5194 for (int c = 0; c < 3; ++c) {
5195 const VectorXd r = generators.col(3 + c);
5196 const double rr = r.squaredNorm();
5197 if (!(rr > 0.0)) {
5198 continue;
5199 }
5200 const double rq = r.dot(h * r) / rr;
5201 if (out.softestVibration > 0.0) {
5202 out.residual[static_cast<size_t>(c)] = rq / out.softestVibration;
5203 out.zero[static_cast<size_t>(c)] =
5204 std::abs(rq) <= fraction * out.softestVibration;
5205 } else {
5206 out.residual[static_cast<size_t>(c)] =
5207 std::numeric_limits<double>::infinity();
5208 }
5209 }
5210 return out;
5211}
std::array< bool, 3 > zero
Definition Tunneling.h:599
double softestVibration
lowest eigenvalue on the complement
Definition Tunneling.h:601
std::array< double, 3 > residual
Definition Tunneling.h:600

◆ singleBarrier()

bool eonc::tunneling::singleBarrier ( const Profile & p)

Whether a profile is one double well: its images rise to exactly one maximum between the two ends.

A path with an intermediate minimum is no two-level system.

Definition at line 557 of file Tunneling.cpp.

557 {
558 const auto &v = p.v();
559 long peaks = 0;
560 long valleys = 0;
561 int last = 0;
562 for (size_t k = 1; k < v.size(); ++k) {
563 const int step = v[k] > v[k - 1] ? 1 : (v[k] < v[k - 1] ? -1 : 0);
564 if (step == 0) {
565 continue;
566 }
567 peaks += (last == 1 && step == -1) ? 1 : 0;
568 valleys += (last == -1 && step == 1) ? 1 : 0;
569 last = step;
570 }
571 return peaks == 1 && valleys == 0;
572}

◆ wellCurvature()

double eonc::tunneling::wellCurvature ( const Profile & p,
bool leftEnd )

d2V/ds2 at one end of the path, in eV / (amu Angstrom^2), from a least squares fit of a s^2 + b s^3 to the points within half the barrier above that end.

The cubic term takes the anharmonic part a parabola alone would fold into the curvature.

Definition at line 131 of file Tunneling.cpp.

131 {
132 return 2.0 * wellFit(p, leftEnd)[0];
133}

◆ wellFit()

std::array< double, 2 > eonc::tunneling::wellFit ( const Profile & p,
bool leftEnd )

{a, b} of that fit, s measured inward from the end: wellCurvature is 2 a.

Definition at line 135 of file Tunneling.cpp.

135 {
136 const auto &s = p.s();
137 const auto &v = p.v();
138 const size_t n = s.size();
139 const double top = *std::max_element(v.begin(), v.end());
140 const double floor = leftEnd ? v.front() : v.back();
141 const double half = 0.5 * (top - floor);
142 // Sums for the normal equations of y = a x^2 + b x^3.
143 double s44 = 0, s45 = 0, s55 = 0, sy2 = 0, sy3 = 0;
144 size_t used = 0;
145 for (size_t j = 1; j < n; ++j) {
146 const size_t i = leftEnd ? j : n - 1 - j;
147 const double x = leftEnd ? s[i] - s.front() : s.back() - s[i];
148 const double y = v[i] - floor;
149 if (y > half) {
150 break;
151 }
152 const double x2 = x * x;
153 s44 += x2 * x2;
154 s45 += x2 * x2 * x;
155 s55 += x2 * x2 * x2;
156 sy2 += y * x2;
157 sy3 += y * x2 * x;
158 ++used;
159 }
160 if (used == 0) {
161 // The next image already stands above half the barrier: the parabola
162 // through it is all the band says about this well.
163 const size_t i = leftEnd ? 1 : n - 2;
164 const double x = leftEnd ? s[i] - s.front() : s.back() - s[i];
165 return {(v[i] - floor) / (x * x), 0.0};
166 }
167 if (used == 1) {
168 return {sy2 / s44, 0.0};
169 }
170 const double det = s44 * s55 - s45 * s45;
171 return {(sy2 * s55 - sy3 * s45) / det, (sy3 * s44 - sy2 * s45) / det};
172}

◆ wkbAction()

double eonc::tunneling::wkbAction ( const Profile & p,
double energy,
int points )

(1/hbar) integral sqrt(2 (V(s) - E)) ds over the path where V > E.

Definition at line 181 of file Tunneling.cpp.

181 {
182 const double a = p.s().front();
183 const double b = p.s().back();
184 const double h = (b - a) / (points - 1);
185 double sum = 0.0;
186 for (int i = 0; i < points; ++i) {
187 const double gap = p(a + i * h) - energy;
188 const double f = gap > 0.0 ? std::sqrt(2.0 * gap) : 0.0;
189 sum += (i == 0 || i == points - 1) ? 0.5 * f : f;
190 }
191 return sum * h / kHbar;
192}

◆ wkbLogRateAlongPath()

double eonc::tunneling::wkbLogRateAlongPath ( const Profile & profile,
double beta,
double hwReactant )

ln(k), k in 1/time, for the one-dimensional thermal rate along profile.

hwReactant is hbar omega of the reactant well, in eV. Below the barrier the transmission is the WKB factor; above it, the parabolic continuation.

Definition at line 468 of file Tunneling.cpp.

469 {
470 if (!(beta > 0.0) || !(hwReactant > 0.0)) {
471 throw std::invalid_argument(
472 "wkbLogRateAlongPath: beta and hbar omega must be positive");
473 }
474 const double vReactant = profile.v().front();
475 const double s0 = profile.s().front();
476 const double s1 = profile.s().back();
477 double vTop = vReactant;
478 double sTop = s0;
479 const int grid = 2000;
480 for (int k = 0; k <= grid; ++k) {
481 const double sk = s0 + (s1 - s0) * static_cast<double>(k) / grid;
482 const double vk = profile(sk);
483 if (vk >= vTop) {
484 vTop = vk;
485 sTop = sk;
486 }
487 }
488 const double barrier = vTop - vReactant;
489 if (!(barrier > 0.0)) {
490 throw std::invalid_argument(
491 "wkbLogRateAlongPath: no barrier above the reactant");
492 }
493 double ds = 1e-3 * (s1 - s0);
494 ds = std::min(ds, std::min(sTop - s0, s1 - sTop));
495 if (!(ds > 0.0)) {
496 throw std::invalid_argument(
497 "wkbLogRateAlongPath: the barrier top is at an end of the path");
498 }
499 const double curvature =
500 std::max(1e-12, -(profile(sTop + ds) - 2.0 * vTop + profile(sTop - ds)) /
501 (ds * ds));
502 const double hwBarrier = kHbar * std::sqrt(curvature);
503 // int P(E) exp(-beta E) dE from the reactant up to where the Boltzmann
504 // factor has died. E is measured from the reactant.
505 const double eMax = barrier + 40.0 / beta;
506 const int points = 600;
507 auto logAdd = [](double a, double b) {
508 if (a == -std::numeric_limits<double>::infinity()) {
509 return b;
510 }
511 const double m = std::max(a, b);
512 return m + std::log(std::exp(a - m) + std::exp(b - m));
513 };
514 double logTerms = -std::numeric_limits<double>::infinity();
515 double prevLog = -std::numeric_limits<double>::infinity();
516 double prevE = 0.0;
517 for (int k = 0; k <= points; ++k) {
518 const double energy = eMax * static_cast<double>(k) / points;
519 double theta = 0.0;
520 if (energy < barrier) {
521 theta = wkbAction(profile, vReactant + energy);
522 } else {
523 theta = -std::numbers::pi * (energy - barrier) / hwBarrier;
524 }
525 const double logP =
526 theta > 20.0 ? -2.0 * theta : -std::log1p(std::exp(2.0 * theta));
527 const double logF = logP - beta * energy;
528 if (k > 0) {
529 const double segment =
530 std::log(0.5 * (energy - prevE)) + logAdd(prevLog, logF);
531 logTerms = logAdd(logTerms, segment);
532 }
533 prevLog = logF;
534 prevE = energy;
535 }
536 const double logFlux = logTerms - std::log(2.0 * std::numbers::pi * kHbar);
537 return logFlux + std::log(2.0 * std::sinh(0.5 * beta * hwReactant));
538}

◆ wkbSplitting()

Splitting eonc::tunneling::wkbSplitting ( const Profile & p,
double hwReactant,
double hwProduct )

delta0 = (hbar omega / pi) exp(-S) with the Landau and Lifshitz prefactor.

The level is the higher of the two harmonic ground states, V_i + hbar omega_i / 2, and omega is the geometric mean of the wells; for a symmetric double well both reduce to the textbook formula.

Definition at line 200 of file Tunneling.cpp.

200 {
201 const auto &v = p.v();
202 Splitting out;
203 const double top = *std::max_element(v.begin(), v.end());
204 out.delta = v.back() - v.front();
205 out.barrier = top - v.front();
206 out.hwReactant = hwReactant;
207 out.hwProduct = hwProduct;
208 out.referenceEnergy =
209 std::max(v.front() + 0.5 * hwReactant, v.back() + 0.5 * hwProduct);
210 out.action = wkbAction(p, out.referenceEnergy);
211 const double hw = std::sqrt(hwReactant * hwProduct);
212 out.delta0 = hw / std::numbers::pi * std::exp(-out.action);
213 out.deepWells =
214 (top - v.front()) > hwReactant && (top - v.back()) > hwProduct;
215 return out;
216}
bool deepWells
Both barriers stand above hbar omega; below that WKB is not the right tool and the number is reported...
Definition Tunneling.h:92
double hwReactant
hbar omega of the reactant well, eV
Definition Tunneling.h:85
double delta0
tunnelling splitting, eV
Definition Tunneling.h:89
double barrier
path maximum above the reactant, eV
Definition Tunneling.h:84
double referenceEnergy
the level tunnelling happens at, eV
Definition Tunneling.h:87
double action
the WKB exponent, dimensionless
Definition Tunneling.h:88
double hwProduct
hbar omega of the product well, eV
Definition Tunneling.h:86
double delta
product minus reactant, eV
Definition Tunneling.h:83

◆ zeroPointDifference()

double eonc::tunneling::zeroPointDifference ( const MatrixXd & hessStart,
const MatrixXd & hessEnd,
long rigidModes )

Harmonic zero-point energy of the end minimum minus that of the start, in eV: (hbar / 2) times the difference of the sums of the vibrational frequencies of the two mass-weighted Hessians.

At each, the rigidModes eigenvalues nearest zero are left out, and another eigenvalue below zero is no vibration. Added to V(end) - V(start) it is the diagonal term of the two-level Hamiltonian, the asymmetry of the local ground states (Anderson, Halperin and Varma 1972; Jahr, Laude and Richardson, J. Chem. Phys. 153, 094101 (2020)).

Definition at line 1263 of file Tunneling.cpp.

1264 {
1265 if (hessStart.rows() != hessEnd.rows() || rigidModes < 0 ||
1266 rigidModes > hessStart.rows()) {
1267 throw std::invalid_argument("zeroPointDifference: Hessians of one size and "
1268 "a rigid count within it");
1269 }
1270 auto zeroPoint = [&](const MatrixXd &h) {
1271 const Eigen::SelfAdjointEigenSolver<MatrixXd> es(0.5 * (h + h.transpose()),
1272 Eigen::EigenvaluesOnly);
1273 std::vector<double> lam(es.eigenvalues().data(),
1274 es.eigenvalues().data() + es.eigenvalues().size());
1275 std::sort(lam.begin(), lam.end(),
1276 [](double a, double b) { return std::abs(a) < std::abs(b); });
1277 double sum = 0.0;
1278 for (size_t k = static_cast<size_t>(rigidModes); k < lam.size(); ++k) {
1279 sum += std::sqrt(std::max(lam[k], 0.0));
1280 }
1281 return 0.5 * kHbar * sum;
1282 };
1283 return zeroPoint(hessEnd) - zeroPoint(hessStart);
1284}

Variable Documentation

◆ kBoltzmann

double eonc::tunneling::kBoltzmann = 8.617333262145177e-5
inlineconstexpr

Boltzmann constant in eV / K, correctly rounded from the exact 1.380649e-23 J / K.

Definition at line 43 of file Tunneling.h.

◆ kDvrMaxPoints

long eonc::tunneling::kDvrMaxPoints = 1500
inlineconstexpr

Largest grid; a longer path takes a coarser spacing.

Definition at line 137 of file Tunneling.h.

◆ kDvrPadLengths

double eonc::tunneling::kDvrPadLengths = 7.0
inlineconstexpr

Oscillator lengths the grid reaches past each minimum.

Definition at line 135 of file Tunneling.h.

◆ kDvrPointsPerLength

long eonc::tunneling::kDvrPointsPerLength = 20
inlineconstexpr

Grid points per oscillator length hbar / sqrt(hbar omega) of the stiffer well.

Fourth-order differences at this spacing put a quartic double well's gap within 2e-5.

Definition at line 133 of file Tunneling.h.

◆ kHbar

double eonc::tunneling::kHbar = 0.06465415129579072
inlineconstexpr

hbar in eV^0.5 amu^0.5 Angstrom, correctly rounded from the exact SI values (h = 6.62607015e-34 J s, e = 1.602176634e-19 C) and the CODATA 2022 dalton, 1.66053906892e-27 kg.

Definition at line 39 of file Tunneling.h.

◆ kRotationZeroFraction

double eonc::tunneling::kRotationZeroFraction = 0.1
inlineconstexpr

Which rotations of a structure are zero modes of its mass-weighted Hessian.

generators holds three translations then three rotations as columns (a zero column for a rotation a linear molecule lacks). A rotation r is a zero mode when its Rayleigh quotient r^T H r / r^T r is at most fraction (default kRotationZeroFraction) of the softest vibration, the lowest eigenvalue of H on the complement of all six generators. Both sides scale with H and neither grows with the atom count, unlike a comparison with ||H||_F. The residual reported is that ratio; a structure with no positive vibration on the complement has no rotational zero modes.

Definition at line 597 of file Tunneling.h.

◆ kTimeUnitSeconds

double eonc::tunneling::kTimeUnitSeconds = 1.0180505717871193e-14
inlineconstexpr

One unit of time, sqrt(amu Angstrom^2 / eV), in seconds.

Definition at line 350 of file Tunneling.h.