Loading...
Searching...
No Matches
XTBPot Class Referencefinal

#include <XTBPot.h>

Inheritance diagram for XTBPot:

Public Member Functions

 XTBPot (const Parameters &p)
virtual ~XTBPot ()
 XTBPot (const XTBPot &)=delete
XTBPotoperator= (const XTBPot &)=delete
void cleanMemory (void)
void force (long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
bool isThreadSafe () const noexcept override
 XTB Fortran library uses per-instance state (env/calc).
bool needsPerImageInstance () const noexcept override
 XTB restart.f90 uses global Fortran file units that collide when multiple environments exist in one process.
Public Member Functions inherited from eonc::Potential
 Potential (PotType a_ptype)
 Potential (PotType a_ptype, const Parameters &)
 Potential (const Parameters &a_params)
virtual ~Potential ()
std::tuple< double, AtomMatrixget_ef (const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
PotType getType () const
virtual bool isSurrogate () const noexcept
 Whether this is a surrogate (GP) potential.
virtual bool requiresIsolatedMoleculeLayout () const noexcept
 True for molecular QM / non-PBC backends (NWChem socket, ASE ORCA/NWChem, …).
virtual bool isSharedInstanceThreadSafe () const noexcept
 Conservative gate for sharing one Potential instance across threads.
virtual bool supportsBatchEvaluation () const noexcept
 Whether this potential supports batched evaluation of N systems in a single call.
virtual void forceBatch (long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes)
 Evaluate forces for N systems in a single call.

Private Types

enum class  GFNMethod { GFNFF , GFN0xTB , GFN1xTB , GFN2xTB }

Private Attributes

xtb_TEnvironment env = nullptr
xtb_TCalculator calc = nullptr
xtb_TMolecule mol = nullptr
xtb_TResults res = nullptr
GFNMethod xtb_paramset
double xtb_acc
double xtb_electronic_temperature
size_t xtb_max_iter
double total_charge = 0.0
int uhf = 0
size_t counter
bool initialized

Additional Inherited Members

Public Attributes inherited from eonc::Potential
std::atomic< size_t > forceCallCounter
Protected Attributes inherited from eonc::Potential
PotType ptype

Detailed Description

Definition at line 20 of file XTBPot.h.

Member Enumeration Documentation

◆ GFNMethod

enum class XTBPot::GFNMethod
strongprivate
Enumerator
GFNFF 
GFN0xTB 
GFN1xTB 
GFN2xTB 

Definition at line 111 of file XTBPot.h.

111{ GFNFF, GFN0xTB, GFN1xTB, GFN2xTB };

Constructor & Destructor Documentation

◆ XTBPot() [1/2]

XTBPot::XTBPot ( const Parameters & p)
inline

Definition at line 23 of file XTBPot.h.

30 // Deprecated for packaging: prefer -Dwith_rgpot=true + potential=RGPOT
31 // backend=xtb (dlopen libxtb_engine.so). Native -Dwith_xtb stays available.
32 std::cerr
33 << "WARNING: native XTBPot (-Dwith_xtb) is deprecated for packaging; "
34 "prefer potential=RGPOT with [RgpotPot] backend=xtb "
35 "(dlopen libxtb_engine.so; set RGPOT_XTB_ENGINE).\n";
36 counter = 0;
37 initialized = false;
40 // Release the default output unit to prevent Fortran NEWUNIT conflicts
41 // when multiple XTB environments coexist (e.g. per-image NEB potentials)
43 if (!env) {
44 throw std::runtime_error("Failed to create xtb environment");
45 }
47 if (!calc) {
49 throw std::runtime_error("Failed to create xtb calculator");
50 }
52 if (!calc) {
54 throw std::runtime_error("Failed to create xtb results");
55 }
56 // Unmarshal parameters
57 if (p.xtb_options.paramset == "GFNFF") {
59 } else if (p.xtb_options.paramset == "GFN0xTB") {
61 } else if (p.xtb_options.paramset == "GFN1xTB") {
63 } else if (p.xtb_options.paramset == "GFN2xTB") {
65 } else {
66 throw std::runtime_error("Parameter set for XTB must be one of GFNFF, "
67 "GFN0xTB, GFN1xTB or GFN2xTB.\n");
68 }
69 }
double xtb_acc
Definition XTBPot.h:118
xtb_TEnvironment env
Definition XTBPot.h:112
double xtb_electronic_temperature
Definition XTBPot.h:119
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
struct eonc::Parameters::xtb_options_t xtb_options
Potential(PotType a_ptype)
Definition Potential.h:35
XTB_API_ENTRY xtb_TCalculator XTB_API_CALL xtb_newCalculator(void) XTB_API_SUFFIX__VERSION_2_0_0
Create new calculator object.
XTB_API_ENTRY void XTB_API_CALL xtb_delResults(xtb_TResults *) XTB_API_SUFFIX__VERSION_2_0_0
Delete singlepoint results object.
XTB_API_ENTRY xtb_TEnvironment XTB_API_CALL xtb_newEnvironment(void) XTB_API_SUFFIX__VERSION_2_0_0
Create new xtb calculation environment object.
#define XTB_VERBOSITY_MUTED
Definition xtb.h:34
XTB_API_ENTRY void XTB_API_CALL xtb_setVerbosity(xtb_TEnvironment, int) XTB_API_SUFFIX__VERSION_2_0_0
Set verbosity of calculation output.
XTB_API_ENTRY void XTB_API_CALL xtb_releaseOutput(xtb_TEnvironment) XTB_API_SUFFIX__VERSION_2_0_0
Release output unit from this environment.
XTB_API_ENTRY void XTB_API_CALL xtb_delEnvironment(xtb_TEnvironment *) XTB_API_SUFFIX__VERSION_2_0_0
Delete a xtb calculation environment object.
XTB_API_ENTRY xtb_TResults XTB_API_CALL xtb_newResults(void) XTB_API_SUFFIX__VERSION_2_0_0
Create new singlepoint results object.

◆ ~XTBPot()

virtual XTBPot::~XTBPot ( )
inlinevirtual

Definition at line 71 of file XTBPot.h.

71 {
72 if (res) {
74 }
75 if (calc) {
77 }
78 if (mol) {
80 }
81 if (env) {
84 }
85 QUILL_LOG_INFO(eonc::log::get(), "[XTB] called potential {} times",
86 counter++);
87 }
xtb_TMolecule mol
Definition XTBPot.h:114
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:44
XTB_API_ENTRY void XTB_API_CALL xtb_delMolecule(xtb_TMolecule *) XTB_API_SUFFIX__VERSION_2_0_0
Delete molecular structure data.
XTB_API_ENTRY void XTB_API_CALL xtb_delCalculator(xtb_TCalculator *) XTB_API_SUFFIX__VERSION_2_0_0
Delete calculator object.

◆ XTBPot() [2/2]

XTBPot::XTBPot ( const XTBPot & )
delete

Member Function Documentation

◆ cleanMemory()

void XTBPot::cleanMemory ( void )

◆ force()

void XTBPot::force ( long N,
const double * R,
const int * atomicNrs,
double * F,
double * U,
double * variance,
const double * box )
overridevirtual

Implements eonc::Potential.

Definition at line 27 of file XTBPot.cpp.

28 {
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
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.

◆ isThreadSafe()

bool XTBPot::isThreadSafe ( ) const
inlinenodiscardoverridevirtualnoexcept

XTB Fortran library uses per-instance state (env/calc).

Thread-safe with separate instances; not safe on same instance.

Reimplemented from eonc::Potential.

Definition at line 101 of file XTBPot.h.

101{ return false; }

◆ needsPerImageInstance()

bool XTBPot::needsPerImageInstance ( ) const
inlinenodiscardoverridevirtualnoexcept

XTB restart.f90 uses global Fortran file units that collide when multiple environments exist in one process.

Run sequentially with a single instance until upstream fixes unit management.

Reimplemented from eonc::Potential.

Definition at line 106 of file XTBPot.h.

106 {
107 return false;
108 }

◆ operator=()

XTBPot & XTBPot::operator= ( const XTBPot & )
delete

Member Data Documentation

◆ calc

xtb_TCalculator XTBPot::calc = nullptr
private

Definition at line 113 of file XTBPot.h.

◆ counter

size_t XTBPot::counter
private

Definition at line 124 of file XTBPot.h.

◆ env

xtb_TEnvironment XTBPot::env = nullptr
private

Definition at line 112 of file XTBPot.h.

◆ initialized

bool XTBPot::initialized
private

Definition at line 125 of file XTBPot.h.

◆ mol

xtb_TMolecule XTBPot::mol = nullptr
private

Definition at line 114 of file XTBPot.h.

◆ res

xtb_TResults XTBPot::res = nullptr
private

Definition at line 115 of file XTBPot.h.

◆ total_charge

double XTBPot::total_charge = 0.0
private

Definition at line 121 of file XTBPot.h.

◆ uhf

int XTBPot::uhf = 0
private

Definition at line 122 of file XTBPot.h.

◆ xtb_acc

double XTBPot::xtb_acc
private

Definition at line 118 of file XTBPot.h.

◆ xtb_electronic_temperature

double XTBPot::xtb_electronic_temperature
private

Definition at line 119 of file XTBPot.h.

◆ xtb_max_iter

size_t XTBPot::xtb_max_iter
private

Definition at line 120 of file XTBPot.h.

◆ xtb_paramset

GFNMethod XTBPot::xtb_paramset
private

Definition at line 117 of file XTBPot.h.


The documentation for this class was generated from the following files:
  • /home/runner/work/eOn/eOn/include/eon/potentials/XTBPot/XTBPot.h
  • /home/runner/work/eOn/eOn/client/potentials/XTBPot/XTBPot.cpp