Loading...
Searching...
No Matches
GPRPotential.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
14#include "subprojects/gprdimer/gpr/auxiliary/AdditionalFunctionality.h"
15#include "subprojects/gprdimer/structures/Structures.h"
16
17#include <stdexcept>
18
20 : eonc::Potential(eonc::PotType::GPR, p) {}
21
23 gpr::GaussianProcessRegression *_gpr_model) {
24 gpr_model = _gpr_model;
25}
26
28
30
31// pointer to number of atoms, pointer to array of positions
32// pointer to array of forces, pointer to internal energy
33// adress to supercell size
34void GPRPotential::force(long N, const double *R, const int *atomicNrs,
35 double *F, double *U, double *variance,
36 const double *box) {
37 (void)atomicNrs;
38 (void)box;
39 if (variance != nullptr) {
40 *variance = 0.0;
41 }
42 if (gpr_model == nullptr) {
43 throw std::runtime_error("GPRPotential: no GPR model registered");
44 }
45 gpr::Observation observation;
46
47 // Copy R points. Note, R should correspond to the moving atoms only.
48 observation.R.resize(1, N * 3);
49 for (int i = 0; i < N; i++) {
50 observation.R.set(i, {R[3 * i], R[3 * i + 1], R[3 * i + 2]});
51 }
52
53 // Note, the following functions should be called before calling for
54 // gpr_model->calculatePotential() gpr_model->decomposeCovarianceMatrix(R,
55 // ind) - takes covariance matrix and vector of repetitive indices
56 // gpr_model->calculateMeanPrediction() - takes a vector of combined energy
57 // and force gpr_model->calculatePosteriorMeanPrediction() - no arguments
58 gpr_model->calculatePotential(observation);
59
60 for (int i = 0; i < N; i++) {
61 F[3 * i] = observation.G[3 * i];
62 F[3 * i + 1] = observation.G[3 * i + 1];
63 F[3 * i + 2] = observation.G[3 * i + 2];
64 }
65
66 if (observation.E.size() < 1) {
67 throw std::runtime_error("GPRPotential: empty energy from GPR model");
68 }
69 *U = observation.E[0];
70}
GPRPotential(const eonc::Parameters &p)
void registerGPRObject(gpr::GaussianProcessRegression *_gpr_model)
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
gpr::GaussianProcessRegression * gpr_model
Potential(PotType a_ptype)
Production default: construction-scope registry, else PotRegistry::get().
RAII resource manager for the ARTn C library with global synchronization.