{ "cells": [ { "cell_type": "markdown", "source": [ "# Polarizability by linear response\n", "\n", "We compute the polarizability of a Helium atom. The polarizability\n", "is defined as the change in dipole moment\n", "$$\n", "\\mu = \\int r ρ(r) dr\n", "$$\n", "with respect to a small uniform electric field E = -x.\n", "\n", "We compute this in two ways: first by finite differences (applying a\n", "finite electric field), then by linear response. Note that DFTK is\n", "not really adapted to isolated atoms because it uses periodic\n", "boundary conditions. Nevertheless we can simply embed the Helium\n", "atom in a large enough box (although this is computationally wasteful).\n", "\n", "As in other tests, this is not fully converged, convergence\n", "parameters were simply selected for fast execution on CI," ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using DFTK\n", "using LinearAlgebra\n", "\n", "a = 10.\n", "lattice = a * I(3) # cube of a bohrs\n", "He = ElementPsp(:He, psp=load_psp(\"hgh/lda/He-q2\"))\n", "atoms = [He => [[1/2; 1/2; 1/2]]] # Helium at the center of the box\n", "\n", "kgrid = [1, 1, 1] # no k-point sampling for an isolated system\n", "Ecut = 30\n", "tol = 1e-8\n", "\n", "# dipole moment of a given density (assuming the current geometry)\n", "function dipole(basis, ρ)\n", " rr = [a * (r[1] - 1/2) for r in r_vectors(basis)]\n", " sum(rr .* ρ) * basis.dvol\n", "end;" ], "metadata": {}, "execution_count": 1 }, { "cell_type": "markdown", "source": [ "## Using finite differences\n", "We first compute the polarizability by finite differences.\n", "First compute the dipole moment at rest:" ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "n Energy Eₙ-Eₙ₋₁ ρout-ρin α Diag\n", "--- --------------- --------- -------- ---- ----\n", " 1 -2.769623389309 NaN 2.95e-01 0.80 8.0\n", " 2 -2.771174788933 -1.55e-03 5.19e-02 0.80 1.0\n", " 3 -2.771212876710 -3.81e-05 1.07e-03 0.80 2.0\n", " 4 -2.771212980625 -1.04e-07 1.78e-04 0.80 2.0\n", " 5 -2.771212981724 -1.10e-09 3.48e-05 0.80 2.0\n" ] }, { "output_type": "execute_result", "data": { "text/plain": "-0.0001361390138976282" }, "metadata": {}, "execution_count": 2 } ], "cell_type": "code", "source": [ "model = model_LDA(lattice, atoms; symmetries=false)\n", "basis = PlaneWaveBasis(model; Ecut, kgrid)\n", "res = self_consistent_field(basis, tol=tol)\n", "μref = dipole(basis, res.ρ)" ], "metadata": {}, "execution_count": 2 }, { "cell_type": "markdown", "source": [ "Then in a small uniform field:" ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "n Energy Eₙ-Eₙ₋₁ ρout-ρin α Diag\n", "--- --------------- --------- -------- ---- ----\n", " 1 -2.770002807670 NaN 2.99e-01 0.80 9.0\n", " 2 -2.771276930867 -1.27e-03 4.75e-02 0.80 1.0\n", " 3 -2.771299473233 -2.25e-05 4.39e-03 0.80 2.0\n", " 4 -2.771300361930 -8.89e-07 9.54e-05 0.80 2.0\n", " 5 -2.771300362350 -4.20e-10 1.03e-05 0.80 2.0\n" ] }, { "output_type": "execute_result", "data": { "text/plain": "0.01761830703783743" }, "metadata": {}, "execution_count": 3 } ], "cell_type": "code", "source": [ "ε = .01\n", "model_ε = model_LDA(lattice, atoms; extra_terms=[ExternalFromReal(r -> -ε * (r[1] - a/2))],\n", " symmetries=false)\n", "basis_ε = PlaneWaveBasis(model_ε; Ecut, kgrid)\n", "res_ε = self_consistent_field(basis_ε, tol=tol)\n", "με = dipole(basis_ε, res_ε.ρ)" ], "metadata": {}, "execution_count": 3 }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reference dipole: -0.0001361390138976282\n", "Displaced dipole: 0.01761830703783743\n", "Polarizability : 1.7754446051735058\n" ] } ], "cell_type": "code", "source": [ "polarizability = (με - μref) / ε\n", "\n", "println(\"Reference dipole: $μref\")\n", "println(\"Displaced dipole:$με\")\n", "println(\"Polarizability : $polarizability\")" ], "metadata": {}, "execution_count": 4 }, { "cell_type": "markdown", "source": [ "The result on more converged grids is very close to published results.\n", "For example [DOI 10.1039/C8CP03569E](https://doi.org/10.1039/C8CP03569E)\n", "quotes **1.65** with LSDA and **1.38** with CCSD(T)." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Using linear response\n", "Now we use linear response to compute this analytically; we refer to standard\n", "textbooks for the formalism. In the following, \\chi_0 is the\n", "independent-particle polarizability, and K the\n", "Hartree-exchange-correlation kernel. We denote with \\delta V_{\\rm ext} an external\n", "perturbing potential (like in this case the uniform electric field). Then:\n", "$$\n", "\\delta\\rho = \\chi_0 \\delta V = \\chi_0 (\\delta V_{\\rm ext} + K \\delta\\rho),\n", "$$\n", "which implies\n", "$$\n", "\\delta\\rho = (1-\\chi_0 K)^-1 \\chi_0 \\delta V_{\\rm ext}.\n", "$$\n", "From this we identify the polarizability operator to be \\chi = (1-\\chi_0 K)^{-1} \\chi_0.\n", "Numerically, we apply \\chi to \\delta V = -x by solving a linear equation\n", "(the Dyson equation) iteratively." ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARNING: using KrylovKit.basis in module ##299 conflicts with an existing identifier.\n", "┌ Info: GMRES linsolve in iter 1; step 1: normres = 2.491879897268e-01\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:55\n", "┌ Info: GMRES linsolve in iter 1; step 2: normres = 3.716159829337e-03\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 1; step 3: normres = 1.189406142900e-04\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 1; step 4: normres = 6.519644366479e-06\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 1; step 5: normres = 6.321696599733e-07\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 1; step 6: normres = 1.868577004875e-09\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 1; step 7: normres = 1.415566786213e-11\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 1; step 8: normres = 1.216373501087e-12\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 1; finished at step 8: normres = 1.216373501087e-12\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:96\n", "┌ Info: GMRES linsolve in iter 2; step 1: normres = 9.623760450371e-07\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:55\n", "┌ Info: GMRES linsolve in iter 2; step 2: normres = 3.872342023505e-08\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 2; step 3: normres = 2.242307819033e-09\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 2; step 4: normres = 1.947660226669e-11\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 2; step 5: normres = 6.561759879075e-13\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 2; finished at step 5: normres = 6.561759879075e-13\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:96\n", "┌ Info: GMRES linsolve in iter 3; step 1: normres = 1.869676299332e-11\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:55\n", "┌ Info: GMRES linsolve in iter 3; step 2: normres = 1.075829261256e-12\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:89\n", "┌ Info: GMRES linsolve in iter 3; finished at step 2: normres = 1.075829261256e-12\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:96\n", "┌ Info: GMRES linsolve converged at iteration 3, step 2:\n", "│ * norm of residual = 1.071364497536787e-12\n", "│ * number of operations = 17\n", "└ @ KrylovKit /home/runner/.julia/packages/KrylovKit/YPiz7/src/linsolve/gmres.jl:127\n", "Non-interacting polarizability: 1.9277533317790276\n", "Interacting polarizability: 1.775160610781069\n" ] } ], "cell_type": "code", "source": [ "using KrylovKit\n", "\n", "# Apply (1- χ0 K)\n", "function dielectric_operator(δρ)\n", " δV = apply_kernel(basis, δρ; ρ=res.ρ)\n", " χ0δV = apply_χ0(res.ham, res.ψ, res.εF, res.eigenvalues, δV)\n", " δρ - χ0δV\n", "end\n", "\n", "# δVext is the potential from a uniform field interacting with the dielectric dipole\n", "# of the density.\n", "δVext = [-a * (r[1] - 1/2) for r in r_vectors(basis)]\n", "δVext = cat(δVext; dims=4)\n", "\n", "# Apply χ0 once to get non-interacting dipole\n", "δρ_nointeract = apply_χ0(res.ham, res.ψ, res.εF, res.eigenvalues, δVext)\n", "\n", "# Solve Dyson equation to get interacting dipole\n", "δρ = linsolve(dielectric_operator, δρ_nointeract, verbosity=3)[1]\n", "\n", "println(\"Non-interacting polarizability:$(dipole(basis, δρ_nointeract))\")\n", "println(\"Interacting polarizability: \$(dipole(basis, δρ))\")" ], "metadata": {}, "execution_count": 5 }, { "cell_type": "markdown", "source": [ "As expected, the interacting polarizability matches the finite difference\n", "result. The non-interacting polarizability is higher." ], "metadata": {} } ], "nbformat_minor": 3, "metadata": { "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.7.0" }, "kernelspec": { "name": "julia-1.7", "display_name": "Julia 1.7.0", "language": "julia" } }, "nbformat": 4 }