Loading...
Searching...
No Matches
XTBPot.h
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#pragma once
13
14#include "eon/Potential.h"
15#include "units.hpp"
16#include "xtb.h"
17
18#include <iostream>
19
20class XTBPot final : public Potential {
21public:
22 // Functions
24 : Potential(PotType::XTB, p),
25 xtb_acc{p.xtb_options.acc},
26 xtb_electronic_temperature{p.xtb_options.elec_temperature},
27 xtb_max_iter{p.xtb_options.maxiter},
28 total_charge{p.xtb_options.charge},
29 uhf{p.xtb_options.uhf} {
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 }
70
71 virtual ~XTBPot() {
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 }
88
89 // Disable copy to prevent double-free of Fortran pointers
90 XTBPot(const XTBPot &) = delete;
91 XTBPot &operator=(const XTBPot &) = delete;
92
93 // To satisfy interface
94 void cleanMemory(void);
95
96 void force(long N, const double *R, const int *atomicNrs, double *F,
97 double *U, double *variance, const double *box) override;
98
101 [[nodiscard]] bool isThreadSafe() const noexcept override { return false; }
102
106 [[nodiscard]] bool needsPerImageInstance() const noexcept override {
107 return false;
108 }
109
110private:
115 xtb_TResults res = nullptr;
116
118 double xtb_acc;
121 double total_charge = 0.0;
122 int uhf = 0;
123
124 size_t counter;
126};
double xtb_acc
Definition XTBPot.h:118
XTBPot(const Parameters &p)
Definition XTBPot.h:23
xtb_TEnvironment env
Definition XTBPot.h:112
double xtb_electronic_temperature
Definition XTBPot.h:119
bool isThreadSafe() const noexcept override
XTB Fortran library uses per-instance state (env/calc).
Definition XTBPot.h:101
virtual ~XTBPot()
Definition XTBPot.h:71
GFNMethod
Definition XTBPot.h:111
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
Definition XTBPot.cpp:27
bool needsPerImageInstance() const noexcept override
XTB restart.f90 uses global Fortran file units that collide when multiple environments exist in one p...
Definition XTBPot.h:106
xtb_TMolecule mol
Definition XTBPot.h:114
bool initialized
Definition XTBPot.h:125
double total_charge
Definition XTBPot.h:121
XTBPot(const XTBPot &)=delete
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
XTBPot & operator=(const XTBPot &)=delete
void cleanMemory(void)
struct eonc::Parameters::xtb_options_t xtb_options
Potential(PotType a_ptype)
Definition Potential.h:35
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:44
Physical constants, unit conversion.
XTB_API_ENTRY xtb_TCalculator XTB_API_CALL xtb_newCalculator(void) XTB_API_SUFFIX__VERSION_2_0_0
Create new calculator object.
struct _xtb_TCalculator * xtb_TCalculator
Single point calculator class.
Definition xtb.h:61
struct _xtb_TEnvironment * xtb_TEnvironment
Calculation environment class.
Definition xtb.h:55
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_delResults(xtb_TResults *) XTB_API_SUFFIX__VERSION_2_0_0
Delete singlepoint results object.
struct _xtb_TMolecule * xtb_TMolecule
Molecular structure data class.
Definition xtb.h:58
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.
struct _xtb_TResults * xtb_TResults
Single point results class.
Definition xtb.h:64
XTB_API_ENTRY void XTB_API_CALL xtb_delCalculator(xtb_TCalculator *) XTB_API_SUFFIX__VERSION_2_0_0
Delete calculator object.