GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
ReactiveAtomTypes.cpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
#include "
ReactiveAtomTypes.h
"
5
6
#include <algorithm>
7
#include <set>
8
#include <stdexcept>
9
10
#include "
CorderoRadii.h
"
11
#include "
MinImage.h
"
12
13
namespace
gpr::geometry
{
14
15
double
covalentRadius
(
int
atomic_number)
16
{
17
constexpr
int
max_z =
static_cast<
int
>
(
kCorderoRadiusPm
.size()) - 1;
18
if
(atomic_number < 1 || atomic_number > max_z) {
19
throw
std::invalid_argument(
"covalent radius: atomic number "
+
20
std::to_string(atomic_number) +
21
" outside the Cordero table"
);
22
}
23
return
kCorderoRadiusPm
[
static_cast<
std::size_t
>
(atomic_number)] / 100.0;
24
}
25
26
std::vector<std::pair<int, int>>
covalentBondGraph
(
27
const
Eigen::VectorXd& positions,
const
std::vector<int>& atomic_numbers,
28
const
std::array<double, 9>& cell)
29
{
30
const
int
n =
static_cast<
int
>
(atomic_numbers.size());
31
if
(positions.size() != 3 *
static_cast<
Eigen::Index
>
(n)) {
32
throw
std::invalid_argument(
33
"covalent bond graph: positions do not match the atom count"
);
34
}
35
const
PairBox
box(cell);
36
std::vector<std::pair<int, int>> bonds;
37
for
(
int
a = 0; a < n; ++a) {
38
const
double
ra =
39
covalentRadius
(atomic_numbers[
static_cast<
std::size_t
>
(a)]);
40
const
Eigen::Vector3d xa = positions.segment<3>(3 * a);
41
for
(
int
b = a + 1; b < n; ++b) {
42
const
double
rb =
43
covalentRadius
(atomic_numbers[
static_cast<
std::size_t
>
(b)]);
44
const
Eigen::Vector3d xb = positions.segment<3>(3 * b);
45
const
double
r = box.
displacement
(xa, xb).norm();
46
if
(r < 1.25 * (ra + rb)) bonds.emplace_back(a, b);
47
}
48
}
49
return
bonds;
50
}
51
52
ReactiveAtomTypes
assignReactiveAtomTypes
(
53
const
Eigen::VectorXd& reactant,
const
Eigen::VectorXd& product,
54
const
std::vector<int>& atomic_numbers,
const
std::vector<Index_t>& types,
55
const
std::unordered_map<std::string, Index_t>& atomtypes,
56
const
std::array<double, 9>& cell)
57
{
58
const
int
n =
static_cast<
int
>
(atomic_numbers.size());
59
if
(types.size() != atomic_numbers.size() ||
60
reactant.size() != 3 *
static_cast<
Eigen::Index
>
(n) ||
61
product.size() != reactant.size()) {
62
throw
std::invalid_argument(
63
"reactive atom types: reactant, product and types must describe "
64
"the same atoms"
);
65
}
66
ReactiveAtomTypes
out
;
67
out
.types = types;
68
out
.atomtypes = atomtypes;
69
std::vector<std::set<int>> react_nb(
static_cast<
std::size_t
>
(n)),
70
prod_nb(
static_cast<
std::size_t
>
(n));
71
for
(
const
auto
& [a, b]:
72
covalentBondGraph
(reactant, atomic_numbers, cell)) {
73
react_nb[
static_cast<
std::size_t
>
(a)].insert(b);
74
react_nb[
static_cast<
std::size_t
>
(b)].insert(a);
75
}
76
for
(
const
auto
& [a, b]:
covalentBondGraph
(product, atomic_numbers, cell)) {
77
prod_nb[
static_cast<
std::size_t
>
(a)].insert(b);
78
prod_nb[
static_cast<
std::size_t
>
(b)].insert(a);
79
}
80
for
(
int
a = 0; a < n; ++a) {
81
if
(react_nb[
static_cast<
std::size_t
>
(a)] ==
82
prod_nb[
static_cast<
std::size_t
>
(a)])
83
continue
;
84
out
.reactive_atoms.push_back(a);
85
const
std::string name =
86
"Z"
+ std::to_string(atomic_numbers[
static_cast<
std::size_t
>
(a)]) +
87
"*"
;
88
auto
it =
out
.atomtypes.find(name);
89
if
(it ==
out
.atomtypes.end()) {
90
Index_t
next = 0;
91
for
(
const
auto
& kv:
out
.atomtypes)
92
next = std::max<Index_t>(next, kv.second + 1);
93
it =
out
.atomtypes.emplace(name, next).first;
94
}
95
out
.types[
static_cast<
std::size_t
>
(a)] = it->second;
96
}
97
return
out
;
98
}
99
100
}
// namespace gpr::geometry
CorderoRadii.h
MinImage.h
ReactiveAtomTypes.h
gpr::geometry::PairBox
Definition
MinImage.h:156
gpr::geometry::PairBox::displacement
void displacement(const double p[3], const double q[3], double dr[3]) const
Displacement from p to q. Cartesian q - p when the cell is zero.
Definition
MinImage.h:210
out
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
Definition
eon_relax_engine.h:240
gpr::geometry
Definition
CorderoRadii.h:9
gpr::geometry::covalentRadius
double covalentRadius(int atomic_number)
Definition
ReactiveAtomTypes.cpp:15
gpr::geometry::kCorderoRadiusPm
constexpr std::array< double, 97 > kCorderoRadiusPm
Definition
CorderoRadii.h:14
gpr::geometry::assignReactiveAtomTypes
ReactiveAtomTypes assignReactiveAtomTypes(const Eigen::VectorXd &reactant, const Eigen::VectorXd &product, const std::vector< int > &atomic_numbers, const std::vector< Index_t > &types, const std::unordered_map< std::string, Index_t > &atomtypes, const std::array< double, 9 > &cell)
Definition
ReactiveAtomTypes.cpp:52
gpr::geometry::covalentBondGraph
std::vector< std::pair< int, int > > covalentBondGraph(const Eigen::VectorXd &positions, const std::vector< int > &atomic_numbers, const std::array< double, 9 > &cell)
Definition
ReactiveAtomTypes.cpp:26
gpr::Index_t
uint32_t Index_t
Definition
Macros.h:17
gpr::geometry::ReactiveAtomTypes
Definition
ReactiveAtomTypes.h:29
gpr
auxiliary
ReactiveAtomTypes.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf