GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
ChainRealign.cpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
5
#include "
ChainRealign.h
"
6
7
#include "
../neb/NEBPath.h
"
8
#include "
IRAAlign.h
"
9
10
namespace
aux
{
11
12
ChainRealignStats
realignChainToPredecessors
(
13
gpr::neb::NEBPath
& path,
const
std::vector<int>& atomic_numbers,
14
std::vector<std::vector<uint64_t>>* image_ids,
double
kmax_factor)
15
{
16
ChainRealignStats
stats;
17
const
int
n = path.
numImages
();
18
const
int
nat =
static_cast<
int
>
(atomic_numbers.size());
19
const
bool
track_ids =
20
image_ids !=
nullptr
&&
static_cast<
int
>
(image_ids->size()) == n;
21
22
for
(
int
i = 1; i <= n - 2; ++i) {
23
const
auto
& ref = path.
image
(i - 1).
positions
;
24
auto
& im = path.
image
(i);
25
const
auto
match =
alignProductToReactant
(
26
ref, im.positions, atomic_numbers, atomic_numbers, kmax_factor);
27
if
(!match.available)
return
stats;
// built without IRA
28
if
(!match.applied) {
29
++stats.
images_failed
;
30
continue
;
// leave the image untouched
31
}
32
if
(match.identity)
continue
;
// bit-equal pass-through
33
34
im.positions = match.aligned;
35
36
// Gradients are covariant under the rigid motion and follow
37
// their atoms under the permutation: g'_slot = R * g[perm].
38
// The energy is invariant.
39
if
(im.evaluated && im.gradient.size() == 3 * nat) {
40
Eigen::VectorXd g_new(3 * nat);
41
const
auto
& R = match.rotation;
// row-major
42
for
(
int
a = 0; a < nat; ++a) {
43
const
int
p = match.permutation[
static_cast<
size_t
>
(a)];
44
for
(
int
d = 0; d < 3; ++d) {
45
g_new[3 * a + d] = R[
static_cast<
size_t
>
(3 * d + 0)] *
46
im.gradient[3 * p + 0] +
47
R[
static_cast<
size_t
>
(3 * d + 1)] *
48
im.gradient[3 * p + 1] +
49
R[
static_cast<
size_t
>
(3 * d + 2)] *
50
im.gradient[3 * p + 2];
51
}
52
}
53
im.gradient = g_new;
54
}
55
56
if
(track_ids) {
57
auto
& ids = (*image_ids)[
static_cast<
size_t
>
(i)];
58
if
(
static_cast<
int
>
(ids.size()) == nat) {
59
std::vector<uint64_t> permuted(
static_cast<
size_t
>
(nat));
60
for
(
int
a = 0; a < nat; ++a)
61
permuted[
static_cast<
size_t
>
(a)] = ids[
static_cast<
size_t
>
(
62
match.permutation[
static_cast<
size_t
>
(a)])];
63
ids = std::move(permuted);
64
}
65
}
66
++stats.
images_realigned
;
67
}
68
return
stats;
69
}
70
71
}
// namespace aux
ChainRealign.h
IRAAlign.h
NEBPath.h
NEB path management: image chain, spring forces, climbing image.
gpr::neb::NEBPath
NEB path: chain of images between two endpoints.
Definition
NEBPath.h:57
gpr::neb::NEBPath::numImages
int numImages() const
Definition
NEBPath.h:338
gpr::neb::NEBPath::image
Image & image(int i)
Access image i.
Definition
NEBPath.h:329
aux
Definition
AdditionalFunctionality.h:18
aux::alignProductToReactant
EndpointAlignResult alignProductToReactant(const Eigen::VectorXd &reactant_positions, const Eigen::VectorXd &product_positions, const std::vector< int > &reactant_types, const std::vector< int > &product_types, double kmax_factor)
Definition
IRAAlign.cpp:63
aux::realignChainToPredecessors
ChainRealignStats realignChainToPredecessors(gpr::neb::NEBPath &path, const std::vector< int > &atomic_numbers, std::vector< std::vector< uint64_t > > *image_ids, double kmax_factor)
Definition
ChainRealign.cpp:12
aux::ChainRealignStats
Definition
ChainRealign.h:36
aux::ChainRealignStats::images_failed
int images_failed
libira errors (image left untouched)
Definition
ChainRealign.h:38
aux::ChainRealignStats::images_realigned
int images_realigned
non-identity assignments applied
Definition
ChainRealign.h:37
gpr::neb::Image::positions
Eigen::VectorXd positions
Definition
NEBPath.h:40
gpr
auxiliary
ChainRealign.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf