Skip to content

Commit

Permalink
Add Builtin LDA Electron-Proton Correlation Functionals (#38)
Browse files Browse the repository at this point in the history
* first commit

* grabbed lda epcs from libxc

* add epc functional options

* enable more epc interface

* added is_epc check and start generating tests

* attemp to add tests for epc lda functionals

* Remove unwanted changes

* skip ground truth comparison for epc functionals and allow is_epc trait to automatically generate

* Update generate_primitive_kernels.py

* change epc checking logic in tests

* check if spin is polarized before constructing epc kernel

* pre libxc7 epc=false
  • Loading branch information
aodongliu authored May 3, 2024
1 parent 21a4700 commit ef88e16
Show file tree
Hide file tree
Showing 50 changed files with 1,161 additions and 38 deletions.
58 changes: 51 additions & 7 deletions bin/generate_primitive_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def get_const_lines( self, _xc_lines, xc_vars ):

class GenMetaData:
def __init__( self, local_name, libxc_file, ofname, xc_type, dens_tol, exx_coeff,
params = {}, needs_laplacian = False, is_kedf = False ):
params = {}, needs_laplacian = False, is_kedf = False, is_epc = False ):
self.local_name = local_name
self.libxc_file = libxc_file
self.ofname = ofname
Expand All @@ -482,6 +482,7 @@ def __init__( self, local_name, libxc_file, ofname, xc_type, dens_tol, exx_coeff
self.params = params
self.needs_laplacian = needs_laplacian
self.is_kedf = is_kedf
self.is_epc = is_epc

self.is_hyb = abs(float(exx_coeff)) > 1e-10

Expand All @@ -493,6 +494,46 @@ def __init__( self, local_name, libxc_file, ofname, xc_type, dens_tol, exx_coeff
kernel_prefix = 'include/exchcxx/impl/builtin/kernels/'
gen_table = {

'EPC17_1' : GenMetaData( 'BuiltinEPC17_1',
libxc_prefix + 'lda_exc/lda_c_epc17.c',
kernel_prefix + 'epc17_1.hpp',
'LDA', 1e-24, 0.,
{ 'a': '2.35',
'b': '2.40',
'c': '3.20' },
False, False, True
),

'EPC17_2' : GenMetaData( 'BuiltinEPC17_2',
libxc_prefix + 'lda_exc/lda_c_epc17.c',
kernel_prefix + 'epc17_2.hpp',
'LDA', 1e-24, 0.,
{ 'a': '2.35',
'b': '2.40',
'c': '6.60' },
False, False, True
),

'EPC18_1' : GenMetaData( 'BuiltinEPC18_1',
libxc_prefix + 'lda_exc/lda_c_epc18.c',
kernel_prefix + 'epc18_1.hpp',
'LDA', 1e-24, 0.,
{ 'a': '1.80',
'b': '0.10',
'c': '0.03' },
False, False, True
),

'EPC18_2' : GenMetaData( 'BuiltinEPC18_2',
libxc_prefix + 'lda_exc/lda_c_epc18.c',
kernel_prefix + 'epc18_2.hpp',
'LDA', 1e-24, 0.,
{ 'a': '3.90',
'b': '0.50',
'c': '0.06' },
False, False, True
),

'SlaterExchange' : GenMetaData( 'BuiltinSlaterExchange',
libxc_prefix + 'lda_exc/lda_x.c',
kernel_prefix + 'slater_exchange.hpp',
Expand Down Expand Up @@ -734,14 +775,15 @@ def __init__( self, local_name, libxc_file, ofname, xc_type, dens_tol, exx_coeff
static constexpr bool is_mgga = {4};
static constexpr bool needs_laplacian = {5};
static constexpr bool is_kedf = {6};
static constexpr bool is_epc = {7};
static constexpr double dens_tol = {7};
static constexpr double dens_tol = {8};
static constexpr double zeta_tol = 1e-15;
static constexpr double sigma_tol = {8};
static constexpr double sigma_tol = {9};
static constexpr double tau_tol = is_kedf ? 0.0 : 1e-20;
static constexpr bool is_hyb = {9};
static constexpr double exx_coeff = {10};
static constexpr bool is_hyb = {10};
static constexpr double exx_coeff = {11};
"""

lda_exc_args_unpolar = "double rho, double& eps"
Expand Down Expand Up @@ -811,11 +853,13 @@ def __init__( self, local_name, libxc_file, ofname, xc_type, dens_tol, exx_coeff
is_mgga = xc_type == 'MGGA'
needs_laplacian = (xc_type == 'MGGA') and meta_data.needs_laplacian
is_kedf = meta_data.is_kedf
is_epc = meta_data.is_epc

xc_struct_prefix = struct_prefix.format(
meta_data.local_name, xc_type.lower(), str(is_lda).lower(),
str(is_gga).lower(), str(is_mgga).lower(), str(needs_laplacian).lower(), str(is_kedf).lower(),
meta_data.dens_tol, meta_data.dens_tol**(4.0/3.0), str(meta_data.is_hyb).lower(), meta_data.exx_coeff )
str(is_gga).lower(), str(is_mgga).lower(), str(needs_laplacian).lower(),
str(is_kedf).lower(), str(is_epc).lower(), meta_data.dens_tol,
meta_data.dens_tol**(4.0/3.0), str(meta_data.is_hyb).lower(), meta_data.exx_coeff )

xc_param_lines = []
for pname, valstr in meta_data.params.items():
Expand Down
6 changes: 5 additions & 1 deletion include/exchcxx/enums/functionals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ enum class Functional {
PBE0,
SCAN,
R2SCAN,
R2SCANL
R2SCANL,
EPC17_1,
EPC17_2,
EPC18_1,
EPC18_2,
};

extern BidirectionalMap<std::string, Functional> functional_map;
Expand Down
6 changes: 6 additions & 0 deletions include/exchcxx/enums/kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ enum class Kernel {
// Hybrid GGA functionals
B3LYP,
PBE0,

// NEO LDA Functionals
EPC17_1,
EPC17_2,
EPC18_1,
EPC18_2,
};

extern BidirectionalMap<std::string, Kernel> kernel_map;
Expand Down
4 changes: 4 additions & 0 deletions include/exchcxx/impl/builtin/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ struct BuiltinSCANL_C;
struct BuiltinR2SCANL_X;
struct BuiltinR2SCANL_C;

struct BuiltinEPC17_1;
struct BuiltinEPC17_2;
struct BuiltinEPC18_1;
struct BuiltinEPC18_2;

template <typename KernelType>
struct kernel_traits;
Expand Down
1 change: 1 addition & 0 deletions include/exchcxx/impl/builtin/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BuiltinKernelInterface : public XCKernelImpl {
bool is_gga_() const noexcept override;
bool is_mgga_() const noexcept override;
bool is_hyb_() const noexcept override;
bool is_epc_() const noexcept override;
bool needs_laplacian_() const noexcept override;
bool needs_tau_() const noexcept override;
bool is_polarized_() const noexcept override;
Expand Down
4 changes: 4 additions & 0 deletions include/exchcxx/impl/builtin/kernel_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class BuiltinKernel {
virtual bool is_gga() const noexcept = 0;
virtual bool is_mgga() const noexcept = 0;
virtual bool is_hyb() const noexcept = 0;
virtual bool is_epc() const noexcept = 0;
virtual bool needs_laplacian() const noexcept = 0;
virtual bool needs_tau() const noexcept = 0;
virtual double hyb_exx() const noexcept = 0;
Expand Down Expand Up @@ -375,6 +376,7 @@ struct BuiltinKernelImpl<
inline bool is_lda() const noexcept override { return traits::is_lda; }
inline bool is_gga() const noexcept override { return traits::is_gga; }
inline bool is_mgga() const noexcept override { return traits::is_mgga; }
inline bool is_epc() const noexcept override { return traits::is_epc; }

inline double hyb_exx() const noexcept override {
return traits::is_hyb ? traits::exx_coeff : 0.;
Expand Down Expand Up @@ -525,6 +527,7 @@ struct BuiltinKernelImpl<
inline bool is_lda() const noexcept override { return traits::is_lda; }
inline bool is_gga() const noexcept override { return traits::is_gga; }
inline bool is_mgga() const noexcept override { return traits::is_mgga; }
inline bool is_epc() const noexcept override { return traits::is_epc; }

inline double hyb_exx() const noexcept override {
return traits::is_hyb ? traits::exx_coeff : 0.;
Expand Down Expand Up @@ -676,6 +679,7 @@ struct BuiltinKernelImpl<
inline bool is_lda() const noexcept override { return traits::is_lda; }
inline bool is_gga() const noexcept override { return traits::is_gga; }
inline bool is_mgga() const noexcept override { return traits::is_mgga; }
inline bool is_epc() const noexcept override { return traits::is_epc; }

inline double hyb_exx() const noexcept override {
return traits::is_hyb ? traits::exx_coeff : 0.;
Expand Down
4 changes: 4 additions & 0 deletions include/exchcxx/impl/builtin/kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@
#include <exchcxx/impl/builtin/kernels/pc07_k.hpp>
#include <exchcxx/impl/builtin/kernels/pc07opt_k.hpp>

#include <exchcxx/impl/builtin/kernels/epc17_1.hpp>
#include <exchcxx/impl/builtin/kernels/epc17_2.hpp>
#include <exchcxx/impl/builtin/kernels/epc18_1.hpp>
#include <exchcxx/impl/builtin/kernels/epc18_2.hpp>

1 change: 1 addition & 0 deletions include/exchcxx/impl/builtin/kernels/b3lyp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct kernel_traits<BuiltinB3LYP> {
static constexpr bool is_lda = false;
static constexpr bool is_gga = true;
static constexpr bool is_mgga = false;
static constexpr bool is_epc = false;
static constexpr double exx_coeff = 0.20;

static constexpr double b3lyp_ax = 0.72; // % GGA X
Expand Down
3 changes: 2 additions & 1 deletion include/exchcxx/impl/builtin/kernels/b88.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct kernel_traits< BuiltinB88 > :
static constexpr bool is_mgga = false;
static constexpr bool needs_laplacian = false;
static constexpr bool is_kedf = false;
static constexpr bool is_epc = false;

static constexpr double dens_tol = 1e-25;
static constexpr double zeta_tol = 1e-15;
Expand Down Expand Up @@ -391,4 +392,4 @@ struct BuiltinB88 : detail::BuiltinKernelImpl< BuiltinB88 > {



} // namespace ExchCXX
} // namespace ExchCXX
1 change: 1 addition & 0 deletions include/exchcxx/impl/builtin/kernels/deorbitalized.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct kernel_traits<Deorbitalized<XCEF,KEDF>> {
static constexpr bool is_mgga = true;
static constexpr bool needs_laplacian = true;
static constexpr bool is_kedf = false;
static constexpr bool is_epc = false;
static constexpr double exx_coeff = xc_traits::exx_coeff + ke_traits::exx_coeff;

BUILTIN_KERNEL_EVAL_RETURN
Expand Down
Loading

0 comments on commit ef88e16

Please sign in to comment.