Skip to content

Commit d957c45

Browse files
authored
DFT Notes (#44)
* backup notes * back up notes * good enough for now * try again * fixed?
1 parent 2d94e0d commit d957c45

4 files changed

Lines changed: 301 additions & 3 deletions

File tree

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
~ limitations under the License.
1515
-->
1616

17-
General instructions for building documentation found throughout the NWChemEx project are available at:
17+
General instructions for building documentation found throughout the NWChemEx
18+
project are available at:
1819
https://github.com/NWChemEx/NWChemEx/blob/master/docs/README.md
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
.. Copyright 2025 NWChemEx-Project
2+
..
3+
.. Licensed under the Apache License, Version 2.0 (the "License");
4+
.. you may not use this file except in compliance with the License.
5+
.. You may obtain a copy of the License at
6+
..
7+
.. http://www.apache.org/licenses/LICENSE-2.0
8+
..
9+
.. Unless required by applicable law or agreed to in writing, software
10+
.. distributed under the License is distributed on an "AS IS" BASIS,
11+
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
.. See the License for the specific language governing permissions and
13+
.. limitations under the License.
14+
15+
#########
16+
DFT Notes
17+
#########
18+
19+
.. |e_xc| replace:: :math:`E^{XC}\left[\rho\left(\vec{r}\right)\right]`
20+
.. |v_xc| replace:: :math:`V^{XC}\left[\rho\left(\vec{r}\right)\right]`
21+
.. |edensity| replace:: :math:`f\left[\rho\left(\vec{r}\right), \cdots\right]`
22+
.. |eparticle| replace:: :math:`\epsilon\left[\rho\left(\vec{r}\right), \cdots\right]`
23+
.. |rho| replace:: :math:`\rho\left(\vec{r}\right)`
24+
.. |rho_i| replace:: :math:`\rho_i`
25+
.. |drho| replace:: :math:`\left|\bigtriangledown\rho\left(\vec{r}\right)\right|^2`
26+
.. |dr| replace:: :math:`d\vec{r}`
27+
28+
These are notes.
29+
30+
Algorithmically, DFT will differ from Hartee-Fock primarily in the fact that we
31+
need to compute two additional quantities:
32+
33+
1. the exchange-correlation (XC) energy, |e_xc|, and
34+
2. the XC potential, |v_xc|,
35+
36+
both of which are functionals of the electron density of the system, |rho|.
37+
By definition, |v_xc| is:
38+
39+
.. math::
40+
41+
\newcommand{\density}{\rho\left(\vec{r}\right)}
42+
\newcommand{\exc}[1]{E^{XC}\left[#1\right]}
43+
\newcommand{\vxc}[1]{V^{XC}\left[#1\right]}
44+
45+
\vxc{\density} \equiv
46+
\frac{\partial \exc{\density}}{\partial \density}
47+
48+
or rearranging for |e_xc|:
49+
50+
.. math::
51+
52+
\exc{\density} = \int \vxc{\density}\density d\vec{r}.
53+
54+
Conceptually, |e_xc| is the XC contribution to the electronic energy and
55+
|v_xc| is the potential needed to make the non-interacting system have the same
56+
density as the real system. Unfortunately, we do not know the analytic form of
57+
|e_xc| (or equivalently |v_xc|) and likely never will.
58+
59+
To make progress, we need to introduce an ansantze for either |e_xc| or |v_xc|.
60+
To do this we define a quantity |edensity| called the XC energy density
61+
which is the XC energy per infinitesimal volume |dr|. In terms of
62+
|edensity|, |e_xc| is written as:
63+
64+
.. math::
65+
66+
\newcommand{\edensity}[1]{f\left[#1\right]}
67+
\newcommand{\eparticle}[1]{\epsilon\left[#1\right]}
68+
69+
\exc{\density} = \int \edensity{\density,\cdots} d\vec{r}.
70+
71+
Related to |edensity| is a quantity |eparticle| which is the XC energy per
72+
unit particle. The exact relationship between the two is:
73+
74+
.. math::
75+
76+
\edensity{\density,\cdots} = \eparticle{\density,\cdots}\density.
77+
78+
It should be noted that, unlike |v_xc| and |e_xc|, |edensity| and |eparticle|
79+
will in general depend on additional functionals beyond the density.
80+
81+
.. warning::
82+
83+
Colloquially speaking, "a DFT functional" (e.g., when someone says they
84+
used "the BLYP DFT functional") can refer to the analytic form of |edensity|
85+
or |eparticle|. Making matters worse, :math:`\epsilon` is commonly used to
86+
denote both quantities. When comparing equations it is critical to
87+
distinguish between these two quantities.
88+
89+
XC functionals are typically classified by the parameters that |edensity| or
90+
|eparticle| depend on. More specifically dependence on:
91+
92+
- only |rho| defines the local density approximation (LDA),
93+
- |rho| and |drho| (the square of the gradient of |rho|) defines the
94+
generalized gradient approximation (GGA), and
95+
- |rho|, |drho|, the Laplacian of |rho|, and the kinetic energy density defines
96+
a meta GGA.
97+
98+
For an LDA we have:
99+
100+
.. math::
101+
102+
\vxc{\density} =& \frac{\partial \exc{\density}}{\partial \density}\\
103+
=& \frac{\partial \edensity{\density}}{\partial \density}
104+
105+
*******************
106+
Introduction of AOs
107+
*******************
108+
109+
In Kohn-Sham DFT we solve the Kohn-Sham equations in an orbital basis that is
110+
obtained as a linear combination of atomic orbitals (AOs). Assume that there
111+
are :math:`N_b` AOs and let :math:`\phi_\mu\left(\vec{r}\right)` be the
112+
:math:`\mu`-th AO. The equation for |e_xc| remains unchanged other than |rho|
113+
is now:
114+
115+
.. math::
116+
\newcommand{\bf}[1]{\phi_{#1}\left(\vec{r}\right)}
117+
118+
\density = \sum_{\mu}^{N_b}\sum_{\nu}^{N_b} \bf{\mu}P_{\mu\nu}\bf{\nu}
119+
120+
where :math:`P_{\mu\nu}` is the :math:`\mu\nu`-th element of the atomic
121+
density matrix. In the AO basis set the :math:`\mu\nu`-th element of |v_xc| is:
122+
123+
.. math::
124+
125+
V^{XC}_{\mu\nu} = \int \bf{\mu} \vxc{\density} \bf{\nu} d\vec{r}.
126+
127+
In the LDA this becomes:
128+
129+
.. math::
130+
131+
V^{XC}_{\mu\nu} = \int \bf{\mu}
132+
\frac{\partial \edensity{\density}}{\partial \density} \bf{\nu} d\vec{r}.
133+
134+
For most DFT functionals, analytic solutions for the above integrals are not
135+
known and |e_xc| and |v_xc| must be evaluated by quadrature.
136+
137+
**************************
138+
Introduction of Quadrature
139+
**************************
140+
141+
In solving an integral by quadrature, we make the following approximation:
142+
143+
.. math::
144+
145+
\int g(\vec{r}) d\vec{r} \approx \sum_{i=1}^{N_g} w_i g(\vec{r_i}).
146+
147+
That is we define a quadrature rule :math:`\mathcal{Q}` which is a set of
148+
:math:`N_g` pairs of the form :math:`\lbrace w_i, \vec{r}_i\rbrace`. Here,
149+
:math:`w_i` and :math:`\vec{r_i}` are respectively the quadrature weight and
150+
real-space location of the :math:`i`-th grid point.
151+
152+
At this point it is helpful to define:
153+
154+
.. math::
155+
156+
\newcommand{\densityg}[1]{\rho_{#1}}
157+
\newcommand{\bfg}[1]{\phi_{#1}}
158+
159+
160+
\densityg{i}\equiv&\rho\left(\vec{r_i}\right)\\
161+
\bfg{\mu i}\equiv&\phi_{\mu}\left(\vec{r_i}\right)
162+
163+
which respectively are the values of the density and the :math:`\mu`-th AO
164+
evaluated at the :math:`i`-th grid point. Similarly, we define:
165+
166+
.. math::
167+
168+
\newcommand{\edensityg}[1]{f_{#1}}
169+
\newcommand{\dedensitygdrho}[1]{f_{#1}^{\left(\rho\right)}}
170+
171+
\edensityg{i}\equiv&\edensity{\densityg{i}}\\
172+
\dedensitygdrho{i}\equiv&
173+
\left.
174+
\frac{\partial \edensity{\density{}}}
175+
{\partial \density{}}
176+
\right|_{\density{}=\densityg{i}}
177+
178+
which are the energy density, and the "derivative of the energy density with
179+
respect to the density" evaluated at |rho_i|.
180+
181+
Using these quantities, |rho_i| is then given by:
182+
183+
.. math::
184+
185+
\densityg{i} =& \sum_{\mu}^{N_b}
186+
\sum_{\nu}^{N_b} \bfg{\mu i}P_{\mu \nu}\bfg{\nu i}\\
187+
=& \sum_{\mu}^{N_b} \bfg{\mu i}X_{\mu i}
188+
189+
where in the second line we defined the common intermediate (the collocation
190+
matrix):
191+
192+
.. math::
193+
194+
X_{\mu i} = \sum_{\nu}^{N_b} P_{\mu\nu}\bfg{\nu i}
195+
196+
Using :math:`\mathcal{Q}`, |e_xc| becomes:
197+
198+
.. math::
199+
200+
\exc{\density{}} = \sum_i^{N_g} w_i\edensityg{i}
201+
202+
and |v_xc| becomes:
203+
204+
.. math::
205+
206+
V_{\mu\nu}^{XC} =&
207+
\sum_i^{N_g} w_i \bfg{\mu i} \dedensitygdrho{i} \bfg{\nu i}\\
208+
=& \sum_i^{N_g} w_i \bfg{\mu i} Z_{\nu i}
209+
210+
where we defined the intermediate:
211+
212+
.. math::
213+
214+
Z_{\mu i} =\dedensitygdrho{i} \bfg{\mu i}.
215+
216+
***********************
217+
As a Sparse Map Problem
218+
***********************
219+
220+
While the last sections have described DFT as a tensor problem it's usually not
221+
solved as one. DFT is not usually treated as a tensor problem because:
222+
223+
- Large tensors. Grids minimally use about 1000 grid points per atom (higher-
224+
quality grids tend to be order 10,000) and most AO basis sets have order 10
225+
basis functions per atom. Tensors like :math:`\phi_{\mu i}` then have
226+
minimally "10,000 times number of atoms squared" elements, meaning the tensor
227+
for 100 atoms already requires gigabytes of memory.
228+
- Sparsity. Most DFT quantities are local. So if basis functions for a tensor
229+
element are spatially far a part, the element is usually close to zero.
230+
231+
To describe the sparsity we introduce sparse maps. Given two basis sets,
232+
:math:`A` and :math:`B`, the sparse map :math:`L` maps each basis
233+
function in :math:`A` to a subset of the basis functions in :math:`B`. Assume
234+
we have some tensor with elements :math:`T_{ab}` where :math:`a` indexes basis
235+
functions in :math:`A` and :math:`b` indexes basis functions in :math:`B`.
236+
For a given value of :math:`a`, the non-zero elements of :math:`T_{ab}` are
237+
those such that :math:`b` is in :math:`L(a)`.
238+
239+
In DFT, we use atom-centered grids and AOs. It is therefore common to define
240+
sparse maps :math:`L(A\rightarrow i)` and :math:`L(A\rightarrow \mu)` which
241+
respectively map atom indices to grid points and atom indices to AOs. Using
242+
these maps the equation for the density becomes:
243+
244+
.. math::
245+
246+
\densityg{i_A} = \sum_{\mu_A} \bfg{\mu_A i_A}X_{\mu_A i_A}
247+
248+
where an index like :math:`i_A` is shorthand for restricting the value of
249+
:math:`i` to those afforded by the sparse map :math:`L(A\rightarrow i)`.
250+
Applying the same logic to the other DFT quantities:
251+
252+
.. math::
253+
254+
X_{\mu_A i_A} =& \sum_{\nu_A} P_{\mu_A\nu_A}\bfg{\nu_A i_A}\\
255+
Z_{\mu_A i_A} =& \dedensitygdrho{i_A} \bfg{\mu_A i_A}\\
256+
V_{\mu_A\nu_A}^{XC} =& \sum_{i_A} w_{i_A}\bfg{\mu_A i_A} Z_{\nu_A i_A}.
257+
258+
Finally, the equation for |e_xc| becomes:
259+
260+
.. math::
261+
262+
\exc{\density{}} = \sum_{A}\sum_{i_A} w_{i_A}\edensityg{i_A}
263+
264+
Of note, for a given grid we expect the number of grid points associated with
265+
an atom to be roughly constant. Similarly, for a given AO basis set we expect
266+
the number of AOs associated with an atom to also be roughly constant. This
267+
means that cost to form all quantities will scale linearly with the number of
268+
atoms.

docs/source/background/index.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. Copyright 2025 NWChemEx-Project
2+
..
3+
.. Licensed under the Apache License, Version 2.0 (the "License");
4+
.. you may not use this file except in compliance with the License.
5+
.. You may obtain a copy of the License at
6+
..
7+
.. http://www.apache.org/licenses/LICENSE-2.0
8+
..
9+
.. Unless required by applicable law or agreed to in writing, software
10+
.. distributed under the License is distributed on an "AS IS" BASIS,
11+
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
.. See the License for the specific language governing permissions and
13+
.. limitations under the License.
14+
15+
##########
16+
Background
17+
##########
18+
19+
.. toctree::
20+
:maxdepth: 2
21+
:caption: Contents
22+
23+
dft_notes

docs/source/index.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
.. See the License for the specific language governing permissions and
1313
.. limitations under the License.
1414
15-
#########
15+
###
1616
SCF
17-
#########
17+
###
18+
19+
.. toctree::
20+
:maxdepth: 2
21+
:caption: Contents
22+
23+
background/index
1824

1925
.. toctree::
2026
:maxdepth: 2

0 commit comments

Comments
 (0)