40#include "rgpot/EMT/EMTPot.hpp"
41#include "rgpot/LennardJones/LJClusterPot.hpp"
42#include "rgpot/LennardJones/LJPot.hpp"
43#include "rgpot/Morse/MorsePot.hpp"
44#include "rgpot/ZBL/ZBLPot.hpp"
46#include "rgpot/D3Pot/D3Pot.hpp"
49#include "rgpot/D4Pot/D4Pot.hpp"
52#include "rgpot/ExprPot/ExprPot.hpp"
54#include "rgpot/MOPACPot/MOPACPot.hpp"
55#include "rgpot/fortran/FortranPots.hpp"
101#include "rgpot/Water/WaterPots.hpp"
107#include "rgpot/XTBPot/XTBPot.hpp"
115 const VectorXi &atmnrs,
117 double energy{std::numeric_limits<double>::infinity()};
118 long nAtoms =
static_cast<long>(pos.rows());
121 const auto n =
static_cast<size_t>(nAtoms);
122 this->
force(std::span<const double>(pos.data(), n * 3),
123 std::span<const int>(atmnrs.data(), n),
124 std::span<double>(forces.data(), n * 3), &energy, &var,
125 std::span<const double>(box.data(), 9));
127 if (!std::isfinite(energy) || !forces.allFinite()) {
128 throw std::runtime_error(
"Potential::get_ef: non-finite energy or forces");
131 return std::make_tuple(energy, forces);
137std::string lower_copy(std::string s) {
139 c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
147template <
class Config> Config pair_config(
const Parameters ¶ms) {
150 if (!(cutoff >= 0.0) || !std::isfinite(cutoff)) {
151 throw std::runtime_error(
152 "[Potential] pair_cutoff must be a finite length, or 0 for the "
153 "potential's own cutoff");
159 if constexpr (
requires { cfg.switch_width; }) {
160 cfg.switch_width = width;
161 }
else if (width != 0.0) {
162 throw std::runtime_error(
163 "[Potential] pair_switch_width needs an rgpot whose pair configs "
164 "carry switch_width");
170#ifdef RGPOT_HAS_DFTD3
171rgpot::D3Damping d3_damping_from_params(
const Parameters ¶ms) {
172 rgpot::D3Damping damp = rgpot::D3Damping::BJ;
174 damp = rgpot::D3Damping::Zero;
180std::unique_ptr<rgpot::PotentialBase> make_expr_term(
const std::string &raw,
181 const Parameters ¶ms) {
182 const std::string name = lower_copy(raw);
184 return std::make_unique<rgpot::LJPot>(pair_config<rgpot::LJConfig>(params));
186 if (name ==
"ljcluster") {
187 return std::make_unique<rgpot::LJClusterPot>(
188 pair_config<rgpot::LJClusterConfig>(params));
190 if (name ==
"morse" || name ==
"morse_pt") {
191 return std::make_unique<rgpot::MorsePot>(
192 pair_config<rgpot::MorseConfig>(params));
195 return std::make_unique<rgpot::ZBLPot>(rgpot::ZBLConfig{
200#ifdef RGPOT_HAS_DFTD3
201 if (name ==
"d3" || name ==
"dftd3") {
202 return std::make_unique<rgpot::D3Pot>(rgpot::D3Config{
203 .damping = d3_damping_from_params(params),
209#ifdef RGPOT_HAS_DFTD4
210 if (name ==
"d4" || name ==
"dftd4") {
211 return std::make_unique<rgpot::D4Pot>(rgpot::D4Config{
218 if (name ==
"mopac") {
219 return std::make_unique<rgpot::MOPACPot>(rgpot::MOPACPot::Config{
226 throw std::runtime_error(
227 "ExprPot unknown term '" + raw +
228 "' (lj, ljcluster, morse, zbl, d3/dftd3, d4/dftd4, mopac)");
231std::vector<rgpot::ExprPot::Term> parse_expr_terms(
const Parameters ¶ms) {
232 std::vector<rgpot::ExprPot::Term> terms;
236 while (!token.empty() &&
237 std::isspace(
static_cast<unsigned char>(token.front()))) {
238 token.erase(token.begin());
240 while (!token.empty() &&
241 std::isspace(
static_cast<unsigned char>(token.back()))) {
244 if (!token.empty()) {
245 terms.emplace_back(token, make_expr_term(token, params));
258 throw std::runtime_error(
259 "ExprPot needs [ExprPot] terms (comma-separated names used in "
274 if (
auto cloned =
pot.clonePotential()) {
279std::unique_ptr<Potential>
300 return (std::make_unique<ExtPot>(params));
305 pair_config<rgpot::LJConfig>(params));
311 pair_config<rgpot::LJClusterConfig>(params));
316 pair_config<rgpot::MorseConfig>(params));
328 rgpot::WaterConfig{});
333 rgpot::WaterConfig{});
338 rgpot::WaterConfig{});
380 return (std::make_unique<VASP>(params));
386 return std::make_unique<LAMMPSPot>(params);
390 return (std::make_unique<MPIPot>(params));
397 return (std::make_unique<ASE>(params));
404 return (std::make_unique<AMS>(params));
408 return (std::make_unique<AMS_IO>(params));
414 return (std::make_unique<CatLearnPot>(params));
422 rgpot::GFNMethod method = rgpot::GFNMethod::GFN2xTB;
423 if (o.paramset ==
"GFNFF") {
424 method = rgpot::GFNMethod::GFNFF;
425 }
else if (o.paramset ==
"GFN0xTB") {
426 method = rgpot::GFNMethod::GFN0xTB;
427 }
else if (o.paramset ==
"GFN1xTB") {
428 method = rgpot::GFNMethod::GFN1xTB;
429 }
else if (o.paramset ==
"GFN2xTB") {
430 method = rgpot::GFNMethod::GFN2xTB;
432 throw std::runtime_error(
433 "Parameter set for XTB must be one of GFNFF, GFN0xTB, GFN1xTB or "
441 .electronic_temperature = o.elec_temperature,
442 .max_iterations =
static_cast<int>(o.maxiter),
451 return (std::make_unique<ASEOrcaPot>(params));
455#ifdef WITH_ASE_NWCHEM
457 return (std::make_unique<ASENwchemPot>(params));
463 return (std::make_unique<MetatomicPotential>(params));
467#ifdef RGPOT_HAS_DFTD3
469 rgpot::D3Damping damp = rgpot::D3Damping::BJ;
471 for (
char &c : dname) {
472 c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
474 if (dname ==
"zero") {
475 damp = rgpot::D3Damping::Zero;
479 rgpot::D3Config{.damping = damp,
485#ifdef RGPOT_HAS_DFTD4
506 return (std::make_unique<SocketNWChemPot>(params));
512 return (std::make_unique<RgpotPot>(params));
519 rgpot::MOPACPot::Config{
530 throw std::runtime_error(
531 "ExprPot needs [ExprPot] expression, e.g. 0.5*lj + d3");
534 parse_expr_terms(params));
535 return std::make_unique<RgpotAdapter<rgpot::ExprPot>>(
PotType::EXPR, params,
542 magic_enum::enum_name(ptype));
544 throw std::runtime_error(
"Terminating");
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
#define EONC_LOG_ERROR(...)
std::unique_ptr< eonc::Potential > makeRgpotDefault(eonc::PotType ptype, const eonc::Parameters ¶ms)
Factory arm helper for kernels whose parameters are fixed tabulated data with no eOn-side configurati...
std::unique_ptr< eonc::Potential > makeRgpot(eonc::PotType ptype, const eonc::Parameters ¶ms, const Cfg &cfg)
Factory arm helper: construct the kernel from its config and wrap it.
const expr_options_t & expr_options() const
const potential_options_t & potential_options() const
const zbl_options_t & zbl_options() const
const mopac_options_t & mopac_options() const
const dftd_options_t & dftd_options() const
const expr_options_t & expr_options() const
const xtb_options_t & xtb_options() const
const potential_options_t & potential_options() const
const zbl_options_t & zbl_options() const
const mopac_options_t & mopac_options() const
const dftd_options_t & dftd_options() const
void add_config_paths(const std::string &colon_paths) override
Inject search paths from the eOn config file.
static PluginLoader & instance()
Thread-safe singleton accessor (Meyer's pattern).
RAII: Potential default construction records on this registry instead of PotRegistry::get().
virtual void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box)=0
std::tuple< double, AtomMatrix > get_ef(const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
void recordForceCall() noexcept
Charge one evaluated geometry to this potential and its owning registry.
Move-only composition root for process resources (dlopen loaders and the potential registry).
PotRegistry & pots() noexcept
PluginLoader & plugins() noexcept
std::shared_ptr< Potential > makeImagePotential(const Potential &pot, const Parameters ¶ms)
A separate instance of pot for one image of a band, dimer or pair of minimizations: a clone when the ...
std::unique_ptr< Potential > makePotential(const Parameters ¶ms)
Exclusive ownership.
std::shared_ptr< Potential > sharePotential(std::unique_ptr< Potential > pot)
Multi-owner boundary: one instance observed by several Matters, images, or a binding.
quill::Logger * get() noexcept
Get or create the default "combi" logger.
std::string potentialsPath
double pairSwitchWidth
Width (Angstrom) of the C^2 quintic switch that takes the lj, ljcluster and morse_pt pair terms to ze...
double pairCutoff
Cutoff (Angstrom) of the lj, ljcluster and morse_pt pair terms.