Loading...
Searching...
No Matches
gpr::neb::NEBPath Class Reference

NEB path: chain of images between two endpoints. More...

#include <gpr/neb/NEBPath.h>

Public Member Functions

 NEBPath (const Eigen::VectorXd &initial, const Eigen::VectorXd &final_state, int n_images, double spring_constant=0.1)
 Initialize path with linear interpolation between endpoints.
 NEBPath (const EigenMatrix &image_positions, double spring_constant=0.1)
 Initialize path from explicit image positions.
void initializeIDPP (int n_atoms, bool collective=false)
 Initialize from IDPP (image dependent pair potential) interpolation.
void initializeIDPP (int n_atoms, const std::vector< char > &moving_atoms, bool collective=false)
void initializeSIDPP (int n_atoms, double alpha=0.33)
 Initialize via Sequential IDPP (SIDPP). rgsaddle_sidpp_alternating_path. The spring on that call is the unit IDPP spring, not the physical NEB spring.
void initializeSIDPP (int n_atoms, const std::vector< char > &moving_atoms, double alpha=0.33)
void initializeSIDPPGeodesic (int n_atoms, double alpha=0.33)
 Initialize via inverse-distance S-IDPP. rgsaddle_sidpp_alternating_inverse_distance_path. This is the –sidpp-geodesic blend (close pairs stay close longer). It is not rgsaddle_geodesic_path, which minimises a redundant-coordinate length and needs a chart.
void initializeSIDPPGeodesic (int n_atoms, const std::vector< char > &moving_atoms, double alpha=0.33)
void computeNEBForces ()
 Compute NEB forces for all intermediate images.
void enableClimbingImage ()
 Enable climbing image on the highest-energy intermediate image.
int highestEnergyImageIndex () const
 Highest finite interior energy, or -1 when none exists.
int highestEnergyImageIndexPreferring (int preferred) const
int highestLocalMaximumImageIndex () const
 Strict interior local maximum, else the highest finite energy.
int highestLocalMaximumImageIndexPreferring (int preferred) const
void setForceVariance (int i, const Eigen::VectorXd &variance)
void clearForceVariance ()
bool hasForceVariance (int i) const
void setPeriodicCell (const std::array< double, 9 > &cell)
void interpolateFromEndpoints ()
 Rebuild interior images on the chord between the current endpoints.
void setMovingAtoms (std::vector< char > moving_atoms)
void setExternalFixedAtoms (bool present)
void setSpringCoordinates (std::vector< Eigen::Index > coordinates, std::vector< double > weights={})
 Band coordinates that carry the springs; empty means all.
const std::vector< Eigen::Index > & springCoordinates () const
const std::vector< double > & springWeights () const
void setMolecularRigidMotion (bool enabled)
bool molecularRigidMotion () const
void projectPhysicalVector (const Eigen::VectorXd &reference, Eigen::Ref< Eigen::VectorXd > vector) const
Eigen::VectorXd alignMolecularGeometry (const Eigen::VectorXd &reference, const Eigen::VectorXd &geometry) const
 Proper rigid alignment with fixed atom correspondence; no reassignment.
void alignMolecularFrames ()
 Normalize seed frames before evaluation, invalidating changed images.
void pinFixedAtoms (Eigen::Ref< Eigen::VectorXd > positions) const
 Copy reactant coordinates onto fixed atoms.
void maskFixedForce (Eigen::Ref< Eigen::VectorXd > force) const
 Zero a force on fixed atoms.
bool usesPeriodicCell () const noexcept
const Eigen::VectorXd & nebForce (int i) const
 Get the NEB force for image i.
double saddleForce (int i) const
void setConvergenceForceNorm (std::optional< ConvergenceNormType > norm)
ConvergenceNormType convergenceForceNorm (Eigen::Index dof) const
double forceMagnitude (const Eigen::VectorXd &force) const
double nebForceMagnitude (int i) const
double tangentStiffness (int i) const
 Stiffness the tangent adds to image i across the path.
Eigen::VectorXd tangentAt (int i) const
 Improved (energy-weighted) tangent at image i, normalised. Used by the OCINEB controller to seed the dimer's initial mode at the CI image when no cached eigenvector is available.
Image & image (int i)
 Access image i.
const Image & image (int i) const
int numImages () const
int numIntermediate () const
EigenMatrix intermediatePositions () const
 Get all intermediate image positions as a matrix.
void setFromObservation (const Observation &obs, int start_image=1)
 Set energies and gradients for images from an Observation.
void setSpringBounds (double k_max, double k_min)
 Set the spring constant bounds for the energy-weighted variable-spring force computation.
void setGeometricSpring (bool on)
 Toggle the geometric (cubic-potential) spring on the intermediate-image NEB force. With geometric=true the parallel spring force becomes ~F_par = k * (d_n^2 - d_p^2) * tau~ (derived from U = (k/3) sum ||R_{i+1}-R_i||^3); the perpendicular component cancels exactly under right-triangle perturbations of dense meshes and ~K_eff = 4 k s~ scales linearly in spacing. The energy-weighted ~spring_constant_min_~ tapering is ignored when geometric mode is on – the cubic potential's natural softening replaces it.
bool geometricSpring () const
void setEnergyWeightedSprings (bool on)
 Allow the energy-weighted spring taper.
bool energyWeightedSprings () const
void setSpringRestLengths (std::vector< double > rest_lengths)
 Per-segment spring rest lengths (numImages()-1 entries).
const std::vector< double > & springRestLengths () const
double maxSpacingDeviation () const
 Maximum relative deviation of image spacing from uniform.
double maxMetricSpacingDeviation (const std::vector< Eigen::MatrixXd > &segment_metric_factors) const
 Maximum relative spacing deviation measured in a pullback metric.
double reparametrizeByArcLength ()
 Redistribute interior images uniformly along arc length.
double reparametrizeByArcLengthKeepingImage (int anchor_index)
 Redistribute the two subchains while preserving one image.
double reparametrizeByMetricArcLength (const std::vector< Eigen::MatrixXd > &segment_metric_factors)
 Redistribute interior images uniformly in a pullback metric.
double reparametrizeByMetricArcLengthKeepingImage (const std::vector< Eigen::MatrixXd > &segment_metric_factors, int anchor_index)
 Metric pullback variant of reparametrizeByArcLengthKeepingImage().
std::vector< Eigen::MatrixXd > inverseDistanceSegmentMetricFactors (int n_atoms) const
 Build segment metric factors for inverse-distance coordinates.
std::vector< Eigen::MatrixXd > inverseDistanceSegmentMetricFactors (int n_atoms, const std::vector< char > &moving_atoms) const
 Build inverse-distance segment factors over active atom pairs.
double reparametrizeByInverseDistanceGeodesicArcLength (int n_atoms)
 Redistribute the band by solving inverse-distance targets.
double reparametrizeByInverseDistanceGeodesicArcLength (int n_atoms, const std::vector< char > &moving_atoms)
double reparametrizeByInverseDistanceGeodesicArcLengthKeepingImage (int n_atoms, const std::vector< char > &moving_atoms, int anchor_index)
 Anchor-preserving inverse-distance geodesic reparameterization.
void setPosteriorVarianceThreshold (double threshold)
 Set the signal-scaled posterior-variance confidence threshold.
void setClimbingCurvatureDirection (Eigen::VectorXd direction)
void clearClimbingCurvatureDirection ()
const Eigen::VectorXd & climbingCurvatureDirection () const
double posteriorVarianceThreshold () const
 Current signal-scaled posterior-variance confidence threshold.

Static Public Member Functions

static Eigen::VectorXd inverseDistanceGeodesicStep (int n_atoms, const std::vector< char > &moving_atoms, const Eigen::VectorXd &positions, const Eigen::VectorXd &cartesian_step, const std::array< double, 9 > *cell=nullptr)
 Apply one inverse-distance internal-coordinate retraction.
static Eigen::VectorXd inverseDistanceGeodesicInterpolate (int n_atoms, const std::vector< char > &moving_atoms, const Eigen::VectorXd &left, const Eigen::VectorXd &right, double alpha, const std::array< double, 9 > *cell=nullptr)
 Interpolate between two geometries in inverse-distance space.

Detailed Description

NEB path: chain of images between two endpoints.

Definition at line 57 of file NEBPath.h.

Constructor & Destructor Documentation

◆ NEBPath() [1/2]

gpr::neb::NEBPath::NEBPath ( const Eigen::VectorXd & initial,
const Eigen::VectorXd & final_state,
int n_images,
double spring_constant = 0.1 )

Initialize path with linear interpolation between endpoints.

Parameters
initialInitial state positions (flat)
final_stateFinal state positions (flat)
n_imagesNumber of intermediate images (excluding endpoints)
spring_constantNEB spring constant k

Definition at line 359 of file NEBPath.cpp.

362 : spring_constant_(spring_constant)
363{
364 int total = n_images + 2; // including endpoints
365 images_.resize(total);
366 neb_forces_.resize(total);
367
368 // Endpoint images
369 images_[0].positions = initial;
370 images_[0].gradient = Eigen::VectorXd::Zero(initial.size());
371 images_[0].is_endpoint = true;
372 images_[total - 1].positions = final_state;
373 images_[total - 1].gradient = Eigen::VectorXd::Zero(final_state.size());
374 images_[total - 1].is_endpoint = true;
375
376 // Linear interpolation for intermediate images
377 for (int i = 1; i < total - 1; ++i) {
378 double t = static_cast<double>(i) / (total - 1);
379 images_[i].positions = (1.0 - t) * initial + t * final_state;
380 images_[i].gradient.resize(initial.size());
381 images_[i].gradient.setZero();
382 }
383
384 for (auto& f: neb_forces_) {
385 f.resize(initial.size());
386 f.setZero();
387 }
388}

◆ NEBPath() [2/2]

gpr::neb::NEBPath::NEBPath ( const EigenMatrix & image_positions,
double spring_constant = 0.1 )

Initialize path from explicit image positions.

Parameters
image_positionsMatrix with one image per row, endpoints included.
spring_constantNEB spring constant k

Definition at line 390 of file NEBPath.cpp.

391 : spring_constant_(spring_constant)
392{
393 if (image_positions.rows() < 2 || image_positions.cols() == 0) {
394 throw std::invalid_argument(
395 "NEBPath image_positions must contain at least two non-empty rows");
396 }
397
398 const int total = static_cast<int>(image_positions.rows());
399 const int n_coords = static_cast<int>(image_positions.cols());
400 images_.resize(total);
401 neb_forces_.resize(total);
402
403 for (int i = 0; i < total; ++i) {
404 images_[i].positions = image_positions.row(i).transpose();
405 images_[i].gradient = Eigen::VectorXd::Zero(n_coords);
406 images_[i].is_endpoint = (i == 0 || i == total - 1);
407 }
408
409 for (auto& f: neb_forces_) {
410 f = Eigen::VectorXd::Zero(n_coords);
411 }
412}

Member Function Documentation

◆ alignMolecularFrames()

void gpr::neb::NEBPath::alignMolecularFrames ( )

Normalize seed frames before evaluation, invalidating changed images.

Definition at line 538 of file NEBPath.cpp.

539{
540 if (!molecularRigidMotion()) return;
541 const Eigen::VectorXd reference = images_[0].positions;
542 for (int i = 1; i < numImages(); ++i) {
543 const Eigen::VectorXd aligned =
544 alignMolecularGeometry(reference, images_[i].positions);
545 if ((aligned.array() == images_[i].positions.array()).all()) continue;
546 images_[i].positions = aligned;
547 invalidateResampledImage(i);
548 neb_forces_[i].setZero();
549 }
550}
int numImages() const
Definition NEBPath.h:338
bool molecularRigidMotion() const
Definition NEBPath.cpp:496
Eigen::VectorXd alignMolecularGeometry(const Eigen::VectorXd &reference, const Eigen::VectorXd &geometry) const
Proper rigid alignment with fixed atom correspondence; no reassignment.
Definition NEBPath.cpp:517

◆ alignMolecularGeometry()

Eigen::VectorXd gpr::neb::NEBPath::alignMolecularGeometry ( const Eigen::VectorXd & reference,
const Eigen::VectorXd & geometry ) const
nodiscard

Proper rigid alignment with fixed atom correspondence; no reassignment.

Definition at line 517 of file NEBPath.cpp.

519{
520 if (!molecularRigidMotion()) return geometry;
521 if (reference.size() != geometry.size() || reference.size() % 3 != 0 ||
522 !reference.allFinite() || !geometry.allFinite())
523 throw std::invalid_argument("invalid molecular rigid alignment input");
524 if ((reference.array() == geometry.array()).all()) return geometry;
525 const Eigen::VectorXd aligned =
526 aux::kabschAlignProductToReactant(reference, geometry);
527 // Retain exact coordinates when a rigid transform differs only by the
528 // roundoff of the centroid and covariance calculations.
529 const double resolution =
530 std::numeric_limits<double>::epsilon() *
531 static_cast<double>(reference.size()) *
532 std::max({1.0, reference.norm(), geometry.norm()});
533 if ((aligned - reference).norm() <= resolution) return reference;
534 if ((aligned - geometry).norm() <= resolution) return geometry;
535 return aligned;
536}
Eigen::VectorXd kabschAlignProductToReactant(const Eigen::VectorXd &reactant_positions, const Eigen::VectorXd &product_positions)

◆ clearClimbingCurvatureDirection()

void gpr::neb::NEBPath::clearClimbingCurvatureDirection ( )
inline

Definition at line 615 of file NEBPath.h.

616 {
617 climbing_curvature_direction_.resize(0);
618 }

◆ clearForceVariance()

void gpr::neb::NEBPath::clearForceVariance ( )

Definition at line 866 of file NEBPath.cpp.

867{
868 force_variance_.clear();
869}

◆ climbingCurvatureDirection()

const Eigen::VectorXd & gpr::neb::NEBPath::climbingCurvatureDirection ( ) const
inlinenodiscard

Definition at line 620 of file NEBPath.h.

621 {
622 return climbing_curvature_direction_;
623 }

◆ computeNEBForces()

void gpr::neb::NEBPath::computeNEBForces ( )

Compute NEB forces for all intermediate images.

For each image i (not endpoint): F_NEB = F_perp + F_spring_parallel

Where: F_perp = F - (F . tau) * tau (perpendicular to path) F_spring = k times [length(r_{i+1} - r_i) - length(r_i - r_{i-1})] times tau tau = normalized tangent along path

For climbing image: F_CI = F - 2*(F . tau)*tau (inverted parallel component)

Definition at line 880 of file NEBPath.cpp.

881{
882 // Energy-weighted variable spring constants. The constant-k
883 // formulation lets images bunch together in low-energy basins
884 // (the spring contracts equally everywhere; near the saddle the
885 // chain is stretched by the climb force without compensating
886 // stiffening). With variable k tied to image energy the springs
887 // stiffen where the band needs cohesion (around high-energy
888 // images, i.e. the saddle region) and slacken in the basins.
889 //
890 // Per-spring k between adjacent images j-1 and j:
891 // E_pair = max(E_j, E_{j-1})
892 // energy_range = E_max - E_ref
893 // if energy_range < 1e-10 or E_pair <= E_ref:
894 // k_pair = k_min
895 // else:
896 // alpha = clamp((E_max - E_pair) / energy_range, 0, 1)
897 // k_pair = (1 - alpha) * k_max + alpha * k_min
898 // with k_max = spring_constant_, k_min = 0.1 * k_max,
899 // E_ref = min(reactant.E, product.E), E_max = max over the path
900 // including endpoints. Saddle-adjacent springs get k_max (alpha
901 // = 0); basin-adjacent springs collapse to k_min (alpha = 1).
902 //
903 // Per-image NEB spring force with two distinct adjacent k's:
904 // F_spring(i) = (k_+ * d_+ - k_- * d_-) * tau
905 // where k_+ is the spring between images i and i+1, k_- between
906 // images i-1 and i.
907 const int n = numImages();
908 const double k_max = spring_constant_;
909 const double k_min =
910 (spring_constant_min_ >= 0.0) ? spring_constant_min_ : 0.1 * k_max;
911 // Energy weighting only on a fully measured (or fully legacy) profile.
912 // Enabling it on GP-OIE bands (measured endpoints, predicted interior)
913 // was tried on 2026-09-07 and rejected: eOn's rule weights against the
914 // lower endpoint, so on an exothermic cell (02_hcch, product 2.2 eV
915 // below the reactant) every image crowded onto the reactant plateau,
916 // the descent was left to two images, and the climbing image settled
917 // on a 0.107 eV plateau saddle while the 0.21 eV ridge sat unresolved
918 // between them. The band's resolution is set at refinement time by the
919 // chord-leak equidistribution instead (resamplePathByRestLengths).
920 const bool any_measured =
921 std::any_of(images_.begin(), images_.end(),
922 [](const Image& image) { return image.evaluated; });
923 const bool complete_measured_profile =
924 std::all_of(images_.begin(), images_.end(), [](const Image& image) {
925 return std::isfinite(image.energy) && image.evaluated;
926 });
927 const bool finite_legacy_profile =
928 !any_measured &&
929 std::all_of(images_.begin(), images_.end(), [](const Image& image) {
930 return std::isfinite(image.energy);
931 });
932 const bool use_energy_weighting =
933 energy_weighted_springs_ &&
934 (complete_measured_profile || finite_legacy_profile);
935
936 // eOn's weighted-spring strategy scales the stiffness over the full
937 // reaction-energy interval, using the lower endpoint as its reference.
938 // Ordered comparisons raise invalid on a quiet NaN, so the reduction
939 // runs only when every image energy is already known finite. That is
940 // also the only case that weights springs; kSpring does not read
941 // these values otherwise.
942 double E_ref = 0.0;
943 double E_max = 0.0;
944 if (use_energy_weighting) {
945 E_ref = std::min(images_[0].energy, images_[n - 1].energy);
946 E_max = E_ref;
947 for (int i = 0; i < n; ++i) {
948 E_max = std::max(E_max, images_[i].energy);
949 }
950 }
951 const double energy_range = E_max - E_ref;
952
953 auto kSpring = [&](int j) -> double {
954 // Spring between images j-1 and j; j is the "upper" image
955 // for index purposes. Valid for j in [1, n-1].
956 if (!use_energy_weighting) return k_max;
957 const double E_pair =
958 std::max(images_[j].energy, images_[j - 1].energy);
959 if (energy_range < 1e-10) return k_min;
960 if (E_pair <= E_ref) return k_min;
961 double alpha = (E_max - E_pair) / energy_range;
962 if (alpha < 0.0) alpha = 0.0;
963 if (alpha > 1.0) alpha = 1.0;
964 return (1.0 - alpha) * k_max + alpha * k_min;
965 };
966
967 for (int i = 1; i < n - 1; ++i) {
968 const Eigen::Index ncoord = images_[i].positions.size();
969 // Non-finite image energy: sized zero NEB gradient, and no abs
970 // of the energy differences inside tangent().
971 if (!std::isfinite(images_[i].energy) ||
972 !std::isfinite(images_[i - 1].energy) ||
973 !std::isfinite(images_[i + 1].energy)) {
974 neb_forces_[i] = Eigen::VectorXd::Zero(ncoord);
975 continue;
976 }
977 Eigen::VectorXd tau = tangent(i);
978 const Eigen::VectorXd& grad = images_[i].gradient;
979
980 // With a surrogate force variance the tangent component is removed in
981 // the Sigma^{-1} metric rather than the Euclidean one; the two agree
982 // exactly when the variance is uniform, so this is a strict
983 // generalisation of the classical projection above.
984 const bool anisotropic =
985 hasForceVariance(i) &&
986 force_variance_[static_cast<std::size_t>(i)].size() == grad.size();
987 // The isotropic branch keeps the original expressions verbatim.
988 // 2 P(F) - F is algebraically -grad + 2 (grad.tau) tau, but floating
989 // point addition does not associate, so routing the classical case
990 // through the general projection would move every existing trajectory
991 // in its last bits.
992 const auto perpendicular = [&](const Eigen::VectorXd& f) {
994 f, tau, force_variance_[static_cast<std::size_t>(i)]);
995 };
996
997 if (images_[i].is_climbing &&
998 climbing_curvature_direction_.size() == tau.size() &&
999 climbing_curvature_direction_.allFinite()) {
1000 tau = climbing_curvature_direction_;
1001 }
1002 if (images_[i].is_climbing) {
1003 // Climbing image: invert parallel component
1004 // F_CI = -grad + 2*(grad . tau)*tau
1005 if (anisotropic) {
1006 const Eigen::VectorXd force = -grad;
1007 neb_forces_[i] = 2.0 * perpendicular(force) - force;
1008 } else {
1009 double grad_parallel = grad.dot(tau);
1010 neb_forces_[i] = -grad + 2.0 * grad_parallel * tau;
1011 }
1012 } else {
1013 // Standard NEB: perpendicular true force + parallel spring force
1014 double grad_parallel = grad.dot(tau);
1015 // Not a ternary: one arm is an Eigen expression template and the
1016 // other a materialised vector, and the classical arm has to be the
1017 // original expression assigned straight into F_perp so it stays
1018 // bit-identical.
1019 Eigen::VectorXd F_perp;
1020 if (anisotropic) {
1021 F_perp = perpendicular(-grad);
1022 } else {
1023 F_perp = -grad + grad_parallel * tau;
1024 }
1025
1026 Eigen::VectorXd delta_plus = segmentDisplacement(
1027 images_[i].positions, images_[i + 1].positions);
1028 Eigen::VectorXd delta_minus = segmentDisplacement(
1029 images_[i - 1].positions, images_[i].positions);
1030 removeNetTranslation(delta_plus);
1031 removeNetTranslation(delta_minus);
1032 // The springs measure the whole chord, or the displacement of
1033 // the spring coordinates alone when a set is given.
1034 const bool restricted_springs = !spring_coordinates_.empty();
1035 // A missing weight vector is weight 1, the unweighted length.
1036 const auto spring_weight = [&](std::size_t n) {
1037 return spring_weights_.empty() ? 1.0 : spring_weights_[n];
1038 };
1039 const auto spring_length = [&](const Eigen::VectorXd& delta) {
1040 double sum = 0.0;
1041 for (std::size_t n = 0; n < spring_coordinates_.size(); ++n) {
1042 const double component = delta(spring_coordinates_[n]);
1043 const double weight = spring_weight(n);
1044 sum += weight * component * component;
1045 }
1046 return std::sqrt(sum);
1047 };
1048 const double d_plus = restricted_springs ? spring_length(delta_plus)
1049 : delta_plus.norm();
1050 const double d_minus = restricted_springs
1051 ? spring_length(delta_minus)
1052 : delta_minus.norm();
1053 double F_spring;
1054 if (static_cast<int>(spring_rest_lengths_.size()) == n - 1) {
1055 // Rest lengths: uniform k_max, each segment pulled toward
1056 // its own rest length, so the equilibrium spacing is the
1057 // rest length plus a common offset.
1058 const double rest_plus =
1059 spring_rest_lengths_[static_cast<std::size_t>(i)];
1060 const double rest_minus =
1061 spring_rest_lengths_[static_cast<std::size_t>(i - 1)];
1062 F_spring =
1063 k_max * ((d_plus - rest_plus) - (d_minus - rest_minus));
1064 } else if (use_geometric_spring_) {
1065 // Geometric (cubic-potential) spring: U_s = (k/3)
1066 // sum ||R_{i+1}-R_i||^3 -> F_par = k*(d_n^2 - d_p^2)
1067 // tau. Perpendicular cancels exactly; K_eff = 4 k s
1068 // scales linearly in image spacing so dense meshes
1069 // auto-soften. Uses a SINGLE k (= spring_constant_,
1070 // the k_max) instead of the energy-weighted taper.
1071 F_spring =
1072 spring_constant_ * (d_plus * d_plus - d_minus * d_minus);
1073 } else {
1074 const double k_plus = kSpring(i + 1);
1075 const double k_minus = kSpring(i);
1076 F_spring = k_plus * d_plus - k_minus * d_minus;
1077 }
1078
1079 if (restricted_springs) {
1080 // The spring acts along the tangent restricted to its
1081 // coordinates; a tangent with no component there leaves
1082 // nothing for the spring to act on.
1083 neb_forces_[i] = F_perp;
1084 const double restricted = spring_length(tau);
1085 if (restricted > 0.0) {
1086 const double scale = F_spring / restricted;
1087 for (std::size_t n = 0; n < spring_coordinates_.size();
1088 ++n) {
1089 const auto k = spring_coordinates_[n];
1090 neb_forces_[i](k) += scale * spring_weight(n) * tau(k);
1091 }
1092 }
1093 } else {
1094 neb_forces_[i] = F_perp + F_spring * tau;
1095 }
1096 }
1097 projectPhysicalVector(images_[i].positions, neb_forces_[i]);
1098 maskFixedForce(neb_forces_[i]);
1099 }
1100}
void maskFixedForce(Eigen::Ref< Eigen::VectorXd > force) const
Zero a force on fixed atoms.
Definition NEBPath.cpp:563
void projectPhysicalVector(const Eigen::VectorXd &reference, Eigen::Ref< Eigen::VectorXd > vector) const
Definition NEBPath.cpp:503
bool hasForceVariance(int i) const
Definition NEBPath.cpp:871
Image & image(int i)
Access image i.
Definition NEBPath.h:329
Eigen::VectorXd projectPerpendicularDiagonal(const Eigen::VectorXd &force, const Eigen::VectorXd &tangent, const Eigen::VectorXd &force_variance)

◆ convergenceForceNorm()

ConvergenceNormType gpr::neb::NEBPath::convergenceForceNorm ( Eigen::Index dof) const
inline

Definition at line 273 of file NEBPath.h.

274 {
275 return convergence_force_norm_.value_or(
278 }

◆ enableClimbingImage()

void gpr::neb::NEBPath::enableClimbingImage ( )

Enable climbing image on the highest-energy intermediate image.

Definition at line 1121 of file NEBPath.cpp.

1122{
1123 for (auto& img: images_) {
1124 img.is_climbing = false;
1125 }
1126 int hi = highestEnergyImageIndex();
1127 if (hi > 0 && hi < numImages() - 1) {
1128 images_[hi].is_climbing = true;
1129 }
1130}
int highestEnergyImageIndex() const
Highest finite interior energy, or -1 when none exists.
Definition NEBPath.cpp:1132

◆ energyWeightedSprings()

bool gpr::neb::NEBPath::energyWeightedSprings ( ) const
inline

Definition at line 418 of file NEBPath.h.

419 {
420 return energy_weighted_springs_;
421 }

◆ forceMagnitude()

double gpr::neb::NEBPath::forceMagnitude ( const Eigen::VectorXd & force) const
inline

Physical and prediction-error forces use the same stopping norm.

Definition at line 281 of file NEBPath.h.

282 {
283 return gpr::forceNorm(force, convergenceForceNorm(force.size()));
284 }
ConvergenceNormType convergenceForceNorm(Eigen::Index dof) const
Definition NEBPath.h:273
double forceNorm(const Eigen::MatrixBase< Derived > &force, ConvergenceNormType norm)
Definition ForceNorm.h:45

◆ geometricSpring()

bool gpr::neb::NEBPath::geometricSpring ( ) const
inline

Definition at line 394 of file NEBPath.h.

395 {
396 return use_geometric_spring_;
397 }

◆ hasForceVariance()

bool gpr::neb::NEBPath::hasForceVariance ( int i) const
nodiscard

Definition at line 871 of file NEBPath.cpp.

872{
873 if (i < 0 || static_cast<std::size_t>(i) >= force_variance_.size()) {
874 return false;
875 }
876 const Eigen::VectorXd& v = force_variance_[static_cast<std::size_t>(i)];
877 return v.size() > 0 && (v.array() > 0.0).any();
878}

◆ highestEnergyImageIndex()

int gpr::neb::NEBPath::highestEnergyImageIndex ( ) const

Highest finite interior energy, or -1 when none exists.

A non-finite energy is not a candidate. A strict interior local maximum wins a tie at that energy over a non-strict shoulder, and loses to any strictly higher interior energy. The lowest index breaks remaining ties.

Definition at line 1132 of file NEBPath.cpp.

1133{
1134 // Highest finite interior energy. A non-finite value is not a
1135 // candidate, and with none the result is -1. A strict interior local
1136 // maximum wins only a tie at that highest energy, against a non-strict
1137 // shoulder; the lowest index breaks any remaining tie. A strict local
1138 // maximum does not outrank a strictly higher interior energy.
1139 if (numImages() <= 2) return -1;
1140 int best_peak = -1;
1141 double best_peak_e = -std::numeric_limits<double>::infinity();
1142 int best_any = -1;
1143 double best_any_e = -std::numeric_limits<double>::infinity();
1144 for (int i = 1; i < numImages() - 1; ++i) {
1145 const double e = images_[i].energy;
1146 if (!std::isfinite(e)) continue;
1147 if (best_any < 0 || e > best_any_e) {
1148 best_any_e = e;
1149 best_any = i;
1150 }
1151 const double e_prev = images_[i - 1].energy;
1152 const double e_next = images_[i + 1].energy;
1153 const bool local_max = std::isfinite(e_prev) && std::isfinite(e_next) &&
1154 e > e_prev && e > e_next;
1155 if (local_max && (best_peak < 0 || e > best_peak_e ||
1156 (e == best_peak_e && i < best_peak))) {
1157 best_peak_e = e;
1158 best_peak = i;
1159 }
1160 }
1161 if (best_peak >= 0 && !(best_any_e > best_peak_e)) return best_peak;
1162 return best_any;
1163}

◆ highestEnergyImageIndexPreferring()

int gpr::neb::NEBPath::highestEnergyImageIndexPreferring ( int preferred) const

Like highestEnergyImageIndex, but if ~preferred~ is still a strict interior local maximum, keep it (CI continuity on multi-saddle bands).

Definition at line 1165 of file NEBPath.cpp.

1166{
1167 // Continuity of the active CI prevents index thrash (which forces OCI
1168 // bursts to re-seed min-mode every outer), BUT it must never park the
1169 // climb on a lower saddle when a higher one exists: the saddle is the
1170 // band's global energy maximum, a property of the PES, not of the image
1171 // count. Keeping the CI on any local max made the choice resolution-
1172 // dependent -- a finer band exposes minor interior maxima near the
1173 // endpoints, and the prior CI sticks to one while the true peak sits far
1174 // higher (03_h2co at nimages=18: CI parked at a near-reactant bump,
1175 // forward barrier ~0 while the real TS image was ~3.4 eV). So keep the
1176 // prior CI only while it remains the band's highest-energy image; the
1177 // moment a higher peak appears, climb that one.
1178 if (numImages() <= 2) return -1;
1179 const int hi = highestEnergyImageIndex();
1180 if (preferred > 0 && preferred < numImages() - 1 && hi > 0 &&
1181 std::isfinite(images_[preferred].energy) &&
1182 images_[preferred].energy >= images_[hi].energy) {
1183 return preferred;
1184 }
1185 return hi;
1186}

◆ highestLocalMaximumImageIndex()

int gpr::neb::NEBPath::highestLocalMaximumImageIndex ( ) const

Strict interior local maximum, else the highest finite energy.

A higher shoulder that is not itself strict does not replace a lower strict maximum. Non-finite energies are not candidates. The GP-OIE candidate uses this so the seeded reaction coordinate keeps the climb. highestEnergyImageIndex remains the global maximum.

Definition at line 1188 of file NEBPath.cpp.

1189{
1190 // A strict interior local maximum wins over a higher shoulder that
1191 // is not strict. With no strict maximum, the highest finite interior
1192 // energy remains. Non-finite energies are not candidates. Ties keep
1193 // the highest energy, then the lowest index.
1194 if (numImages() <= 2) return -1;
1195 int best_peak = -1;
1196 double best_peak_e = -std::numeric_limits<double>::infinity();
1197 int best_any = -1;
1198 double best_any_e = -std::numeric_limits<double>::infinity();
1199 for (int i = 1; i < numImages() - 1; ++i) {
1200 const double e = images_[i].energy;
1201 if (!std::isfinite(e)) continue;
1202 if (best_any < 0 || e > best_any_e) {
1203 best_any_e = e;
1204 best_any = i;
1205 }
1206 const double e_prev = images_[i - 1].energy;
1207 const double e_next = images_[i + 1].energy;
1208 const bool local_max = std::isfinite(e_prev) && std::isfinite(e_next) &&
1209 e > e_prev && e > e_next;
1210 if (local_max && (best_peak < 0 || e > best_peak_e ||
1211 (e == best_peak_e && i < best_peak))) {
1212 best_peak_e = e;
1213 best_peak = i;
1214 }
1215 }
1216 return best_peak >= 0 ? best_peak : best_any;
1217}

◆ highestLocalMaximumImageIndexPreferring()

int gpr::neb::NEBPath::highestLocalMaximumImageIndexPreferring ( int preferred) const

Definition at line 1219 of file NEBPath.cpp.

1220{
1221 if (numImages() <= 2) return -1;
1222 const int hi = highestLocalMaximumImageIndex();
1223 if (preferred > 0 && preferred < numImages() - 1 && hi > 0 &&
1224 std::isfinite(images_[preferred].energy) &&
1225 images_[preferred].energy >= images_[hi].energy) {
1226 return preferred;
1227 }
1228 return hi;
1229}
int highestLocalMaximumImageIndex() const
Strict interior local maximum, else the highest finite energy.
Definition NEBPath.cpp:1188

◆ image() [1/2]

Image & gpr::neb::NEBPath::image ( int i)
inline

Access image i.

Definition at line 329 of file NEBPath.h.

330 {
331 return images_[i];
332 }

◆ image() [2/2]

const Image & gpr::neb::NEBPath::image ( int i) const
inline

Definition at line 333 of file NEBPath.h.

334 {
335 return images_[i];
336 }

◆ initializeIDPP() [1/2]

void gpr::neb::NEBPath::initializeIDPP ( int n_atoms,
bool collective = false )

Initialize from IDPP (image dependent pair potential) interpolation.

Better initial path than linear interpolation for molecular systems. The per-image seed is rgsaddle_idpp_fixed_path. collective is the alternating S-IDPP seed with the insertion stage skipped; rgsaddle has no collective entry of its own.

Parameters
n_atomsNumber of atoms (positions.size() / 3)
collectiveIf true, relax the whole chain together.

Definition at line 697 of file NEBPath.cpp.

698{
699 initializeIDPP(n_atoms, {}, collective);
700}
void initializeIDPP(int n_atoms, bool collective=false)
Initialize from IDPP (image dependent pair potential) interpolation.
Definition NEBPath.cpp:697

◆ initializeIDPP() [2/2]

void gpr::neb::NEBPath::initializeIDPP ( int n_atoms,
const std::vector< char > & moving_atoms,
bool collective = false )

Definition at line 702 of file NEBPath.cpp.

704{
705 int n_int = numIntermediate();
706 if (n_int <= 0 || n_atoms <= 0) return;
707
708 seedFromRuntime(collective ? RuntimeSeed::Collective : RuntimeSeed::Idpp,
709 n_atoms, moving_atoms, 0.0);
710}
int numIntermediate() const
Definition NEBPath.h:342

◆ initializeSIDPP() [1/2]

void gpr::neb::NEBPath::initializeSIDPP ( int n_atoms,
const std::vector< char > & moving_atoms,
double alpha = 0.33 )

Definition at line 717 of file NEBPath.cpp.

720{
721 int n_int = numIntermediate();
722 if (n_int <= 0 || n_atoms <= 0) return;
723 // The IDPP interpolation relaxes on the image-dependent-pair-potential
724 // surface, whose spring is in normalized pair-distance units -- NOT the
725 // physical NEB spring constant (eV/A). Feeding the NEB k_max (energy-
726 // weighted, up to ~9.72) over-stiffens the IDPP relaxation and produces a
727 // distorted initial path that drops the band into a higher-saddle basin.
728 // Use the standard unit IDPP spring, decoupled from the NEB spring.
729 seedFromRuntime(RuntimeSeed::Sidpp, n_atoms, moving_atoms, alpha);
730}

◆ initializeSIDPP() [2/2]

void gpr::neb::NEBPath::initializeSIDPP ( int n_atoms,
double alpha = 0.33 )

Initialize via Sequential IDPP (SIDPP). rgsaddle_sidpp_alternating_path. The spring on that call is the unit IDPP spring, not the physical NEB spring.

Definition at line 712 of file NEBPath.cpp.

713{
714 initializeSIDPP(n_atoms, {}, alpha);
715}
void initializeSIDPP(int n_atoms, double alpha=0.33)
Initialize via Sequential IDPP (SIDPP). rgsaddle_sidpp_alternating_path. The spring on that call is t...
Definition NEBPath.cpp:712

◆ initializeSIDPPGeodesic() [1/2]

void gpr::neb::NEBPath::initializeSIDPPGeodesic ( int n_atoms,
const std::vector< char > & moving_atoms,
double alpha = 0.33 )

Definition at line 737 of file NEBPath.cpp.

740{
741 int n_int = numIntermediate();
742 if (n_int <= 0 || n_atoms <= 0) return;
743 // Same decoupled unit IDPP spring as initializeSIDPP: the geodesic
744 // inverse-distance relaxation runs on the normalized pair-distance
745 // surface, so feeding the physical NEB k_max (up to ~9.72) over-stiffens
746 // it and distorts the path into a higher-saddle basin.
747 seedFromRuntime(RuntimeSeed::SidppInverseDistance, n_atoms, moving_atoms,
748 alpha);
749}

◆ initializeSIDPPGeodesic() [2/2]

void gpr::neb::NEBPath::initializeSIDPPGeodesic ( int n_atoms,
double alpha = 0.33 )

Initialize via inverse-distance S-IDPP. rgsaddle_sidpp_alternating_inverse_distance_path. This is the –sidpp-geodesic blend (close pairs stay close longer). It is not rgsaddle_geodesic_path, which minimises a redundant-coordinate length and needs a chart.

Definition at line 732 of file NEBPath.cpp.

733{
734 initializeSIDPPGeodesic(n_atoms, {}, alpha);
735}
void initializeSIDPPGeodesic(int n_atoms, double alpha=0.33)
Initialize via inverse-distance S-IDPP. rgsaddle_sidpp_alternating_inverse_distance_path....
Definition NEBPath.cpp:732

◆ intermediatePositions()

EigenMatrix gpr::neb::NEBPath::intermediatePositions ( ) const

Get all intermediate image positions as a matrix.

Returns
Matrix of shape (n_intermediate, n_coords)

Definition at line 1231 of file NEBPath.cpp.

1232{
1233 int n_int = numIntermediate();
1234 int n_coords = static_cast<int>(images_[0].positions.size());
1235 EigenMatrix R(n_int, n_coords);
1236 for (int i = 0; i < n_int; ++i) {
1237 R.row(i) = images_[i + 1].positions.transpose();
1238 }
1239 return R;
1240}
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20

◆ interpolateFromEndpoints()

void gpr::neb::NEBPath::interpolateFromEndpoints ( )

Rebuild interior images on the chord between the current endpoints.

Definition at line 610 of file NEBPath.cpp.

611{
612 const int total = numImages();
613 if (total < 2) return;
614 const Eigen::VectorXd initial = images_[0].positions;
615 const Eigen::VectorXd final_state = images_.back().positions;
616 const Eigen::VectorXd chord = segmentDisplacement(initial, final_state);
617 for (int i = 1; i < total - 1; ++i) {
618 const double t = static_cast<double>(i) / (total - 1);
619 if (periodic_)
620 images_[i].positions = initial + t * chord;
621 else
622 images_[i].positions = (1.0 - t) * initial + t * final_state;
623 images_[i].gradient = Eigen::VectorXd::Zero(initial.size());
624 images_[i].energy = 0.0;
625 images_[i].evaluated = false;
626 images_[i].is_endpoint = false;
627 pinFixedAtoms(images_[i].positions);
628 }
629}
void pinFixedAtoms(Eigen::Ref< Eigen::VectorXd > positions) const
Copy reactant coordinates onto fixed atoms.
Definition NEBPath.cpp:552

◆ inverseDistanceGeodesicInterpolate()

Eigen::VectorXd gpr::neb::NEBPath::inverseDistanceGeodesicInterpolate ( int n_atoms,
const std::vector< char > & moving_atoms,
const Eigen::VectorXd & left,
const Eigen::VectorXd & right,
double alpha,
const std::array< double, 9 > * cell = nullptr )
staticnodiscard

Interpolate between two geometries in inverse-distance space.

Active atom-pair inverse distances follow ~(1 - alpha) q(left) + alpha q(right)~. Inactive Cartesian columns are held at the left geometry, so fixed-atom masks remain fixed during trust bisection and line-search interpolation.

Definition at line 1629 of file NEBPath.cpp.

1633{
1634 if (left.size() != right.size()) {
1635 throw std::invalid_argument(
1636 "NEBPath inverse-distance interpolation size mismatch");
1637 }
1638 if (!left.allFinite() || !right.allFinite() || !std::isfinite(alpha)) {
1639 throw std::invalid_argument(
1640 "NEBPath inverse-distance interpolation received invalid "
1641 "coordinates");
1642 }
1643 if (alpha < 0.0 || alpha > 1.0) {
1644 throw std::invalid_argument(
1645 "NEBPath inverse-distance interpolation requires alpha in [0, 1]");
1646 }
1647 if (alpha == 0.0) return left;
1648
1649 gpr::geometry::PairBox periodic_box;
1650 const bool periodic =
1651 cell != nullptr && gpr::geometry::cellIsMicLattice(cell->data());
1652 if (periodic) periodic_box.reset(cell->data());
1653 const auto system = makeInverseDistanceSystem(
1654 n_atoms, left.size(), moving_atoms, periodic ? &periodic_box : nullptr);
1655 Eigen::VectorXd right_active = left;
1656 Eigen::VectorXd start = left;
1657 for (Eigen::Index col = 0;
1658 col < static_cast<Eigen::Index>(system.active_columns.size()); ++col) {
1659 const Eigen::Index full_col =
1660 system.active_columns[static_cast<std::size_t>(col)];
1661 right_active(full_col) = right(full_col);
1662 if (periodic) {
1663 const Eigen::Index origin = full_col - full_col % 3;
1664 const Eigen::Vector3d from = left.segment<3>(origin);
1665 const Eigen::Vector3d to = right.segment<3>(origin);
1666 const Eigen::Vector3d chord = periodic_box.displacement(from, to);
1667 start(full_col) =
1668 left(full_col) + alpha * chord(static_cast<int>(full_col % 3));
1669 } else {
1670 start(full_col) =
1671 (1.0 - alpha) * left(full_col) + alpha * right(full_col);
1672 }
1673 }
1674 if (alpha == 1.0) return right_active;
1675
1676 const Eigen::VectorXd target = (1.0 - alpha) * system.values(left) +
1677 alpha * system.values(right_active);
1678 return solveInverseDistanceTarget(system, start, target);
1679}
void reset(const double cell[9])
Definition MinImage.h:180
void displacement(const double p[3], const double q[3], double dr[3]) const
Displacement from p to q. Cartesian q - p when the cell is zero.
Definition MinImage.h:210
bool cellIsMicLattice(const double cell[9]) noexcept
Nonzero ASE 3x3 that is not the 25 A vacuum convention.
Definition MinImage.h:56

◆ inverseDistanceGeodesicStep()

Eigen::VectorXd gpr::neb::NEBPath::inverseDistanceGeodesicStep ( int n_atoms,
const std::vector< char > & moving_atoms,
const Eigen::VectorXd & positions,
const Eigen::VectorXd & cartesian_step,
const std::array< double, 9 > * cell = nullptr )
staticnodiscard

Apply one inverse-distance internal-coordinate retraction.

The Cartesian step defines a linearized internal-coordinate target q(R) + J(R) dR for q_ab = 1 / ||R_a - R_b|| over active atom pairs. The target is mapped back to Cartesian coordinates with the same SVD Gauss-Newton solve used by the band geodesic reparameterizer.

Definition at line 1593 of file NEBPath.cpp.

1597{
1598 if (positions.size() != cartesian_step.size()) {
1599 throw std::invalid_argument(
1600 "NEBPath inverse-distance geodesic step size mismatch");
1601 }
1602 if (!positions.allFinite() || !cartesian_step.allFinite()) {
1603 throw std::invalid_argument(
1604 "NEBPath inverse-distance geodesic step received invalid "
1605 "coordinates");
1606 }
1607 gpr::geometry::PairBox periodic_box;
1608 const bool periodic =
1609 cell != nullptr && gpr::geometry::cellIsMicLattice(cell->data());
1610 if (periodic) periodic_box.reset(cell->data());
1611 const auto system =
1612 makeInverseDistanceSystem(n_atoms, positions.size(), moving_atoms,
1613 periodic ? &periodic_box : nullptr);
1614 Eigen::VectorXd active_step(
1615 static_cast<Eigen::Index>(system.active_columns.size()));
1616 Eigen::VectorXd start = positions;
1617 for (Eigen::Index col = 0; col < active_step.size(); ++col) {
1618 const Eigen::Index full_col =
1619 system.active_columns[static_cast<std::size_t>(col)];
1620 active_step(col) = cartesian_step(full_col);
1621 start(full_col) += cartesian_step(full_col);
1622 }
1623 const Eigen::VectorXd target =
1624 system.values(positions) +
1625 system.jacobianActive(positions) * active_step;
1626 return solveInverseDistanceTarget(system, start, target);
1627}

◆ inverseDistanceSegmentMetricFactors() [1/2]

std::vector< Eigen::MatrixXd > gpr::neb::NEBPath::inverseDistanceSegmentMetricFactors ( int n_atoms) const

Build segment metric factors for inverse-distance coordinates.

For each segment, evaluates the Jacobian of q_ab = 1 / r_ab at the segment midpoint for every atom pair a < b. Passing the returned factors into reparametrizeByMetricArcLength() spaces the band uniformly in the local inverse-distance coordinate metric used by geodesic IDPP.

Definition at line 1398 of file NEBPath.cpp.

1400{
1401 return inverseDistanceSegmentMetricFactors(n_atoms, {});
1402}
std::vector< Eigen::MatrixXd > inverseDistanceSegmentMetricFactors(int n_atoms) const
Build segment metric factors for inverse-distance coordinates.
Definition NEBPath.cpp:1398

◆ inverseDistanceSegmentMetricFactors() [2/2]

std::vector< Eigen::MatrixXd > gpr::neb::NEBPath::inverseDistanceSegmentMetricFactors ( int n_atoms,
const std::vector< char > & moving_atoms ) const

Build inverse-distance segment factors over active atom pairs.

moving_atoms[a] marks atoms whose coordinates may change along the band. Pairs where both atoms are fixed are removed from the pullback metric, while moving-moving and moving-fixed pairs remain. An empty mask keeps every pair active.

Definition at line 1404 of file NEBPath.cpp.

1406{
1407 const int N = numImages();
1408 if (N < 2) return {};
1409 if (n_atoms < 2) {
1410 throw std::invalid_argument(
1411 "NEBPath inverse-distance metric requires at least two atoms");
1412 }
1413 const Eigen::Index dof = images_[0].positions.size();
1414 if (dof != static_cast<Eigen::Index>(3 * n_atoms)) {
1415 throw std::invalid_argument(
1416 "NEBPath inverse-distance metric atom count does not match "
1417 "coordinates");
1418 }
1419 if (!moving_atoms.empty() &&
1420 static_cast<int>(moving_atoms.size()) != n_atoms) {
1421 throw std::invalid_argument(
1422 "NEBPath inverse-distance moving-atom mask size mismatch");
1423 }
1424 std::vector<std::pair<int, int>> active_pairs;
1425 active_pairs.reserve(static_cast<std::size_t>(n_atoms * (n_atoms - 1) / 2));
1426 for (int a = 0; a < n_atoms; ++a) {
1427 const bool a_active =
1428 moving_atoms.empty() || moving_atoms[static_cast<std::size_t>(a)];
1429 for (int b = a + 1; b < n_atoms; ++b) {
1430 const bool b_active = moving_atoms.empty() ||
1431 moving_atoms[static_cast<std::size_t>(b)];
1432 if (a_active || b_active) active_pairs.emplace_back(a, b);
1433 }
1434 }
1435 if (active_pairs.empty()) {
1436 throw std::invalid_argument(
1437 "NEBPath inverse-distance metric has no active atom pairs");
1438 }
1439 const Eigen::Index n_pairs = static_cast<Eigen::Index>(active_pairs.size());
1440 std::vector<Eigen::MatrixXd> factors(static_cast<std::size_t>(N - 1));
1441
1442 for (int seg = 0; seg < N - 1; ++seg) {
1443 Eigen::VectorXd midpoint;
1444 if (molecularRigidMotion()) {
1445 midpoint = images_[seg].positions +
1446 0.5 * segmentDisplacement(images_[seg].positions,
1447 images_[seg + 1].positions);
1448 } else {
1449 midpoint =
1450 0.5 * (images_[seg].positions + images_[seg + 1].positions);
1451 }
1452 if (midpoint.size() != dof || !midpoint.allFinite()) {
1453 throw std::invalid_argument(
1454 "NEBPath inverse-distance metric received invalid coordinates");
1455 }
1456
1457 Eigen::MatrixXd B = Eigen::MatrixXd::Zero(n_pairs, dof);
1458 Eigen::Index row = 0;
1459 for (const auto& pair: active_pairs) {
1460 const int a = pair.first;
1461 const int b = pair.second;
1462 const Eigen::Vector3d Ra = midpoint.segment<3>(3 * a);
1463 const Eigen::Vector3d Rb = midpoint.segment<3>(3 * b);
1464 const Eigen::Vector3d d = Rb - Ra;
1465 const double r2 = d.squaredNorm();
1466 if (r2 <= std::numeric_limits<double>::min()) {
1467 throw std::invalid_argument(
1468 "NEBPath inverse-distance metric has a degenerate atom "
1469 "pair");
1470 }
1471 const double inv_r3 = 1.0 / (r2 * std::sqrt(r2));
1472 const Eigen::Vector3d grad_a = inv_r3 * d;
1473 B.block<1, 3>(row, 3 * a) = grad_a.transpose();
1474 B.block<1, 3>(row, 3 * b) = -grad_a.transpose();
1475 ++row;
1476 }
1477 factors[static_cast<std::size_t>(seg)] = std::move(B);
1478 }
1479
1480 return factors;
1481}

◆ maskFixedForce()

void gpr::neb::NEBPath::maskFixedForce ( Eigen::Ref< Eigen::VectorXd > force) const

Zero a force on fixed atoms.

Definition at line 563 of file NEBPath.cpp.

564{
565 if (moving_atoms_.empty()) return;
566 if (force.size() != static_cast<Eigen::Index>(moving_atoms_.size() * 3))
567 return;
568 for (int atom = 0; atom < static_cast<int>(moving_atoms_.size()); ++atom) {
569 if (moving_atoms_[static_cast<std::size_t>(atom)]) continue;
570 force.segment<3>(3 * atom).setZero();
571 }
572}

◆ maxMetricSpacingDeviation()

double gpr::neb::NEBPath::maxMetricSpacingDeviation ( const std::vector< Eigen::MatrixXd > & segment_metric_factors) const

Maximum relative spacing deviation measured in a pullback metric.

Uses the same segment metric factors consumed by reparametrizeByMetricArcLength(). The deviation is local and scale-free: max_i abs(ell_i - mean(ell)) / mean(ell), where ell_i is the metric length of segment i.

Definition at line 1277 of file NEBPath.cpp.

1279{
1280 const int N = numImages();
1281 if (N < 3) return 0.0;
1282 const Eigen::Index dof = images_[0].positions.size();
1283 if (static_cast<int>(segment_metric_factors.size()) != N - 1) {
1284 throw std::invalid_argument(
1285 "NEBPath metric spacing requires one factor per segment");
1286 }
1287
1288 double total = 0.0;
1289 std::vector<double> seg(static_cast<std::size_t>(N - 1), 0.0);
1290 for (int i = 0; i < N - 1; ++i) {
1291 const Eigen::MatrixXd& B =
1292 segment_metric_factors[static_cast<std::size_t>(i)];
1293 if (B.cols() != dof || B.rows() == 0 || !B.allFinite()) {
1294 throw std::invalid_argument(
1295 "NEBPath metric factor has incompatible shape or non-finite "
1296 "entries");
1297 }
1298 const Eigen::VectorXd delta =
1299 segmentDisplacement(images_[i].positions, images_[i + 1].positions);
1300 seg[static_cast<std::size_t>(i)] = (B * delta).norm();
1301 total += seg[static_cast<std::size_t>(i)];
1302 }
1303 if (total <= std::numeric_limits<double>::min()) return 0.0;
1304 const double h = total / static_cast<double>(N - 1);
1305 double max_dev = 0.0;
1306 for (double length: seg) {
1307 max_dev = std::max(max_dev, std::abs(length - h) / h);
1308 }
1309 return max_dev;
1310}

◆ maxSpacingDeviation()

double gpr::neb::NEBPath::maxSpacingDeviation ( ) const

Maximum relative deviation of image spacing from uniform.

For a chain of total arc length L with N images, the uniform segment length is h = L / (N-1). This returns max_i abs(s_i - h) / h where s_i = ||r_{i+1} - r_i||. Zero means uniformly spaced; a value >1 means at least one segment is more than 2x the mean. Callers gate path reparametrization on this returning above a tolerance.

Definition at line 1255 of file NEBPath.cpp.

1256{
1257 const int N = numImages();
1258 if (N < 3) return 0.0;
1259
1260 double total = 0.0;
1261 std::vector<double> seg(N - 1, 0.0);
1262 for (int i = 0; i < N - 1; ++i) {
1263 seg[i] =
1264 segmentDisplacement(images_[i].positions, images_[i + 1].positions)
1265 .norm();
1266 total += seg[i];
1267 }
1268 if (total < 1e-30) return 0.0;
1269 const double h = total / static_cast<double>(N - 1);
1270 double max_dev = 0.0;
1271 for (int i = 0; i < N - 1; ++i) {
1272 max_dev = std::max(max_dev, std::abs(seg[i] - h) / h);
1273 }
1274 return max_dev;
1275}

◆ molecularRigidMotion()

bool gpr::neb::NEBPath::molecularRigidMotion ( ) const
nodiscard

Definition at line 496 of file NEBPath.cpp.

497{
498 return molecular_rigid_motion_ && !periodic_ && allAtomsFree() &&
499 !images_.empty() && images_[0].positions.size() >= 6 &&
500 images_[0].positions.size() % 3 == 0;
501}

◆ nebForce()

const Eigen::VectorXd & gpr::neb::NEBPath::nebForce ( int i) const
inline

Get the NEB force for image i.

Definition at line 257 of file NEBPath.h.

258 {
259 return neb_forces_[i];
260 }

◆ nebForceMagnitude()

double gpr::neb::NEBPath::nebForceMagnitude ( int i) const
inline

The automatic whole-band measure is the Euclidean image norm.

Definition at line 287 of file NEBPath.h.

288 {
289 if (!convergence_force_norm_) return neb_forces_[i].norm();
290 return gpr::forceNorm(neb_forces_[i], *convergence_force_norm_);
291 }

◆ numImages()

int gpr::neb::NEBPath::numImages ( ) const
inline

Definition at line 338 of file NEBPath.h.

339 {
340 return static_cast<int>(images_.size());
341 }

◆ numIntermediate()

int gpr::neb::NEBPath::numIntermediate ( ) const
inline

Definition at line 342 of file NEBPath.h.

343 {
344 return numImages() - 2;
345 }

◆ pinFixedAtoms()

void gpr::neb::NEBPath::pinFixedAtoms ( Eigen::Ref< Eigen::VectorXd > positions) const

Copy reactant coordinates onto fixed atoms.

Definition at line 552 of file NEBPath.cpp.

553{
554 if (moving_atoms_.empty() || images_.empty()) return;
555 const Eigen::VectorXd& reference = images_[0].positions;
556 if (positions.size() != reference.size()) return;
557 for (int atom = 0; atom < static_cast<int>(moving_atoms_.size()); ++atom) {
558 if (moving_atoms_[static_cast<std::size_t>(atom)]) continue;
559 positions.segment<3>(3 * atom) = reference.segment<3>(3 * atom);
560 }
561}

◆ posteriorVarianceThreshold()

double gpr::neb::NEBPath::posteriorVarianceThreshold ( ) const
inlinenodiscard

Current signal-scaled posterior-variance confidence threshold.

Definition at line 626 of file NEBPath.h.

627 {
628 return posterior_variance_threshold_;
629 }

◆ projectPhysicalVector()

void gpr::neb::NEBPath::projectPhysicalVector ( const Eigen::VectorXd & reference,
Eigen::Ref< Eigen::VectorXd > vector ) const

Project a force or step onto the molecular internal-motion space. Linear molecules retain both bending directions.

Definition at line 503 of file NEBPath.cpp.

505{
506 if (!molecularRigidMotion()) return;
507 if (reference.size() != vector.size() || reference.size() % 3 != 0 ||
508 !reference.allFinite() || !vector.allFinite())
509 throw std::invalid_argument("invalid molecular rigid projection input");
510 gpr::Coord coordinates(1, reference.size());
511 coordinates.row(0) = reference.transpose();
512 const Eigen::MatrixXd basis = dimer::rigid_motion_basis(coordinates);
513 const Eigen::VectorXd coefficients = basis.transpose() * vector;
514 vector.noalias() -= basis * coefficients;
515}
Eigen::MatrixXd rigid_motion_basis(const gpr::Coord &R, bool rotations)
Build an orthonormal basis for rigid-body translations and rotations.
Definition Dimer.cpp:30
FieldMatrixd Coord
Definition Macros.h:35

◆ reparametrizeByArcLength()

double gpr::neb::NEBPath::reparametrizeByArcLength ( )

Redistribute interior images uniformly along arc length.

Computes cumulative arc length along the current chain, then resamples each interior image at uniform arc-length spacing via piecewise-linear interpolation between the original positions. Endpoints are unchanged. A resampled image drops its energy, gradient, evaluated flag, posterior variance (back to +infinity), and force variance, because that state does not describe the new positions. Cached NEB forces on every intermediate image are zeroed. The caller must refresh the surrogate predictions and call computeNEBForces() before the next L-BFGS step.

Returns the maxSpacingDeviation() measured BEFORE reparametrizing.

Quasi-Newton state held by the band L-BFGS optimizer is invalidated by this operation: every curvature pair (s_k, y_k) is indexed against the pre-reparam parameterization, so the caller MUST reset its optimizer's history after this call returns.

Definition at line 1312 of file NEBPath.cpp.

1313{
1314 const int N = numImages();
1315 if (N < 3) return 0.0;
1316
1317 // Cumulative arc length along the current chain.
1318 std::vector<double> s(N, 0.0);
1319 for (int i = 1; i < N; ++i) {
1320 s[i] = s[i - 1] + segmentDisplacement(images_[i - 1].positions,
1321 images_[i].positions)
1322 .norm();
1323 }
1324 return reparametrizeFromCumulativeArc(s);
1325}

◆ reparametrizeByArcLengthKeepingImage()

double gpr::neb::NEBPath::reparametrizeByArcLengthKeepingImage ( int anchor_index)

Redistribute the two subchains while preserving one image.

The preserved image is an exact observation anchor, such as a dimer-refined saddle row. Images on each side are resampled uniformly along their own arc-length interval; endpoints and the anchor retain their coordinates and exact-data state. Non-anchor interiors are invalidated like reparametrizeByArcLength().

Definition at line 1327 of file NEBPath.cpp.

1328{
1329 const int N = numImages();
1330 if (N < 3) return 0.0;
1331
1332 std::vector<double> s(N, 0.0);
1333 for (int i = 1; i < N; ++i) {
1334 s[i] = s[i - 1] + segmentDisplacement(images_[i - 1].positions,
1335 images_[i].positions)
1336 .norm();
1337 }
1338 return reparametrizeFromCumulativeArc(s, anchor_index);
1339}

◆ reparametrizeByInverseDistanceGeodesicArcLength() [1/2]

double gpr::neb::NEBPath::reparametrizeByInverseDistanceGeodesicArcLength ( int n_atoms)

Redistribute the band by solving inverse-distance targets.

Builds q_ab(R) = 1 / ||R_a - R_b|| for every active atom pair and spaces the chain along that q-space arc. Spring rest lengths, when set, fix the cumulative fractions; otherwise the spacing is uniform. Each target q is mapped back to Cartesian coordinates with an SVD Gauss-Newton internal-coordinate step. Moved images are invalidated like reparametrizeByArcLength(). This is the NEB reparameterization analogue of the geodesic internal coordinate update in Hermes et al. (doi:10.1063/5.0060146).

Definition at line 1497 of file NEBPath.cpp.

1498{
1500}
double reparametrizeByInverseDistanceGeodesicArcLength(int n_atoms)
Redistribute the band by solving inverse-distance targets.
Definition NEBPath.cpp:1497

◆ reparametrizeByInverseDistanceGeodesicArcLength() [2/2]

double gpr::neb::NEBPath::reparametrizeByInverseDistanceGeodesicArcLength ( int n_atoms,
const std::vector< char > & moving_atoms )

Definition at line 1502 of file NEBPath.cpp.

1504{
1506 n_atoms, moving_atoms, -1);
1507}
double reparametrizeByInverseDistanceGeodesicArcLengthKeepingImage(int n_atoms, const std::vector< char > &moving_atoms, int anchor_index)
Anchor-preserving inverse-distance geodesic reparameterization.
Definition NEBPath.cpp:1509

◆ reparametrizeByInverseDistanceGeodesicArcLengthKeepingImage()

double gpr::neb::NEBPath::reparametrizeByInverseDistanceGeodesicArcLengthKeepingImage ( int n_atoms,
const std::vector< char > & moving_atoms,
int anchor_index )

Anchor-preserving inverse-distance geodesic reparameterization.

Definition at line 1509 of file NEBPath.cpp.

1511{
1512 const int N = numImages();
1513 if (N < 3) return 0.0;
1514 const Eigen::Index dof = images_[0].positions.size();
1515 const auto system = makeInverseDistanceSystem(
1516 n_atoms, dof, moving_atoms, periodic_ ? &periodic_box_ : nullptr);
1517 const bool keep_anchor = anchor_index > 0 && anchor_index < N - 1;
1518
1519 std::vector<Eigen::VectorXd> orig(static_cast<std::size_t>(N));
1520 std::vector<Eigen::VectorXd> q(static_cast<std::size_t>(N));
1521 for (int i = 0; i < N; ++i) {
1522 orig[static_cast<std::size_t>(i)] = images_[i].positions;
1523 if (orig[static_cast<std::size_t>(i)].size() != dof ||
1524 !orig[static_cast<std::size_t>(i)].allFinite()) {
1525 throw std::invalid_argument(
1526 "NEBPath inverse-distance geodesic received invalid "
1527 "coordinates");
1528 }
1529 q[static_cast<std::size_t>(i)] =
1530 system.values(orig[static_cast<std::size_t>(i)]);
1531 }
1532
1533 std::vector<double> s(static_cast<std::size_t>(N), 0.0);
1534 for (int i = 1; i < N; ++i) {
1535 s[static_cast<std::size_t>(i)] = s[static_cast<std::size_t>(i - 1)] +
1536 (q[static_cast<std::size_t>(i)] -
1537 q[static_cast<std::size_t>(i - 1)])
1538 .norm();
1539 }
1540 const double total = s.back() - s.front();
1541 if (total <= std::numeric_limits<double>::min()) return 0.0;
1542 // Rest lengths are fractions of this q-space arc, including on each side
1543 // of an anchor. Without them the chain stays equally spaced in q.
1544 const std::vector<double> rest_targets =
1545 restLengthSegmentTargets(s, spring_rest_lengths_, anchor_index);
1546 const double max_dev =
1547 rest_targets.empty()
1548 ? spacingDeviationFromCumulativeArc(s, anchor_index)
1549 : deviationFromSegmentTargets(s, rest_targets);
1550 if (max_dev <= std::sqrt(std::numeric_limits<double>::epsilon())) {
1551 return max_dev;
1552 }
1553
1554 for (int j = 1; j < N - 1; ++j) {
1555 if (keep_anchor && j == anchor_index) continue;
1556 const double s_target = rest_targets.empty()
1557 ? targetArcForImage(s, j, anchor_index)
1558 : cumulativeTargetArc(s, rest_targets, j);
1559 int k = 0;
1560 while (k < N - 2 && s[static_cast<std::size_t>(k + 1)] < s_target) {
1561 ++k;
1562 }
1563 const double denom =
1564 s[static_cast<std::size_t>(k + 1)] - s[static_cast<std::size_t>(k)];
1565 const double alpha =
1566 (denom > std::numeric_limits<double>::min())
1567 ? (s_target - s[static_cast<std::size_t>(k)]) / denom
1568 : 0.0;
1569 const Eigen::VectorXd q_target =
1570 q[static_cast<std::size_t>(k)] +
1571 alpha * (q[static_cast<std::size_t>(k + 1)] -
1572 q[static_cast<std::size_t>(k)]);
1573 const Eigen::VectorXd start =
1574 orig[static_cast<std::size_t>(k)] +
1575 alpha * segmentDisplacement(orig[static_cast<std::size_t>(k)],
1576 orig[static_cast<std::size_t>(k + 1)]);
1577 images_[j].positions = alignMolecularGeometry(
1578 orig[static_cast<std::size_t>(j)],
1579 solveInverseDistanceTarget(system, start, q_target));
1580 pinFixedAtoms(images_[j].positions);
1581 invalidateResampledImage(j);
1582 }
1583
1584 for (int i = 1; i < N - 1; ++i) {
1585 if (neb_forces_[i].size() == dof) {
1586 neb_forces_[i].setZero();
1587 }
1588 }
1589
1590 return max_dev;
1591}

◆ reparametrizeByMetricArcLength()

double gpr::neb::NEBPath::reparametrizeByMetricArcLength ( const std::vector< Eigen::MatrixXd > & segment_metric_factors)

Redistribute interior images uniformly in a pullback metric.

segment_metric_factors[i] maps the Cartesian displacement images[i+1].positions - images[i].positions into the coordinate space used to measure that segment. For internal-coordinate spacing this factor is an internal-coordinate Jacobian (or a midpoint/trapezoid representative of neighbouring Jacobians); for IRC mass weighting it is diag(sqrt(m)).

The segment length is ||B_i * (R_{i+1} - R_i)||. Endpoints are unchanged; interior energies, gradients, evaluated flags, posterior variances, force variances, and cached NEB forces are invalidated in the same way as reparametrizeByArcLength().

Definition at line 1341 of file NEBPath.cpp.

1343{
1344 const int N = numImages();
1345 if (N < 3) return 0.0;
1346 const Eigen::Index dof = images_[0].positions.size();
1347 if (static_cast<int>(segment_metric_factors.size()) != N - 1) {
1348 throw std::invalid_argument(
1349 "NEBPath metric reparameterization requires one factor per "
1350 "segment");
1351 }
1352
1353 std::vector<double> s(N, 0.0);
1354 for (int i = 1; i < N; ++i) {
1355 const Eigen::MatrixXd& B =
1356 segment_metric_factors[static_cast<std::size_t>(i - 1)];
1357 if (B.cols() != dof || B.rows() == 0 || !B.allFinite()) {
1358 throw std::invalid_argument(
1359 "NEBPath metric factor has incompatible shape or non-finite "
1360 "entries");
1361 }
1362 const Eigen::VectorXd delta =
1363 segmentDisplacement(images_[i - 1].positions, images_[i].positions);
1364 s[i] = s[i - 1] + (B * delta).norm();
1365 }
1366 return reparametrizeFromCumulativeArc(s);
1367}

◆ reparametrizeByMetricArcLengthKeepingImage()

double gpr::neb::NEBPath::reparametrizeByMetricArcLengthKeepingImage ( const std::vector< Eigen::MatrixXd > & segment_metric_factors,
int anchor_index )

Metric pullback variant of reparametrizeByArcLengthKeepingImage().

Definition at line 1369 of file NEBPath.cpp.

1372{
1373 const int N = numImages();
1374 if (N < 3) return 0.0;
1375 const Eigen::Index dof = images_[0].positions.size();
1376 if (static_cast<int>(segment_metric_factors.size()) != N - 1) {
1377 throw std::invalid_argument(
1378 "NEBPath metric reparameterization requires one factor per "
1379 "segment");
1380 }
1381
1382 std::vector<double> s(N, 0.0);
1383 for (int i = 1; i < N; ++i) {
1384 const Eigen::MatrixXd& B =
1385 segment_metric_factors[static_cast<std::size_t>(i - 1)];
1386 if (B.cols() != dof || B.rows() == 0 || !B.allFinite()) {
1387 throw std::invalid_argument(
1388 "NEBPath metric factor has incompatible shape or non-finite "
1389 "entries");
1390 }
1391 const Eigen::VectorXd delta =
1392 segmentDisplacement(images_[i - 1].positions, images_[i].positions);
1393 s[i] = s[i - 1] + (B * delta).norm();
1394 }
1395 return reparametrizeFromCumulativeArc(s, anchor_index);
1396}

◆ saddleForce()

double gpr::neb::NEBPath::saddleForce ( int i) const
inline

Physical force magnitude without the climbing-image reflection.

Definition at line 263 of file NEBPath.h.

264 {
265 return forceMagnitude(images_[i].gradient);
266 }
double forceMagnitude(const Eigen::VectorXd &force) const
Definition NEBPath.h:281

◆ setClimbingCurvatureDirection()

void gpr::neb::NEBPath::setClimbingCurvatureDirection ( Eigen::VectorXd direction)
inline

Unit climb direction from a true-force secant. Empty keeps the path tangent, which is the climb direction when the option is off.

Definition at line 610 of file NEBPath.h.

611 {
612 climbing_curvature_direction_ = std::move(direction);
613 }

◆ setConvergenceForceNorm()

void gpr::neb::NEBPath::setConvergenceForceNorm ( std::optional< ConvergenceNormType > norm)
inline

Definition at line 268 of file NEBPath.h.

269 {
270 convergence_force_norm_ = norm;
271 }

◆ setEnergyWeightedSprings()

void gpr::neb::NEBPath::setEnergyWeightedSprings ( bool on)
inline

Allow the energy-weighted spring taper.

With the taper allowed (the default) the springs are weighted by image energy whenever the whole profile is measured, or whenever none of it is, and sit at ~k_max~ on a mixed profile. A band that relaxes on a surrogate (measured endpoints, predicted interior) and is certified on measured rows passes through both states at the same geometry: the relaxation stops on uniform springs, the full-band measurement then reads the weighted springs, and the difference ~(k_+ - k_-) d~ on the basin-side images is reported as a true NEB force that no surrogate step can remove. Such a band turns the taper off so that every image carries the same spring law whichever of its rows are measured.

Definition at line 414 of file NEBPath.h.

415 {
416 energy_weighted_springs_ = on;
417 }

◆ setExternalFixedAtoms()

void gpr::neb::NEBPath::setExternalFixedAtoms ( bool present)

Fixed atoms that pin the frame but are not part of the band coordinates (the band carries only the moving atoms). A periodic band then keeps its net translation: it is a real displacement against the fixed atoms, not a free slide of the crystal.

Definition at line 436 of file NEBPath.cpp.

437{
438 external_fixed_atoms_ = present;
439}

◆ setForceVariance()

void gpr::neb::NEBPath::setForceVariance ( int i,
const Eigen::VectorXd & variance )

Per-degree-of-freedom force variance for image i, from the surrogate. When set, computeNEBForces removes the tangent component in the Sigma^{-1} metric instead of the Euclidean one (UA-NEB, Yu and Wang, DOI 10.48550/arxiv.2605.24401), so a direction the model has not resolved does not steer the band as strongly as one it has. Passing an empty vector, or never calling this, keeps the classical projection.

Definition at line 857 of file NEBPath.cpp.

858{
859 if (i < 0 || i >= static_cast<int>(images_.size())) return;
860 if (force_variance_.size() != images_.size()) {
861 force_variance_.assign(images_.size(), Eigen::VectorXd());
862 }
863 force_variance_[static_cast<std::size_t>(i)] = variance;
864}

◆ setFromObservation()

void gpr::neb::NEBPath::setFromObservation ( const Observation & obs,
int start_image = 1 )

Set energies and gradients for images from an Observation.

Definition at line 1242 of file NEBPath.cpp.

1243{
1244 for (Eigen::Index row = 0; row < obs.R.rows(); ++row) {
1245 int img_idx = start_image + static_cast<int>(row);
1246 if (img_idx >= 0 && img_idx < numImages()) {
1247 images_[img_idx].energy = obs.E(row, 0);
1248 images_[img_idx].gradient =
1249 obs.G.row(row).transpose().cast<double>();
1250 images_[img_idx].evaluated = true;
1251 }
1252 }
1253}

◆ setGeometricSpring()

void gpr::neb::NEBPath::setGeometricSpring ( bool on)
inline

Toggle the geometric (cubic-potential) spring on the intermediate-image NEB force. With geometric=true the parallel spring force becomes ~F_par = k * (d_n^2 - d_p^2) * tau~ (derived from U = (k/3) sum ||R_{i+1}-R_i||^3); the perpendicular component cancels exactly under right-triangle perturbations of dense meshes and ~K_eff = 4 k s~ scales linearly in spacing. The energy-weighted ~spring_constant_min_~ tapering is ignored when geometric mode is on – the cubic potential's natural softening replaces it.

Definition at line 390 of file NEBPath.h.

391 {
392 use_geometric_spring_ = on;
393 }

◆ setMolecularRigidMotion()

void gpr::neb::NEBPath::setMolecularRigidMotion ( bool enabled)

Remove whole-molecule rigid motion from an isolated, unfrozen path. Generic coordinate paths retain their Cartesian geometry by default.

Definition at line 491 of file NEBPath.cpp.

492{
493 molecular_rigid_motion_ = enabled;
494}

◆ setMovingAtoms()

void gpr::neb::NEBPath::setMovingAtoms ( std::vector< char > moving_atoms)

Zero entries stay at the reactant coordinate and carry no NEB force. Empty means every atom moves.

Definition at line 424 of file NEBPath.cpp.

425{
426 if (!images_.empty() && !moving_atoms.empty() &&
427 static_cast<Eigen::Index>(moving_atoms.size() * 3) !=
428 images_[0].positions.size()) {
429 throw std::invalid_argument("NEBPath moving-atom mask size mismatch");
430 }
431 moving_atoms_ = std::move(moving_atoms);
432 for (int i = 1; i < numImages() - 1; ++i)
433 pinFixedAtoms(images_[i].positions);
434}

◆ setPeriodicCell()

void gpr::neb::NEBPath::setPeriodicCell ( const std::array< double, 9 > & cell)

ASE row-major cell. A lattice other than the 25 A vacuum box makes inter-image chords, tangents, springs and arc-length resampling use the minimum image on the periodic axes. A zero cell keeps the Cartesian difference.

Definition at line 414 of file NEBPath.cpp.

415{
416 cell_ = cell;
417 periodic_ = gpr::geometry::cellIsMicLattice(cell_.data());
418 if (periodic_)
419 periodic_box_.reset(cell_.data());
420 else
421 periodic_box_ = gpr::geometry::PairBox();
422}

◆ setPosteriorVarianceThreshold()

void gpr::neb::NEBPath::setPosteriorVarianceThreshold ( double threshold)
inline

Set the signal-scaled posterior-variance confidence threshold.

The GP-OIE outer loop sets this each iteration to ~unc_convergence * magnSigma2(now)~ (a scale-free fraction of the GP signal variance). Image posterior variances below it mark the GP as confident about that image's energy at its current geometry.

Definition at line 603 of file NEBPath.h.

604 {
605 posterior_variance_threshold_ = threshold;
606 }

◆ setSpringBounds()

void gpr::neb::NEBPath::setSpringBounds ( double k_max,
double k_min )
inline

Set the spring constant bounds for the energy-weighted variable-spring force computation.

Mirrors the eOn ~WeightedSpring~ parameters (~neb_options.spring.weighting.k_min~ and ~.k_max~). Springs in the saddle region (E_pair near E_max) approach ~k_max~; springs in the basins (E_pair near or below E_ref) drop to ~k_min~. See ~computeNEBForces~ for the alpha-blend formula.

Default ~k_min~ derived from the constructor's spring_constant as ~0.1 * spring_constant~ for backwards compatibility; the spring_constant ctor parameter is the k_max value.

Definition at line 373 of file NEBPath.h.

374 {
375 spring_constant_ = k_max;
376 spring_constant_min_ = k_min;
377 }

◆ setSpringCoordinates()

void gpr::neb::NEBPath::setSpringCoordinates ( std::vector< Eigen::Index > coordinates,
std::vector< double > weights = {} )

Band coordinates that carry the springs; empty means all.

With a non-empty set the spring of a segment measures the displacement of these coordinates alone and acts along the tangent restricted to them. The perpendicular projection keeps the full tangent. The restricted direction has a positive projection on the tangent, so a stationary band still has zero perpendicular force and balanced springs on every image: the path is the same nudged elastic band, with its images spaced by the motion of these coordinates.

A spring acts along the tangent, where the true force is projected out. A spectator mode softer than the spring constant (the free layers of a slab sliding rigidly over its fixed layers) that enters the tangent is then held by nothing but the spring, which drives it. Restricting the springs to the coordinates the reaction moves leaves such modes to the true force alone.

Spring rest lengths, when set, are lengths in the same measure. weights parallels coordinates. A weight is the share of the configured spring that coordinate carries: 1 is the full spring, 0 leaves the coordinate out of the length and the force. Empty weights are 1 on every listed coordinate.

Definition at line 441 of file NEBPath.cpp.

443{
444 const Eigen::Index n_coordinates =
445 images_.empty() ? Eigen::Index(0) : images_.front().positions.size();
446 if (!weights.empty() && weights.size() != coordinates.size()) {
447 throw std::invalid_argument(
448 "NEBPath spring weights must match the spring coordinates");
449 }
450 std::vector<std::pair<Eigen::Index, double>> paired;
451 paired.reserve(coordinates.size());
452 for (std::size_t i = 0; i < coordinates.size(); ++i) {
453 const double weight = weights.empty() ? 1.0 : weights[i];
454 if (!std::isfinite(weight) || weight < 0.0) {
455 throw std::invalid_argument(
456 "NEBPath spring weights must be finite and non-negative");
457 }
458 paired.emplace_back(coordinates[i], weight);
459 }
460 std::sort(paired.begin(), paired.end(),
461 [](const std::pair<Eigen::Index, double>& a,
462 const std::pair<Eigen::Index, double>& b) {
463 return a.first < b.first;
464 });
465 for (std::size_t i = 1; i < paired.size(); ++i) {
466 if (paired[i].first == paired[i - 1].first) {
467 throw std::invalid_argument(
468 "NEBPath spring coordinates must be distinct");
469 }
470 }
471 if (!paired.empty() &&
472 (paired.front().first < 0 || paired.back().first >= n_coordinates)) {
473 throw std::invalid_argument(
474 "NEBPath spring coordinates must index the band coordinates");
475 }
476 spring_coordinates_.resize(paired.size());
477 spring_weights_.clear();
478 const bool weighted =
479 !weights.empty() &&
480 std::any_of(paired.begin(), paired.end(),
481 [](const std::pair<Eigen::Index, double>& item) {
482 return item.second != 1.0;
483 });
484 if (weighted) spring_weights_.resize(paired.size());
485 for (std::size_t i = 0; i < paired.size(); ++i) {
486 spring_coordinates_[i] = paired[i].first;
487 if (weighted) spring_weights_[i] = paired[i].second;
488 }
489}

◆ setSpringRestLengths()

void gpr::neb::NEBPath::setSpringRestLengths ( std::vector< double > rest_lengths)

Per-segment spring rest lengths (numImages()-1 entries).

When set, the intermediate-image spring force is ~k_max ((d_plus - l_plus) - (d_minus - l_minus))~ with the uniform ~k_max~, so the relaxed band reproduces the rest lengths up to a common offset, and every arc-length reparametrization places the images at the cumulative rest-length fractions instead of at equal spacing. The inverse-distance geodesic reparameterizer applies the same fractions along its q-space arc. An empty vector restores the zero-rest-length energy-weighted spring and equal spacing. The rest lengths are the equidistribution of the chord-tangent leak (gpr::neb::detail::chordLeakSpringRestLengths).

Definition at line 1102 of file NEBPath.cpp.

1103{
1104 if (rest_lengths.empty()) {
1105 spring_rest_lengths_.clear();
1106 return;
1107 }
1108 if (static_cast<int>(rest_lengths.size()) != numImages() - 1) {
1109 throw std::invalid_argument(
1110 "NEBPath spring rest lengths need one entry per segment");
1111 }
1112 for (double rest: rest_lengths) {
1113 if (!(rest > 0.0) || !std::isfinite(rest)) {
1114 throw std::invalid_argument(
1115 "NEBPath spring rest lengths must be positive and finite");
1116 }
1117 }
1118 spring_rest_lengths_ = std::move(rest_lengths);
1119}

◆ springCoordinates()

const std::vector< Eigen::Index > & gpr::neb::NEBPath::springCoordinates ( ) const
inline

Definition at line 216 of file NEBPath.h.

217 {
218 return spring_coordinates_;
219 }

◆ springRestLengths()

const std::vector< double > & gpr::neb::NEBPath::springRestLengths ( ) const
inline

Definition at line 438 of file NEBPath.h.

439 {
440 return spring_rest_lengths_;
441 }

◆ springWeights()

const std::vector< double > & gpr::neb::NEBPath::springWeights ( ) const
inline

Definition at line 220 of file NEBPath.h.

221 {
222 return spring_weights_;
223 }

◆ tangentAt()

Eigen::VectorXd gpr::neb::NEBPath::tangentAt ( int i) const
inline

Improved (energy-weighted) tangent at image i, normalised. Used by the OCINEB controller to seed the dimer's initial mode at the CI image when no cached eigenvector is available.

Definition at line 321 of file NEBPath.h.

322 {
323 return tangent(i);
324 }

◆ tangentStiffness()

double gpr::neb::NEBPath::tangentStiffness ( int i) const
nodiscard

Stiffness the tangent adds to image i across the path.

The band force of an image, -g + (g . tau) tau, depends on the image's own position through its tangent as well as through the gradient. With the unnormalised tangent t = a tau_plus + b tau_minus the derivative of the force with respect to that position is -(H + s (I - tau tau^T)) up to terms that vanish with the perpendicular force, where s = -(g . tau) (b - a) / abs(t). On a rising profile the tangent is the forward chord (a = 1, b = 0) and on a falling one the backward chord (a = 0, b = 1), so s = abs(g . tau) / abs(t): the image is held across the path by the parallel gradient over the chord length in addition to the curvature of the surface. A climbing image carries the term twice. The value is negative where the gradient opposes the energy ordering, and zero for endpoints, non-finite energies and a vanishing tangent.

A relaxation that preconditions with the Hessian alone overshoots every mode softer than this stiffness.

Definition at line 838 of file NEBPath.cpp.

839{
840 if (i <= 0 || i >= numImages() - 1) return 0.0;
841 Eigen::VectorXd tau, tau_plus;
842 double own_weight = 0.0;
843 if (!rawTangent(i, tau, tau_plus, own_weight)) return 0.0;
844 const Eigen::VectorXd& gradient = images_[i].gradient;
845 const double length = tau.norm();
846 if (!(length > 1e-10) || gradient.size() != tau.size() ||
847 !gradient.allFinite())
848 return 0.0;
849 // d(tau_hat)/dx_i = own_weight / |t| (I - tau_hat tau_hat^T), and the
850 // band force holds (g . tau_hat) tau_hat once, or twice on a climbing
851 // image.
852 const double parallel = gradient.dot(tau) / length;
853 const double reflections = images_[i].is_climbing ? 2.0 : 1.0;
854 return -reflections * parallel * own_weight / length;
855}

◆ usesPeriodicCell()

bool gpr::neb::NEBPath::usesPeriodicCell ( ) const
inlinenodiscardnoexcept

Definition at line 249 of file NEBPath.h.

250 {
251 return periodic_;
252 }

The documentation for this class was generated from the following files: