Loading...
Searching...
No Matches
XTBPot.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 <cstddef>
15#include <vector>
16
17// Conversion factors
18// const double angstromToBohr = 1.8897261349925714;
19// const double hartreeToEV = 27.21138386;
20// const double hartreeBohr_to_eVA = 14.399645472115932;
23
24// pointer to number of atoms, pointer to array of positions
25// pointer to array of forces, pointer to internal energy
26// address to supercell size
27void XTBPot::force(long N, const double *R, const int *atomicNrs, double *F,
28 double *U, double *variance, const double *box) {
29 variance = nullptr;
30 int intN = static_cast<int>(N);
31 // TODO: Periodicity shouldn't crash
32 const bool periodicity[3]{false, false, false};
33 double box_bohr[3 * 3];
34
35 // Allocate memory for converted positions
36 std::vector<double> R_bohr(3 * N);
37
38 // Convert positions from Angstrom to Bohr
39 for (long idx = 0; idx < 3 * N; ++idx) {
40 R_bohr[idx] = R[idx] / BOHR;
41 }
42 for (long idx = 0; idx < 9; ++idx) {
43 box_bohr[idx] = box[idx] / BOHR;
44 }
45
46 if (!initialized) {
47 // First call: Create the molecule and load the Hamiltonian
48 mol = xtb_newMolecule(env, &intN, atomicNrs, R_bohr.data(), &total_charge,
49 &uhf, box_bohr, periodicity);
50
51 switch (xtb_paramset) {
53 xtb_loadGFNFF(env, mol, calc, nullptr);
54 break;
56 xtb_loadGFN0xTB(env, mol, calc, nullptr);
57 break;
59 xtb_loadGFN1xTB(env, mol, calc, nullptr);
60 break;
62 xtb_loadGFN2xTB(env, mol, calc, nullptr);
63 break;
64 }
65
69 initialized = true;
70 } else {
71 // Subsequent calls: Only update coordinates and lattice
72 xtb_updateMolecule(env, mol, R_bohr.data(), box_bohr);
73 }
74
76
77 // Check for SCF convergence or internal xTB errors
78 if (xtb_checkEnvironment(env) != 0) {
79 char err_msg[512];
80 xtb_getError(env, err_msg, nullptr);
81 throw std::runtime_error(std::string("xTB Error: ") + err_msg);
82 }
83
86
87 // Convert Hartree/Bohr to eV/Angstrom
88 for (long i = 0; i < 3 * N; ++i) {
89 F[i] *= -1.0 * (HARTREE / BOHR);
90 }
91 *U *= HARTREE;
92 counter++;
93}
const double HARTREE
const double BOHR
double xtb_acc
Definition XTBPot.h:118
xtb_TEnvironment env
Definition XTBPot.h:112
double xtb_electronic_temperature
Definition XTBPot.h:119
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
Definition XTBPot.cpp:27
xtb_TMolecule mol
Definition XTBPot.h:114
bool initialized
Definition XTBPot.h:125
double total_charge
Definition XTBPot.h:121
size_t counter
Definition XTBPot.h:124
size_t xtb_max_iter
Definition XTBPot.h:120
xtb_TResults res
Definition XTBPot.h:115
int uhf
Definition XTBPot.h:122
xtb_TCalculator calc
Definition XTBPot.h:113
GFNMethod xtb_paramset
Definition XTBPot.h:117
XTB_API_ENTRY void XTB_API_CALL xtb_getGradient(xtb_TEnvironment, xtb_TResults, double *) XTB_API_SUFFIX__VERSION_2_0_0
Query singlepoint results object for gradient in Hartree / Bohr.
XTB_API_ENTRY xtb_TMolecule XTB_API_CALL xtb_newMolecule(xtb_TEnvironment, const int *, const int *, const double *, const double *, const int *, const double *, const bool *) XTB_API_SUFFIX__VERSION_2_0_0
Create new molecular structure data (quantities in Bohr).
XTB_API_ENTRY void XTB_API_CALL xtb_getEnergy(xtb_TEnvironment, xtb_TResults, double *) XTB_API_SUFFIX__VERSION_2_0_0
Query singlepoint results object for energy in Hartree.
XTB_API_ENTRY void XTB_API_CALL xtb_loadGFN0xTB(xtb_TEnvironment, xtb_TMolecule, xtb_TCalculator, char *) XTB_API_SUFFIX__VERSION_2_0_0
Load GFN0-xTB calculator.
XTB_API_ENTRY int XTB_API_CALL xtb_checkEnvironment(xtb_TEnvironment) XTB_API_SUFFIX__VERSION_2_0_0
Check current status of calculation environment.
XTB_API_ENTRY void XTB_API_CALL xtb_updateMolecule(xtb_TEnvironment, xtb_TMolecule, const double *, const double *) XTB_API_SUFFIX__VERSION_2_0_0
Update coordinates and lattice parameters (quantities in Bohr).
XTB_API_ENTRY void XTB_API_CALL xtb_setElectronicTemp(xtb_TEnvironment, xtb_TCalculator, double) XTB_API_SUFFIX__VERSION_2_0_0
Set electronic temperature for level filling in tight binding calculators in K.
XTB_API_ENTRY void XTB_API_CALL xtb_loadGFNFF(xtb_TEnvironment, xtb_TMolecule, xtb_TCalculator, char *) XTB_API_SUFFIX__VERSION_2_0_0
Load GFN-FF calculator.
XTB_API_ENTRY void XTB_API_CALL xtb_loadGFN1xTB(xtb_TEnvironment, xtb_TMolecule, xtb_TCalculator, char *) XTB_API_SUFFIX__VERSION_2_0_0
Load GFN1-xTB calculator.
XTB_API_ENTRY void XTB_API_CALL xtb_setAccuracy(xtb_TEnvironment, xtb_TCalculator, double) XTB_API_SUFFIX__VERSION_2_0_0
Set numerical accuracy of calculator in the range of 1000 to 0.0001.
XTB_API_ENTRY void XTB_API_CALL xtb_setMaxIter(xtb_TEnvironment, xtb_TCalculator, int) XTB_API_SUFFIX__VERSION_2_0_0
Set maximum number of iterations for self-consistent TB calculators.
XTB_API_ENTRY void XTB_API_CALL xtb_loadGFN2xTB(xtb_TEnvironment, xtb_TMolecule, xtb_TCalculator, char *) XTB_API_SUFFIX__VERSION_2_0_0
Load GFN2-xTB calculator.
XTB_API_ENTRY void XTB_API_CALL xtb_singlepoint(xtb_TEnvironment, xtb_TMolecule, xtb_TCalculator, xtb_TResults) XTB_API_SUFFIX__VERSION_2_0_0
Perform singlepoint calculation.
XTB_API_ENTRY void XTB_API_CALL xtb_getError(xtb_TEnvironment, char *, const int *) XTB_API_SUFFIX__VERSION_2_0_0
Return and empty error stack.