betaFeedback

WorksPhysics and Astronomy

PyCDFT: A Python-scriptable library for analytical evaluation of orbital conceptual density (matrix) functional theory

Abstract

Conceptual density functional theory (CDFT) defines chemical reactivity descriptors as derivatives of the electronic energy with respect to the number of electrons and the external potential, or combinations thereof; in practice, however, researchers almost always replace these derivatives with finite-difference and frontier-orbital approximations, and no common software exists for their analytical evaluation. We present PyCDFT, to our knowledge, the first standardized, open-source, and scriptable code that analytically computes the descriptors of conceptual density (matrix) functional theory for ground and excited states up to second order, including the orbital hardness, the Fukui function and Fukui matrix, and the linear response function, from a single converged mean-field wavefunction imported from virtually any electronic-structure package. The descriptors are obtained from matrix-free, preconditioned Krylov-subspace solutions of the coupled-perturbed self-consistent-field equations for both spin-unpolarized and spin-polarized references, with the work distributed over MPI ranks and all data flowing through a single HDF5 checkpoint file that supports restart, post-processing, and the export of real-space descriptors as cube files for visualization. The design delegates integrals, grids, and exchange-correlation kernels to PySCF and Libxc, keeping the library compact, user-friendly, and interoperable. Worked examples on the ground state of H2_2O and a broken-symmetry ΔΔSCF excited state of NH3_3 show that a complete second-order CDFT analysis requires only a few lines of user code.

checkpoint file that supports restart, post-processing, and the export of real-space descriptors as cube files for visualization. The design delegates integrals, grids, and exchange–correlation kernels to PySCF and Libxc, keeping the library compact, user-friendly, and interoperable. Worked examples on the ground state of H2O\mathrm{H_2O} and a broken-symmetry Δ\DeltaSCF excited state of NH3\mathrm{NH_3} show that a complete second-order CDFT analysis requires only a few lines of user code.

Introduction

Over more than four decades, conceptual density functional theory (CDFT)[1, 2, 3, 4, 5, 6, 7, 8, 9], also referred to as density functional reactivity theory (DFRT), has matured into a firmly rooted framework for the study of chemical reactivity. Its basic idea, going back to Parr and co-workers in the late 1970s and early 1980s[10], is that concepts that chemists had long used intuitively can be given precise, computable definitions as derivatives (response functions) of the energy functional E[N,v]E[N,v] with respect to the number of electrons NN and the external potential v(r)v(\mathbf{r}): the electronic chemical potential μ\mu[10, 11, 12] and the density ρ(r)\rho(\mathbf{r})[1] appear at first order, followed at second order by the chemical hardness η\eta[13, 14, 15, 16, 17], the Fukui function f(r)f(\mathbf{r})[18, 19], and the linear response function (LRF) χ(r,r′)\chi(\mathbf{r},\mathbf{r}')[1, 20, 21, 22, 23, 24], while higher-order response functions[25] follow in the same way. A reaction is thereby viewed as the response of a molecule to the changes ΔN\Delta N and Δv(r)\Delta v(\mathbf{r}) imposed by its reaction partner. In applications, these derivatives are seldom computed from their definitions. The NN-derivatives are often estimated by finite differences involving the ionized systems (μ≈−(I+A)/2\mu\approx-(I+A)/2, η≈I−A\eta\approx I-A), the Fukui function is on the other hand obtained from N±1N \pm1 density differences or identified with a frontier orbital density,[18] and atomic resolution is introduced through a partitioning scheme.[26, 27] This toolbox has carried most applied CDFT work, but each ingredient has known weaknesses: the calculations on anions in the finite difference approximation can be difficult to converge and are prone to spin contamination and delocalization error,[28, 29, 30, 31] the frontier orbital picture ignores orbital relaxation and fails for (quasi-)degenerate frontier orbitals,[32] and the outcome may change qualitatively with the choice of approximation or partitioning method.[27] For the LRF, the difficulties become prohibitive: a two-point kernel cannot be obtained by finite differences, as this would require perturbing v(r)v(\mathbf{r}) numerically and independently at every point in space, which is prohibitively expensive, and for a long time χ(r,r′)\chi(\mathbf{r},\mathbf{r}') was accessible only through simplified models or truncated expressions such as the independent particle approximation (IPA).[20, 33, 34] The decisive first step was the analytical evaluation of the LRF from coupled-perturbed self-consistent-field (CP-SCF) theory,[22, 35] which yields the kernel exactly for a given density functional approximation;[24] on this basis the LRF has been applied to problems ranging from atomic shell structure[21] and substituent effects to electron delocalization[33, 34] and the nearsightedness of electronic matter,[36] with quantitatively reliable and readily interpretable results.

The analytical route also pays off beyond reactivity analysis itself. In the development of density functionals,[37] the deviation between the analytical and finite-difference Fukui functions makes the delocalization error of an approximate functional directly visible,[31] and the analytically evaluated hardness permits an explicit test of the hardness condition that the exact functional must obey.[30] Moreover, the same derivative framework is not restricted to the perturbation (NN and v(r)v(\mathbf{r})) exerted by an approaching reagent. Treating the nuclear charges as continuous variables connects CDFT to alchemical perturbation theory with a rational exploration of chemical compound space coming within range.[36, 38, 39] Reactivity indices have recently been reformulated for molecules under external electric[40] and magnetic fields,[41, 42] mechanical forces,[43, 44] and isotropic pressure[45, 46] or chemical constraints.[47] In all of these settings, finite-difference protocols become increasingly challenging or sometimes ill-defined, whereas an analytical formulation provides a single systematic starting point and leaves room for perturbations that have not been considered yet. Meanwhile, the theory continues to grow in directions where analytical evaluation is unavoidable: generalizing the external potential to the one-electron integrals hpqh_{pq} is the gate to conceptual density matrix functional theory (CDMFT) extending the theory from atoms to bonds;[48] varying individual occupation numbers defines orbital-resolved CDFT,[49, 50] and descriptors under external fields[51] and higher-order response functions[25, 52] are under active investigation. All of these developments, however, run into the same practical bottlenecks: (1) there is no common, openly available code for analytical CDFT,[53] so the CP-SCF machinery is re-implemented separately for each study; (2) the notation for the response functions varies considerably across the literature, making the published expressions difficult to compare and combine; and (3) no single reference work explains how the analytical framework should be implemented and carried through to its most general orbital and matrix extensions. In the present work we therefore introduce PyCDFT, an open, Python-scriptable library that analytically computes the orbital CD(M)FT descriptors up to second order from a single converged wavefunction. Sec. 2 collects the working equations, Sec. 3 describes the structure and implementation of the library, Sec. 4 illustrates its use, and Sec. 5 closes with an outlook.

Fundamentals of analytical CDFT

Before proceeding, we establish the notation used throughout: the indices i,j,k,l,…,m,n,…i,j,k,l,\ldots,m,n,\ldots denote occupied orbitals a,b,c,d,…a,b,c,d,\ldots virtual orbitals, and p,q,r,s,…p,q,r,s,\ldots general orbitals, while the index ff denotes a frontier orbital. Spin indices are represented by σ,τ,λ,θ,…\sigma,\tau,\lambda,\theta,\ldots, and the spin orbital energies are denoted by εpσ\varepsilon_{p\sigma}. The foundation of conceptual density functional theory lies in the power series expansion of the energy functional with respect to its two intrinsic variables, namely the number of electrons NN and the external potential v(r)v(\mathbf{r}). In the canonical ensemble, this expansion reads

E[N+ΔN,v+Δv]=E[N,v]+(∂E∂N)vΔN+∫(δEδv(r))NΔv(r) dr+12(∂2E∂N2)vΔN2+ΔN∫∂2E∂Nδv(r)Δv(r) dr+12∬(δ2Eδv(r)δv(r′))NΔv(r)Δv(r′) drdr′+⋯ΔE[N,v]=μΔN+∫ρ(r)Δv(r) dr+12ηΔN2+ΔN∫f(r)Δv(r) dr+12∬χ(r,r′)Δv(r)Δv(r′) drdr′+⋯ .(1)\begin{aligned} E[N+\Delta N,v+\Delta v] &= E[N,v]+\left(\frac{\partial E}{\partial N}\right)_{v}\Delta N+\int\left(\frac{\delta E}{\delta v(\mathbf{r})}\right)_{N}\Delta v(\mathbf{r})\,\mathrm{d}r \\ &\quad+\frac{1}{2}\left(\frac{\partial^{2}E}{\partial N^{2}}\right)_{v}\Delta N^{2}+\Delta N\int\frac{\partial^{2}E}{\partial N\delta v(\mathbf{r})}\Delta v(\mathbf{r})\,\mathrm{d}r \\ &\quad+\frac{1}{2}\iint\left(\frac{\delta^{2}E}{\delta v(\mathbf{r})\delta v(\mathbf{r}')}\right)_{N}\Delta v(\mathbf{r})\Delta v(\mathbf{r}')\,\mathrm{d}r\mathrm{d}r'+\cdots\\ \Delta E[N,v] &= \mu\Delta N+\int\rho(\mathbf{r})\Delta v(\mathbf{r})\,\mathrm{d}r+\frac{1}{2}\eta\Delta N^{2} \\ &\quad+\Delta N\int f(\mathbf{r})\Delta v(\mathbf{r})\,\mathrm{d}r+\frac{1}{2}\iint\chi(\mathbf{r},\mathbf{r}')\Delta v(\mathbf{r})\Delta v(\mathbf{r}')\,\mathrm{d}r\mathrm{d}r'+\cdots. \tag*{(1)} \end{aligned}

The energy derivatives or the response functions introduced in the above Taylor expansion are the CDFT reactivity indices. For example, the first-order descriptors are the chemical potential μ\mu[10] and the electron density ρ(r)\rho(\mathbf{r})[1]; the second-order descriptors are the chemical hardness η\eta[13, 14], the Fukui function f(r)f(\mathbf{r})[18], and the linear response function χ(r,r′)\chi(\mathbf{r},\mathbf{r}')[1]. Higher-order response functions e.g., the third order dual descriptor f(2)(r)f^{(2)}(\mathbf{r})[54] and the Fukui kernel g(r,r′)g(\mathbf{r},\mathbf{r}')[50] (it is sometimes referred as f(r,r′)f(\mathbf{r},\mathbf{r}') in literature, to name the CDFT indices systematically and avoid confusion with the Fukui matrix FpqF_{pq} we prefer denote it as g(r,r′)g(\mathbf{r},\mathbf{r}')) capture chemical reactivity in greater detail. Two generalisations have recently been proposed to extend the applicability of the theory and to extract deeper physicochemical insight from it. First, for the ground state of electronic systems, the external potential v(r)v(\mathbf{r}) is replaced by the one-electron integrals hpqh_{pq}, giving rise to conceptual density matrix functional theory (CDMFT).[48, 55] The second one replaces the total number of electrons NN by the orbital occupation numbers nin_i, leading to ground state orbital-based CDFT.[49] Extending this approach to excited states through the generalised adiabatic connection Kohn–Sham (GAC-KS) theorem,[50, 56, 57] an arbitrary KS state index JJ is introduced to the orbital CDFT in order to contain sufficient information about the excited state; the energy functional is then written as EJ[{npσ},v(r)]E_J[\{n_{p\sigma}\},v(\mathbf{r})], unifying the ground and the excited states description. An alternative approach to establish the foundation of the Δ\DeltaSCF approach, introduced by Yang and Ayers, is via the potential functional theory(PFT) as well as the Φ\Phi and γS\gamma_S functional theories,[58] which also place the orbital CDFT for excited states on a firm ground. Putting everything together, the final generalised spin-resolved perturbation expansion of the energy function is then written as

ΔEJ[nm,hpq]=∑m(∂EJ∂nm){hpq}Δnm+∑pq(∂EJ∂hpq){nm}Δhpq+12∑mn(∂2EJ∂nm∂nn){hpq}ΔnmΔnn+∑m∑pqΔnm∂2EJ∂nm∂hpqΔhpq+12∑pq∑rs(∂2EJ∂hpq∂hrs){nm}ΔhpqΔhrs+⋯=∑mμmJΔnm+∑pqPpqJΔhpq+12∑mnηmnJΔnmΔnn+∑m∑pqΔnmFm,pqJΔhpq+12∑pq∑rsXpqrsJΔhpqΔhrs+⋯ ,(2)\begin{aligned} \Delta E_J[n_m,h_{pq}] ={}& \sum_m \left(\frac{\partial E_J}{\partial n_m}\right)_{\{h_{pq}\}} \Delta n_m + \sum_{pq} \left(\frac{\partial E_J}{\partial h_{pq}}\right)_{\{n_m\}} \Delta h_{pq} \\ &+ \frac{1}{2}\sum_{mn}\left(\frac{\partial^2 E_J}{\partial n_m\partial n_n}\right)_{\{h_{pq}\}}\Delta n_m\Delta n_n + \sum_m\sum_{pq}\Delta n_m\frac{\partial^2 E_J}{\partial n_m\partial h_{pq}}\Delta h_{pq} \\ &+ \frac{1}{2}\sum_{pq}\sum_{rs}\left(\frac{\partial^2 E_J}{\partial h_{pq}\partial h_{rs}}\right)_{\{n_m\}}\Delta h_{pq}\Delta h_{rs}+\cdots\\ ={}& \sum_m \mu_m^J\Delta n_m+\sum_{pq}P_{pq}^J\Delta h_{pq}+\frac{1}{2}\sum_{mn}\eta_{mn}^J\Delta n_m\Delta n_n \\ &+\sum_m\sum_{pq}\Delta n_mF_{m,pq}^J\Delta h_{pq}+\frac{1}{2}\sum_{pq}\sum_{rs}X_{pqrs}^J\Delta h_{pq}\Delta h_{rs}+\cdots, \tag*{(2)} \end{aligned}

where the superscript JJ for the newly introduced CDMFT descriptors will be dropped from now on for simplicity. By solving the spin-polarised coupled-perturbed self-consistent-field (CP-SCF) equations, analytical expressions for the newly introduced CDFT descriptors are obtained. Herein, we propose an original orbital CDMFT, in the most general form, where the first order contains the the (Kohn–Sham) orbital chemical potential μm\mu_m, which equals the KS orbital energy

μmσ=εmσ=⟨ϕmσ∣h^∣ϕmσ⟩,(3)\mu_{m\sigma}=\varepsilon_{m\sigma}=\langle\phi_{m\sigma}|\hat{h}|\phi_{m\sigma}\rangle, \tag*{(3)}

and the density matrix PpqσP^\sigma_{pq}

Ppqσ=∑ioccniσδpiδqi.(4)P^\sigma_{pq}=\sum_{i}^{\mathrm{occ}} n_{i\sigma}\delta_{pi}\delta_{qi}. \tag*{(4)}

The second order consists of the orbital hardness matrix ηmσnτ\eta_{m\sigma n\tau}

ηmσnτ=Kmσmσnτnτη−∑λθ∑iλaλ,jθbθMiλaλ,jθbθ−1KnτnτjθbθfKmσmσiλaλη−cHFδστ∑pτqτFnτ,pτqτ(ϕmσϕpτ∣ϕmσϕqτ),(5)\begin{aligned} \eta_{m\sigma n\tau}={}&K^\eta_{m\sigma m\sigma n\tau n\tau} -\sum_{\lambda\theta}\sum_{i\lambda a\lambda,j\theta b\theta} M^{-1}_{i\lambda a\lambda,j\theta b\theta} K^f_{n\tau n\tau j\theta b\theta} K^\eta_{m\sigma m\sigma i\lambda a\lambda}\\ &-c_{\mathrm{HF}}\delta_{\sigma\tau}\sum_{p_\tau q_\tau} F_{n\tau,p_\tau q_\tau} (\phi_{m\sigma}\phi_{p\tau}|\phi_{m\sigma}\phi_{q\tau}), \tag*{(5)} \end{aligned}

which is also interpreted as the generalised screened interaction,[37] where the last term is the exact-exchange contribution for hybrid functionals (cHF≠0c_{\mathrm{HF}}\ne0); the orbital Fukui matrix Fmσ,pτqτF_{m\sigma,p\tau q\tau} entering this term is

Fmσ,pτqτ=∂Ppτqτ∂nmσ=δστδmσqσδmσpσ−12∑λ∑iτaτ,jλbλMiτaτ,jλbλ−1Kmσmσjλbλf(δpσaσδqσiσ+δqσaσδpσiσ),(6)\begin{aligned} F_{m\sigma,p\tau q\tau} &=\frac{\partial P_{p\tau q\tau}}{\partial n_{m\sigma}}\\ &=\delta_{\sigma\tau}\delta_{m\sigma q\sigma}\delta_{m\sigma p\sigma} -\frac{1}{2}\sum_{\lambda}\sum_{i\tau a\tau,j\lambda b\lambda} M^{-1}_{i\tau a\tau,j\lambda b\lambda} K^f_{m\sigma m\sigma j\lambda b\lambda} (\delta_{p\sigma a\sigma}\delta_{q\sigma i\sigma} +\delta_{q\sigma a\sigma}\delta_{p\sigma i\sigma}), \tag*{(6)} \end{aligned}

and the linear response matrix Xpσqσ,rτsτX_{p\sigma q\sigma,r\tau s\tau}

Xpσqσ,rτsτ=∂Ppσqσ∂hrτsτ=−12∑iσaσ,jτbτMiσaσ,jτbτ−1(δjτrτδbτsτ+δjτsτδbτrτ)(δaσqσδiσpσ+δaσpσδiσqσ).(7)\begin{aligned} X_{p\sigma q\sigma,r\tau s\tau} &=\frac{\partial P_{p\sigma q\sigma}}{\partial h_{r\tau s\tau}}\\ &=-\frac{1}{2}\sum_{i\sigma a\sigma,j\tau b\tau} M^{-1}_{i\sigma a\sigma,j\tau b\tau} (\delta_{j\tau r\tau}\delta_{b\tau s\tau} +\delta_{j\tau s\tau}\delta_{b\tau r\tau}) (\delta_{a\sigma q\sigma}\delta_{i\sigma p\sigma} +\delta_{a\sigma p\sigma}\delta_{i\sigma q\sigma}). \tag*{(7)} \end{aligned}

The local version of the orbital Fukui function fpσ(r)f_{p\sigma}(\mathbf{r}) and linear response function χ(r,r′)\chi(\mathbf{r},\mathbf{r}') are

fpσ(r)=∣ϕpσ(r)∣2−∑λτ∑iλaλjτbτMiλaλjτbτ−1Kpσpσjτbτfϕiλ(r)ϕaλ(r)(8)f_{p\sigma}(\mathbf{r}) = \lvert\phi_{p\sigma}(\mathbf{r}) \rvert^2 - \sum_{\lambda\tau}\sum_{i_\lambda a_\lambda j_\tau b_\tau} M^{-1}_{i_\lambda a_\lambda j_\tau b_\tau} K^{f}_{p\sigma p_\sigma j_\tau b_\tau} \phi_{i_\lambda}(\mathbf{r})\phi_{a_\lambda}(\mathbf{r}) \tag*{(8)}
χ(r,r′)=−2∑στ∑iσaσjτbτMiσaσjτbτ−1ϕiσ(r)ϕaσ(r)ϕjτ(r′)ϕbτ(r′)(9)\chi(\mathbf{r},\mathbf{r}') = -2\sum_{\sigma\tau}\sum_{i_\sigma a_\sigma j_\tau b_\tau} M^{-1}_{i_\sigma a_\sigma j_\tau b_\tau}\phi_{i_\sigma}(\mathbf{r})\phi_{a_\sigma}(\mathbf{r})\phi_{j_\tau}(\mathbf{r}')\phi_{b_\tau}(\mathbf{r}') \tag*{(9)}

where the matrices are defined in the preceding equations; these expressions hold when a single hybrid functional, e.g. B3LYP (cHF=0.2c_{\mathrm{HF}} = 0.2), is employed.

Miσaσjτbτ=δστδijδab(εaσ−εiσ)+2(ϕiσϕaσ∣ϕjτϕbτ)−cHFδστ[(ϕiσϕbσ∣ϕjσϕaσ)+(ϕiσϕjσ∣ϕaσϕbσ)]+2(ϕiσϕaσ∣fxcστ∣ϕjτϕbτ)(10)M_{i_\sigma a_\sigma j_\tau b_\tau} = \delta_{\sigma\tau}\delta_{ij}\delta_{ab}(\varepsilon_{a_\sigma} - \varepsilon_{i_\sigma}) + 2(\phi_{i_\sigma}\phi_{a_\sigma} \mid\phi_{j_\tau}\phi_{b_\tau}) - c_{\mathrm{HF}}\delta_{\sigma\tau}\left[(\phi_{i_\sigma}\phi_{b_\sigma} \mid\phi_{j_\sigma}\phi_{a_\sigma}) + (\phi_{i_\sigma}\phi_{j_\sigma} \mid\phi_{a_\sigma}\phi_{b_\sigma})\right] + 2(\phi_{i_\sigma}\phi_{a_\sigma} \mid f_{\mathrm{xc}}^{\sigma\tau} \mid\phi_{j_\tau}\phi_{b_\tau}) \tag*{(10)}
Kpσpσjτbτf=2(ϕpσϕpσ∣ϕjτϕbτ)−2cHFδστ(ϕpσϕjσ∣ϕpσϕbσ)+2(ϕpσϕpσ∣fxcστ∣ϕjτϕbτ)(11)K^{f}_{p_\sigma p_\sigma j_\tau b_\tau} = 2(\phi_{p_\sigma}\phi_{p_\sigma} \mid\phi_{j_\tau}\phi_{b_\tau}) - 2c_{\mathrm{HF}}\delta_{\sigma\tau}(\phi_{p_\sigma}\phi_{j_\sigma} \mid\phi_{p_\sigma}\phi_{b_\sigma}) + 2(\phi_{p_\sigma}\phi_{p_\sigma} \mid f_{\mathrm{xc}}^{\sigma\tau} \mid\phi_{j_\tau}\phi_{b_\tau}) \tag*{(11)}
Kpσpσqτqτη=(ϕpσϕpσ∣ϕqτϕqτ)+(ϕpσϕpσ∣fxcστ∣ϕqτϕqτ)(12)K^{\eta}_{p_\sigma p_\sigma q_\tau q_\tau} = (\phi_{p_\sigma}\phi_{p_\sigma} \mid\phi_{q_\tau}\phi_{q_\tau}) + (\phi_{p_\sigma}\phi_{p_\sigma} \mid f_{\mathrm{xc}}^{\sigma\tau} \mid\phi_{q_\tau}\phi_{q_\tau}) \tag*{(12)}
Kpσpσiλaλη=(ϕpσϕpσ∣ϕiλϕaλ)+(ϕpσϕpσ∣fxcσλ∣ϕiλϕaλ)(13)K^{\eta}_{p_\sigma p_\sigma i_\lambda a_\lambda} = (\phi_{p_\sigma}\phi_{p_\sigma} \mid\phi_{i_\lambda}\phi_{a_\lambda}) + (\phi_{p_\sigma}\phi_{p_\sigma} \mid f_{\mathrm{xc}}^{\sigma\lambda} \mid\phi_{i_\lambda}\phi_{a_\lambda}) \tag*{(13)}

As can be inferred from orbital conceptual density (matrix) functional theory, the NN-derivatives of classical CDFT are a special case in which the derivative is taken at the frontier orbital occupation level, i.e. when p=fp = f so that dN=dnf\mathrm{d}N = \mathrm{d}n_f. A generalised CDFT pyramid plot is given in Figure 1. The evaluation of the orbital CDFT for ground and excited states from Eq. (2) assumes the KS state JJ is correctly mapped to the corresponding state of interest of the interacting electronic system e.g. ΨI\Psi_I from the Δ\DeltaSCF approach. Thus the KS state index JJ is inherited from the Δ\DeltaSCF wavefunction and the expansion in Eq. (2) evaluates the orbital CDFT response functions for that state with respect to the two independent variables {nmσ}\{n_{m\sigma}\} and v(r)v(\mathbf{r}).

Pyramid plot of the generalised orbital-based conceptual density (matrix) functional theory

Figure 1. Pyramid plot of the generalised orbital-based conceptual density (matrix) functional theory. The left green lateral face shows the orbital CDFT, while the orbital CDMFT is given on the right orange lateral face. Derivative level is indicated by shaded intersections. CDFT descriptors are marked by solid black dots, whereas irrelevant responses (mixed vv and hh derivates) are denoted by empty circles. The traditional CDFT is retrieved in the left green lateral face of the pyramid by replacing the nn by NN with concomitant disappearance of all indices.

Development of PyCDFT

Code structure and interoperability

To evaluate the orbital CD(M)FT descriptors analytically and systematically, we developed PyCDFT, a pure Python library that computes them starting from a converged wavefunction produced by third-party software. The library is organized as a set of loosely coupled modules, each with a single responsibility: fileio collects the mean-field solution and writes all necessary information and settings into a master input file for the CDFT engine; dataio manages the creation, chunking, and compression of all intermediate and result datasets; aim performs the supported atoms-in-molecules (AIM) analyses and passes the resulting weights on for condensed CDFT evaluation; helper provides auxiliary functions that, e.g., classify the wavefunction, detect orbital degeneracies, and evaluate exchange–correlation kernels; and acdft implements the computational kernels that build, transform, and evaluate the response functions. A user-facing driver, eval_acdft, chains these kernels into a complete workflow, but every stage can equally be invoked from an interactive Python session or a user script, e.g. to restart an error-terminated job, in keeping with the library-first philosophy of the modern Python simulation ecosystem. The largest share is borrowed from PySCF[59, 60], whose optimized C backends supply the two-electron integrals, DFT quadrature grids, and atomic-orbital values on grid points, so that PyCDFT inherits near-native integral performance without reimplementing this machinery.

The exchange–correlation kernels fxcf_{\mathrm{xc}} are evaluated with Libxc[61], tensor contractions and the coupled-perturbed solver rely on NumPy[62] and SciPy[63], the MBIS partitioning is performed by denspart[64] with the grid library[65], and parallelism and storage are handled by mpi4py[66] and h5py through the parallel HDF5 (MPI-IO) driver.

The workflow is summarized in Figure 2. The reference Kohn–Sham DFT wavefunction may be converged with any electronic-structure package and is passed to PyCDFT as a Gaussian formatted checkpoint (fchk) file, written directly by Gaussian or Q-Chem, or generated from standard wavefunction formats (e.g., Molden) with tools such as MOKIT[67] or Multiwfn[68, 69]. In the first step, the fchk data are loaded into a PySCF mean-field object and stored, together with the user-defined functional (ExcE_{\mathrm{xc}} type and αx\alpha_{\mathrm{x}}), AIM scheme, and quadrature grid, in the scf/ group of a single HDF5 checkpoint file that serves as the sole input for the second, computationally intensive step.

Two-step workflow of PyCDFT

Figure 2. Two-step workflow of PyCDFT: a converged wavefunction (.fchk) and user settings are written to a shared HDF5 checkpoint (Step 1), from which the response matrices and (condensed) CDFT descriptors are evaluated analytically (Step 2), with optional export of real-space descriptors as cube files.

All expensive stages of the second step—integral generation, AO to MO transformation, coupled-perturbed matrix assembly, and the CP-SCF solutions—are parallelized by round-robin distribution of the outermost loop index over MPI ranks, which requires no communication beyond synchronization barriers because the work items are mutually independent. All ranks access the shared checkpoint concurrently through MPI-IO, writing datasets in slabs aligned with their chunk layout, and each finished dataset is repacked with gzip compression to reduce the disk footprint of the four-index quantities. Because each MPI rank additionally spawns its own set of BLAS threads, the parallel calculation is started through a lightweight launcher, pycdft.py, which fixes the number of threads per rank to the per-node core allocation before the numerical libraries are loaded; this prevents the thread oversubscription that would otherwise slow the compute stages several-fold on multi-core nodes. A calculation is therefore launched as mpirun -np N python pycdft.py userjob.py. The intermediate matrices reside in the mat/ group—the transformed integrals (pq∣rs)στ(pq|rs)^{\sigma\tau}, the coupled-perturbed matrix M, the coupling matrices Kf^{f} and Kη^{\eta}, the atomic overlaps S, the contracted response matrices UK^{K} and US^{S}, and the Fukui matrices Fmσ,pqτF_{m\sigma,pq\tau}—while the condensed CDFT descriptors χAB\chi_{AB}, fA,pf_{A,p}, and ηpq\eta_{pq} are collected in cdft/ and grid-resolved quantities for visualization in cub/ if additional grid point evaluation is invoked (§ 3.3). The intermediates are retained on purpose, since CD(M)FT analyses reuse the M and K matrices and deleting them would force a costly recomputation; when they are no longer needed, the mat/ group, by far the largest part of the file, can be safely removed with the provided file-reduction utility, leaving a compact record of the reference data and CDFT results.

Implementation details

Although the working equations of § 2 are written in terms of the inverse coupled-perturbed matrix, M−1\mathbf{M}^{-1} is never constructed in practice. The dimension of M is noccnvirn_{\mathrm{occ}}n_{\mathrm{vir}} per spin channel, so an explicit inversion would scale as O(nocc3nvir3)O(n_{\mathrm{occ}}^{3}n_{\mathrm{vir}}^{3}) and return a dense matrix that is never needed as such: in every descriptor, M−1\mathbf{M}^{-1} appears contracted with a small set of vectors. PyCDFT therefore recasts each evaluation as a family of linear systems whose right-hand side is dictated by the target property,

∑τ∑jτbτMiσaσjτbτUmλ,jτbτK=Kmλ,iσaσf,∑τ∑jτbτMiσaσjτbτUA,jτbτS=SiσaσA,(14)\sum_{\tau}\sum_{j_{\tau}b_{\tau}} M_{i_{\sigma}a_{\sigma}j_{\tau}b_{\tau}}U^{K}_{m_{\lambda},j_{\tau}b_{\tau}}=K^{f}_{m_{\lambda},i_{\sigma}a_{\sigma}}, \qquad\sum_{\tau}\sum_{j_{\tau}b_{\tau}} M_{i_{\sigma}a_{\sigma}j_{\tau}b_{\tau}}U^{S}_{A,j_{\tau}b_{\tau}}=S^{A}_{i_{\sigma}a_{\sigma}}, \tag*{(14)}

where SiσaσA=∑gwgwA(rg)ϕiσ(rg)ϕaσ(rg)S^{A}_{i_{\sigma}a_{\sigma}}=\sum_{g}w_{g}w_{A}(\mathbf{r}_{g})\phi_{i_{\sigma}}(\mathbf{r}_{g})\phi_{a_{\sigma}}(\mathbf{r}_{g}) is the atomic overlap matrix of atom AA evaluated by quadrature with the AIM weights. The MU = K family—one system per molecular orbital mm—generates all orbital-resolved descriptors, whereas the MU = S family—one system per atom AA—generates the atom-condensed linear response function. Once the U\mathbf{U} matrices are known, all second-order descriptors reduce to inexpensive tensor contractions,

ηmσnτ=Kmσmσnτnτη−∑λ∑iλaλKmσmσ,iλaληUnτ,iλaλK−cHFδστ∑pτqτFnτ,pτqτ(ϕmσϕpτ∣ϕmσϕqτ)(15)\eta_{m\sigma n\tau}=K^{\eta}_{m\sigma m\sigma n\tau n\tau}-\sum_{\lambda}\sum_{i_\lambda a_\lambda}K^{\eta}_{m\sigma m\sigma,i_\lambda a_\lambda}U^{K}_{n\tau,i_\lambda a_\lambda} -c_{\mathrm{HF}}\delta_{\sigma\tau}\sum_{p_\tau q_\tau}F_{n\tau,p_\tau q_\tau}(\phi_{m\sigma}\phi_{p\tau}|\phi_{m\sigma}\phi_{q\tau}) \tag*{(15)}
fA,mσ=SmσmσA−∑λ∑iλaλSiλaλAUmσ,iλaλK(16)f_{A,m\sigma}=S^{A}_{m\sigma m\sigma}-\sum_{\lambda}\sum_{i_\lambda a_\lambda}S^{A}_{i_\lambda a_\lambda}U^{K}_{m\sigma,i_\lambda a_\lambda} \tag*{(16)}
χAB=−2∑σ∑iσaσSiσaσBUA,iσaσS(17)\chi_{AB}=-2\sum_{\sigma}\sum_{i_\sigma a_\sigma}S^{B}_{i_\sigma a_\sigma}U^{S}_{A,i_\sigma a_\sigma} \tag*{(17)}

where SmσmσAS^{A}_{m_\sigma m_\sigma} is defined analogously to SiσaσAS^{A}_{i_\sigma a_\sigma} with the orbital density ϕmσ2(rg)\phi_{m_\sigma}^{2}(r_g). The last term of the hardness expression is the exact-exchange contribution, present only for hybrid functionals (cHF≠0c_{\mathrm{HF}}\ne0) and only between same-spin orbitals; it is assembled from the orbital Fukui matrix Fnσ,pσqσF_{n\sigma,p_\sigma q_\sigma}, whose off-diagonal blocks are built from −12UnσK-\frac{1}{2}U^{K}_{n\sigma}, Eq. (6), so no additional linear systems are required. Note that only one of the two spin summations of § 2 is absorbed into the U\mathbf{U} matrices through Eq. (14); the remaining sum over the spin of the occupied–virtual pair index must be carried out explicitly in the contractions.

The systems in Eq. (14) are solved by a direct or an iterative method, selected automatically from the system size. When M\mathbf{M} fits within the memory limit it is assembled once and factorized, so that every right-hand side follows by inexpensive back-substitution; larger systems fall back to a matrix-free, iterative solver. For a ground-state (Aufbau) reference M\mathbf{M} is symmetric positive definite, the regime in which the preconditioned conjugate gradient (CG) is the Krylov method of choice. Broken-symmetry and Δ\DeltaSCF references, however, generally yield an indefinite M\mathbf{M} for which CG has no convergence guarantee; PyCDFT detects this and switches automatically to the minimal residual method (MINRES), the corresponding method for symmetric indefinite systems, with an explicit residual check so that a solve which has not genuinely converged is never accepted. In the iterative path the matrix itself is never held in memory; it is exposed to SciPy as a matrix-free LinearOperator whose matrix–vector product streams slabs of M\mathbf{M} from the checkpoint file, so the memory footprint remains bounded by the user-defined limit irrespective of system size. Convergence is accelerated by a Jacobi preconditioner assembled once from the diagonal of the coupled-perturbed matrix,

diσaσ=Miσaσiσaσ=εaσ−εiσ+2(ϕiσϕaσ∣ϕiσϕaσ)+2(ϕiσϕaσ∣fxcσσ∣ϕiσϕaσ)−cHF[(ϕiσϕaσ∣ϕiσϕaσ)+(ϕiσϕiσ∣ϕaσϕaσ)],(18)d_{i_\sigma a_\sigma}=M_{i_\sigma a_\sigma i_\sigma a_\sigma}=\varepsilon_{a_\sigma}-\varepsilon_{i_\sigma}+2(\phi_{i_\sigma}\phi_{a_\sigma}|\phi_{i_\sigma}\phi_{a_\sigma})+2(\phi_{i_\sigma}\phi_{a_\sigma}|f_{\mathrm{xc}}^{\sigma\sigma}|\phi_{i_\sigma}\phi_{a_\sigma}) -c_{\mathrm{HF}}[(\phi_{i_\sigma}\phi_{a_\sigma}|\phi_{i_\sigma}\phi_{a_\sigma})+(\phi_{i_\sigma}\phi_{i_\sigma}|\phi_{a_\sigma}\phi_{a_\sigma})], \tag*{(18)}

taken for the operator actually solved, i.e., with the correspondingly spin-folded prefactors for a closed-shell reference (see below). The diagonal is dominated by the occupied–virtual gap εa−εi\varepsilon_a-\varepsilon_i; because the off-diagonal coupling is comparatively weak, the preconditioned spectrum is strongly clustered and a few tens of iterations typically suffice at the default thresholds (rtol=10−7\mathrm{rtol}=10^{-7}, atol=10−10\mathrm{atol}=10^{-10}). The essential structure of the solver, as implemented in acdft, is shown in listing 1.

Listing 1: Essential structure of the matrix-free preconditioned conjugate-gradient solver for the MU=K\mathrm{MU}=\mathrm{K} systems.

import numpy as np
from scipy.sparse.linalg import LinearOperator, cg

def matvec(x):
    """y = M @ x, with M streamed slab-wise from the checkpoint."""
    x = x.reshape(nocc, nvir)
    y = np.empty_like(x)
    for i in range(nocc):
        for a in range(nvir):
            y[i, a] = np.einsum('jb,jb->', M_h5[i, a], x)
    return y.ravel()

M_op = LinearOperator((nov, nov), matvec=matvec)
prec = LinearOperator((nov, nov), matvec=lambda r: r * dinv)  # dinv = 1/d
for m in range(nmo):        # independent RHS, round-robin over MPI ranks
    if m % size != rank:
        continue

    u, info = cg(M_op, K_f[m].ravel(), M=prec, rtol=1e-7, atol=1e-10)
    U_K[m] = u.reshape(nocc, nvir)

For a closed-shell reference the α\alpha and β\beta responses coincide, the systems are folded onto spatial orbital pairs of dimension noccnvirn_{\mathrm{occ}}n_{\mathrm{vir}}, which doubles the Coulomb and exchange–correlation kernel prefactors of Eq. (10) (the factors 2 become 4, with fxcστf_{\mathrm{xc}}^{\sigma\tau} replaced by the total-density kernel) while the exact-exchange terms retain the single factor cHFc_{\mathrm{HF}}. For an unrestricted reference the two spin channels remain coupled through the Coulomb and fxcαβf_{\mathrm{xc}}^{\alpha\beta} terms, and the same solver is applied to the block system

(MααMαβMβαMββ)(UαUβ)=(RαRβ)(19)\begin{pmatrix} \mathbf{M}^{\alpha\alpha} & \mathbf{M}^{\alpha\beta} \\ \mathbf{M}^{\beta\alpha} & \mathbf{M}^{\beta\beta} \end{pmatrix} \begin{pmatrix} \mathbf{U}^{\alpha} \\ \mathbf{U}^{\beta} \end{pmatrix} = \begin{pmatrix} \mathbf{R}^{\alpha} \\ \mathbf{R}^{\beta} \tag*{(19)} \end{pmatrix}

of dimension noccαnvirα+noccβnvirβn_{\mathrm{occ}}^{\alpha}n_{\mathrm{vir}}^{\alpha} + n_{\mathrm{occ}}^{\beta}n_{\mathrm{vir}}^{\beta}, so that each orbital mm requires two solves, with stacked right-hand sides (Kmf,αα,Kmf,αβ)(\mathbf{K}_{m}^{f,\alpha\alpha},\mathbf{K}_{m}^{f,\alpha\beta}) and (Kmf,βα,Kmf,ββ)(\mathbf{K}_{m}^{f,\beta\alpha},\mathbf{K}_{m}^{f,\beta\beta}), and each atom one solve with (SA,α,SA,β)(\mathbf{S}^{A,\alpha},\mathbf{S}^{A,\beta}). The Jacobi preconditioner generalizes trivially: the opposite-spin blocks contribute nothing to the diagonal of the block system, so d\mathbf{d} is the concatenation of the αα\alpha\alpha and ββ\beta\beta diagonals of Eq. (18). To preserve the invariance of the descriptors under rotations within degenerate shells, the right-hand sides and the resulting descriptor rows are additionally averaged over degenerate orbital sets detected from the orbital energies. Since all right-hand sides share the same operator and are mutually independent, the solves are embarrassingly parallel and distributed round-robin over the MPI ranks.

The same machinery yields the real-space descriptors. Evaluating fpσ(r)f_{p\sigma}(\mathbf{r}) or χ(r,r′)\chi(\mathbf{r},\mathbf{r}') of Eqs. (8) and (9) on a visualization grid requires the action of M−1\mathbf{M}^{-1} on the orbital-pair products sia(rg)=ϕi(rg)ϕa(rg)s_{ia}(\mathbf{r}_g)=\phi_i(\mathbf{r}_g)\phi_a(\mathbf{r}_g), so one MU = S solve is performed per point rg\mathbf{r}_g of the user-defined cube grid and the resulting U matrices are cached in the cub/ group of the checkpoint file. Any kernel value χ(rg,r)\chi(\mathbf{r}_g,\mathbf{r}) is then synthesized as a simple contraction of the cached U matrices with orbital products, so that repeated visualizations at different iso-values or probe points incur no further solver cost (§ 3.3).

Auxiliary functionality for analysis and visualization

Beyond the condensed descriptors, PyCDFT can evaluate the CDFT response functions on real-space grids for pictorial analysis. This cube analysis is carried out after the evaluation of the CDFT indices, so that all necessary matrices are already pre-computed and stored in the checkpoint file; one usually performs it at a later stage, once the condensed results have singled out the orbitals, atoms, or probe points worth visualizing. A built-in generator constructs a rectilinear cube grid from the molecular geometry, with a user-defined number of points along each axis and a padding distance around the atomic positions, and a companion writer exports any scalar field on this grid in the standard Gaussian cube format, so that iso-surfaces can be rendered directly in common viewers such as GaussView, VMD, or Avogadro. Three high-level functions cover the typical use cases. fukui_cube_file writes the orbital-resolved Fukui functions fpσ(r)f_{p\sigma}(\mathbf{r}) of Eq. (8) for a user-selected window of orbitals around the frontier. lrf_pc_cube_file evaluates the partially condensed linear response function,

χA(r)=−2∑σ∑iσaσUA,iσaσSϕiσ(r)ϕaσ(r),(20)\chi_A(\mathbf{r})=-2\sum_{\sigma}\sum_{i_\sigma a_\sigma}U^{S}_{A,i_\sigma a_\sigma}\phi_{i_\sigma}(\mathbf{r})\phi_{a_\sigma}(\mathbf{r}), \tag*{(20)}

i.e., the response of the density at r\mathbf{r} to a perturbation condensed on atom AA, obtained by contracting the stored US\mathbf{U}^{S} matrices of Eq. (14) with the orbital products on the cube grid. lrf_fp_cube_file evaluates the fixed-point linear response function for an arbitrary probe point r0\mathbf{r}_0,

χ(r0,r)=−2∑σ∑iσaσUr0,iσaσSϕiσ(r)ϕaσ(r),(21)\chi(\mathbf{r}_0,\mathbf{r})=-2\sum_{\sigma}\sum_{i_\sigma a_\sigma}U^{S}_{\mathbf{r}_0,i_\sigma a_\sigma}\phi_{i_\sigma}(\mathbf{r})\phi_{a_\sigma}(\mathbf{r}), \tag*{(21)}

where Ur0S\mathbf{U}^{S}_{\mathbf{r}_0} is the solution of Eq. (14) with the point right-hand side siσaσ(r0)=ϕiσ(r0)ϕaσ(r0)s_{i_\sigma a_\sigma}(\mathbf{r}_0)=\phi_{i_\sigma}(\mathbf{r}_0)\phi_{a_\sigma}(\mathbf{r}_0), taken from the U\mathbf{U} matrices stored in the cub/ group (§ 3.2).

All of these functions operate solely on the checkpoint file as they are pure post-processing steps that require neither the original wavefunction file nor any recomputation of the response matrices, so grids can be refined, probe points moved, or orbital windows changed at negligible cost after the expensive evaluation has finished. For more specialized analyses, the underlying routines also return the raw two-point kernel χ(r,r′)\chi(\mathbf{r},\mathbf{r}') on arbitrary user-supplied point sets, which can be processed further in Python, e.g., to integrate the kernel over custom regions or to construct domain-condensed variants beyond the built-in AIM schemes.

Examples

Ground state of H2_2O

As a first example, we evaluate the complete set of second-order CDFT descriptors for ground-state H2_2O. The reference wavefunction is converged in Gaussian at the PBE level and exported as a formatted checkpoint file (H2O_gs.fch); listings 2 and 3 then constitute the entire PyCDFT input. The molecule is reconstructed from the fchk file with MOKIT, and a restricted Kohn–Sham object is built merely as a container: a single SCF cycle initializes the quadrature grid and the checkpoint file, after which the molecular-orbital coefficients and energies are overwritten by the converged values read from the fchk file. The density functional approximation is specified as a list [exchange, correlation, family, cHF] using Libxc functional names—here PBE exchange and correlation with cHF=0c_{\mathrm{HF}} = 0, consistent with the pure GGA reference calculation. The calculation is organized in two short scripts that mirror the two steps of Figure 2. The first, genh5.py, prepares the HDF5 checkpoint input; since it creates the file with the serial HDF5 driver, it is executed as an ordinary serial Python script (listing 2).

Listing 2: genh5.py: preparation of the HDF5 checkpoint input for ground-state H2_2O, executed serially as python genh5.py.

from pyscf import dft

from mokit.lib.gaussian import load_mol_from_fch, mo_fch2py

from fileio import read_mo_energy, wfn_info


h5name = ’H2O_gs.h5’
fchname = ’H2O_gs.fch’
# density functional approximation: [exchange, correlation, family, c_HF]
dfa = ['GGA_X_PBE', 'GGA_C_PBE', 'GGA', 0.0]        # PBE

# rebuild the molecule and a mean-field container from the fchk file
mol = load_mol_from_fch(fchname)
mol.verbose = 3
mf = dft.RKS(mol)
mf.max_cycle = 1                    # container only: orbitals replaced below
mf.chkfile = h5name
mf.grids.atom_grid = (75, 434)
mf.kernel()

# overwrite with the converged wavefunction from the fchk file
# MO occupation
# default Aufbau principle
# MO coefficient
mf.mo_coeff = mo_fch2py(fchname)
# MO energy
mf.mo_energy = read_mo_energy(fchname)

# write the scf/ group of the checkpoint file
wfn_info(h5name, mf, dfa, part='MBIS')

The second script, cdft.py, performs the computationally intensive evaluation. It reads its entire input from the checkpoint file, fills the mat/ and cdft/ groups, and is launched under MPI through the pycdft.py launcher (§ 3), with the work distributed over the ranks as described in § 3.2 (listing 3).

Listing 3: cdft.py: parallel analytical CDFT evaluation, executed as mpirun -np 8 python pycdft.py cdft.py.

from acdft import eval_acdft
eval_acdft(’H2O_gs.h5’, memlimit=1024)    # memory limit in MB per process

Upon normal termination, the condensed descriptors χAB\chi_{AB}, fA,pf_{A,p}, and ηpq\eta_{pq} reside in the cdft/ group of H2O_gs.h5 and can be inspected with a few lines of h5py. One can write a simple script to extract the condensed orbital CDFT response functions as well as the traditional CDFT indices from the checkpoint as follows.

Listing 4: Extrating data from the h5 checkpoint file.

import h5py

with h5py.File(’H2O_gs.h5’, ’r’) as f:

    # orbital CDFT descriptors

    lrf = f[’cdft/lrf_a’][...]        # condensed linear response chi_AB
    fukui = f[’cdft/ff_a’][...]       # condensed orbital Fukui f_{A,p}
    eta = f[’cdft/eta_aa’][...]       # orbital hardness eta_pq

    # orbital indices

    occ = f[’scf/occ_a’][...]         # occupied MO indices
    vir = f[’scf/vir_a’][...]         # virtual MO indices


# traditional CDFT: the frontier limit p = f, i.e. dN = dn_f
homo, lumo = occ[-1], vir[0]          # HOMO, LUMO indices
fukui_minus = fukui[:, homo]          # condensed Fukui f_A^-
fukui_plus = fukui[:, lumo]           # condensed Fukui f_A^+
eta_minus = eta[homo, homo]           # hardness eta^-
eta_plus = eta[lumo, lumo]            # hardness eta^+

Singly excited state of NH3_3 via Δ\DeltaSCF

The second example demonstrates that PyCDFT is not limited to ground states: any single-determinant reference can be analyzed, including Δ\DeltaSCF solutions for excited states. Here the lowest singly excited singlet state of NH3_3 is converged in Q-Chem with the restricted open-shell Kohn–Sham (ROKS) approach at the PBE0 level, and the converged wavefunction is exported to the fchk format. A broken-symmetry unrestricted determinant is then constructed from the ROKS orbitals to represent the singlet excited-state density and its response. The preparation script (listing 5) accordingly differs from that of § 4.1 in three respects. First, an unrestricted container (UKS) is used, and the occupation vector is edited by hand to the open-shell singly excited configuration—one β\beta electron is moved from the HOMO to the LUMO—so that the broken-symmetry reference is presented to PyCDFT as an unrestricted wavefunction and the spin-resolved machinery of § 3.2 is engaged automatically. Second, the hybrid functional is specified through its combined Libxc name (HYB GGA XC PBEH, with the correlation entry set to None), so that the semilocal part of the kernel fxcf_{\mathrm{xc}} is returned with the correct internal scaling, while cHF=0.25c_{\mathrm{HF}} = 0.25 supplies the exact-exchange fraction entering Eq. (10). Third, the condensed descriptors are requested with the Hirshfeld partitioning, for which the spherically averaged pro-atom densities are generated on the fly from neutral-atom calculations with the same functional and basis set.

Listing 5: genh5.py: preparation of the checkpoint input for the broken-symmetry singly excited state of NH3\mathrm{NH}_3, executed serially as python genh5.py.

from pyscf import dft

from mokit.lib.gaussian import load_mol_from_fch, mo_fch2py

from fileio import read_mo_energy, wfn_info


h5name = ’NH3_bs.h5’                    # bs: broken-symmetry reference

fchname = ’NH3_bs.fch’


# hybrid functional via its combined Libxc name: PBE0

dfa = [’HYB_GGA_XC_PBEH’, None, ’GGA’, 0.25]


# rebuild the molecule and a mean-field container from the fchk file

mol = load_mol_from_fch(fchname)

mol.verbose = 3

mf = dft.UKS(mol)

mf.max_cycle = 1                       # container only: orbitals replaced below

mf.chkfile = h5name

mf.grids.atom_grid = (75, 434)
mf.kernel()

# singly excited configuration: promote one beta electron (HOMO -> LUMO)
mf.mo_occ[1][4] = 0
mf.mo_occ[1][5] = 1

# overwrite with the converged ROKS Delta-SCF wavefunction from the fchk file
mf.mo_coeff  = mo_fch2py(fchname)
mf.mo_energy = read_mo_energy(fchname)

# write the scf/ group of the checkpoint file
wfn_info(h5name, mf, dfa, part=’Hirshfeld’)

The evaluation script is identical to listing 3 and is not repeated. Because the reference is open-shell, the second step solves the coupled block system of Eq. (19), and the cdft/ group is populated with the spin-resolved descriptors, i.e., χABσ\chi_{AB}^{\sigma}, fA,pσf_{A,p}^{\sigma}, and the four spin blocks ηpqστ\eta_{pq}^{\sigma\tau} of the orbital hardness.

Cube files for iso-surface visualization

The final example illustrates the auxiliary functionality of § 3.3, using the checkpoint file produced in § 4.1. Since all required matrices are already stored, this is a pure post-processing step executed as a short serial script at any time after the evaluation. Each function generates the cube grid internally from the molecular geometry, with grid_point voxels along each axis and a padding of delta bohr around the atomic positions, and writes standard .cub files that can be opened directly in GaussView or VMD. In listing 6, the partially condensed linear response function χA(r)\chi_A(\mathbf{r}) of Eq. (20) is exported for the first two atoms (atom indices are zero-based), the fixed-point linear response function χ(r0,r)\chi(\mathbf{r}_0,\mathbf{r}) of Eq. (21) is evaluated for a perturbation placed at the origin, drawing on the U matrices stored in the cub/ group, and the orbital Fukui functions fp(r)f_p(\mathbf{r}) of Eq. (8) are written for a frontier window of window+1 orbitals on each side of the gap, here HOMO−1, HOMO, LUMO, and LUMO+1.

Listing 6: cube.py: post-processing export of real-space CDFT descriptors as Gaussian cube files, executed as python cube.py.

import numpy as np

import fileio

filename = ’H2O_gs.h5’

# partially condensed LRF chi_A(r) for the first two atoms (O and H)
fileio.lrf_pc_cube_file(filename, np.array([0, 1]), grid_point=(50, 50, 50),
    delta=5)

# fixed-point LRF chi(r0, r) with the perturbation placed at the origin
fileio.lrf_fp_cube_file(filename, np.array([0.0, 0.0, 0.0]))

# orbital Fukui functions f_p(r) for HOMO−1, HOMO, LUMO, LUMO+1
fileio.fukui_cube_file(filename, window=1, grid_point=(50, 50, 50), delta=5)

Conclusions

We have presented PyCDFT, a Python-scriptable library for the analytical evaluation of conceptual density (matrix) functional theory descriptors. From a single converged wavefunction, imported from essentially any electronic-structure package, the library evaluates the ground and excited states’ orbital-resolved and atom-condensed second-order descriptors—orbital hardness, Fukui functions, and the linear response function—without recourse to finite-difference protocols, for closed-shell as well as broken-symmetry open-shell references, and exports real-space descriptors for direct visualization. The worked examples show that a complete analysis requires only a few lines of user code. Beyond its immediate use in chemical reactivity studies, the analytical machinery opens several directions. The exact descriptors provide reference values against which the common approximate CDFT schemes can be benchmarked systematically, and the response quantities themselves may serve in density-based method development, e.g., in the construction and diagnosis of density functionals or as features for machine-learned reactivity models. On the code side, planned improvements include a hierarchy of cheaper approximations to the coupling matrix MM for large systems, GGA and meta-GGA kernels,[24] additional AIM partitionings, and extensions toward higher-order and field-dependent descriptors of conceptual density matrix functional theory; given its modular, library-first design, the functionality could also be merged into widely used packages such as PySCF or Psi4, bringing analytical CDFT to their broad user communities. We hope that a standardized, open implementation will lower the entry barrier for analytical CDFT and make new reactivity concepts easy to test against a common reference.

Acknowledgement

FDP acknowledges support of the Vrije Universiteit Brussel through a Strategic Research Program (SRP73) awarded to his research group. BW acknowledges the junior postdoctoral fellowship support from FWO research project grant 1225526N.

Data Availability

PyCDFT is free and open-source software, licensed under the Apache License, Version 2.0. Source code, installation instructions, worked examples with reference data, and detailed documentation are available at https://github.com/lucienwb/PyCDFT.

Figure 3 (PDF p. 29). Graphical abstract

References

  1. [1]1R. G. Parr and W. Yang, Density-Functional Theory of Atoms and Molecules (Oxford University Press, Walton Street, Oxford, United Kingdom, 1989).
  2. [2]2H. Chermette, “Chemical reactivity indexes in density functional theory”, J. Comput. Chem. 20, 129 (1999).doi.org/10.1002/(sici)1096-987x(19990115)20:1<129::aid-jcc13>3.0.co;2-a
  3. [3]3P. Geerlings, F. De Proft, and W. Langenaeker, “Conceptual density functional theory”, Chem. Rev. 103, 1793 (2003).
  4. [4]4P. W. Ayers, J. S. M. Anderson, and L. J. Bartolotti, “Perturbative perspectives on the chemical reaction prediction problem”, Int. J. Quantum Chem. 101, 520 (2005).DOI
  5. [5]5J. L. Gázquez, “Perspectives on the density functional theory of chemical reactivity”, J. Mex. Chem. Soc. 52, 3 (2008).DOI
  6. [6]6S. Liu, “Conceptual density functional theory and some recent developments”, Acta Phys.-Chim. Sin. 25, 590 (2009).DOI
  7. [7]7P. Geerlings, E. Chamorro, P. K. Chattaraj, F. De Proft, J. L. Gázquez, et al., “Conceptual density functional theory: Status, prospects, issues”, Theor. Chem. Acc. 139, 36 (2020).DOI
  8. [8]8S. Liu, Conceptual Density Functional Theory: Towards a New Chemical Reactivity Theory (Wiley-VCH, Weinheim, Germany, 2022).
  9. [9]9S. Liu, Exploring Chemical Concepts Through Theory and Computation (John Wiley & Sons, Hoboken, New Jersey, United States, 2024).DOI
  10. [10]10R. G. Parr, R. A. Donnelly, M. Levy, and W. E. Palke, “Electronegativity: The density functional viewpoint”, J. Chem. Phys. 68, 3801 (1978).DOI
  11. [11]11R. S. Mulliken, “A new electroaffinity scale; Together with data on valence states and on valence ionization potentials and electron affinities”, J. Chem. Phys. 2, Electroaffinity, 782 (1934).DOI
  12. [12]12R. P. Iczkowski and J. L. Margrave, “Electronegativity”, J. Am. Chem. Soc. 83, 3547 (1961).DOI
  13. [13]13R. G. Pearson, “Hard and soft acids and bases”, J. Am. Chem. Soc. 85, 3533 (1963).
  14. [14]14R. G. Parr and R. G. Pearson, “Absolute hardness: Companion parameter to absolute electronegativity”, J. Am. Chem. Soc. 105, 7512 (1983).DOI
  15. [15]15R. G. Parr and P. K. Chattaraj, “Principle of maximum hardness”, J. Am. Chem. Soc. 113, 1854 (1991).DOI
  16. [16]16R. G. Pearson, “The principle of maximum hardness”, Acc. Chem. Res. 26, MHP, 250 (1993).DOI
  17. [17]17R. G. Pearson, Chemical Hardness: Applications from Molecules to Solids, MHP (Wiley-VCH, Weinheim, Germany, 1997).
  18. [18]18R. G. Parr and W. Yang, “Density functional approach to the frontier-electron theory of chemical reactivity”, J. Am. Chem. Soc. 106, 4049 (1984).DOI
  19. [19]W. Yang, R. G. Parr, and R. Pucci, “Electron density, Kohn–Sham frontier orbitals, and Fukui functions”, J. Chem. Phys. 81, 2862 (1984).
  20. [20]N. Sablon, F. De Proft, P. W. Ayers, and P. Geerlings, “Computing second-order functional derivatives with respect to the external potential”, J. Chem. Theory Comput. 6, 3671 (2010).DOI
  21. [21]Z. Boisdenghien, C. Van Alsenoy, F. De Proft, and P. Geerlings, “Evaluating and interpreting the chemical relevance of the linear response kernel for atoms”, J. Chem. Theory Comput. 9, 1007 (2013).DOI
  22. [22]P. Geerlings, S. Fias, Z. Boisdenghien, and F. De Proft, “Conceptual DFT: Chemistry from the linear response function”, Chem. Soc. Rev. 43, 4989 (2014).DOI
  23. [23]S. Fias, P. W. Ayers, F. De Proft, and P. Geerlings, “Properties of the density functional response kernels and its implications on chemistry”, J. Chem. Phys. 157, 114102 (2022).DOI
  24. [24]B. Wang, P. Geerlings, C. Van Alsenoy, F. Heider-Zadeh, P. W. Ayers, et al., “Investigating the linear response function under approximations following the coupled-perturbed approach for atoms and molecules”, J. Chem. Theory Comput. 19, 3223 (2023).DOI
  25. [25]P. Geerlings and F. De Proft, “Conceptual DFT: The chemical relevance of higher response functions”, Phys. Chem. Chem. Phys. 10, 3028 (2008).DOI
  26. [26]W. Yang and W. J. Mortier, “The use of global and local molecular parameters for the analysis of the gas-phase basicity of amines”, J. Am. Chem. Soc. 108, 5708 (1986).DOI
  27. [27]B. Wang, C. Rong, P. K. Chattaraj, and S. Liu, “A comparative study to predict regioselectivity, electrophilicity and nucleophilicity with Fukui function and Hirshfeld charge”, Theor. Chem. Acc. 138, 124 (2019).DOI
  28. [28]A. J. Cohen, P. Mori-Sánchez, and W. Yang, “Insights into current limitations of density functional theory”, Science 321, 792 (2008).DOI
  29. [29]A. J. Cohen, P. Mori-Sánchez, and W. Yang, “Challenges for density functional theory”, Chem. Rev. 112, 289 (2012).DOI
  30. [30]B. Wang, P. Geerlings, F. Heidar-Zadeh, P. W. Ayers, and F. De Proft, “Slope of the delocalization function is proportional to analytical hardness”, J. Phys. Chem. Lett. 15, 11259 (2024).DOI
  31. [31]B. Wang, P. Geerlings, S. Liu, and F. De Proft, “Extending the scope of conceptual density functional theory with second order analytical methodologies”, J. Chem. Theory Comput. 20, 1169 (2024).DOI
  32. [32]P. Bultinck, C. Cardenas, P. Fuentealba, P. A. Johnson, and P. W. Ayers, “How to compute the Fukui matrix and function for systems with (quasi-)degenerate states”, J. Chem. Theory Comput. 10, 202 (2014).DOI
  33. [33]N. Sablon, F. De Proft, and P. Geerlings, “The linear response kernel of conceptual DFT as a measure of electron delocalisation”, Chem. Phys. Lett. 498, 192 (2010).DOI
  34. [34]N. Sablon, F. De Proft, and P. Geerlings, “The linear response kernel: Inductive and resonance effects quantified”, J. Phys. Chem. Lett. 1, 1228 (2010).DOI
  35. [35]W. Yang, A. J. Cohen, F. De Proft, and P. Geerlings, “Analytical evaluation of Fukui functions and real-space linear response function”, J. Chem. Phys. 136, 144110 (2012).DOI
  36. [36]S. Fias, F. Heidar-Zadeh, P. Geerlings, and P. W. Ayers, “Chemical transferability of functional groups follows from the nearsightedness of electronic matter”, Proc. Natl. Acad. Sci. U.S.A. 114, 11633 (2017).DOI
  37. [37]Y. Mei, Z. Chen, and W. Yang, “Exact second-order corrections and accurate quasiparticle energy calculations in density functional theory”, J. Phys. Chem. Lett. 12, 7236 (2021).
  38. [38]D. Sheppard, G. Henkelman, and O. A. von Lilienfeld, “Alchemical derivatives of reaction energetics”, J. Chem. Phys. 133, 084104 (2010).DOI
  39. [39]R. Balawender, M. Lesiuk, F. De Proft, and P. Geerlings, “Exploring chemical space with alchemical derivatives: bn-simultaneous substitution patterns in c60”, J. Chem. Theory Comput. 14, 1154 (2018).DOI
  40. [40]T. Clarys, T. Stuyver, F. De Proft, and P. Geerlings, “Extending conceptual DFT to include additional variables: Oriented external electric field”, Phys. Chem. Chem. Phys. 23, 990 (2021).DOI
  41. [41]R. Francotte, T. J. P. Irons, A. M. Teale, F. De Proft, and P. Geerlings, “Extending conceptual DFT to include external variables: The influence of magnetic fields”, Chem. Sci. 13, 5311 (2022).DOI
  42. [42]M. Wibowo-Teale, B. C. Huynh, A. M. Wibowo-Teale, F. De Proft, and P. Geerlings, “Symmetry and reactivity of π-systems in electric and magnetic fields: A perspective from conceptual DFT”, Phys. Chem. Chem. Phys. 26, 15156 (2024).
  43. [43]T. Bettens, M. Alonso, P. Geerlings, and F. De Proft, “Implementing the mechanical force into the conceptual DFT framework: Understanding and predicting molecular mechanochemical properties”, Phys. Chem. Chem. Phys. 21, 7378 (2019).
  44. [44]T. Bettens and F. De Proft, “Mechanical Force”, in Conceptual Density Functional Theory, edited by S. Liu (Wiley-VCH, Weinheim, Germany, 2022), pp. 245–262.DOI
  45. [45]J. Eeckhoudt, T. Bettens, P. Geerlings, R. Cammi, B. Chen, et al., “Conceptual density functional theory under pressure: Part I. XP-PCM method applied to atoms”, Chem. Sci. 13, 9329 (2022).DOI
  46. [46]J. Eeckhoudt, M. Alonso, P. Geerlings, and F. De Proft, “Bond lengths and dipole moments of diatomic molecules under isotropic pressure with the XP-PCM and GOSTSHYP models”, J. Chem. Theory Comput. 20, 7430 (2024).DOI
  47. [47]B. Kaduk, T. Kowalczyk, and T. Van Voorhis, “Constrained density functional theory”, Chem. Rev. 112, 321 (2012).DOI
  48. [48]B. Wang, P. Geerlings, F. Heidar-Zadeh, P. W. Ayers, and F. De Proft, “Exploring intrinsic bond properties with the Fukui matrix from conceptual density matrix functional theory”, J. Chem. Theory Comput. 21, 1695 (2025).DOI
  49. [49]G.-H. Liu, “Orbital hardness matrix and Fukui indices, their direct self-consistent-field calculations, and a derivation of localized Kohn–Sham orbitals”, J. Chem. Phys. 106, 165 (1997).DOI
  50. [50]B. Wang, P. Geerlings, and F. De Proft, “Exploring chemical concepts and reactivities from conceptual density functional theory in excited states via ΔSCF approach”, In revision (2026).DOI
  51. [51]M. Franco-Pérez, F. Heidar-Zadeh, P. W. Ayers, F. De Proft, A. Vela, et al., “Temperature and external fields in conceptual density functional theory”, Chem. Sci. 15, 20090 (2024).
  52. [52]G. Hoffmann, O. Aroule, R. Grincourt, H. Chermette, and C. Morell, “Extending conceptual dft to fourth order: from quartic curvature to third-order fukui response”, J. Chem. Theory Comput. 22, 3484 (2026).DOI
  53. [53]O. X. Guerrero-Gutiérrez, A. Acosta-García, and A. Vela, “Pycrdft: a python package to evaluate chemical reactivity descriptors within conceptual dft”, J. Chem. Sci. 138, 23 (2026).
  54. [54]C. Morell, A. Grand, and A. Toro-Labbé, “New dual descriptor for chemical reactivity”, J. Phys. Chem. A 109, 205 (2005).pubmed.ncbi.nlm.nih.gov/16839107
  55. [55]G. Acke, D. Van Hende, X. De Vriendt, and P. Bultinck, “Extending conceptual density functional theory toward first-order reduced density matrices: an open subsystems viewpoint on the fukui matrix”, J. Chem. Theory Comput. 19, 5418 (2023).DOI
  56. [56]A. Görling, “Density-functional theory beyond the Hohenberg–Kohn theorem”, Phys. Rev. A 59, 3359 (1999).DOI
  57. [57]E. Trushin, O. Bertleff, and A. Görling, “Potential-averaged Δscf methods: underlying formalism and evaluation of accuracy of excitation energies”, J. Chem. Theory Comput. 22, 8324 (2026).DOI
  58. [58]W. Yang and P. W. Ayers, “Foundation for the Δscf approach in density functional theory”, arXiv, 2403.04604 (2024).arxiv.org/abs/2403.04604
  59. [59]Q. Sun, T. C. Berkelbach, N. S. Blunt, G. H. Booth, S. Guo, et al., “PySCF: The Python-based simulations of chemistry framework”, Wiley Interdiscip. Rev. Comput. Mol. Sci. 8, e1340 (2018).arxiv.org/abs/1701.08223
  60. [60]Q. Sun, X. Zhang, S. Banerjee, P. Bao, M. Barbry, et al., “Recent developments in the PySCF program package”, J. Chem. Phys. 153, 024109 (2020).DOI
  61. [61]S. Lehtola, C. Steigemann, M. J. T. Oliveira, and M. A. L. Marques, “Recent developments in libxc — A comprehensive library of functionals for density functional theory”, SoftwareX 7, 1 (2018).DOI
  62. [62]C. R. Harris, K. J. Millman, S. J. van der Walt, R. Gommers, P. Virtanen, et al., “Array programming with NumPy”, Nature 585, 357 (2020).
  63. [63]P. Virtanen, R. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, et al., “SciPy 1.0: fundamental algorithms for scientific computing in Python”, Nat. Methods 17, 261 (2020).
  64. [64]64T. Verstraelen, S. Vandenbrande, F. Heidar-Zadeh, L. Vandu​yfhuys, V. Van Speybroeck, et al., “Minimal basis iterative stockholder: Atoms in molecules for force-field development”, J. Chem. Theory Comput. 12, 3894 (2016).DOI
  65. [65]65A. Tehrani, X. D. Yang, M. Martínez-González, L. Pujal, R. Hernández-Esparza, et al., “Grid: A Python library for molecular integration, interpolation, differentiation, and more”, J. Chem. Phys. 160, 172503 (2024).DOI
  66. [66]66L. Dalcin and Y. L. L. Fang, “mpi4py: Status update after 12 years of development”, Comput. Sci. Eng. 23, mpi4py, 47 (2021).DOI
  67. [67]67J. Zou, MOKIT: Molecular orbital kit, https://gitlab.com/jxzou/mokit, Accessed: 2026-01-01.
  68. [68]68T. Lu and F. Chen, “Multiwin: A multifunctional wavefunction analyzer”, J. Comput. Chem. 33, 580 (2012).DOI
  69. [69]69T. Lu, “A comprehensive electron wavefunction analysis toolbox for chemists, Multiwfn”, J. Chem. Phys. 161, 082503 (2024).DOI

Paper details

vlnc:W_xkuaggum
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 1

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Physics and Astronomy

Not recorded for this paper

View statement
Looking for related papers…
Contents