eOn client
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
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
22
#include "
eon/potentials/CatLearnPot/CatLearnPot.h
"
23
#endif
24
25
#ifdef WITH_GPRD
26
#include "
eon/potentials/GPRPotential/GPRPotential.h
"
27
#endif
28
29
#include "
eon/potentials/EAM/EAM.h
"
30
#include "
eon/potentials/EMT/EffectiveMediumTheory.h
"
31
#include "
eon/potentials/ExtPot/ExtPot.h
"
32
#include "
eon/potentials/PluginLoader.h
"
33
#include "
eon/potentials/RgpotAdapter/RgpotAdapter.h
"
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
40
#include "
eon/potentials/SocketNWChem/SocketNWChemPot.h
"
41
#ifdef WITH_RGPOT
42
#include "
eon/potentials/Rgpot/RgpotPot.h
"
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
50
#include "
eon/potentials/ASE/ASE.h
"
51
#endif
52
#endif
53
54
#ifdef EONMPI
55
#include "
eon/potentials/MPIPot/MPIPot.h
"
56
#endif
57
58
#include "
eon/potentials/LAMMPS/LAMMPSPot.h
"
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
66
#include "
eon/potentials/VASP/VASP.h
"
67
#endif
68
#endif
69
70
#ifdef WITH_AMS
71
#include "
eon/potentials/AMS/AMS.h
"
72
#include "
eon/potentials/AMS_IO/AMS_IO.h
"
73
#endif
74
75
#ifdef WITH_ASE_ORCA
76
#include "
eon/potentials/ASE_ORCA/ASE_ORCA.h
"
77
#endif
78
79
#ifdef WITH_ASE_NWCHEM
80
#include "
eon/potentials/ASE_NWCHEM/ASE_NWCHEM.h
"
81
#endif
82
83
#ifdef WITH_METATOMIC
84
#include "
eon/potentials/Metatomic/MetatomicPotential.h
"
85
#endif
86
87
#ifdef WITH_WATER
88
#include "
eon/potentials/Water/Water.hpp
"
89
#ifdef WITH_FORTRAN
90
#endif
91
#include "
eon/potentials/Water_Pt/Tip4p_Pt.hpp
"
92
#endif
93
94
// Should respect Fortran availability
95
96
#ifdef WITH_XTB
97
#include "
eon/potentials/XTBPot/XTBPot.h
"
98
#endif
99
100
#include <limits>
101
102
std::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());
111
forceCallCounter
++;
112
PotRegistry::get
().
on_force_call
(
ptype
);
113
114
return
std::make_tuple(energy, forces);
115
}
116
117
namespace
eonc::helpers
{
118
std::shared_ptr<Potential>
makePotential
(
const
Parameters
¶ms) {
119
// Inject config-file path before any potential constructor runs
120
PluginLoader::instance
().add_config_paths(
121
params.
potential_options
.
potentialsPath
);
122
return
makePotential
(params.
potential_options
.
potential
, params);
123
}
124
std::shared_ptr<Potential>
makePotential
(
PotType
ptype,
125
const
Parameters
¶ms) {
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(
129
params.
potential_options
.
potentialsPath
);
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
: {
145
return
makeRgpot<rgpot::LJClusterPot>
(
PotType::LJCLUSTER
, params,
146
rgpot::LJClusterConfig{});
147
break
;
148
}
149
case
PotType::MORSE_PT
: {
150
return
makeRgpot<rgpot::MorsePot>
(
PotType::MORSE_PT
, params,
151
rgpot::MorseConfig{});
152
break
;
153
}
154
#ifdef CUH2_POT
155
case
PotType::CUH2
: {
156
return
makeRgpotDefault<rgpot::fortranpots::CuH2Pot>
(
PotType::CUH2
, params);
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
: {
175
return
makeRgpotDefault<rgpot::fortranpots::WaterHPot>
(
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
: {
183
return
makeRgpotDefault<rgpot::fortranpots::EAMAlPot>
(
PotType::EAM_AL
,
184
params);
185
break
;
186
}
187
case
PotType::EDIP
: {
188
return
makeRgpotDefault<rgpot::fortranpots::EDIPPot>
(
PotType::EDIP
, params);
189
break
;
190
}
191
case
PotType::FEHE
: {
192
return
makeRgpotDefault<rgpot::fortranpots::FeHePot>
(
PotType::FEHE
, params);
193
break
;
194
}
195
case
PotType::LENOSKY_SI
: {
196
return
makeRgpotDefault<rgpot::fortranpots::LenoskyPot>
(
PotType::LENOSKY_SI
,
197
params);
198
break
;
199
}
200
case
PotType::SW_SI
: {
201
return
makeRgpotDefault<rgpot::fortranpots::SWPot>
(
PotType::SW_SI
, params);
202
break
;
203
}
204
case
PotType::TERSOFF_SI
: {
205
return
makeRgpotDefault<rgpot::fortranpots::TersoffPot>
(
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
: {
276
return
makeRgpot<rgpot::ZBLPot>
(
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
285
case
PotType::SocketNWChem
: {
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
AMS.h
AMS_IO.h
ASE.h
ASE_NWCHEM.h
ASE_ORCA.h
CatLearnPot.h
EAM.h
EffectiveMediumTheory.h
Matrix3d
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Definition
Eigen.h:35
AtomMatrix
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition
Eigen.h:37
EonLogger.h
EONC_LOG_ERROR
#define EONC_LOG_ERROR(...)
Definition
EonLogger.h:262
ExtPot.h
GPRPotential.h
HelperFunctions.h
LAMMPSPot.h
MPIPot.h
MetatomicPotential.h
Parameters.h
PluginLoader.h
Potential.h
RgpotAdapter.h
makeRgpot
std::shared_ptr< Potential > makeRgpot(PotType ptype, const Parameters ¶ms, const Cfg &cfg)
Factory arm helper: construct the kernel from its config and wrap it.
Definition
RgpotAdapter.h:122
makeRgpotDefault
std::shared_ptr< Potential > makeRgpotDefault(PotType ptype, const Parameters ¶ms)
Factory arm helper for kernels whose parameters are fixed tabulated data with no eOn-side configurati...
Definition
RgpotAdapter.h:115
RgpotPot.h
SocketNWChemPot.h
Tip4p_Pt.hpp
Wrapper for Eon.
VASP.h
Water.hpp
Wrapper for Eon.
XTBPot.h
Potential::get_ef
std::tuple< double, AtomMatrix > get_ef(const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
Definition
Potential.cpp:102
eonc::Parameters
Definition
Parameters.h:28
eonc::Parameters::potential_options
struct eonc::Parameters::potential_options_t potential_options
eonc::Parameters::zbl_options
struct eonc::Parameters::zbl_options_t zbl_options
eonc::PluginLoader::instance
static PluginLoader & instance()
Thread-safe singleton accessor (Meyer's pattern).
Definition
PluginLoader.cpp:20
eonc::PotRegistry::get
static PotRegistry & get() noexcept
Process-lifetime singleton.
Definition
PotRegistry.cpp:50
eonc::PotRegistry::on_force_call
void on_force_call(PotType t) noexcept
Definition
PotRegistry.cpp:88
eonc::Potential::forceCallCounter
std::atomic< size_t > forceCallCounter
Definition
Potential.h:32
eonc::Potential::force
virtual void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box)=0
eonc::Potential::ptype
PotType ptype
Definition
Potential.h:25
eonc::helpers
Definition
EnvHelpers.cc:5
eonc::helpers::makePotential
std::shared_ptr< Potential > makePotential(const Parameters ¶ms)
Definition
Potential.cpp:118
eonc::log::get
quill::Logger * get() noexcept
Get or create the default "combi" logger.
Definition
EonLogger.h:44
eonc::PotType
PotType
Definition
BaseStructures.h:36
eonc::PotType::LJCLUSTER
@ LJCLUSTER
Definition
BaseStructures.h:42
eonc::PotType::EMT
@ EMT
Definition
BaseStructures.h:39
eonc::PotType::AMS
@ AMS
Definition
BaseStructures.h:59
eonc::PotType::ASE_POT
@ ASE_POT
Definition
BaseStructures.h:65
eonc::PotType::TIP4P_H
@ TIP4P_H
Definition
BaseStructures.h:47
eonc::PotType::XTB
@ XTB
Definition
BaseStructures.h:63
eonc::PotType::TERSOFF_SI
@ TERSOFF_SI
Definition
BaseStructures.h:54
eonc::PotType::METATOMIC
@ METATOMIC
Definition
BaseStructures.h:67
eonc::PotType::EDIP
@ EDIP
Definition
BaseStructures.h:50
eonc::PotType::LJ
@ LJ
Definition
BaseStructures.h:41
eonc::PotType::MPI
@ MPI
Definition
BaseStructures.h:57
eonc::PotType::TIP4P
@ TIP4P
Definition
BaseStructures.h:45
eonc::PotType::RGPOT
@ RGPOT
Definition
BaseStructures.h:70
eonc::PotType::ZBL
@ ZBL
Definition
BaseStructures.h:68
eonc::PotType::ASE_ORCA
@ ASE_ORCA
Definition
BaseStructures.h:64
eonc::PotType::CatLearn
@ CatLearn
Definition
BaseStructures.h:62
eonc::PotType::LENOSKY_SI
@ LENOSKY_SI
Definition
BaseStructures.h:52
eonc::PotType::SW_SI
@ SW_SI
Definition
BaseStructures.h:53
eonc::PotType::EAM_AL
@ EAM_AL
Definition
BaseStructures.h:49
eonc::PotType::ASE_NWCHEM
@ ASE_NWCHEM
Definition
BaseStructures.h:66
eonc::PotType::SPCE
@ SPCE
Definition
BaseStructures.h:48
eonc::PotType::CUH2
@ CUH2
Definition
BaseStructures.h:44
eonc::PotType::EXT_POT
@ EXT_POT
Definition
BaseStructures.h:40
eonc::PotType::LAMMPS
@ LAMMPS
Definition
BaseStructures.h:56
eonc::PotType::AMS_IO
@ AMS_IO
Definition
BaseStructures.h:60
eonc::PotType::SocketNWChem
@ SocketNWChem
Definition
BaseStructures.h:69
eonc::PotType::FEHE
@ FEHE
Definition
BaseStructures.h:51
eonc::PotType::MORSE_PT
@ MORSE_PT
Definition
BaseStructures.h:43
eonc::PotType::VASP
@ VASP
Definition
BaseStructures.h:55
eonc::PotType::TIP4P_PT
@ TIP4P_PT
Definition
BaseStructures.h:46
eonc::Parameters::potential_options_t::potentialsPath
std::string potentialsPath
Definition
Parameters.h:74
eonc::Parameters::potential_options_t::potential
PotType potential
Definition
Parameters.h:67
eonc::Parameters::zbl_options_t::cut_global
double cut_global
Definition
Parameters.h:113
eonc::Parameters::zbl_options_t::cut_inner
double cut_inner
Definition
Parameters.h:112
client
Potential.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf