eOn client
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
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
*/
12
#include "
eon/NudgedElasticBand.h
"
13
14
namespace
eonc
{
15
16
VectorXd
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
29
double
NEBObjectiveFunction::getEnergy
() {
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
37
void
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
46
VectorXd
NEBObjectiveFunction::getPositions
() {
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
56
int
NEBObjectiveFunction::degreesOfFreedom
() {
57
return
3 *
neb
->numImages *
neb
->atoms;
58
}
59
60
bool
NEBObjectiveFunction::isUncertain
() {
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) {
71
this->
status
=
NudgedElasticBand::NEBStatus::MAX_UNCERTAINTY
;
72
}
73
return
unc_conv;
74
}
75
76
bool
NEBObjectiveFunction::isConverged
() {
77
bool
force_conv =
getConvergence
() <
params
.neb_options.force_tolerance;
78
return
force_conv;
79
}
80
81
double
NEBObjectiveFunction::getConvergence
() {
82
return
neb
->convergenceForce();
83
}
84
85
VectorXd
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
NudgedElasticBand.h
eonc::NEBObjectiveFunction::getGradient
VectorXd getGradient(bool fdstep=false)
Definition
NEBObjectiveFunction.cpp:16
eonc::NEBObjectiveFunction::getPositions
VectorXd getPositions()
Definition
NEBObjectiveFunction.cpp:46
eonc::NEBObjectiveFunction::status
NudgedElasticBand::NEBStatus status
Definition
NudgedElasticBand.h:125
eonc::NEBObjectiveFunction::getConvergence
double getConvergence()
Definition
NEBObjectiveFunction.cpp:81
eonc::NEBObjectiveFunction::getEnergy
double getEnergy()
Definition
NEBObjectiveFunction.cpp:29
eonc::NEBObjectiveFunction::neb
NudgedElasticBand * neb
Definition
NudgedElasticBand.h:128
eonc::NEBObjectiveFunction::difference
VectorXd difference(const VectorXd &a, const VectorXd &b)
Definition
NEBObjectiveFunction.cpp:85
eonc::NEBObjectiveFunction::isConverged
bool isConverged()
Definition
NEBObjectiveFunction.cpp:76
eonc::NEBObjectiveFunction::degreesOfFreedom
int degreesOfFreedom()
Definition
NEBObjectiveFunction.cpp:56
eonc::NEBObjectiveFunction::isUncertain
bool isUncertain()
Definition
NEBObjectiveFunction.cpp:60
eonc::NEBObjectiveFunction::setPositions
void setPositions(const VectorXd &x)
Definition
NEBObjectiveFunction.cpp:37
eonc::NudgedElasticBand::NEBStatus::MAX_UNCERTAINTY
@ MAX_UNCERTAINTY
Definition
NudgedElasticBand.h:47
eonc::ObjectiveFunction::params
const Parameters & params
Definition
ObjectiveFunction.h:20
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:19
client
NEBObjectiveFunction.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf