class gpr::neb::NEBPath

Overview

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

#include <gpr/neb/NEBPath.h>
 
class NEBPath {
public:
    // construction
 
    NEBPath(const Eigen::VectorXd& initial, const Eigen::VectorXd& final_state, int n_images, double spring_constant = 0.1);
    NEBPath(const EigenMatrix& image_positions, double spring_constant = 0.1);
 
    // methods
 
    void initializeIDPP(int n_atoms, bool collective = false);
    void initializeIDPP(int n_atoms, const std::vector<char>& moving_atoms, bool collective = false);
    void initializeSIDPP(int n_atoms, double alpha = 0.33);
    void initializeSIDPP(int n_atoms, const std::vector<char>& moving_atoms, double alpha = 0.33);
    void initializeSIDPPGeodesic(int n_atoms, double alpha = 0.33);
    void initializeSIDPPGeodesic(int n_atoms, const std::vector<char>& moving_atoms, double alpha = 0.33);
    void computeNEBForces();
    void enableClimbingImage();
    int highestEnergyImageIndex() const;
    int highestEnergyImageIndexPreferring(int preferred) const;
    int highestLocalMaximumImageIndex() const;
    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();
    void setMovingAtoms(std::vector<char> moving_atoms);
    void setExternalFixedAtoms(bool present);
    void setSpringCoordinates(std::vector<Eigen::Index> coordinates, std::vector<double> weights = {});
    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;
    void alignMolecularFrames();
    void pinFixedAtoms(Eigen::Ref<Eigen::VectorXd> positions) const;
    void maskFixedForce(Eigen::Ref<Eigen::VectorXd> force) const;
    bool usesPeriodicCell() const;
    const Eigen::VectorXd& nebForce(int i) const;
    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;
    Eigen::VectorXd tangentAt(int i) const;
    Image& image(int i);
    const Image& image(int i) const;
    int numImages() const;
    int numIntermediate() const;
    EigenMatrix intermediatePositions() const;
    void setFromObservation(const Observation& obs, int start_image = 1);
    void setSpringBounds(double k_max, double k_min);
    void setGeometricSpring(bool on);
    bool geometricSpring() const;
    void setEnergyWeightedSprings(bool on);
    bool energyWeightedSprings() const;
    void setSpringRestLengths(std::vector<double> rest_lengths);
    const std::vector<double>& springRestLengths() const;
    double maxSpacingDeviation() const;
    double maxMetricSpacingDeviation(const std::vector<Eigen::MatrixXd>& segment_metric_factors) const;
    double reparametrizeByArcLength();
    double reparametrizeByArcLengthKeepingImage(int anchor_index);
    double reparametrizeByMetricArcLength(const std::vector<Eigen::MatrixXd>& segment_metric_factors);
    double reparametrizeByMetricArcLengthKeepingImage(const std::vector<Eigen::MatrixXd>& segment_metric_factors, int anchor_index);
    std::vector<Eigen::MatrixXd> inverseDistanceSegmentMetricFactors(int n_atoms) const;
    std::vector<Eigen::MatrixXd> inverseDistanceSegmentMetricFactors(int n_atoms, const std::vector<char>& moving_atoms) const;
    double reparametrizeByInverseDistanceGeodesicArcLength(int n_atoms);
    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);
    void setPosteriorVarianceThreshold(double threshold);
    void setClimbingCurvatureDirection(Eigen::VectorXd direction);
    void clearClimbingCurvatureDirection();
    const Eigen::VectorXd& climbingCurvatureDirection() const;
    double posteriorVarianceThreshold() const;
    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);
    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);
};

Detailed Documentation

NEB path: chain of images between two endpoints.

Construction

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:

initial

Initial state positions (flat)

final_state

Final state positions (flat)

n_images

Number of intermediate images (excluding endpoints)

spring_constant

NEB spring constant k

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

Initialize path from explicit image positions.

Parameters:

image_positions

Matrix with one image per row, endpoints included.

spring_constant

NEB spring constant k

Methods

void 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_atoms

Number of atoms (positions.size() / 3)

collective

If true, relax the whole chain together.

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 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 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)

void enableClimbingImage()

Enable climbing image on the highest-energy intermediate image.

int 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.

int highestEnergyImageIndexPreferring(int preferred) const

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

int 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.

void 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.

void 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.

void interpolateFromEndpoints()

Rebuild interior images on the chord between the current endpoints.

void setMovingAtoms(std::vector<char> moving_atoms)

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

void 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.

void 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.

void setMolecularRigidMotion(bool enabled)

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

void 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.

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.

const Eigen::VectorXd& nebForce(int i) const

Get the NEB force for image i.

double saddleForce(int i) const

Physical force magnitude without the climbing-image reflection.

double forceMagnitude(const Eigen::VectorXd& force) const

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

double nebForceMagnitude(int i) const

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

double tangentStiffness(int i) const

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.

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.

EigenMatrix intermediatePositions() const

Get all intermediate image positions as a matrix.

Returns:

Matrix of shape (n_intermediate, n_coords)

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.

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.

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.

void setEnergyWeightedSprings(bool on)

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.

void 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).

double 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.

double 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.

double 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.

double 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().

double 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().

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.

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.

std::vector<Eigen::MatrixXd> 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.

double 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).

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.

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.

void setClimbingCurvatureDirection(Eigen::VectorXd direction)

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

double posteriorVarianceThreshold() const

Current signal-scaled posterior-variance confidence threshold.

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.

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.

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.

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.