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
17namespace {
18
19const char *elementArray[] = {
20 "Unknown", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na",
21 "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V",
22 "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br",
23 "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag",
24 "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr",
25 "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu",
26 "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi",
27 "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", NULL};
28
29// guess the atom type from the atomic mass,
30std::string mass2atom(double atomicmass) {
31 return elementArray[int(atomicmass + .5)];
32}
33
34int symbol2atomicNumber(char const *symbol) {
35 int i = 0;
36
37 while (elementArray[i] != NULL) {
38 if (strcmp(symbol, elementArray[i]) == 0) {
39 return i;
40 }
41 i++;
42 }
43 // invalid symbol
44 return -1;
45}
46
47char const *atomicNumber2symbol(int n) { return elementArray[n]; }
48} // namespace
49
51 : Potential(PotType::GPR, p) {
52 gpr_model = nullptr;
53}
54
56 gpr::GaussianProcessRegression *_gpr_model) {
57 gpr_model = _gpr_model;
58}
59
61
63
64// pointer to number of atoms, pointer to array of positions
65// pointer to array of forces, pointer to internal energy
66// adress to supercell size
67void GPRPotential::force(long N, const double *R, const int *atomicNrs,
68 double *F, double *U, double *variance,
69 const double *box) {
70 variance = nullptr;
71 gpr::Observation observation;
72
73 // Copy R points. Note, R should correspond to the moving atoms only.
74 observation.R.resize(1, N * 3);
75 for (int i = 0; i < N; i++) {
76 observation.R.set(i, {R[3 * i], R[3 * i + 1], R[3 * i + 2]});
77 }
78
79 // Note, the following functions should be called before calling for
80 // gpr_model->calculatePotential() gpr_model->decomposeCovarianceMatrix(R,
81 // ind) - takes covariance matrix and vector of repetitive indices
82 // gpr_model->calculateMeanPrediction() - takes a vector of combined energy
83 // and force gpr_model->calculatePosteriorMeanPrediction() - no arguments
84 gpr_model->calculatePotential(observation);
85
86 for (int i = 0; i < N; i++) {
87 F[3 * i] = observation.G[3 * i];
88 F[3 * i + 1] = observation.G[3 * i + 1];
89 F[3 * i + 2] = observation.G[3 * i + 2];
90 }
91
92 // FIXME: Test conversion, E should only have one element here
93 *U = observation.E[0];
94}
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box)
void registerGPRObject(gpr::GaussianProcessRegression *_gpr_model)
GPRPotential(const Parameters &p)
void cleanMemory(void)
gpr::GaussianProcessRegression * gpr_model
void initialize(void)
Potential(PotType a_ptype)
Definition Potential.h:35