Loading...
Searching...
No Matches
RgpotPot.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3*/
6
7#include <algorithm>
8#include <cctype>
9#include <cstdlib>
10#include <iostream>
11#include <string>
12
14 : Potential(PotType::RGPOT, p) {
16 const auto &o = p.rgpot_options;
17 opt.backend = o.backend;
18 opt.basis = o.basis;
19 opt.theory = o.theory;
20 opt.scf_type = o.scf_type;
21 opt.functional = o.functional;
22 opt.cutoff_ry = o.cutoff_ry;
23 opt.charge = o.charge;
24 opt.multiplicity = o.multiplicity;
25 opt.engine_path = o.engine_path;
26 opt.engine_library = o.engine_library;
27 opt.engine_root = o.engine_root;
28 opt.title = o.title;
29 opt.memory_mb = o.memory_mb;
30 opt.scratch_dir = o.scratch_dir;
31 opt.input_block = o.input_block;
32 opt.model_path = o.model_path;
33 opt.device = o.device;
34 opt.length_unit = o.length_unit;
35 opt.extensions_directory = o.extensions_directory;
36 opt.check_consistency = o.check_consistency;
37 opt.uncertainty_threshold = o.uncertainty_threshold;
38 opt.torch_determinism_strict = o.torch_determinism_strict;
39 opt.xtb_paramset = o.xtb_paramset;
40 opt.xtb_accuracy = o.xtb_accuracy;
41 opt.xtb_electronic_temperature = o.xtb_electronic_temperature;
42 opt.xtb_max_iterations = o.xtb_max_iterations;
43 opt.xtb_charge = o.xtb_charge;
44 opt.xtb_uhf = o.xtb_uhf;
45
46 // Env overrides (CI / benchmarks)
47 if (const char *e = std::getenv("RGPOT_BACKEND"))
48 opt.backend = e;
49 if (const char *e = std::getenv("RGPOT_NWCHEM_BASIS"))
50 opt.basis = e;
51 if (const char *e = std::getenv("RGPOT_NWCHEM_THEORY"))
52 opt.theory = e;
53 if (const char *e = std::getenv("RGPOT_NWCHEM_SCF_TYPE"))
54 opt.scf_type = e;
55 // Engine-path env overrides are backend-scoped: NWCHEMC_LIBRARY must not
56 // leak into a cpmdc configure (CPMDPot resolves CPMDC_LIBRARY itself).
57 std::string backend_lc = opt.backend;
58 std::transform(backend_lc.begin(), backend_lc.end(), backend_lc.begin(),
59 [](unsigned char c) { return std::tolower(c); });
60 if (backend_lc.rfind("nwchem", 0) == 0) {
61 if (const char *e = std::getenv("NWCHEMC_LIBRARY"))
62 opt.engine_path = e;
63 else if (const char *e = std::getenv("RGPOT_NWCHEMC_ENGINE"))
64 opt.engine_path = e;
65 } else if (backend_lc.rfind("cpmd", 0) == 0) {
66 if (const char *e = std::getenv("CPMDC_LIBRARY"))
67 opt.engine_path = e;
68 else if (const char *e = std::getenv("RGPOT_CPMDC_ENGINE"))
69 opt.engine_path = e;
70 } else if (backend_lc.rfind("meta", 0) == 0 || backend_lc == "mta") {
71 if (const char *e = std::getenv("RGPOT_METATOMIC_ENGINE"))
72 opt.engine_path = e;
73 else if (const char *e = std::getenv("METATOMIC_ENGINE"))
74 opt.engine_path = e;
75 if (const char *e = std::getenv("RGPOT_METATOMIC_MODEL"))
76 opt.model_path = e;
77 } else if (backend_lc == "xtb" || backend_lc == "xtbpot" ||
78 backend_lc == "gfn" || backend_lc == "gfnxtb") {
79 if (const char *e = std::getenv("RGPOT_XTB_ENGINE"))
80 opt.engine_path = e;
81 else if (const char *e = std::getenv("XTB_ENGINE"))
82 opt.engine_path = e;
83 if (opt.xtb_paramset.empty() || opt.xtb_paramset == "GFN2xTB") {
84 if (!p.xtb_options.paramset.empty())
86 }
87 }
88
89 // Dual-read [Metatomic] when RGPOT backend is metatomic
90 if ((backend_lc.rfind("meta", 0) == 0 || backend_lc == "mta") &&
91 opt.model_path.empty())
93 if ((backend_lc.rfind("meta", 0) == 0 || backend_lc == "mta") &&
94 opt.device == "cpu" && !p.metatomic_options.device.empty())
96
97 impl_ = std::make_unique<RGPotEngine>(opt);
98 backend_ = impl_->backend();
99 std::cout
100 << "RgpotPot: in-process rgpot backend=" << backend_
101 << " (dlopen: libnwchemc/libcpmdc/libmetatomic_engine/libxtb_engine)"
102 << std::endl;
103}
104
105RgpotPot::~RgpotPot() = default;
106
107bool RgpotPot::engineAvailable() const { return impl_ && impl_->available(); }
108
109void RgpotPot::force(long N, const double *R, const int *atomicNrs, double *F,
110 double *U, double *variance, const double *box) {
111 (void)variance;
112 impl_->force(N, R, atomicNrs, F, U, box);
113}
bool engineAvailable() const
Definition RgpotPot.cpp:107
std::string backend_
Definition RgpotPot.h:46
RgpotPot(const Parameters &p)
Definition RgpotPot.cpp:13
std::unique_ptr< RGPotEngine > impl_
Definition RgpotPot.h:45
~RgpotPot() override
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
Definition RgpotPot.cpp:109
struct eonc::Parameters::xtb_options_t xtb_options
struct eonc::Parameters::rgpot_options_t rgpot_options
struct eonc::Parameters::metatomic_options_t metatomic_options
Potential(PotType a_ptype)
Definition Potential.h:35
std::string scf_type
Definition RGPotEngine.h:10
std::string title
Definition RGPotEngine.h:18
std::string xtb_paramset
Definition RGPotEngine.h:31
std::string basis
Definition RGPotEngine.h:8
std::string scratch_dir
Definition RGPotEngine.h:20
std::string engine_path
Definition RGPotEngine.h:15
std::string backend
Definition RGPotEngine.h:7
std::string extensions_directory
Definition RGPotEngine.h:26
std::string engine_library
Definition RGPotEngine.h:16
double xtb_electronic_temperature
Definition RGPotEngine.h:33
std::string functional
Definition RGPotEngine.h:11
std::string length_unit
Definition RGPotEngine.h:25
bool torch_determinism_strict
Definition RGPotEngine.h:29
std::string device
Definition RGPotEngine.h:24
std::string model_path
Definition RGPotEngine.h:23
std::string engine_root
Definition RGPotEngine.h:17
double uncertainty_threshold
Definition RGPotEngine.h:28
std::string theory
Definition RGPotEngine.h:9
std::string input_block
Definition RGPotEngine.h:21