Loading...
Searching...
No Matches
NEBObjectiveFunction.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
13
14namespace eonc {
15
16VectorXd NEBObjectiveFunction::getGradient(bool fdstep) {
17 if (neb->movedAfterForceCall)
18 neb->updateForces();
19 const long seg = 3 * neb->atoms;
20 VectorXd gradV(seg * neb->numImages);
21 for (long i = 1; i <= neb->numImages; i++) {
22 // Negate in-place during copy to avoid a second pass over 40KB
23 gradV.segment(seg * (i - 1), seg) =
24 -VectorXd::Map(neb->projectedForce[i]->data(), seg);
25 }
26 return gradV;
27}
28
30 double Energy{0};
31 for (long i = 1; i <= neb->numImages; i++) {
32 Energy += neb->path[i]->getPotentialEnergy();
33 }
34 return Energy;
35}
36
37void NEBObjectiveFunction::setPositions(const VectorXd &x) {
38 neb->movedAfterForceCall = true;
39 for (long i = 1; i <= neb->numImages; i++) {
40 neb->path[i]->setPositions(AtomMatrix::Map(
41 x.segment(3 * neb->atoms * (i - 1), 3 * neb->atoms).data(), neb->atoms,
42 3));
43 }
44}
45
47 VectorXd posV;
48 posV.resize(3 * neb->atoms * neb->numImages);
49 for (long i = 1; i <= neb->numImages; i++) {
50 posV.segment(3 * neb->atoms * (i - 1), 3 * neb->atoms) =
51 VectorXd::Map(neb->path[i]->getPositions().data(), 3 * neb->atoms);
52 }
53 return posV;
54}
55
57 return 3 * neb->numImages * neb->atoms;
58}
59
61 double maxMaxUnc = std::numeric_limits<double>::lowest();
62 double currentMaxUnc{0};
63 for (long idx = 0; idx <= neb->numImages; idx++) {
64 currentMaxUnc = neb->path[idx]->getEnergyVariance();
65 if (currentMaxUnc > maxMaxUnc) {
66 maxMaxUnc = currentMaxUnc;
67 }
68 }
69 bool unc_conv{maxMaxUnc > params.gp_surrogate_options.uncertainty};
70 if (unc_conv) {
72 }
73 return unc_conv;
74}
75
77 bool force_conv = getConvergence() < params.neb_options.force_tolerance;
78 return force_conv;
79}
80
82 return neb->convergenceForce();
83}
84
85VectorXd NEBObjectiveFunction::difference(const VectorXd &a,
86 const VectorXd &b) {
87 VectorXd pbcDiff(3 * neb->numImages * neb->atoms);
88 for (int i = 1; i <= neb->numImages; i++) {
89 int n = (i - 1) * 3 * neb->atoms;
90 int m = 3 * neb->atoms;
91 pbcDiff.segment(n, m) =
92 neb->path[i]->pbcV(a.segment(n, m) - b.segment(n, m));
93 }
94 return pbcDiff;
95}
96
97} // namespace eonc
VectorXd getGradient(bool fdstep=false)
NudgedElasticBand::NEBStatus status
VectorXd difference(const VectorXd &a, const VectorXd &b)
void setPositions(const VectorXd &x)
const Parameters & params
RAII resource manager for the ARTn C library with global synchronization.