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

#include <XTBPot.h>

Inheritance diagram for XTBPot:

Public Member Functions

 XTBPot (const eonc::Parameters &p)
virtual ~XTBPot ()
 XTBPot (const XTBPot &)=delete
XTBPot & operator= (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.
bool computesStress () const noexcept override
 True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.
Matrix3d cauchyStress () const override
 Cauchy stress in eV/Angstrom^3.
Public Member Functions inherited from eonc::Potential
 Potential (PotType a_ptype)
 Production default: construction-scope registry, else PotRegistry::get().
 Potential (PotType a_ptype, IPotRegistry &registry)
 Test seam: injected registry, no process-default get() counters.
 Potential (PotType a_ptype, const Parameters &p)
 Potential (const Parameters &a_params)
virtual ~Potential ()
void force (std::span< const double > positions, std::span< const int > atomicNrs, std::span< double > forces, double *energy, double *variance, std::span< const double > box)
 C++ call site: size-checked view over the raw FFI force().
virtual void setFixedMask (long nAtoms, const double *isFixed)
 Optional frozen-atom mask (nAtoms*3, 1.0 = fixed).
std::tuple< double, AtomMatrix > get_ef (const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
PotType getType () const
virtual double finiteCutoff () const noexcept
 Finite interaction range in position length units.
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 unsigned layoutFlags () const noexcept
virtual bool isSharedInstanceThreadSafe () const noexcept
 Conservative gate for sharing one Potential instance across threads.
virtual std::shared_ptr< Potential > clonePotential () const
 Independent instance that does not reload from disk.
virtual bool supportsBatchEvaluation () const noexcept
 Whether this potential supports batched evaluation of N systems in a single call.
virtual void forceBatchOwned (long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes, const long *owners)
 Evaluate forces for 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)

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
Matrix3d stress_ {Matrix3d::Zero()}
bool haveStress_ {false}

Additional Inherited Members

Public Types inherited from eonc::Potential
enum class  PotLayout : unsigned { InProcess = 1u << 0 , NeedsWorkingDirectory = 1u << 1 , Subprocess = 1u << 2 }
 How the pot is executed. Combine with bitwise or. More...
Public Attributes inherited from eonc::Potential
std::atomic< size_t > forceCallCounter
Protected Attributes inherited from eonc::Potential
PotType ptype

Detailed Description

Definition at line 21 of file XTBPot.h.

Member Enumeration Documentation

◆ GFNMethod

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

Definition at line 116 of file XTBPot.h.

116{ GFNFF, GFN0xTB, GFN1xTB, GFN2xTB };

Constructor & Destructor Documentation

◆ XTBPot() [1/2]

XTBPot::XTBPot ( const eonc::Parameters & p)
inline

Definition at line 24 of file XTBPot.h.

25 : eonc::Potential(eonc::PotType::XTB, p), xtb_acc{p.xtb_options().acc},
29 // Deprecated for packaging: prefer potential=RGPOT
30 // backend=xtb (dlopen libxtb_engine.so). Native -Dwith_xtb stays available.
31 std::cerr
32 << "WARNING: native XTBPot (-Dwith_xtb) is deprecated for packaging; "
33 "prefer potential=RGPOT with [RgpotPot] backend=xtb "
34 "(dlopen libxtb_engine.so; set RGPOT_XTB_ENGINE).\n";
35 counter = 0;
36 initialized = false;
39 // Release the default output unit to prevent Fortran NEWUNIT conflicts
40 // when multiple XTB environments coexist (e.g. per-image NEB potentials)
42 if (!env) {
43 throw std::runtime_error("Failed to create xtb environment");
44 }
46 if (!calc) {
48 throw std::runtime_error("Failed to create xtb calculator");
49 }
51 if (!calc) {
53 throw std::runtime_error("Failed to create xtb results");
54 }
55 // Unmarshal parameters
56 if (p.xtb_options().paramset == "GFNFF") {
58 } else if (p.xtb_options().paramset == "GFN0xTB") {
60 } else if (p.xtb_options().paramset == "GFN1xTB") {
62 } else if (p.xtb_options().paramset == "GFN2xTB") {
64 } else {
65 throw std::runtime_error("Parameter set for XTB must be one of GFNFF, "
66 "GFN0xTB, GFN1xTB or GFN2xTB.\n");
67 }
68 }
double xtb_acc
Definition XTBPot.h:123
xtb_TEnvironment env
Definition XTBPot.h:117
double xtb_electronic_temperature
Definition XTBPot.h:124
bool initialized
Definition XTBPot.h:130
double total_charge
Definition XTBPot.h:126
size_t counter
Definition XTBPot.h:129
size_t xtb_max_iter
Definition XTBPot.h:125
xtb_TResults res
Definition XTBPot.h:120
int uhf
Definition XTBPot.h:127
xtb_TCalculator calc
Definition XTBPot.h:118
GFNMethod xtb_paramset
Definition XTBPot.h:122
const xtb_options_t & xtb_options() const
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 70 of file XTBPot.h.

70 {
71 if (res) {
73 }
74 if (calc) {
76 }
77 if (mol) {
79 }
80 if (env) {
83 }
84 QUILL_LOG_INFO(eonc::log::get(), "[XTB] called potential {} times",
85 counter++);
86 }
xtb_TMolecule mol
Definition XTBPot.h:119
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

◆ cauchyStress()

Matrix3d XTBPot::cauchyStress ( ) const
inlinenodiscardoverridevirtual

Cauchy stress in eV/Angstrom^3.

sigma = (1/V) dE/dε for the right strain h <- h (I+ε) at fixed fractional coordinates.

Reimplemented from eonc::Potential.

Definition at line 113 of file XTBPot.h.

113{ return stress_; }
Matrix3d stress_
Definition XTBPot.h:131

◆ cleanMemory()

void XTBPot::cleanMemory ( void )

◆ computesStress()

bool XTBPot::computesStress ( ) const
inlinenodiscardoverridevirtualnoexcept

True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.

Reimplemented from eonc::Potential.

Definition at line 109 of file XTBPot.h.

109 {
110 return haveStress_;
111 }
bool haveStress_
Definition XTBPot.h:132

◆ 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 28 of file XTBPot.cpp.

29 {
30 variance = nullptr;
31 int intN = static_cast<int>(N);
32 const bool periodicity[3]{std::abs(box[0]) > 1e-8, std::abs(box[4]) > 1e-8,
33 std::abs(box[8]) > 1e-8};
34 double box_bohr[3 * 3];
35
36 // Allocate memory for converted positions
37 std::vector<double> R_bohr(3 * N);
38
39 // Convert positions from Angstrom to Bohr
40 for (long idx = 0; idx < 3 * N; ++idx) {
41 R_bohr[idx] = R[idx] / BOHR;
42 }
43 for (long idx = 0; idx < 9; ++idx) {
44 box_bohr[idx] = box[idx] / BOHR;
45 }
46
47 if (!initialized) {
48 // First call: Create the molecule and load the Hamiltonian
49 mol = xtb_newMolecule(env, &intN, atomicNrs, R_bohr.data(), &total_charge,
50 &uhf, box_bohr, periodicity);
51
52 switch (xtb_paramset) {
54 xtb_loadGFNFF(env, mol, calc, nullptr);
55 break;
57 xtb_loadGFN0xTB(env, mol, calc, nullptr);
58 break;
60 xtb_loadGFN1xTB(env, mol, calc, nullptr);
61 break;
63 xtb_loadGFN2xTB(env, mol, calc, nullptr);
64 break;
65 }
66
70 initialized = true;
71 } else {
72 // Subsequent calls: Only update coordinates and lattice
73 xtb_updateMolecule(env, mol, R_bohr.data(), box_bohr);
74 }
75
77
78 // Check for SCF convergence or internal xTB errors
79 if (xtb_checkEnvironment(env) != 0) {
80 char err_msg[512];
81 xtb_getError(env, err_msg, nullptr);
82 throw std::runtime_error(std::string("xTB Error: ") + err_msg);
83 }
84
87
88 // Convert Hartree/Bohr to eV/Angstrom
89 for (long i = 0; i < 3 * N; ++i) {
90 F[i] *= -1.0 * (HARTREE / BOHR);
91 }
92 *U *= HARTREE;
93
94 // xtb's virial is dE/dε in Hartree, column-major. sigma = virial / V.
95 double virial[9] = {};
96 xtb_getVirial(env, res, virial);
97 const double volume = std::abs(Matrix3d::Map(box).determinant());
98 stress_.setZero();
99 haveStress_ = volume > 0.0;
100 if (haveStress_) {
101 const double scale = HARTREE / volume;
102 for (int col = 0; col < 3; ++col) {
103 for (int row = 0; row < 3; ++row) {
104 const double vij =
105 0.5 * (virial[row + 3 * col] + virial[col + 3 * row]);
106 stress_(row, col) = vij * scale;
107 }
108 }
109 }
110 counter++;
111}
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_getVirial(xtb_TEnvironment, xtb_TResults, double *) XTB_API_SUFFIX__VERSION_2_0_0
Query singlepoint results object for virial in Hartree.
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 100 of file XTBPot.h.

100{ 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 105 of file XTBPot.h.

105 {
106 return false;
107 }

◆ operator=()

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

Member Data Documentation

◆ calc

xtb_TCalculator XTBPot::calc = nullptr
private

Definition at line 118 of file XTBPot.h.

◆ counter

size_t XTBPot::counter
private

Definition at line 129 of file XTBPot.h.

◆ env

xtb_TEnvironment XTBPot::env = nullptr
private

Definition at line 117 of file XTBPot.h.

◆ haveStress_

bool XTBPot::haveStress_ {false}
private

Definition at line 132 of file XTBPot.h.

132{false};

◆ initialized

bool XTBPot::initialized
private

Definition at line 130 of file XTBPot.h.

◆ mol

xtb_TMolecule XTBPot::mol = nullptr
private

Definition at line 119 of file XTBPot.h.

◆ res

xtb_TResults XTBPot::res = nullptr
private

Definition at line 120 of file XTBPot.h.

◆ stress_

Matrix3d XTBPot::stress_ {Matrix3d::Zero()}
private

Definition at line 131 of file XTBPot.h.

131{Matrix3d::Zero()};

◆ total_charge

double XTBPot::total_charge = 0.0
private

Definition at line 126 of file XTBPot.h.

◆ uhf

int XTBPot::uhf = 0
private

Definition at line 127 of file XTBPot.h.

◆ xtb_acc

double XTBPot::xtb_acc
private

Definition at line 123 of file XTBPot.h.

◆ xtb_electronic_temperature

double XTBPot::xtb_electronic_temperature
private

Definition at line 124 of file XTBPot.h.

◆ xtb_max_iter

size_t XTBPot::xtb_max_iter
private

Definition at line 125 of file XTBPot.h.

◆ xtb_paramset

GFNMethod XTBPot::xtb_paramset
private

Definition at line 122 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