77 const auto N =
static_cast<Eigen::Index
>(ring.
beads.size());
78 if (N < 4 || !(ring.
betaN > 0) || !std::isfinite(ring.
betaN) ||
80 throw std::invalid_argument(
81 "At least four beads, positive beta_N and a curvature derivative "
83 const Eigen::Index d = ring.
beads.front().size();
85 if (d == 0 || ring.
hessian.rows() != N * d ||
92 throw std::invalid_argument(
93 "Ring, reactant and Hessian dimensions must match");
102 throw std::invalid_argument(
103 "Excluded ring modes must be orthonormal columns");
107 throw std::invalid_argument(
108 "A finite log-factor gradient over all bead coordinates is "
110 for (
const auto& q: ring.
beads)
111 if (q.size() != d || !q.allFinite())
112 throw std::invalid_argument(
113 "Finite beads of one dimension required");
116 throw std::invalid_argument(
"Finite ring data required");
117 const double scale = std::max(1., ring.
hessian.cwiseAbs().maxCoeff());
118 if ((ring.
hessian - ring.
hessian.transpose()).cwiseAbs().maxCoeff() >
120 throw std::invalid_argument(
"Symmetric ring Hessian required");
124 Matrix Q = Matrix::Identity(N * d, N * d);
127 const Matrix full = qr.householderQ();
130 const Eigen::Index m = Q.cols();
132 Q.transpose() * (.5 * (ring.
hessian + ring.
hessian.transpose())) * Q;
133 Eigen::SelfAdjointEigenSolver<Matrix> spectrum(reduced);
134 if (spectrum.info() != Eigen::Success)
135 throw std::runtime_error(
"Ring Hessian spectrum failed");
136 const Vector& lambda = spectrum.eigenvalues();
137 const Matrix U = Q * spectrum.eigenvectors();
141 for (Eigen::Index j = 0; j < N; ++j)
142 tangent.segment(j * d, d) =
143 ring.
beads[(j + 1) % N] - ring.
beads[(j + N - 1) % N];
144 if (!(tangent.norm() > 0))
145 throw std::domain_error(
"A nonconstant orbit is required");
149 if (!(tangent.norm() > 0))
150 throw std::domain_error(
"The orbit tangent lies in the excluded modes");
152 for (Eigen::Index k = 0; k < m; ++k) {
153 const double overlap = std::abs(U.col(k).dot(tangent));
160 throw std::domain_error(
"No ring mode follows the orbit tangent");
165 const Eigen::Index unstable = result.
phaseMode == 0 ? 1 : 0;
166 if (!(lambda(unstable) < 0))
167 throw std::domain_error(
"A ring Hessian of index one is required");
169 const double spectralScale = lambda.cwiseAbs().maxCoeff();
170 for (Eigen::Index k = unstable + 1; k < m; ++k) {
173 throw std::domain_error(
"A ring Hessian of index one is required");
174 if (!(lambda(k) > 1e-10 * spectralScale))
175 throw std::domain_error(
176 "An unresolved zero mode must be supplied as an excluded mode");
180 for (Eigen::Index k = 0; k < m; ++k)
183 U.col(k) * U.col(k).transpose() / lambda(k);
186 Vector dqCoefficient = Vector::Zero(N * d);
187 for (Eigen::Index j = 0; j < N; ++j) {
189 const double length = link.norm();
190 if (!(length > 0))
throw std::domain_error(
"Coincident adjacent beads");
193 for (Eigen::Index j = 0; j < N; ++j) {
196 dqCoefficient.segment(j * d, d) +=
197 (previous / previous.norm() - link / link.norm()) /
200 dqCoefficient.segment(j * d, d) -=
201 .5 * traceGradient(ring.
beads[j], block);
208 Matrix reactantBlock = Matrix::Zero(d, d);
209 Vector reactantGradient = Vector::Zero(d);
213 if (reactantRing.info() != Eigen::Success ||
214 reactantPoint.info() != Eigen::Success)
215 throw std::domain_error(
216 "A positive reactant curvature is required");
217 const Matrix reactantInverse =
218 reactantRing.solve(Matrix::Identity(N * d, N * d));
219 for (Eigen::Index j = 0; j < N; ++j)
220 reactantBlock += reactantInverse.block(j * d, j * d, d, d);
221 reactantGradient = -.5 * reactantPoint.solve(traceGradient(
225 const Eigen::Index sites = hasReactant ? N + 1 : N;
226 result.
channels = Vector::Zero(sites * (d + 1));
228 if (hasReactant) result.
channels(N) = ring.
betaN *
static_cast<double>(N);
230 for (Eigen::Index k = 0; k < d; ++k) {
231 for (Eigen::Index j = 0; j < N; ++j)
237 for (Eigen::Index j = 0; j < N; ++j)
240 if (hasReactant) result.
curvature.push_back(.5 * reactantBlock);
247 const std::vector<Vector>& gradients)
249 const Eigen::Index sites = energies.size();
250 if (sites == 0 || gradients.size() !=
static_cast<std::size_t
>(sites))
251 throw std::invalid_argument(
252 "One energy and gradient per site required");
253 const Eigen::Index d = gradients.front().size();
254 Vector packed(sites * (d + 1));
255 packed.head(sites) = energies;
256 for (Eigen::Index s = 0; s < sites; ++s) {
257 if (gradients[s].size() != d)
258 throw std::invalid_argument(
"Gradients of one dimension required");
259 for (Eigen::Index k = 0; k < d; ++k)
260 packed(
siteChannel(sites, s, k)) = gradients[s](k);