32#include "magic_enum/magic_enum.hpp"
45#ifdef EON_PARALLEL_NEB
54namespace fs = std::filesystem;
59 std::shared_ptr<Matter> finalPassed,
61 std::shared_ptr<Potential> potPassed)
64 auto &init_opt = parametersPassed.
neb_options().initialization;
65 const size_t base_count =
70 throw std::invalid_argument(
71 "solid_state accepts initializer linear or file");
74 auto aligned = eonc::IRACompare::alignReactantToProduct(
75 *initialPassed, *finalPassed, 1.0);
76 auto *log = eonc::log::get();
77 if (aligned.error != 0) {
80 "match_endpoints: IRA align failed (error {}), "
81 "interpolating the input order",
85 "match_endpoints: Hausdorff {:.4f} A after IRA "
86 "permute+rotate of the reactant",
87 aligned.hausdorffDistance);
92 const size_t relax_count =
94 ? base_count * init_opt.oversampling_factor
97 std::vector<Matter> path;
98 switch (init_opt.method) {
100 std::vector<fs::path> file_paths =
101 eonc::helpers::neb_paths::readFilePaths(init_opt.input_path);
102 path = eonc::helpers::neb_paths::filePathInit(
103 file_paths, *initialPassed, base_count);
106 path.front() = Matter(*initialPassed);
107 path.back() = Matter(*finalPassed);
112 *initialPassed, *finalPassed, relax_count, parametersPassed);
116 *initialPassed, *finalPassed, relax_count, parametersPassed);
121 *initialPassed, *finalPassed, relax_count, parametersPassed,
127 *initialPassed, *finalPassed, base_count);
132 if (init_opt.oversampling && path.size() > (base_count + 2)) {
133 auto *log = eonc::log::get();
135 "Decimating oversampled path ({} images) to "
136 "{} images via cubic spline.",
137 path.size() - 2, base_count);
140 path = eonc::helpers::neb_paths::resamplePath(path, base_count);
145 log,
"Relaxing decimated path to restore IDPP surface...");
148 std::shared_ptr<ObjectiveFunction> post_decim_objf =
149 std::make_shared<CollectiveIDPPObjectiveFunction>(
150 path, parametersPassed);
153 bool use_zbl = (init_opt.method == NEBInit::SIDPP_ZBL);
155 auto zbl_pot = eonc::helpers::neb_paths::createZBLPotential();
156 post_decim_objf = std::make_shared<ZBLRepulsiveIDPPObjective>(
157 post_decim_objf, zbl_pot, path, parametersPassed, 1.0);
161 post_decim_objf, parametersPassed.neb_options().opt_method,
166 parametersPassed.neb_options().initialization.max_iterations,
167 parametersPassed.neb_options().initialization.max_move);
169 if (parametersPassed.neb_options().solid_state.enabled &&
170 init_opt.method == NEBInit::LINEAR) {
171 if (init_opt.oversampling) {
172 throw std::invalid_argument(
173 "solid_state NEB does not oversample the initial path");
175 for (
Matter &image : path) {
179 }
else if (parametersPassed.neb_options().solid_state.enabled &&
180 init_opt.method == NEBInit::FILE) {
181 for (
Matter &image : path) {
187 parametersPassed, potPassed) {}
192 std::shared_ptr<Potential> potPassed)
193 :
ci_enabled_{parametersPassed.neb_options().climbing_image.enabled},
200 params.optimizer_options().convergence_metric,
"[Nudged Elastic Band]");
203 if (initPath.empty()) {
204 throw std::invalid_argument(
"NEB: initPath is empty");
206 if (initPath.size() !=
static_cast<size_t>(
numImages + 2)) {
207 throw std::invalid_argument(
"NEB: initPath.size() must be image_count + 2");
209 atoms = initPath.front().numberOfAtoms();
210 for (
size_t i = 1; i < initPath.size(); ++i) {
212 initPath[i],
"path images");
231 QUILL_LOG_INFO(
log,
"NEB: one potential instance per image ({} images)",
235 for (
long i = 0; i <=
numImages + 1; i++) {
236 path[i] = std::make_shared<Matter>(std::move(initPath[i]));
244 tangent[i] = std::make_shared<AtomMatrix>();
270 k_u =
params.neb_options().spring.weighting.k_max;
271 k_l =
params.neb_options().spring.weighting.k_min;
272 if (
params.neb_options().spring.weighting.enabled) {
275 ksp =
params.neb_options().spring.constant;
283 if (
params.debug_options().estimate_neb_eigenvalues) {
285 for (
long i = 0; i <=
numImages + 1; i++) {
297 QUILL_LOG_DEBUG(
log,
"Nudged elastic band calculation started.");
300 E_ref = std::max(
path[0]->getPotentialEnergy(),
305 auto objf = std::make_shared<NEBObjectiveFunction>(
this,
params);
307 bool switched{
false};
309 std::unique_ptr<XtsciBand> rustBand;
311 std::unique_ptr<Optimizer> optim;
312 std::unique_ptr<Optimizer> refine_optim;
314 const auto bandMethod =
params.neb_options().opt_method;
315 if (!
params.neb_options().spring.geometric &&
318 rustBand = std::make_unique<XtsciBand>(*
this,
params);
322 const auto &band =
params.neb_options().band;
323 if (band.precon !=
"none" || band.stepper !=
"auto") {
324 throw std::invalid_argument(
325 "band_precon and band_stepper act on the rgsaddle band: a build "
326 "with rgsaddle, opt_method lbfgs, fire or xtsci, and no "
333 objf,
params.optimizer_options().refine.method,
params);
339 bool zoomDone{
false};
344 double activation_force{0.0};
349 const double moveBase =
params.optimizer_options().max_move;
351 double moveNow = moveBase;
352 double bestForce = std::numeric_limits<double>::infinity();
357 path.front()->pollCancel(
"neb");
359 if (
params.debug_options().write_movies &&
360 (iteration %
params.debug_options().write_movies_interval == 0)) {
361 bool append = (iteration != 0);
364 params.debug_options().estimate_neb_eigenvalues,
365 std::format(
"neb_path_{:03d}.con", iteration), iteration,
367 QUILL_LOG_ERROR(
log,
"Failed to write NEB path movie for iteration {}",
374 path[0]->pbc(
path[1]->getPositions() -
path[0]->getPositions());
381 eonc::safemath::safe_normalize_inplace(maxTang);
385 maxImageMetadata.neb_bead =
static_cast<uint64_t
>(
maxEnergyImage);
386 maxImageMetadata.neb_band =
static_cast<uint64_t
>(iteration);
387 maxImageMetadata.scalars.push_back(
390 maxImageMetadata.scalars.push_back(
393 maxImageMetadata.strings.push_back({
"movie_kind",
"neb_maximage"});
395 "neb_maximage.con", append, &maxImageMetadata))) {
401 VectorXd pos = objf->getPositions();
406 if (iteration == 0) {
408 activation_force = convForce;
412 auto &ci_opt =
params.neb_options().climbing_image;
413 auto &mmf_opt = ci_opt.ocineb;
414 auto fmt_trigger = [](
double val) -> std::string {
417 return std::format(
"{:.4f}", val);
422 "===============================================================");
423 QUILL_LOG_INFO(
log,
" NEB Optimization Configuration");
426 "===============================================================");
429 std::string ci_status = ci_opt.enabled ?
"ENABLED" :
"DISABLED";
430 QUILL_LOG_INFO(
log,
" {:<25} : {}",
"Climbing Image (CI)", ci_status);
431 if (ci_opt.enabled) {
433 QUILL_LOG_INFO(
log,
" - {:<21} : {} (Factor: {:.2f})",
434 "Relative Trigger", fmt_trigger(ci_rel_val),
435 ci_opt.trigger_factor);
436 QUILL_LOG_INFO(
log,
" - {:<21} : {}",
"Absolute Trigger",
437 fmt_trigger(ci_opt.trigger_force));
438 QUILL_LOG_INFO(
log,
" - {:<21} : {}",
"Converged Only",
439 ci_opt.converged_only);
442 std::string mmf_status =
443 (ci_opt.enabled && mmf_opt.use_mmf) ?
"ENABLED" :
"DISABLED";
444 QUILL_LOG_INFO(
log,
" {:<25} : {}",
"Hybrid MMF (OCINEB)", mmf_status);
445 if (ci_opt.enabled && mmf_opt.use_mmf) {
446 QUILL_LOG_INFO(
log,
" - {:<21} : {:.4f} (Factor: {:.2f})",
448 mmf_opt.trigger_factor);
449 QUILL_LOG_INFO(
log,
" - {:<21} : {:.4f}",
"Absolute Floor",
450 mmf_opt.trigger_force);
451 QUILL_LOG_INFO(
log,
" - {:<21} : {:.4f}",
"Angle Tolerance",
456 "---------------------------------------------------------------");
458 EONC_LOG_DEBUG(
"{:>10s} {:>12s} {:>14s} {:>11s} {:>12s}",
"iteration",
460 params.optimizer_options().convergence_metric_label,
461 "max image",
"max energy");
464 "---------------------------------------------------------------\n");
469 params.neb_options().climbing_image.enabled &&
472 params.neb_options().climbing_image.trigger_factor ||
473 activation_force <
params.neb_options().climbing_image.trigger_force);
475 bool zoomedThisStep =
false;
476 if (iteration && !zoomDone &&
params.neb_options().zoom.enabled &&
484 const auto &zoom =
params.neb_options().zoom;
485 const double zoomForce =
486 zoom.activation_threshold > 0.0
487 ? zoom.activation_threshold
488 : 10.0 *
params.neb_options().force_tolerance;
489 if (zoomStable >= zoom.stability_count && convForce < zoomForce) {
490 std::vector<double> energy;
491 energy.reserve(
path.size());
492 for (
const auto &image :
path) {
493 energy.push_back(image->getPotentialEnergy());
498 zoom.interpolation)) {
503 zoomedThisStep =
true;
505 QUILL_LOG_INFO(
log,
"Zoom-NEB: packed the band onto images [{}, {}]",
506 window.lo, window.hi);
514 double mmfForce = convForce;
518 params.optimizer_options().convergence_metric);
522 if (!zoomedThisStep &&
525 auto result = ocineb.
run(*
this, convForce);
527 if (result.convergedAfterMMF) {
533 if (result.shouldResetOptimizer) {
536 rustBand->syncFromPath();
547 long iterLimit =
params.neb_options().max_iterations;
548 if (zoomDone &&
params.neb_options().zoom.max_iterations > 0 &&
550 iterLimit = zoomAt +
params.neb_options().zoom.max_iterations;
552 if (iteration >= iterLimit) {
557 if (zoomedThisStep) {
569 rustBand->step(moveNow);
575 convForce <=
params.optimizer_options().refine.threshold)
579 convForce <=
params.optimizer_options().refine.threshold &&
583 magic_enum::enum_name<OptType>(
584 params.optimizer_options().refine.method));
586 activeOptim->step(moveNow);
590 if (adaptCg && activation_force < bestForce * 0.98) {
591 bestForce = activation_force;
593 if (moveNow < moveBase && convForce > 0.0 &&
594 activation_force < 0.8 * convForce) {
595 moveNow = std::min(moveBase, moveNow * 1.5);
597 }
else if (adaptCg) {
599 if (convForce > 0.0 && activation_force > 2.0 * convForce) {
600 moveNow = std::max(moveNow * 0.5, moveBase * 0.2);
603 moveNow = std::max(moveBase * 0.2, moveNow * 0.5);
615 objf,
params.optimizer_options().refine.method,
params);
618 QUILL_LOG_DEBUG(
log,
"Band stalled; reset optimizer, step {:.4e}",
628 double stepSize = 0.0;
630 const VectorXd delta = objf->difference(objf->getPositions(), pos);
631 const long seg = 3L *
atoms + 9L;
632 for (
long image = 0; image <
numImages; ++image) {
634 stepSize, delta.segment(image * seg, seg).cwiseAbs().maxCoeff());
638 path[0]->pbcV(objf->getPositions() - pos));
640 QUILL_LOG_DEBUG(
log,
"{:>10} {:>12.4e} {:>14.4e} {:>11} {:>12.4}",
645 if (objf->isUncertain()) {
646 QUILL_LOG_DEBUG(
log,
"NEB failed due to high uncertainty");
649 }
else if (objf->isConverged()) {
650 QUILL_LOG_DEBUG(
log,
"NEB converged\n");
655 if (objf->isConverged()) {
656 QUILL_LOG_DEBUG(
log,
"NEB converged\n");
670 auto imageForce = [&](
long i) ->
double {
671 const double cellNorm =
673 if (
params.optimizer_options().convergence_metric ==
"norm") {
676 if (
params.optimizer_options().convergence_metric ==
"max_atom") {
680 if (
params.optimizer_options().convergence_metric ==
"max_component") {
683 component = std::max(
691 log,
"[Nudged Elastic Band] unknown opt_convergence_metric: {}",
692 params.optimizer_options().convergence_metric);
693 throw std::invalid_argument(
694 std::format(
"[Nudged Elastic Band] unknown convergence_metric: {}",
695 params.optimizer_options().convergence_metric));
700 bandMax = std::max(bandMax, imageForce(i));
703 const bool ciOnly =
params.neb_options().climbing_image.converged_only &&
710 const double slack =
params.neb_options().climbing_image.band_slack;
711 const double tol =
params.neb_options().force_tolerance;
712 if (slack > 0.0 && bandMax > slack * tol) {
730 std::vector<long> dirty;
733 if (
path[i]->needsForceUpdate()) {
738 if (!dirty.empty()) {
740 path.front()->pollCancel(
"neb");
742 auto nDirty =
static_cast<long>(dirty.size());
743 std::vector<VectorXi> nrsStore;
744 std::vector<Matrix3d> boxStore;
745 std::vector<const double *> posVec, boxVec;
746 std::vector<const int *> nrsVec;
747 std::vector<double *> frcVec;
748 nrsStore.reserve(
static_cast<size_t>(nDirty));
749 boxStore.reserve(
static_cast<size_t>(nDirty));
750 posVec.reserve(
static_cast<size_t>(nDirty));
751 boxVec.reserve(
static_cast<size_t>(nDirty));
752 nrsVec.reserve(
static_cast<size_t>(nDirty));
753 frcVec.reserve(
static_cast<size_t>(nDirty));
755 for (
long idx : dirty) {
756 nrsStore.push_back(
path[idx]->getAtomicNrs());
761 (
path[idx]->getPeriodic() ||
pot->forwardsStoredCell())
762 ?
path[idx]->getCell()
765 for (
long j = 0; j < nDirty; j++) {
766 auto idx = dirty[
static_cast<size_t>(j)];
767 posVec.push_back(
path[idx]->getPositions().data());
768 nrsVec.push_back(nrsStore[
static_cast<size_t>(j)].data());
769 frcVec.push_back(
path[idx]->forcesData());
770 boxVec.push_back(boxStore[
static_cast<size_t>(j)].data());
773 std::vector<double> energies(nDirty), variances(nDirty);
776 std::vector<long> owners(
static_cast<size_t>(nDirty));
777 for (
long j = 0; j < nDirty; j++) {
778 owners[
static_cast<size_t>(j)] =
779 imageOwner(
static_cast<size_t>(dirty[
static_cast<size_t>(j)]));
781 pot->forceBatchOwned(nDirty,
atoms, posVec.data(), nrsVec.data(),
782 frcVec.data(), energies.data(), variances.data(),
783 boxVec.data(), owners.data());
784 for (
long j = 0; j < nDirty; j++) {
785 path[dirty[j]]->setComputedPotential(energies[j], variances[j]);
793#ifdef EON_PARALLEL_NEB
795 std::vector<long> beads(
static_cast<size_t>(
numImages));
796 std::iota(beads.begin(), beads.end(), 1);
797 std::exception_ptr neb_cancel;
798 std::mutex neb_cancel_mu;
799 std::for_each(std::execution::par, beads.begin(), beads.end(),
800 [
this, &neb_cancel, &neb_cancel_mu](
long i) {
802 path[i]->getForcesRaw();
804 std::lock_guard<std::mutex> lock(neb_cancel_mu);
806 neb_cancel = std::current_exception();
811 std::rethrow_exception(neb_cancel);
815 [
this](
long i) {
path[i]->getForcesRaw(); });
819 path[i]->getForcesRaw();
825 projectSolidState(ci_active);
826 movedAfterForceCall = ci_active != ci_enabled_;
831 auto first = path.begin() + 1;
832 auto last = path.begin() + numImages + 1;
833 auto it = std::max_element(
835 [](
const std::shared_ptr<Matter> &a,
const std::shared_ptr<Matter> &b) {
836 return a->getPotentialEnergy() < b->getPotentialEnergy();
838 maxEnergyImage = std::distance(path.begin(), it);
839 double maxEnergy = (*it)->getPotentialEnergy();
843 if (params.neb_options().spring.weighting.enabled) {
844 E_ref = std::max(path[0]->getPotentialEnergy(),
845 path[numImages + 1]->getPotentialEnergy());
850 const double endpointEnergy = std::max(path.front()->getPotentialEnergy(),
851 path.back()->getPotentialEnergy());
852 const bool climb = ci_active && maxEnergy > endpointEnergy;
853 const long previousCI =
static_cast<long>(climbingImage);
861 if (
const auto *uniform = std::get_if<eonc::neb::UniformSpring>(&spring)) {
869 long ciTarget =
static_cast<long>(maxEnergyImage);
870 if (climb && previousCI > 0 && previousCI <= numImages) {
871 const double eCI = path[previousCI]->getPotentialEnergy();
872 if (eCI > path[previousCI - 1]->getPotentialEnergy() &&
873 eCI > path[previousCI + 1]->getPotentialEnergy()) {
874 ciTarget = previousCI;
878 climbingImage =
static_cast<size_t>(ciTarget);
884 auto projectImage = [&](
long i) {
885 AtomMatrix posDiffNext(atoms, 3), posDiffPrev(atoms, 3);
886 const AtomMatrix &force = path[i]->getForces();
887 const AtomMatrix &pos = path[i]->getPositions();
888 const AtomMatrix &posPrev = path[i - 1]->getPositions();
889 const AtomMatrix &posNext = path[i + 1]->getPositions();
890 double energy = path[i]->getPotentialEnergy();
891 double energyPrev = path[i - 1]->getPotentialEnergy();
892 double energyNext = path[i + 1]->getPotentialEnergy();
893 posDiffNext.noalias() = posNext - pos;
894 posDiffNext = path[i]->pbc(posDiffNext);
895 posDiffPrev.noalias() = pos - posPrev;
896 posDiffPrev = path[i]->pbc(posDiffPrev);
897 double distNext = posDiffNext.norm();
898 double distPrev = posDiffPrev.norm();
901 *tangent[i] = std::visit(
903 return t.compute(posDiffNext, posDiffPrev, energy, energyPrev,
909 eonc::neb::SpringResult springResult = std::visit(
910 [&](
auto &s) -> eonc::neb::SpringResult {
911 using T = std::decay_t<
decltype(s)>;
912 if constexpr (std::is_same_v<T, eonc::neb::UniformSpring>) {
913 return s.compute(i, *tangent[i], distNext, distPrev, posDiffNext,
914 posDiffPrev, path[i]);
915 }
else if constexpr (std::is_same_v<T, eonc::neb::WeightedSpring>) {
916 return s.compute(i, *tangent[i], distNext, distPrev);
917 }
else if constexpr (std::is_same_v<T, eonc::neb::GeometricSpring>) {
918 return s.compute(i, *tangent[i], distNext, distPrev);
920 return s.compute(i, *tangent[i], posNext, posPrev, pos, path[i]);
926 if (climb && i == ciTarget) {
928 AtomMatrix forceDNEB = AtomMatrix::Zero(atoms, 3);
929 if (
const auto *dnebProj =
930 std::get_if<eonc::neb::DNEB_Projection>(&projectionStrat_)) {
934 dnebProj->use_switching);
939 eonc::neb::ImageForceData data{force, *tangent[i], springResult,
940 path[i]->numberOfFreeAtoms(),
941 path[i]->numberOfAtoms()};
942 *projectedForce[i] = std::visit([&](
auto &p) {
return p.project(data); },
949 if (path[i]->numberOfFreeAtoms() < path[i]->numberOfAtoms()) {
950 for (
long j = 0; j < atoms; j++) {
951 if (path[i]->getFixed(j)) {
952 projectedForce[i]->row(j).setZero();
958 path[i]->numberOfAtoms());
960 if (numImages > 1 && params.main_options().parallel) {
963 for (
long i = 1; i <= numImages; i++) {
968 movedAfterForceCall = ci_active != ci_enabled_;
974 if (
path[i]->getPotentialEnergy() >
path[highest]->getPotentialEnergy()) {
983 path[i]->pbc(
path[i + 1]->getPositions() - pos);
985 path[i]->pbc(pos -
path[i - 1]->getPositions());
986 const double energy =
path[i]->getPotentialEnergy();
987 const double energyPrev =
path[i - 1]->getPotentialEnergy();
988 const double energyNext =
path[i + 1]->getPotentialEnergy();
991 return t.compute(posDiffNext, posDiffPrev, energy, energyPrev,
1002 params.debug_options().estimate_neb_eigenvalues,
1014std::vector<readcon::ConFrame>
1018 params.debug_options().estimate_neb_eigenvalues, bandIndex,
1024void refuseSolidStateCombination(
const Parameters ¶ms) {
1026 if (!
neb.solid_state.enabled) {
1029 if (neb.climbing_image.ocineb.use_mmf) {
1030 throw std::invalid_argument(
1031 "solid_state is set and ci_mmf is true. The min-mode walk does not "
1034 if (neb.zoom.enabled) {
1035 throw std::invalid_argument(
1036 "solid_state is set and zoom_neb is true. Zoom does not move the cell");
1038 if (neb.spring.om.enabled) {
1039 throw std::invalid_argument(
1040 "solid_state is set and onsager_machlup is true");
1042 if (neb.spring.geometric) {
1043 throw std::invalid_argument(
1044 "solid_state is set and geometric_spring is true");
1046 if (neb.spring.doubly_nudged) {
1047 throw std::invalid_argument(
1048 "solid_state is set and neb_doubly_nudged is true");
1050 if (neb.spring.use_elastic_band) {
1051 throw std::invalid_argument(
1052 "solid_state is set and neb_elastic_band is true");
1055 if (method != NEBInit::LINEAR && method != NEBInit::FILE) {
1056 throw std::invalid_argument(
1057 "solid_state accepts initializer linear or file");
1059 if (!(neb.solid_state.weight > 0.0)) {
1060 throw std::invalid_argument(
"solid_state_weight must be positive");
1066 packed.topRows(atomic.rows()) = atomic;
1067 packed.bottomRows(3) = cell;
1072 double distNext,
double distPrev) {
1073 if (
const auto *uniform = std::get_if<eonc::neb::UniformSpring>(&spring)) {
1074 return uniform->ksp * (distNext - distPrev);
1076 if (
const auto *weighted = std::get_if<eonc::neb::WeightedSpring>(&spring)) {
1077 return weighted->springConstants[
static_cast<size_t>(image)] * distNext -
1078 weighted->springConstants[
static_cast<size_t>(image - 1)] * distPrev;
1080 throw std::invalid_argument(
1081 "solid_state NEB does not use this spring strategy");
1087 if (!
params.neb_options().solid_state.enabled) {
1090 refuseSolidStateCombination(
params);
1091 for (
const auto &image :
path) {
1092 if (!image->getPeriodic()) {
1093 throw std::invalid_argument(
1094 "solid_state NEB requires periodic boundaries on every image");
1098 const double volume0 = std::abs(
path.front()->getCell().determinant());
1099 const double volume1 = std::abs(
path.back()->getCell().determinant());
1102 params.neb_options().solid_state.weight);
1106 QUILL_LOG_INFO(
log,
"Solid-state NEB Jacobian {:.6f} Angstrom",
1112 const double pressure =
params.neb_options().solid_state.pressure;
1113 const Matrix3d external = Matrix3d::Identity() * pressure;
1114 std::vector<double> enthalpy(
static_cast<size_t>(
numImages + 2));
1115 for (
long i = 0; i <=
numImages + 1; ++i) {
1116 enthalpy[
static_cast<size_t>(i)] =
1122 if (enthalpy[
static_cast<size_t>(i)] >
1123 enthalpy[
static_cast<size_t>(highest)]) {
1128 const double endpointEnthalpy = std::max(enthalpy.front(), enthalpy.back());
1130 ci_active && enthalpy[
static_cast<size_t>(highest)] > endpointEnthalpy;
1133 if (
params.neb_options().spring.weighting.enabled) {
1134 E_ref = std::max(
path[0]->getPotentialEnergy(),
1137 const double maxEnergy =
path[highest]->getPotentialEnergy();
1140 if (
const auto *uniform = std::get_if<eonc::neb::UniformSpring>(&spring)) {
1144 if (!
pot->computesStress()) {
1145 throw std::invalid_argument(
1146 "solid_state NEB requires a potential that reports the Cauchy stress");
1150 const double volume = std::abs(
path[i]->getCell().determinant());
1155 for (
long atom = 0; atom <
atoms; ++atom) {
1156 if (
path[i]->getFixed(atom)) {
1157 atomicTrue.row(atom).setZero();
1167 const double energy = enthalpy[
static_cast<size_t>(i)];
1168 const double energyPrev = enthalpy[
static_cast<size_t>(i - 1)];
1169 const double energyNext = enthalpy[
static_cast<size_t>(i + 1)];
1171 [&](
auto &tangentStrategy) {
1172 return tangentStrategy.compute(packedNext, packedPrev, energy,
1173 energyPrev, energyNext);
1178 AtomMatrix packedForce = packJoint(atomicTrue, cellTrue);
1180 if (climb && i == highest) {
1182 const double parallel =
matDot(packedForce, packedTangent);
1183 total = packedForce - 2.0 * parallel * packedTangent;
1185 const double parallel =
matDot(packedForce, packedTangent);
1186 const AtomMatrix perpendicular = packedForce - parallel * packedTangent;
1189 total = perpendicular + scale * packedTangent;
1196 for (
long atom = 0; atom <
atoms; ++atom) {
1197 if (
path[i]->getFixed(atom)) {
1202 path[i]->numberOfAtoms());
double matDot(const AtomMatrix &a, const AtomMatrix &b)
SIMD-optimized dot product for contiguous Eigen matrices.
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
#define EONC_LOG_DEBUG(...)
#define EONC_LOG_WARNING(...)
The optimizer class is used to serve as an abstract class for all optimizers, as well as to call an o...
NudgedElasticBand(std::shared_ptr< Matter > initialPassed, std::shared_ptr< Matter > finalPassed, const Parameters ¶metersPassed, std::shared_ptr< Potential > potPassed)
Cooperative stop. Loops poll and throw; they do not abort the process.
NudgedElasticBand::NEBStatus compute(void)
NudgedElasticBand(std::shared_ptr< Matter > initialPassed, std::shared_ptr< Matter > finalPassed, const Parameters ¶metersPassed, std::shared_ptr< Potential > potPassed)
std::vector< double > extremumEnergy
std::size_t maxEnergyImage
std::vector< std::shared_ptr< AtomMatrix > > tangent
void printImageData(bool writeToFile=false, size_t idx=0)
std::vector< std::shared_ptr< Matter > > path
bool perImagePotentials_
Whether per-image potential instances exist.
std::vector< double > extremumPosition
std::vector< std::shared_ptr< EigenmodeStrategy > > eigenmode_solvers
void projectSolidState(bool ci_active)
std::vector< readcon::ConFrame > pathFrames(std::optional< size_t > bandIndex=std::nullopt)
In-memory ConFrames with the same NEB stamps as writePathCon / neb.con.
double convergenceForce(void)
neb::TangentStrategy tangentStrat_
void adoptSessionProjection(long ciIndex)
Host bookkeeping for a band whose projected force came from the rgsaddle session: the highest interio...
std::vector< std::shared_ptr< AtomMatrix > > projectedForce
long imageOwner(std::size_t i) const noexcept
The identity band image i carries in a batch (forceBatchOwned): interior image i is i - 1,...
void setCIEnabled(bool enabled)
std::shared_ptr< Potential > pot
neb::ProjectionStrategy projectionStrat_
std::vector< double > extremumCurvature
std::vector< Matrix3d > projectedCellForce
const neb_options_t & neb_options() const
bool shouldTrigger(double convForce, bool ci_active, long climbingImage, long numImages, int ciStabilityCounter) const
static Config fromParams(const Parameters ¶ms)
void updateStability(long climbingImage)
MMFResult run(eonc::NudgedElasticBand &neb, double convForce)
void initBaseline(double baseline_force)
int stabilityCount() const
static double forceMeasure(const AtomMatrix &freeForces, std::string_view metric)
Measure free-atom forces with the band's configured convergence metric.
double maxAtomMotionV(const VectorXd v1)
std::unique_ptr< Optimizer > mkOptim(std::shared_ptr< ObjectiveFunction > a_objf, OptType a_otype, const Parameters &a_params)
std::vector< Matter > sidppPath(const Matter &initImg, const Matter &finalImg, size_t target_nimgs, const Parameters ¶ms, bool use_zbl)
std::vector< Matter > linearPath(const Matter &initImg, const Matter &finalImg, const size_t nimgs)
void requireSameAtomCount(const Matter &a, const Matter &b, std::string_view what)
Abort before Eigen subtracts two position matrices of different size.
std::vector< Matter > idppPath(const Matter &initImg, const Matter &finalImg, const size_t nimgs, const Parameters ¶ms, bool use_zbl)
std::vector< Matter > idppCollectivePath(const Matter &initImg, const Matter &finalImg, size_t nimgs, const Parameters ¶ms, bool use_zbl)
std::shared_ptr< Potential > makeImagePotential(const Potential &pot, const Parameters ¶ms)
A separate instance of pot for one image of a band, dimer or pair of minimizations: a clone when the ...
void requireKnownConvergenceMetric(std::string_view metric, std::string_view context)
Throws std::invalid_argument naming context when metric is unrecognized.
constexpr bool io_ok(IoStatus s) noexcept
quill::Logger * get() noexcept
Get or create the default "combi" logger.
quill::Logger * traceback() noexcept
Get or create the "_traceback" logger for traceback logging.
Window selectWindow(const std::vector< double > &energy, std::size_t climbingImage, const neb_options_t::zoom_options_t &cfg)
Auto: contiguous images around the climbing image whose energy is above E_ref + alpha * barrier.
bool redistributePath(std::vector< std::shared_ptr< Matter > > &path, Window window, neb_options_t::zoom_options_t::Interpolation how)
Place every band image on the window by equal arc length.
std::vector< readcon::ConFrame > pathToConFrames(const std::vector< std::shared_ptr< Matter > > &path, const std::vector< std::shared_ptr< AtomMatrix > > &tangent, const std::vector< std::shared_ptr< EigenmodeStrategy > > &eigenmode_solvers, long numImages, bool estimateEigenvalues, std::optional< size_t > bandIndex, double referenceEnergy, const std::vector< double > *quantumFreeEnergy, const eonc::tunneling::BandWalls *walls)
Build stamped ConFrames for a NEB band (same metadata as writePathCon).
void interpolateSolidStateLinear(std::vector< Matter > &images)
Replace interior images by a fractional linear interpolation of the oriented endpoints.
AtomMatrix computeDNEBComponent(const AtomMatrix &forceSpring, const AtomMatrix &tangent, const AtomMatrix &fPerp, bool useSwitching)
Compute the DNEB force component for a given image.
void zeroTranslation(AtomMatrix &projectedForce, int nFreeAtoms, int nAtoms)
Zero net translational force for fully free systems.
SpringStrategy buildSpringStrategy(const Parameters ¶ms, const std::vector< std::shared_ptr< Matter > > &path, long numImages, int atoms, double maxEnergy, double E_ref)
Build the appropriate spring strategy from parameters and current path state.
TangentStrategy buildTangentStrategy(const Parameters ¶ms)
Build the tangent strategy from parameters.
double jointNorm(const JointBlock &block)
ProjectionStrategy buildProjectionStrategy(const Parameters ¶ms)
Build the projection strategy from parameters.
AtomMatrix climbingImageForce(const AtomMatrix &force, const AtomMatrix &tangent, const AtomMatrix &forceDNEB)
Compute the climbing image projected force.
JointBlock jointDisplacement(const Matter &from, const Matter &to, double jacobian)
Displacement of to relative to from in the joint metric.
eonc::io::IoStatus writePathCon(const std::vector< std::shared_ptr< Matter > > &path, const std::vector< std::shared_ptr< AtomMatrix > > &tangent, const std::vector< std::shared_ptr< EigenmodeStrategy > > &eigenmode_solvers, long numImages, bool estimateEigenvalues, std::string filename, std::optional< size_t > bandIndex, double referenceEnergy, const std::vector< double > *quantumFreeEnergy, const eonc::tunneling::BandWalls *walls)
Write a NEB band as a multi-frame .con via readcon ConFrameBuilder::clone().
void printImageData(const std::vector< std::shared_ptr< Matter > > &path, const std::vector< std::shared_ptr< AtomMatrix > > &tangent, const std::vector< std::shared_ptr< EigenmodeStrategy > > &eigenmode_solvers, long numImages, bool estimateEigenvalues, bool writeToFile, size_t idx, eonc::log::Scoped log, double referenceEnergy)
Print NEB image data to log and optionally to file.
double solidStateEnthalpy(const Matter &image, const Matter &reference, double pressure)
Potential energy plus P : (h0^{-1} (h-h0)) * V0.
double solidStateJacobian(double meanVolume, int nAtoms, double weight)
J = (V/N)^{1/3} * N^{1/2} * weight, with V the mean endpoint volume.
AtomMatrix forcePerp(const AtomMatrix &force, const AtomMatrix &tangent)
Compute the perpendicular component of force relative to the tangent.
void orientSolidStateMatter(Matter &image)
ExtremaResult findSplineExtrema(const std::vector< std::shared_ptr< Matter > > &path, const std::vector< std::shared_ptr< AtomMatrix > > &tangent, long numImages)
Find extrema along the MEP using cubic spline interpolation.
Matrix3d cellNebForce(const Matrix3d &cauchy, double volume, double jacobian, const Matrix3d &externalStress)
NEB force on the Jacobian-scaled strain.
std::variant< UniformSpring, WeightedSpring, GeometricSpring, OnsagerMachlupSpring > SpringStrategy
RAII resource manager for the ARTn C library with global synchronization.
std::shared_ptr< LowestEigenmode > buildEigenmodeStrategy(std::shared_ptr< Matter > matter, const Parameters ¶ms, std::shared_ptr< Potential > pot)
bool potAllowsSharedInstance(const P &p) noexcept
void forEachImage(long n, Work &&work)
void evaluateTogether(Potential &pot, std::span< Matter *const > systems, bool threads, std::span< const long > owners)
Evaluates every system that needs a force update.
struct eonc::neb_options_t::solid_state_options_t solid_state
bool match_endpoints
Permute+rotate the reactant onto the product before interpolation.
struct eonc::neb_options_t::path_initialization_t initialization