Loading...
Searching...
No Matches
Potential.cpp
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#include "eon/EonLogger.h"
13#include <csignal>
14#include <ctime>
15#include <limits>
16#include <utility>
17
18#include "eon/HelperFunctions.h"
19#include "eon/Parameters.h"
20#include "eon/Potential.h"
21#ifdef WITH_CATLEARN
23#endif
24
25#ifdef WITH_GPRD
27#endif
28
34#include "rgpot/LennardJones/LJClusterPot.hpp"
35#include "rgpot/LennardJones/LJPot.hpp"
36#include "rgpot/Morse/MorsePot.hpp"
37#include "rgpot/ZBL/ZBLPot.hpp"
38#include "rgpot/fortran/FortranPots.hpp"
39#ifndef IS_WINDOWS
41#ifdef WITH_RGPOT
43#endif
44#endif
45
46// Fortran potentials: always compiled, loaded at runtime via dlopen
47
48#ifdef EMBED_PYTHON
49#ifdef WITH_ASE_POT
51#endif
52#endif
53
54#ifdef EONMPI
56#endif
57
59
60// TODO: This should be guarded by WITH_FORTRAN as well
61#ifdef CUH2_POT
62#endif
63
64#ifndef _WIN32
65#ifdef WITH_VASP
67#endif
68#endif
69
70#ifdef WITH_AMS
73#endif
74
75#ifdef WITH_ASE_ORCA
77#endif
78
79#ifdef WITH_ASE_NWCHEM
81#endif
82
83#ifdef WITH_METATOMIC
85#endif
86
87#ifdef WITH_WATER
89#ifdef WITH_FORTRAN
90#endif
92#endif
93
94// Should respect Fortran availability
95
96#ifdef WITH_XTB
98#endif
99
100#include <limits>
101
102std::tuple<double, AtomMatrix> Potential::get_ef(const AtomMatrix &pos,
103 const VectorXi &atmnrs,
104 const Matrix3d &box) {
105 double energy{std::numeric_limits<double>::infinity()};
106 long nAtoms = static_cast<long>(pos.rows());
107 AtomMatrix forces{MatrixXd::Zero(nAtoms, 3)};
108 double var{0}; // no variance for true potentials
109 this->force(nAtoms, pos.data(), atmnrs.data(), forces.data(), &energy, &var,
110 box.data());
113
114 return std::make_tuple(energy, forces);
115}
116
117namespace eonc::helpers {
118std::shared_ptr<Potential> makePotential(const Parameters &params) {
119 // Inject config-file path before any potential constructor runs
120 PluginLoader::instance().add_config_paths(
122 return makePotential(params.potential_options.potential, params);
123}
124std::shared_ptr<Potential> makePotential(PotType ptype,
125 const Parameters &params) {
126 // Inject config-file path before any potential constructor runs.
127 // Called on every code path including Job::Job which uses this overload.
128 PluginLoader::instance().add_config_paths(
130 switch (ptype) {
131 // TODO: Every potential must know their own type
132 case PotType::EMT: {
133 return (std::make_shared<EffectiveMediumTheory>(params));
134 break;
135 }
136 case PotType::EXT_POT: {
137 return (std::make_shared<ExtPot>(params));
138 break;
139 }
140 case PotType::LJ: {
141 return makeRgpot<rgpot::LJPot>(PotType::LJ, params, rgpot::LJConfig{});
142 break;
143 }
144 case PotType::LJCLUSTER: {
146 rgpot::LJClusterConfig{});
147 break;
148 }
149 case PotType::MORSE_PT: {
151 rgpot::MorseConfig{});
152 break;
153 }
154#ifdef CUH2_POT
155 case PotType::CUH2: {
157 break;
158 }
159#endif
160#ifdef WITH_WATER
161 case PotType::TIP4P: {
162 return (std::make_shared<Tip4p>(params));
163 break;
164 }
165 case PotType::SPCE: {
166 return (std::make_shared<SpceCcl>(params));
167 break;
168 }
169#ifdef WITH_FORTRAN
170 case PotType::TIP4P_PT: {
171 return (std::make_shared<Tip4p_Pt>(params));
172 break;
173 }
174 case PotType::TIP4P_H: {
176 params);
177 break;
178 }
179#endif
180#endif
181 // Fortran potentials: always available, loaded at runtime via dlopen
182 case PotType::EAM_AL: {
184 params);
185 break;
186 }
187 case PotType::EDIP: {
189 break;
190 }
191 case PotType::FEHE: {
193 break;
194 }
195 case PotType::LENOSKY_SI: {
197 params);
198 break;
199 }
200 case PotType::SW_SI: {
202 break;
203 }
204 case PotType::TERSOFF_SI: {
206 params);
207 break;
208 }
209#ifndef _WIN32
210#ifdef WITH_VASP
211 case PotType::VASP: {
212 return (std::make_shared<VASP>(params));
213 break;
214 }
215#endif
216#endif
217 case PotType::LAMMPS: {
218 return std::make_shared<LAMMPSPot>(params);
219 }
220#ifdef EONMPI
221 case PotType::MPI: {
222 return (std::make_shared<MPIPot>(params));
223 break;
224 }
225#endif
226#ifdef EMBED_PYTHON
227#ifdef WITH_ASE_POT
228 case PotType::ASE_POT: {
229 return (std::make_shared<ASE>(params));
230 break;
231 }
232#endif
233#endif
234#ifdef WITH_AMS
235 case PotType::AMS: {
236 return (std::make_shared<AMS>(params));
237 break;
238 }
239 case PotType::AMS_IO: {
240 return (std::make_shared<AMS_IO>(params));
241 break;
242 }
243#endif
244#ifdef WITH_CATLEARN
245 case PotType::CatLearn: {
246 return (std::make_shared<CatLearnPot>(params));
247 break;
248 }
249#endif
250// TODO: Handle Fortran interaction
251#ifdef WITH_XTB
252 case PotType::XTB: {
253 return (std::make_shared<XTBPot>(params));
254 break;
255 }
256#endif
257#ifdef WITH_ASE_ORCA
258 case PotType::ASE_ORCA: {
259 return (std::make_shared<ASEOrcaPot>(params));
260 break;
261 }
262#endif
263#ifdef WITH_ASE_NWCHEM
264 case PotType::ASE_NWCHEM: {
265 return (std::make_shared<ASENwchemPot>(params));
266 break;
267 }
268#endif
269#ifdef WITH_METATOMIC
270 case PotType::METATOMIC: {
271 return (std::make_shared<MetatomicPotential>(params));
272 break;
273 }
274#endif
275 case PotType::ZBL: {
277 PotType::ZBL, params,
278 rgpot::ZBLConfig{
279 .cut_inner = params.zbl_options.cut_inner,
280 .cut_global = params.zbl_options.cut_global,
281 });
282 break;
283 }
284#ifndef IS_WINDOWS
286 return (std::make_shared<SocketNWChemPot>(params));
287 break;
288 }
289#endif
290#ifdef WITH_RGPOT
291 case PotType::RGPOT: {
292 return (std::make_shared<RgpotPot>(params));
293 break;
294 }
295#endif
296 default:
297 EONC_LOG_ERROR("No known potential could be constructed from {}",
298 magic_enum::enum_name(ptype));
299 eonc::log::get()->flush_log();
300 throw std::runtime_error("Terminating");
301 break;
302 }
303}
304
305} // namespace eonc::helpers
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Definition Eigen.h:35
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
#define EONC_LOG_ERROR(...)
Definition EonLogger.h:262
std::shared_ptr< Potential > makeRgpot(PotType ptype, const Parameters &params, const Cfg &cfg)
Factory arm helper: construct the kernel from its config and wrap it.
std::shared_ptr< Potential > makeRgpotDefault(PotType ptype, const Parameters &params)
Factory arm helper for kernels whose parameters are fixed tabulated data with no eOn-side configurati...
Wrapper for Eon.
Wrapper for Eon.
std::tuple< double, AtomMatrix > get_ef(const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
struct eonc::Parameters::potential_options_t potential_options
struct eonc::Parameters::zbl_options_t zbl_options
static PluginLoader & instance()
Thread-safe singleton accessor (Meyer's pattern).
static PotRegistry & get() noexcept
Process-lifetime singleton.
void on_force_call(PotType t) noexcept
std::atomic< size_t > forceCallCounter
Definition Potential.h:32
virtual void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box)=0
PotType ptype
Definition Potential.h:25
std::shared_ptr< Potential > makePotential(const Parameters &params)
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition EonLogger.h:44