eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
CatLearnPot.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
13
#include "
eon/potentials/CatLearnPot/CatLearnPot.h
"
14
#include "Eigen/src/Core/Matrix.h"
15
#include "
eon/Parameters.h
"
16
17
CatLearnPot::CatLearnPot
(
const
eonc::Parameters
&a_params)
18
:
eonc
::
SurrogatePotential
(
eonc
::PotType::CatLearn, a_params) {
19
using namespace
pybind11::literals;
20
py::module_ sys = py::module_::import(
"sys"
);
21
sys.attr(
"path"
).attr(
"insert"
)(0, a_params.
catlearn_options
().path);
22
23
py::module_ gp_module = py::module_::import(
24
"catlearn.regression.gaussianprocess.calculator.mlmodel"
);
25
26
// Import the required modules
27
// GP Model
28
this->
m_gpmod
= gp_module.attr(
"get_default_model"
)(
29
"model"
_a = a_params.
catlearn_options
().model);
30
};
31
32
void
CatLearnPot::train_optimize
(
const
MatrixXd
&features,
33
const
MatrixXd
&targets) {
34
m_gpmod
.attr(
"optimize"
)(features, targets, py::arg(
"retrain"
) =
true
);
35
return
;
36
}
37
38
void
CatLearnPot::force
(
long
nAtoms,
const
double
*positions,
39
const
int
*atomicNrs,
double
*forces,
double
*energy,
40
double
*variance,
const
double
*box) {
41
using namespace
pybind11::literals;
42
(void)atomicNrs;
43
(void)box;
44
py::gil_scoped_acquire gil;
45
const
Eigen::Map<const MatrixXd> features(positions, 1, nAtoms * 3);
46
py::tuple ef_and_unc = (this->
m_gpmod
.attr(
"predict"
)(
47
features,
"get_variance"
_a =
true
,
"get_derivatives"
_a =
true
));
48
auto
ef_dat = ef_and_unc[0].cast<
MatrixXd
>();
49
auto
vari = ef_and_unc[1].cast<
MatrixXd
>();
50
auto
gradients = ef_dat.block(0, 1, 1, nAtoms * 3);
51
for
(
int
idx = 0; idx < nAtoms; idx++) {
52
forces[3 * idx] = gradients(0, 3 * idx) * -1;
53
forces[3 * idx + 1] = gradients(0, 3 * idx + 1) * -1;
54
forces[3 * idx + 2] = gradients(0, 3 * idx + 2) * -1;
55
}
56
if
(variance !=
nullptr
) {
57
*variance = vari(0, 0);
// energy variance only
58
}
59
*energy = ef_dat(0, 0);
60
return
;
61
}
CatLearnPot.h
MatrixXd
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, eOnStorageOrder > MatrixXd
Definition
Eigen.h:33
Parameters.h
CatLearnPot::train_optimize
void train_optimize(const MatrixXd &features, const MatrixXd &targets) override
Definition
CatLearnPot.cpp:32
CatLearnPot::force
void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box) override
Definition
CatLearnPot.cpp:38
CatLearnPot::m_gpmod
py::object m_gpmod
Definition
CatLearnPot.h:36
CatLearnPot::CatLearnPot
CatLearnPot(const eonc::Parameters &a_params)
Definition
CatLearnPot.cpp:17
eonc::Parameters
Definition
Parameters.h:35
eonc::Parameters::catlearn_options
const catlearn_options_t & catlearn_options() const
Definition
ParametersAccess.cpp:148
eonc::SurrogatePotential::SurrogatePotential
SurrogatePotential(PotType a_ptype, const Parameters &a_params)
Definition
SurrogatePotential.h:21
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
client
potentials
CatLearnPot
CatLearnPot.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf