Loading...
Searching...
No Matches
dimer::Dimer Class Reference

Dimer method. More...

#include <gpr/dimer/Dimer.h>

Public Types

enum class  RotationStepResult { Converged , Updated , EvaluationFailed }
using Image1Evaluator = std::function<bool(gpr::Observation&)>
using HessianVectorEvaluator

Public Member Functions

 Dimer (double separation, bool is_subsystem=false)
 Default constructor.
virtual ~Dimer ()
void translate (const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &F, const double curv, const gpr::TransitionParameters &param_trans, gpr::LBFGSInfo &transinfo, gpr::Coord &R_new)
 Translate dimer.
void translateWithForce (const gpr::Coord &R, const gpr::Coord &force, const gpr::TransitionParameters &parameters, gpr::LBFGSInfo &history, gpr::Coord &output)
void rotate (const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &G01, const uint8_t potential, const double T_anglerot, const bool estim_Curv, const gpr::Observation &all_obs, gpr::GaussianProcessRegression *gpr_model, gpr::LBFGSInfo &rotinfo, gpr::Coord &orient_new, double &Curv, gpr::Observation &image1)
 Rotate dimer.
RotationStepResult rotateWithImage1Evaluator (const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &G01, const double T_anglerot, const bool estim_Curv, const Image1Evaluator &image1_evaluator, gpr::LBFGSInfo &rotinfo, gpr::Coord &orient_new, double &Curv, gpr::Observation &image1)
RotationStepResult rotateWithHessian (const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &G01, const bool estim_Curv, const Image1Evaluator &image1_evaluator, gpr::Coord &orient_new, double &Curv, gpr::Observation &image1, const HessianVectorEvaluator &hessian_evaluator)
RotationStepResult rotateWithRgminDimer (const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &G01, const bool estim_Curv, const Image1Evaluator &image1_evaluator, gpr::Coord &orient_new, double &Curv, gpr::Observation &image1)
RotationStepResult rotateWithRgminDimer (const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &G01, const bool estim_Curv, const Image1Evaluator &image1_evaluator, gpr::Coord &orient_new, double &Curv, gpr::Observation &image1, const HessianVectorEvaluator &hessian_evaluator)
void rotateForce (const gpr::Coord &G01, const gpr::Coord &orient, gpr::Coord &F_rot)
 Calculate rotational force acting on image 1 of the dimer.
void setForceVariance (const Eigen::VectorXd &variance)
void clearForceVariance ()
bool hasForceVariance () const
void translateForce (const gpr::Coord &F, const gpr::Coord &orient, gpr::Coord &F_trans)
 Calculate translational force acting on image 1 of the dimer.
double estimateRotationalAngle (const gpr::Coord &orient, const gpr::Coord &G01, const gpr::Coord &F_rot_oriented)
 Calculate a rough estimate of the optimal Rotation angle.
void setProjectRotations (bool enabled) noexcept
 A fixed periodic cell admits translations but not rigid rotations.
void setRotationBasis (Eigen::MatrixXd basis)
 Orthonormal columns span the allowed Cartesian rotation directions.
void setRotationObservation (const gpr::Observation *endpoint) noexcept
 The observed endpoint supplies the sphere objective's energy origin.
void bindRgminTranslation (gpr::optim::RgminStep *session) noexcept
double calculateCurvature (const gpr::Coord &G01, const gpr::Coord &orient)
 Calculate curvature of the energy along the dimer.
void calculatePotential (const uint8_t potential, gpr::GaussianProcessRegression *gpr_model, gpr::Observation &image1)
 Calculate potential.

Friends

gpr::PublicLayoutBytes gpr::libraryPublicLayout ()
gpr::PublicLayoutBytes gpr::consumerPublicLayout ()

Detailed Description

Dimer method.

Definition at line 59 of file Dimer.h.

Member Typedef Documentation

◆ HessianVectorEvaluator

Initial value:
std::function<bool(const Eigen::VectorXd&, Eigen::VectorXd&)>

Definition at line 62 of file Dimer.h.

◆ Image1Evaluator

using dimer::Dimer::Image1Evaluator = std::function<bool(gpr::Observation&)>

Definition at line 61 of file Dimer.h.

Member Enumeration Documentation

◆ RotationStepResult

Enumerator
Converged 
Updated 
EvaluationFailed 

Definition at line 65 of file Dimer.h.

65 {
67 Updated,
68 EvaluationFailed,
69 };
@ Converged
The requested force and certificate conditions were satisfied.
Definition GPNEB.h:3674

Constructor & Destructor Documentation

◆ Dimer()

dimer::Dimer::Dimer ( double separation,
bool is_subsystem = false )
inline

Default constructor.

Parameters
separationDimer separation
is_subsystemTrue when the dimer coordinates are a subset of a larger system. Skips rigid rotation/translation removal, which is not robust on partial coordinates.

Definition at line 79 of file Dimer.h.

80 : dimer_sep(separation), is_subsystem(is_subsystem){};

◆ ~Dimer()

virtual dimer::Dimer::~Dimer ( )
inlinevirtual

Definition at line 82 of file Dimer.h.

82{ }

Member Function Documentation

◆ bindRgminTranslation()

void dimer::Dimer::bindRgminTranslation ( gpr::optim::RgminStep * session)
inlinenoexcept

The owner supplies a session that outlives each Dimer call so accepted L-BFGS pairs persist across outer iterations.

Definition at line 247 of file Dimer.h.

248 {
249 rgmin_trans_ = session;
250 }

◆ calculateCurvature()

double dimer::Dimer::calculateCurvature ( const gpr::Coord & G01,
const gpr::Coord & orient )

Calculate curvature of the energy along the dimer.

Two-point estimate from the gradients at the midpoint and at image 1; also the index-1 witness a force-converged start must pass.

Parameters
G01Gradient at the middle point and image 1 of the dimer.
orientUnit vector along the direction of the dimer.
Returns
Curvature.

Definition at line 484 of file Dimer.cpp.

486{
487 if (G01.rows() < 2 || G01.cols() != orient.cols() || !(dimer_sep > 0.0) ||
488 !std::isfinite(dimer_sep)) {
489 return std::numeric_limits<double>::quiet_NaN();
490 }
491
492 double C = 0.;
493
494 for (gpr::Index_t n = 0; n < G01.cols(); ++n) {
495 C += (G01(1, n) - G01(0, n)) * orient(0, n);
496 }
497 C /= dimer_sep;
498
499 return C;
500}
uint32_t Index_t
Definition Macros.h:17

◆ calculatePotential()

void dimer::Dimer::calculatePotential ( const uint8_t potential,
gpr::GaussianProcessRegression * gpr_model,
gpr::Observation & image1 )

Calculate potential.

Parameters
potentialPotential type.
gpr_modelPointer to the GPR model (or nullptr).
image1Observation to populate with the selected potential's energy and gradient.

Definition at line 502 of file Dimer.cpp.

505{
506 gpr::io::ErrorManager err;
507
508 switch (potential) {
509 case POTENTIAL_GP:
510 gpr::assertMsg(gpr_model != nullptr,
511 "Error! NULL pointer is passed!");
512 // Dispatched predict: the inner calculatePotential returns the
513 // standardized residual E~ = (E - y_mean_)/y_scale_; only the
514 // dispatched wrapper restores physical units and the prior
515 // mean. The dimer's energies meet raw oracle energies in the
516 // saddle certificates, so they must be physical.
517 {
518 gpr::ScopedPredictTimer predict_timer;
519 gpr_model->calculatePotentialDispatched(image1);
520 }
521 break;
522
523 // This case is used in unit tests
524 case POTENTIAL_TEST1:
525 image1.E.resize(1, 1);
526 image1.G.resize(1, 2 * 3);
527
528 image1.E(0, 0) = 140.981934401792e-006;
529
530 image1.G(0, 0) = 22.0169292639464e-003;
531 image1.G(0, 1) = -25.3799869163130e-003;
532 image1.G(0, 2) = 20.4383773983493e-003;
533 image1.G(0, 3) = -17.5501833843735e-003;
534 image1.G(0, 4) = 21.9491835909580e-003;
535 image1.G(0, 5) = -28.6553826196841e-003;
536
537 break;
538
539 // This case is used in unit tests
540 case POTENTIAL_TEST2:
541 image1.E.resize(1, 1);
542 image1.G.resize(1, 2 * 3);
543
544 image1.E(0, 0) = 268.422097239501e-006;
545
546 image1.G(0, 0) = 21.4263025463240e-003;
547 image1.G(0, 1) = -30.4813824740716e-003;
548 image1.G(0, 2) = 26.0833530773849e-003;
549 image1.G(0, 3) = -16.2806875633080e-003;
550 image1.G(0, 4) = 21.0852193621926e-003;
551 image1.G(0, 5) = -35.3650094447835e-003;
552
553 break;
554
555 default:
556 err << "Error! The type of the potential is unknown!";
557
558 break;
559 }
560}
@ POTENTIAL_TEST1
Definition Enums.h:16
@ POTENTIAL_TEST2
Definition Enums.h:16
@ POTENTIAL_GP
Definition Enums.h:16
void calculatePotentialDispatched(Observation &image1)
Definition Predict.cpp:982
FieldMatrixd E

◆ clearForceVariance()

void dimer::Dimer::clearForceVariance ( )
inline

Definition at line 191 of file Dimer.h.

192 {
193 force_variance_.resize(0);
194 }

◆ estimateRotationalAngle()

double dimer::Dimer::estimateRotationalAngle ( const gpr::Coord & orient,
const gpr::Coord & G01,
const gpr::Coord & F_rot_oriented )

Calculate a rough estimate of the optimal Rotation angle.

Parameters
orientUnit vector along the direction of the dimer (before rotation).
G01Gradient at the middle point and image 1 of the dimer (before rotation). Each point occupies one row in the field.
F_rot_orientedOriented rotational force acting on image 1 of the dimer.
Returns
Rough estimate of the optimal Rotation angle.

Definition at line 562 of file Dimer.cpp.

565{
566 double F_0 = F_rot_oriented.norm();
567 double C_0 = calculateCurvature(G01, orient);
568
569 return 0.5 * atan(0.5 * F_0 / fabs(C_0));
570}
double calculateCurvature(const gpr::Coord &G01, const gpr::Coord &orient)
Calculate curvature of the energy along the dimer.
Definition Dimer.cpp:484

◆ hasForceVariance()

bool dimer::Dimer::hasForceVariance ( ) const
inlinenodiscard

Definition at line 195 of file Dimer.h.

196 {
197 return force_variance_.size() > 0 &&
198 (force_variance_.array() > 0.0).any();
199 }

◆ rotate()

void dimer::Dimer::rotate ( const gpr::Coord & R,
const gpr::Coord & orient,
const gpr::Coord & G01,
const uint8_t potential,
const double T_anglerot,
const bool estim_Curv,
const gpr::Observation & all_obs,
gpr::GaussianProcessRegression * gpr_model,
gpr::LBFGSInfo & rotinfo,
gpr::Coord & orient_new,
double & Curv,
gpr::Observation & image1 )

Rotate dimer.

The dimer is rotated one step towards its minimum energy orientation. The first call seeds the mode with rgmin's measured Rayleigh-Ritz plane solve; later calls with the same rotinfo continue a persistent sphere L-BFGS refinement of the curvature.

Parameters
RCoordinates of the middle point of the dimer.
orientUnit vector along the direction of the dimer.
G01Gradient at the middle point and image 1 of the dimer.
potentialPotential and gradient function.
T_anglerotUnused; the caller owns rotation convergence.
estim_CurvIf true, an estimate for the curvature along the direction of the dimer after the rotation is calculated.
all_obsObject of all observed points.
gpr_modelPointer to the GPR model.
rotinfoStructure with information on previous external iterations.
orient_newUnit vector along the direction of the dimer after optimal rotation.
CurvEstimate for the curvature along the direction of the dimer after the rotation (0 if estim_Curv = 0 or no rotation).
image1Observation of the new observed location.

Definition at line 210 of file Dimer.cpp.

217{
218 auto image1_evaluator = [&](gpr::Observation& candidate) {
219 calculatePotential(potential, gpr_model, candidate);
220 return candidate.G.rows() == 1 && candidate.G.cols() == G01.cols() &&
221 candidate.G.allFinite() && candidate.E.rows() >= 1 &&
222 candidate.E.cols() >= 1 && candidate.E.allFinite();
223 };
224 (void)rotateWithImage1Evaluator(R, orient, G01, T_anglerot, estim_Curv,
225 image1_evaluator, rotinfo, orient_new, Curv,
226 image1);
227}
RotationStepResult rotateWithImage1Evaluator(const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &G01, const double T_anglerot, const bool estim_Curv, const Image1Evaluator &image1_evaluator, gpr::LBFGSInfo &rotinfo, gpr::Coord &orient_new, double &Curv, gpr::Observation &image1)
Definition Dimer.cpp:376
void calculatePotential(const uint8_t potential, gpr::GaussianProcessRegression *gpr_model, gpr::Observation &image1)
Calculate potential.
Definition Dimer.cpp:502

◆ rotateForce()

void dimer::Dimer::rotateForce ( const gpr::Coord & G01,
const gpr::Coord & orient,
gpr::Coord & F_rot )

Calculate rotational force acting on image 1 of the dimer.

Parameters
G01Gradient vectors at the middle point and image 1 of the dimer.
orientUnit vector along the direction of the dimer.
F_rotRotational force acting on image 1 of the dimer.

Definition at line 428 of file Dimer.cpp.

430{
431 gpr::Index_t D = G01.cols();
432 gpr::FieldMatrixd F1(1, D);
433 gpr::FieldMatrixd F2(1, D);
434 gpr::FieldMatrixd F1_rot(1, D);
435 gpr::FieldMatrixd F2_rot(1, D);
436
437 F_rot.resize(1, G01.cols());
438
439 F1 = G01.row(1);
440 F1 *= -1.;
441
442 F2 = G01.row(0);
443 F2 *= -2.;
444 F2 += G01.row(1);
445
446 // UA-Dimer: with a surrogate force variance the axial component comes off
447 // in the Sigma^{-1} metric. The classical branch keeps its exact
448 // expression: it assumes a unit orient and does not divide by the norm, so
449 // routing it through the general projection would shift every existing
450 // rotation in its last bits.
451 if (hasForceVariance() &&
452 force_variance_.size() == static_cast<Eigen::Index>(D)) {
453 const Eigen::VectorXd axis = orient.row(0).transpose();
455 F1.row(0).transpose(), axis, force_variance_)
456 .transpose();
458 F2.row(0).transpose(), axis, force_variance_)
459 .transpose();
460 } else {
461 F1_rot = F1 - orient * gpr::field::flatDot(F1, orient);
462 F2_rot = F2 - orient * gpr::field::flatDot(F2, orient);
463 }
464
465 F_rot = (F1_rot - F2_rot) / dimer_sep;
466 if (rotation_basis_.rows() > 0) {
467 if (rotation_basis_.rows() != D || !rotation_basis_.allFinite())
468 throw std::invalid_argument("invalid dimer rotation basis");
469 // The rotation plane belongs to the same physical subspace as the
470 // measured mode; rigid-force noise cannot supply a tangent direction.
471 F_rot = (rotation_basis_ *
472 (rotation_basis_.transpose() * F_rot.row(0).transpose()))
473 .transpose()
474 .eval();
475 }
476}
bool hasForceVariance() const
Definition Dimer.h:195
double flatDot(const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedB > &b)
Eigen::VectorXd projectPerpendicularDiagonal(const Eigen::VectorXd &force, const Eigen::VectorXd &tangent, const Eigen::VectorXd &force_variance)
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Definition Macros.h:25

◆ rotateWithHessian()

Dimer::RotationStepResult dimer::Dimer::rotateWithHessian ( const gpr::Coord & R,
const gpr::Coord & orient,
const gpr::Coord & G01,
const bool estim_Curv,
const Image1Evaluator & image1_evaluator,
gpr::Coord & orient_new,
double & Curv,
gpr::Observation & image1,
const HessianVectorEvaluator & hessian_evaluator )

Minimize the analytic curvature in the seed and Hessian-residual plane, then query the resulting endpoint on the supplied potential.

Definition at line 229 of file Dimer.cpp.

234{
235 return rotateWithRgminDimer(R, orient, G01, estim_Curv, image1_evaluator,
236 orient_new, Curv, image1, hessian_evaluator);
237}
RotationStepResult rotateWithRgminDimer(const gpr::Coord &R, const gpr::Coord &orient, const gpr::Coord &G01, const bool estim_Curv, const Image1Evaluator &image1_evaluator, gpr::Coord &orient_new, double &Curv, gpr::Observation &image1)
Definition Dimer.cpp:239

◆ rotateWithImage1Evaluator()

Dimer::RotationStepResult dimer::Dimer::rotateWithImage1Evaluator ( const gpr::Coord & R,
const gpr::Coord & orient,
const gpr::Coord & G01,
const double T_anglerot,
const bool estim_Curv,
const Image1Evaluator & image1_evaluator,
gpr::LBFGSInfo & rotinfo,
gpr::Coord & orient_new,
double & Curv,
gpr::Observation & image1 )

Definition at line 376 of file Dimer.cpp.

381{
382 if (R.cols() > 2) {
383 if (R.rows() != 1 || orient.rows() != 1 || orient.cols() != R.cols() ||
384 G01.rows() < 2 || G01.cols() != R.cols() || !R.allFinite() ||
385 !G01.allFinite() || !(dimer_sep > 0.0) || !std::isfinite(dimer_sep))
387 Eigen::MatrixXd physical = rotation_basis_;
388 if (physical.rows() == 0)
389 physical = Eigen::MatrixXd::Identity(R.cols(), R.cols());
390 if (!rotinfo.sphere_rotation || !rotinfo.sphere_rotation.unique()) {
391 // The measured Rayleigh-Ritz initializer resolves a two-mode
392 // quadratic directly. The sphere session retains curvature
393 // across all subsequent tangent directions.
394 gpr::Observation seed_endpoint;
395 const auto initialize = [&](gpr::Observation& endpoint) {
396 if (!image1_evaluator(endpoint)) return false;
397 if (seed_endpoint.R.size() == 0) seed_endpoint = endpoint;
398 return true;
399 };
400 const auto result =
401 rotateWithRgminDimer(R, orient, G01, estim_Curv, initialize,
402 orient_new, Curv, image1);
403 if (result == RotationStepResult::EvaluationFailed) return result;
404 rotinfo.sphere_rotation = std::make_shared<SphereRotation>();
405 if (!rotinfo.sphere_rotation->start(
406 R, G01.row(0).transpose(), dimer_sep, physical,
407 std::max<gpr::Index_t>(rotinfo.num_lbfgs_iter, 1), image1,
408 &seed_endpoint))
410 return result;
411 }
412 if (!rotinfo.sphere_rotation->step(
413 R, orient, G01.row(0).transpose(), dimer_sep, physical,
414 std::max<gpr::Index_t>(rotinfo.num_lbfgs_iter, 1),
415 image1_evaluator, rotation_observation_, orient_new, image1))
417 Curv = estim_Curv
418 ? (image1.G.row(0) - G01.row(0)).dot(orient_new.row(0)) /
419 dimer_sep
420 : 0.0;
422 }
423 // A two-coordinate problem has only one tangent direction.
424 return rotateWithRgminDimer(R, orient, G01, estim_Curv, image1_evaluator,
425 orient_new, Curv, image1);
426}
bool step(const gpr::Coord &center, const gpr::Coord &orientation, const Eigen::VectorXd &gradient, double separation, const Eigen::MatrixXd &physical, std::size_t memory, const Evaluator &evaluate, const gpr::Observation *initial_endpoint, gpr::Coord &rotated, gpr::Observation &endpoint)
bool start(const gpr::Coord &center, const Eigen::VectorXd &gradient, double separation, const Eigen::MatrixXd &physical, std::size_t memory, const gpr::Observation &endpoint, const gpr::Observation *previous=nullptr)
Index_t num_lbfgs_iter
Definition Structures.h:984
std::shared_ptr< dimer::SphereRotation > sphere_rotation
A copied history starts an independent sphere solve when written.
Definition Structures.h:979

◆ rotateWithRgminDimer() [1/2]

Dimer::RotationStepResult dimer::Dimer::rotateWithRgminDimer ( const gpr::Coord & R,
const gpr::Coord & orient,
const gpr::Coord & G01,
const bool estim_Curv,
const Image1Evaluator & image1_evaluator,
gpr::Coord & orient_new,
double & Curv,
gpr::Observation & image1 )

Rotate through rgmin's dimer plane solve and query the resulting endpoint. The Hessian action overload uses a fixed linear operator at R; the image-only overload uses finite dimer differences.

Definition at line 239 of file Dimer.cpp.

243{
244 return rotateWithRgminDimer(R, orient, G01, estim_Curv, image1_evaluator,
245 orient_new, Curv, image1, {});
246}

◆ rotateWithRgminDimer() [2/2]

Dimer::RotationStepResult dimer::Dimer::rotateWithRgminDimer ( const gpr::Coord & R,
const gpr::Coord & orient,
const gpr::Coord & G01,
const bool estim_Curv,
const Image1Evaluator & image1_evaluator,
gpr::Coord & orient_new,
double & Curv,
gpr::Observation & image1,
const HessianVectorEvaluator & hessian_evaluator )

Definition at line 248 of file Dimer.cpp.

253{
254 if (R.rows() != 1 || R.cols() == 0 || orient.rows() != 1 ||
255 G01.rows() < 2 || G01.cols() != R.cols() || orient.cols() != R.cols() ||
256 !R.allFinite() || !(dimer_sep > 0.0) || !std::isfinite(dimer_sep)) {
258 }
259 const Eigen::Index n = R.cols();
260 Eigen::VectorXd seed = orient.row(0).transpose();
261 if (rotation_basis_.rows() > 0) {
262 if (rotation_basis_.rows() != n || !rotation_basis_.allFinite())
264 seed = rotation_basis_ * (rotation_basis_.transpose() * seed);
265 }
266 const double seed_norm = seed.norm();
267 if (!(seed_norm > 0.0) || !std::isfinite(seed_norm)) {
269 }
270 seed /= seed_norm;
271 const Eigen::VectorXd g0 = G01.row(0).transpose();
272 if (!g0.allFinite()) return RotationStepResult::EvaluationFailed;
273
274 struct Context {
275 const gpr::Coord& center;
276 const Eigen::VectorXd& gradient;
277 const Image1Evaluator& evaluate;
278 const HessianVectorEvaluator& hessian;
279 const Eigen::MatrixXd& physical;
280 double separation;
281 bool failed = false;
282 } context{
283 R, g0, image1_evaluator, hessian_evaluator, rotation_basis_, dimer_sep};
284 const auto action = [](void* user, const DLManagedTensorVersioned*,
285 const DLManagedTensorVersioned* direction,
286 DLManagedTensorVersioned* output) noexcept {
287 auto& ctx = *static_cast<Context*>(user);
288 if (ctx.failed) return RGMIN_INTERNAL_ERROR;
289 try {
290 const Eigen::Index size = ctx.center.cols();
291 const auto* vp = reinterpret_cast<const double*>(
292 static_cast<const uint8_t*>(direction->dl_tensor.data) +
293 direction->dl_tensor.byte_offset);
294 auto* hp = reinterpret_cast<double*>(
295 static_cast<uint8_t*>(output->dl_tensor.data) +
296 output->dl_tensor.byte_offset);
297 const Eigen::Map<const Eigen::VectorXd> v(vp, size);
298 Eigen::Map<Eigen::VectorXd> hv(hp, size);
299 if (ctx.hessian) {
300 Eigen::VectorXd value;
301 if (!ctx.hessian(v, value) || value.size() != size ||
302 !value.allFinite()) {
303 ctx.failed = true;
304 return RGMIN_INTERNAL_ERROR;
305 }
306 hv = value;
307 } else {
308 gpr::Observation trial;
309 trial.R = ctx.center;
310 trial.R.row(0) += ctx.separation * v.transpose();
311 if (!ctx.evaluate(trial) || trial.G.rows() != 1 ||
312 trial.G.cols() != size || !trial.G.allFinite()) {
313 ctx.failed = true;
314 return RGMIN_INTERNAL_ERROR;
315 }
316 hv = (trial.G.row(0).transpose() - ctx.gradient) /
317 ctx.separation;
318 }
319 if (ctx.physical.rows() > 0)
320 hv = (ctx.physical * (ctx.physical.transpose() * hv)).eval();
321 if (!hv.allFinite()) {
322 ctx.failed = true;
323 return RGMIN_INTERNAL_ERROR;
324 }
325 return RGMIN_SUCCESS;
326 } catch (...) {
327 ctx.failed = true;
328 return RGMIN_INTERNAL_ERROR;
329 }
330 };
331 Eigen::VectorXd center = R.row(0).transpose();
332 Eigen::VectorXd mode(n);
333 using Tensor =
334 std::unique_ptr<DLManagedTensorVersioned, decltype(&rgmin_tensor_free)>;
336 Tensor xt(rgmin_tensor_borrow_cpu_f64(center.data(), n), rgmin_tensor_free);
337 Tensor st(rgmin_tensor_borrow_cpu_f64(seed.data(), n), rgmin_tensor_free);
338 Tensor mt(rgmin_tensor_borrow_cpu_f64(mode.data(), n), rgmin_tensor_free);
339 if (!xt || !st || !mt) return RotationStepResult::EvaluationFailed;
340
341 // The caller owns rotation convergence; rgmin owns each plane solve.
342 const rgmin_eigen_params_t params{RGMIN_EIGEN_DIMER, 1, 2, 1, 1e-8};
343 rgmin_lowest_mode_t result{};
344 const auto status = rgmin_lowest_eigenpair(
345 action, &context, xt.get(), st.get(), mt.get(), &params, &result);
346 if (status != RGMIN_SUCCESS || context.failed || !mode.allFinite() ||
347 !(mode.norm() > 0.0)) {
349 }
350 mode.normalize();
351 if (mode.dot(seed) < 0.0) mode *= -1.0;
352
353 // Finite dimer differences are not a linear operator on a nonquadratic
354 // surface. Endpoint measurements must come from the endpoint query.
355 gpr::Observation endpoint;
356 endpoint.R = R;
357 endpoint.R.row(0) += dimer_sep * mode.transpose();
358 if (!image1_evaluator(endpoint) || endpoint.G.rows() != 1 ||
359 endpoint.G.cols() != n || !endpoint.G.allFinite() ||
360 endpoint.E.rows() != 1 || endpoint.E.cols() != 1 ||
361 !endpoint.E.allFinite()) {
363 }
364 const double curvature =
365 hessian_evaluator
366 ? result.value
367 : (endpoint.G.row(0).transpose() - g0).dot(mode) / dimer_sep;
368 if (!std::isfinite(curvature)) return RotationStepResult::EvaluationFailed;
369 orient_new.resize(1, n);
370 orient_new.row(0) = mode.transpose();
371 Curv = estim_Curv ? curvature : 0.0;
372 image1 = std::move(endpoint);
374}
int status
eon_relax_band_t eon_relax_surface_fn void * user
void requireCompatibleLibrary()
Definition RgminAbi.h:90
VecchiaResult evaluate(const Eigen::MatrixXd &points, const Eigen::VectorXd &y, double lengthscale, double noise, int max_neighbours)
FieldMatrixd Coord
Definition Macros.h:35

◆ setForceVariance()

void dimer::Dimer::setForceVariance ( const Eigen::VectorXd & variance)
inline

UA-Dimer: per-degree-of-freedom force variance from the surrogate. When set and sized to the configuration, rotateForce removes the axial component in that Sigma^{-1} metric rather than the Euclidean one (Yu and Wang, DOI 10.48550/arxiv.2605.24401), so the rotation follows curvature the model resolves instead of the largest raw force difference. Unset leaves the classical arithmetic untouched.

Definition at line 187 of file Dimer.h.

188 {
189 force_variance_ = variance;
190 }
double variance(const Weights &w, const Matrix &covariance)

◆ setProjectRotations()

void dimer::Dimer::setProjectRotations ( bool enabled)
inlinenoexcept

A fixed periodic cell admits translations but not rigid rotations.

Definition at line 228 of file Dimer.h.

229 {
230 project_rotations_ = enabled;
231 }

◆ setRotationBasis()

void dimer::Dimer::setRotationBasis ( Eigen::MatrixXd basis)
inline

Orthonormal columns span the allowed Cartesian rotation directions.

Definition at line 234 of file Dimer.h.

235 {
236 rotation_basis_ = std::move(basis);
237 }

◆ setRotationObservation()

void dimer::Dimer::setRotationObservation ( const gpr::Observation * endpoint)
inlinenoexcept

The observed endpoint supplies the sphere objective's energy origin.

Definition at line 240 of file Dimer.h.

241 {
242 rotation_observation_ = endpoint;
243 }

◆ translate()

void dimer::Dimer::translate ( const gpr::Coord & R,
const gpr::Coord & orient,
const gpr::Coord & F,
const double curv,
const gpr::TransitionParameters & param_trans,
gpr::LBFGSInfo & transinfo,
gpr::Coord & R_new )

Translate dimer.

The dimer is translated one step towards saddle point by the bound rgmin L-BFGS session (bindRgminTranslation), or by rgmin's empty-memory step when no session is bound.

Parameters
RCoordinates of the middle point of the dimer.
orientUnit vector along the direction of the dimer.
FForce at the middle point of the dimer.
curvCurvature of energy along the direction of the dimer.
param_transPredefined step length for convex regions, maximum step length.
transinfoUnused; the curvature pairs live in the rgmin session.
R_newCoordinates of the new middle point of the dimer.

Definition at line 128 of file Dimer.cpp.

132{
133 R_new.resize(0, 0);
134 R_new = R;
135
136 if (curv < 0.) {
137 translateDimerForNegCurv(orient, F, param_trans, transinfo, R_new);
138 } else {
139 translateDimerForPosCurv(orient, F, param_trans, transinfo, R_new);
140 }
141}

◆ translateForce()

void dimer::Dimer::translateForce ( const gpr::Coord & F,
const gpr::Coord & orient,
gpr::Coord & F_trans )

Calculate translational force acting on image 1 of the dimer.

Parameters
FForce at the middle point of the dimer.
orientUnit vector along the direction of the dimer.
F_transTranslational force acting on image 1 of the dimer.

Definition at line 478 of file Dimer.cpp.

480{
481 F_trans = F - orient * (gpr::field::flatDot(F, orient)) * 2.;
482}

◆ translateWithForce()

void dimer::Dimer::translateWithForce ( const gpr::Coord & R,
const gpr::Coord & force,
const gpr::TransitionParameters & parameters,
gpr::LBFGSInfo & history,
gpr::Coord & output )

Apply a caller-assembled dimer force through the same rgmin translation step.

Definition at line 153 of file Dimer.cpp.

158{
159 R = positions;
160 // The owner's persistent session keeps the curvature pairs across outer
161 // iterations, one gradient per outer. Without one the step is rgmin's
162 // empty-memory step. empty_scale 0.01 bounds that first step: a full -g
163 // overshoots max_step_length every outer and the search cycles for
164 // hundreds of phases.
165 gpr::optim::RgminStep transient;
166 gpr::optim::RgminStep& session =
167 rgmin_trans_ != nullptr ? *rgmin_trans_ : transient;
168 const Eigen::Index n = F_trans.size();
169 Eigen::VectorXd x = Eigen::Map<const Eigen::VectorXd>(R.data(), n);
170 const Eigen::VectorXd x_before = x;
171 const Eigen::VectorXd g =
172 -Eigen::Map<const Eigen::VectorXd>(F_trans.data(), n);
173 // A refusal after a pushed pair forgets the whole session, so the
174 // retry is the empty-memory step from the same point. A second refusal
175 // is a zero or unusable force, and the dimer stays where it is.
176 if (!session.step(x, g, param_trans.max_step_length, 0.01) &&
177 !session.step(x, g, param_trans.max_step_length, 0.01))
178 return;
179 Eigen::VectorXd r_final = x_before - x;
180
181 if (!this->is_subsystem) {
182 // Rigid rotation/translation comes off the step: a torqued step
183 // feeds the session's next curvature pair with rigid motion.
184 const Eigen::MatrixXd basis = rigid_motion_basis(R, project_rotations_);
185 r_final -= basis * (basis.transpose() * r_final);
186 }
187 Eigen::Map<Eigen::VectorXd>(R.data(), R.size()) -= r_final;
188}
@ x
Definition Enums.h:28
bool step(Eigen::VectorXd &x, const Eigen::VectorXd &gradient, double max_move, double empty_scale, Objective objective=Objective::Unspecified)
Definition RgminStep.h:122
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

◆ gpr::consumerPublicLayout

◆ gpr::libraryPublicLayout


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