13#ifndef GPR_ATOMICDIMER_INL_
14#define GPR_ATOMICDIMER_INL_
18inline double AtomicDimer::calculateCurvature(
20 const bool use_hssvd_analytic,
const double cached_hssvd_curvature)
30 if (use_hssvd_analytic && std::isfinite(cached_hssvd_curvature))
31 return cached_hssvd_curvature;
33 if (use_hssvd_analytic) {
34 double analytic_curvature = std::numeric_limits<double>::quiet_NaN();
35 if (gpr_model ==
nullptr || orient.rows() != 1 ||
36 approx_obs.
R.rows() < 1 || approx_obs.
R.cols() != orient.cols() ||
37 !orient.allFinite() || !approx_obs.
R.row(0).allFinite())
38 return analytic_curvature;
39 const gpr::Coord midpoint = approx_obs.
R.topRows(1);
40 const Eigen::VectorXd direction = orient.row(0).transpose();
43 return analytic_curvature;
45 Eigen::VectorXd hessian_vector;
46 if (!hessian || !hessian(direction, hessian_vector) ||
47 hessian_vector.size() != direction.size())
48 return std::numeric_limits<double>::quiet_NaN();
49 analytic_curvature = direction.dot(hessian_vector);
50 if (!std::isfinite(analytic_curvature))
51 return std::numeric_limits<double>::quiet_NaN();
54 if (!inexact_curvature_logged_) {
55 inexact_curvature_logged_ =
true;
56 log_man <<
"Dimer curvature is v^T H v of the posterior-mean "
57 "Hessian action. The kernel does not report an exact "
60 return analytic_curvature;
63 if (approx_obs.
G.rows() < 2 || approx_obs.
G.cols() != orient.cols() ||
64 !(dimer_sep > 0.0) || !std::isfinite(dimer_sep)) {
65 return std::numeric_limits<double>::quiet_NaN();
68 double curvature = 0.;
71 curvature += (approx_obs.
G(1, j) - approx_obs.
G(0, j)) * orient(0, j);
73 curvature /= dimer_sep;
80 Eigen::VectorXd gradient(middle_point_final.G.cols());
83 gradient(n) = middle_point_final.G(0, n);
95 return forceNormForConvergence(middle_point_final);
100 Eigen::VectorXd coord(middle_point_final.R.cols());
103 coord(n) = middle_point_final.R(0, n);
110 return num_of_gen_potential_calls;
115 if (gpr_model !=
nullptr) {
116 return gpr_model->getNumberOfPotentialCalls();
123 return totalIterations;
128 return middle_point_final.E(0, 0);
133 return curvature_final;
138 return final_converged_;
148 markObservedDataChanged();
157 markObservedDataChanged();
166 markObservedDataChanged();
184inline void AtomicDimer::assignFinalResults(
186 const std::pair<double, gpr::Coord>& eigen_data)
188 middle_point_final.
R = middle_point.
R;
189 middle_point_final.
E = middle_point.
E;
190 middle_point_final.
G = middle_point.
G;
191 curvature_final = eigen_data.first;
192 latest_mode_curvature_ = eigen_data.first;
193 orient_final = eigen_data.second;
gpr::GaussianProcessRegression * getGPRModel()
Get GPR model.
Eigen::VectorXd getFinalCoordOfMidPoint() const
Return final coordinates of the middle point.
void setAtomsConfiguration(const gpr::AtomsConfiguration &_atoms_config)
Set configuration of the atoms.
gpr::Coord & getGradientForAllObservationPointsRef()
Return gradients for all observed points.
gpr::Index_t getTotalGPRForceCalls() const
Return the total number of force calls.
gpr::AtomsConfiguration atoms_config
gpr::FieldMatrixd & getEnergyForAllObservationPointsRef()
Return energies for all observed points.
Eigen::VectorXd getFinalGradientAtMidPoint() const
Return the final gradient dE/dR at the middle point.
const gpr::Coord & getFinalOrientation() const
Return final orientation of the dimer.
gpr::Index_t getTotalForceCalls() const
Return the total number of force calls.
double getFinalForceNormForConvergence() const
Return final force in the configured convergence norm.
double getFinalEnergy() const
Return final energy.
Eigen::VectorXd getFinalForceAtMidPoint() const
Deprecated alias of getFinalGradientAtMidPoint().
double getFinalCurvature() const
Return final curvature.
bool getConverged() const
Return true when the final force convergence criterion is met.
gpr::Coord & getMidPointCoordForAllObservationPointsRef()
Return gpr::Coordinates of all observed points.
gpr::Index_t getIterations() const
Return the total number of cycles.
bool calculateExactDirectionalCurvature(const Coord &R, const Eigen::VectorXd &direction, double &curvature)
MeanHessianAction prepareMeanHessian(const Coord &R)
Linear action of the physical posterior mean at one geometry.
The atomic dimer search (class AtomicDimer) and its status types.
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Stores configurations of all atoms in the system.
Observation data: energy, gradient and positions.