diff --git a/pyproject.toml b/pyproject.toml index a56ec977..4cab98fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,2 @@ [build-system] -requires = ["setuptools", "wheel", "cmake", "pyscf", "numpy", "cffi"] +requires = ["setuptools", "wheel", "cmake", "pyscf", "numpy"] diff --git a/pyscf/dft2/_libxc_header.py b/pyscf/dft2/_libxc_header.py deleted file mode 100644 index 1bef2efe..00000000 --- a/pyscf/dft2/_libxc_header.py +++ /dev/null @@ -1,42 +0,0 @@ -import sys -import subprocess -import re - -def preprocess_header(path): - '''Call gcc to preprocess `xc.h` macros. This will let cffi recognize most constants.''' - command = ['gcc', '-E', '-P', '-xc', '-dD', '-'] - process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) - - with open(path, 'r') as f: - for line in f: - if not line.strip().startswith('#include'): - process.stdin.write(line) - - process.stdin.close() - - # Process only constants with integer numbers and constants defined with one left shift operator - # Also exclude builtins that start with underscore - # Limitations: Flags with other operators are not included - # e.g.: #define XC_FLAGS_HAVE_ALL - CONST_PATTERN = re.compile(r'#define [^_][^ ]* -?\d+\s*') - SHIFT_PATTERN = re.compile(r'#define ([^_][^ ]*) \(\s*(\d+)\s*<<\s*(\d+)\s*\)') - - def read(): - for line in process.stdout: - if line.startswith('#define'): - pat = SHIFT_PATTERN.match(line) - if pat: - name, a, b = pat.groups() - yield f'#define {name} {int(a) << int(b)}\n' - continue - elif not CONST_PATTERN.fullmatch(line): - # print('Warning: ignore #define line:', line.strip()) - continue - yield line - - return ''.join(read()) - -def load_file(path): - with open(path) as f: - return f.read() - diff --git a/pyscf/dft2/libxc.py b/pyscf/dft2/libxc.py index a50c5b94..4da62e49 100644 --- a/pyscf/dft2/libxc.py +++ b/pyscf/dft2/libxc.py @@ -16,6 +16,7 @@ # # Authors: Qiming Sun # Susi Lehtola +# Dayou Zhang # This file is adapted from `dft/libxc.py` of the PySCF core module # commit 25eaa9572977b903de24d5c11ad345cecd744728 @@ -876,7 +877,7 @@ def _eval_xc(xc_code, rho, spin=0, deriv=1, omega=None): if omega is not None: raise NotImplementedError('use register_custom_functional_() to set omega') - if _needs_laplacian(xc.nfunc, xc.xc_arr): + if xc.needs_laplacian: raise NotImplementedError('laplacian in meta-GGA method') nvar, xlen = xc_deriv._XC_NVAR[xctype, spin] diff --git a/pyscf/lib/CMakeLists.txt b/pyscf/lib/CMakeLists.txt index 5fe091e5..15ffa28d 100644 --- a/pyscf/lib/CMakeLists.txt +++ b/pyscf/lib/CMakeLists.txt @@ -58,8 +58,6 @@ else() endif() endif() -option(BUILD_CFFI_API_MODE "Compiling CFFI library with CFFI API mode support" OFF) - set(CMAKE_INCLUDE_CURRENT_DIR ON) # Whether or not to compile with MKL diff --git a/pyscf/lib/dft/libxc_itrf2.c b/pyscf/lib/dft/libxc_itrf2.c index 2b58b780..c2336be3 100644 --- a/pyscf/lib/dft/libxc_itrf2.c +++ b/pyscf/lib/dft/libxc_itrf2.c @@ -16,6 +16,7 @@ * Authors: Qiming Sun * Susi Lehtola * Xing Zhang + * Dayou Zhang * * libxc from * http://www.tddft.org/programs/octopus/wiki/index.php/Libxc:manual diff --git a/pyscf/mcdcft/dcfnal.py b/pyscf/mcdcft/dcfnal.py index cece864c..d7e72cdb 100644 --- a/pyscf/mcdcft/dcfnal.py +++ b/pyscf/mcdcft/dcfnal.py @@ -118,6 +118,32 @@ def get_converted_rho(natorb, occ, ao, type_id, f=f_v2, negative_rho=False): _LIBXC_REGISTER_PREFIX = '_MC-DCFT_' def register_dcfnal_(dc_code, preset): + ''' + Register a new density coherence functional. Once registered, + users may use the functional by passing `dc_code` to any MC-DCFT module. + If `dc_code` has previously been registered, the older functional will + be replaced with the new definition. New `dcfnal` isinstances must be + re-constructed after updating a functional to avoid inconsistencies. + + Args: + dc_code : str + The string identifier of the density coherence functional + preset : dict + A dict that defines the functional. It can contain the following keys-value pairs: + xc_code : int or str (required) + the xc_code of the underlying Kohn-Sham functional. It follows the format of + xc_code in LibXC interface + hyb_x : float (required) + mixing factor of MCSCF exchange-correlation energy + display_name : str + display name of the functional + ext_params : dict, with LibXC functional integer ID as key, and an array-like + object containing the functional parameters as value. + Set the external parameters of the LibXC functional componet from the dict. + args : dict + keyword arguments to be passed to `get_converted_rho`. See `get_converted_rho` + for a description of the keyword arguments. + ''' libxc_register_code = _LIBXC_REGISTER_PREFIX + dc_code libxc_base_code = preset['xc_code'] @@ -127,6 +153,10 @@ def register_dcfnal_(dc_code, preset): _REGISTERED_PRESETS[dc_code] = preset def unregister_dcfnal_(dc_code): + ''' + Unregister a density coherence functional with name `dc_code` that was previously registered + through `register_dcfnal_`. + ''' libxc_register_code = _LIBXC_REGISTER_PREFIX + dc_code libxc.unregister_custom_functional_(libxc_register_code) del _REGISTERED_PRESETS[dc_code] @@ -171,15 +201,14 @@ def __init__ (self, mol, dc_code, grids_level=None, verbose=0, **kwargs): self.ms = 0.0 def get_E_dc(self, natorb, occ, ao, weight): - ''' E_xc[dm] = V_xc[rho_converted] + ''' E_dc[dm] = V_xc[rho_converted] Args: natorb : ndarray of shape (nao, nao) generated by natorb occ : ndarray with shape (nao,) occupation numbers of natorb - ao : ndarray of shape (ngrids, nao) for LDA or (4, ngrids, nao) for GGA - and MGGA + ao : ndarray of shape (ngrids, nao) for LDA or (4, ngrids, nao) for GGA and MGGA magnitude of atomic basis function [and gradients] weight : ndarray of shape (ngrids) containing numerical integration weights