28 const Eigen::MatrixXd& directions)
30 const auto d = hessian.rows(), k = directions.cols();
31 if (!d || !k || k > d || directions.rows() != d || !directions.allFinite())
32 throw std::invalid_argument(
33 "Finite nonempty matching reaction directions required");
34 symmetric(hessian, d);
35 Eigen::ColPivHouseholderQR<Eigen::MatrixXd> qr(directions);
37 throw std::invalid_argument(
"Independent reaction directions required");
38 const Eigen::MatrixXd q =
39 qr.householderQ() * Eigen::MatrixXd::Identity(d, d);
40 const Eigen::MatrixXd v = q.leftCols(k), w = q.rightCols(d - k);
41 const Eigen::MatrixXd a = v.transpose() * hessian * v;
42 const double tolerance =
43 128 * std::numeric_limits<double>::epsilon() * d * hessian.norm();
44 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> gram(a);
45 if (gram.info() != Eigen::Success || !gram.eigenvalues().allFinite() ||
46 gram.eigenvalues().maxCoeff() >= -tolerance)
47 throw std::invalid_argument(
48 "Reaction restriction must be resolved negative definite");
49 if (k == d)
return Eigen::MatrixXd::Zero(d, d);
50 const Eigen::MatrixXd b = v.transpose() * hessian * w;
51 const Eigen::MatrixXd schur =
52 w.transpose() * hessian * w - b.transpose() * a.ldlt().solve(b);
53 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> bath(
54 .5 * (schur + schur.transpose()));
55 if (bath.info() != Eigen::Success || !bath.eigenvalues().allFinite() ||
56 bath.eigenvalues().minCoeff() < -tolerance)
57 throw std::invalid_argument(
58 "Reaction span leaves an unstable bath direction");
59 const Eigen::MatrixXd factor =
60 w * bath.eigenvectors() *
61 bath.eigenvalues().cwiseMax(0.).cwiseSqrt().asDiagonal();
62 const Eigen::MatrixXd result = factor * factor.transpose();
63 if (!result.allFinite())
64 throw std::overflow_error(
"Nonfinite stationary bath reference");
74 : curvature_(
std::move(curvature))
76 if (!curvature_.rows())
77 throw std::invalid_argument(
"Nonempty reference required");
78 symmetric(curvature_, curvature_.rows());
85 throw std::invalid_argument(
"Unknown reference discretization");
86 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(curvature_);
87 const double tolerance = 128 * std::numeric_limits<double>::epsilon() *
88 curvature_.rows() * curvature_.norm();
89 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite() ||
90 eigen.eigenvalues().minCoeff() < -tolerance)
91 throw std::invalid_argument(
92 "Harmonic reference must be positive semidefinite");
93 if (eigen.eigenvalues().minCoeff() < 0)
94 curvature_ = eigen.eigenvectors() *
95 eigen.eigenvalues().cwiseMax(0.).asDiagonal() *
96 eigen.eigenvectors().transpose();
100 const Eigen::VectorXd& left,
const Eigen::VectorXd& right,
104 const auto d = curvature_.rows();
105 if (left.size() != d || right.size() != d || !left.allFinite() ||
106 !right.allFinite() || leftPotential.
gradient.size() != d ||
107 rightPotential.
gradient.size() != d ||
108 !leftPotential.
gradient.allFinite() ||
109 !rightPotential.
gradient.allFinite() ||
110 !std::isfinite(leftPotential.
energy) ||
111 !std::isfinite(rightPotential.
energy) || !std::isfinite(energyShift))
112 throw std::invalid_argument(
113 "Finite mass-coordinate link values required");
114 const double h = kernel_.duration;
116 const Eigen::VectorXd difference = left - right;
118 result.
action = .5 * difference.dot(kernel_.L * difference) +
120 ((leftPotential.
energy - energyShift) +
121 (rightPotential.
energy - energyShift));
123 kernel_.L * difference + .5 * h * leftPotential.
gradient;
125 -kernel_.L * difference + .5 * h * rightPotential.
gradient;
128 throw std::overflow_error(
"Nonfinite frequency-fitted link action");
131 const Eigen::VectorXd sum = left + right, difference = left - right;
132 const Eigen::MatrixXd slow = kernel_.A - kernel_.L,
133 fast = kernel_.A + kernel_.L;
135 result.
action = .25 * sum.dot(slow * sum) +
136 .25 * difference.dot(fast * difference) +
138 ((leftPotential.
energy - energyShift) -
139 .5 * left.dot(curvature_ * left) +
140 (rightPotential.
energy - energyShift) -
141 .5 * right.dot(curvature_ * right));
142 result.
leftGradient = .5 * (slow * sum + fast * difference) +
143 .5 * h * (leftPotential.
gradient - curvature_ * left);
145 .5 * (slow * sum - fast * difference) +
146 .5 * h * (rightPotential.
gradient - curvature_ * right);
149 throw std::overflow_error(
"Nonfinite harmonic-reference link action");
153 const Eigen::MatrixXd& leftHessian,
154 const Eigen::MatrixXd& rightHessian)
const
156 symmetric(leftHessian, curvature_.rows());
157 symmetric(rightHessian, curvature_.rows());
158 auto result = kernel_;
160 result.A += .5 * kernel_.duration * leftHessian;
161 result.rightA = kernel_.A + .5 * kernel_.duration * rightHessian;
162 if (!result.A.allFinite() || !result.rightA.allFinite())
163 throw std::overflow_error(
164 "Nonfinite frequency-fitted link Hessian");
167 result.A += .5 * kernel_.duration * (leftHessian - curvature_);
169 kernel_.A + .5 * kernel_.duration * (rightHessian - curvature_);
170 if (!result.A.allFinite() || !result.rightA.allFinite())
171 throw std::overflow_error(
"Nonfinite harmonic-reference link Hessian");