eOn client
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
16
CatLearnPot::CatLearnPot
(
const
Parameters
&a_params)
17
:
SurrogatePotential
(
PotType
::CatLearn, a_params) {
18
py::module_ sys = py::module_::import(
"sys"
);
19
py::exec(
20
std::format(
"sys.path.insert(0, {})"
, a_params.
catlearn_options
.
path
));
21
22
py::module_ gp_module = py::module_::import(
23
"catlearn.regression.gaussianprocess.calculator.mlmodel"
);
24
25
// Import the required modules
26
// GP Model
27
this->
m_gpmod
= gp_module.attr(
"get_default_model"
)(
28
"model"
_a = a_params.
catlearn_options
.
model
);
29
};
30
31
void
CatLearnPot::train_optimize
(
MatrixXd
features,
MatrixXd
targets) {
32
m_gpmod
.attr(
"optimize"
)(features, targets, py::arg(
"retrain"
) =
true
);
33
return
;
34
}
35
36
void
CatLearnPot::force
(
long
nAtoms,
const
double
*positions,
37
const
int
*atomicNrs,
double
*forces,
double
*energy,
38
double
*
variance
,
const
double
*box) {
39
MatrixXd
features =
40
Eigen::Map<MatrixXd>(
const_cast<
double
*
>
(positions), 1, nAtoms * 3);
41
py::tuple ef_and_unc = (this->
m_gpmod
.attr(
"predict"
)(
42
features,
"get_variance"
_a =
true
,
"get_derivatives"
_a =
true
));
43
auto
ef_dat = ef_and_unc[0].cast<
MatrixXd
>();
44
auto
vari = ef_and_unc[1].cast<
MatrixXd
>();
45
auto
gradients = ef_dat.block(0, 1, 1, nAtoms * 3);
46
for
(
int
idx = 0; idx < nAtoms; idx++) {
47
forces[3 * idx] = gradients(0, 3 * idx) * -1;
48
forces[3 * idx + 1] = gradients(0, 3 * idx + 1) * -1;
49
forces[3 * idx + 2] = gradients(0, 3 * idx + 2) * -1;
50
}
51
*
variance
= vari(0, 0);
// energy variance only
52
*energy = ef_dat(0, 0);
53
return
;
54
}
CatLearnPot.h
MatrixXd
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, eOnStorageOrder > MatrixXd
Definition
Eigen.h:33
CatLearnPot::train_optimize
void train_optimize(const MatrixXd &features, const MatrixXd &targets) override
Definition
CatLearnPot.cpp:31
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:36
CatLearnPot::m_gpmod
py::object m_gpmod
Definition
CatLearnPot.h:38
CatLearnPot::CatLearnPot
CatLearnPot(const Parameters &a_params)
Definition
CatLearnPot.cpp:16
CatLearnPot::variance
MatrixXd variance
Definition
CatLearnPot.h:40
eonc::Parameters
Definition
Parameters.h:28
eonc::Parameters::catlearn_options
struct eonc::Parameters::catlearn_options_t catlearn_options
eonc::SurrogatePotential::SurrogatePotential
SurrogatePotential(PotType a_ptype, const Parameters &a_params)
Definition
SurrogatePotential.h:21
eonc::PotType
PotType
Definition
BaseStructures.h:36
eonc::Parameters::catlearn_options_t::path
std::string path
Definition
Parameters.h:348
eonc::Parameters::catlearn_options_t::model
std::string model
Definition
Parameters.h:349
client
potentials
CatLearnPot
CatLearnPot.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf