{ "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", "# Helium at the center of the box\n", "atoms = [ElementPsp(:He, psp=load_psp(\"hgh/lda/He-q2\"))]\n", "positions = [[1/2, 1/2, 1/2]]\n", "\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 = [(r[1] - a/2) for r in r_vectors_cart(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 log10(ΔE) log10(Δρ) Diag\n", "--- --------------- --------- --------- ----\n", " 1 -2.770368237156 -0.53 8.0\n", " 2 -2.771674719268 -2.88 -1.29 1.0\n", " 3 -2.771714591553 -4.40 -2.84 2.0\n", " 4 -2.771714713326 -6.91 -3.69 2.0\n", " 5 -2.771714715212 -8.72 -4.45 2.0\n" ] }, { "output_type": "execute_result", "data": { "text/plain": "-0.00013425080761394765" }, "metadata": {}, "execution_count": 2 } ], "cell_type": "code", "source": [ "model = model_LDA(lattice, atoms, positions; 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 log10(ΔE) log10(Δρ) Diag\n", "--- --------------- --------- --------- ----\n", " 1 -2.770487607571 -0.52 9.0\n", " 2 -2.771778814203 -2.89 -1.32 1.0\n", " 3 -2.771801233539 -4.65 -2.36 2.0\n", " 4 -2.771802073966 -6.08 -4.04 2.0\n", " 5 -2.771802074463 -9.30 -4.98 2.0\n" ] }, { "output_type": "execute_result", "data": { "text/plain": "0.017613515075492962" }, "metadata": {}, "execution_count": 3 } ], "cell_type": "code", "source": [ "ε = .01\n", "model_ε = model_LDA(lattice, atoms, positions;\n", " 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.00013425080761394765\n", "Displaced dipole: 0.017613515075492962\n", "Polarizability : 1.774776588310691\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 ##352 conflicts with an existing identifier.\n", "[ Info: GMRES linsolve in iter 1; step 1: normres = 2.493960994241e-01\n", "[ Info: GMRES linsolve in iter 1; step 2: normres = 3.766366718930e-03\n", "[ Info: GMRES linsolve in iter 1; step 3: normres = 2.845722327751e-04\n", "[ Info: GMRES linsolve in iter 1; step 4: normres = 4.694835823521e-06\n", "[ Info: GMRES linsolve in iter 1; step 5: normres = 1.093071004865e-08\n", "[ Info: GMRES linsolve in iter 1; step 6: normres = 2.074071454657e-10\n", "[ Info: GMRES linsolve in iter 1; step 7: normres = 1.075635404455e-11\n", "[ Info: GMRES linsolve in iter 1; step 8: normres = 1.123910552290e-13\n", "[ Info: GMRES linsolve in iter 1; finished at step 8: normres = 1.123910552290e-13\n", "[ Info: GMRES linsolve in iter 2; step 1: normres = 8.973332962649e-11\n", "[ Info: GMRES linsolve in iter 2; step 2: normres = 7.799012026293e-12\n", "[ Info: GMRES linsolve in iter 2; step 3: normres = 3.533387081846e-13\n", "[ Info: GMRES linsolve in iter 2; finished at step 3: normres = 3.533387081846e-13\n", "┌ Info: GMRES linsolve converged at iteration 2, step 3:\n", "│ * norm of residual = 3.5335749639422155e-13\n", "└ * number of operations = 13\n", "Non-interacting polarizability: 1.9257641897280278\n", "Interacting polarizability: 1.7737031542947217\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, δ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 = [-(r[1] - a/2) for r in r_vectors_cart(basis)]\n", "δVext = cat(δVext; dims=4)\n", "\n", "# Apply χ0 once to get non-interacting dipole\n", "δρ_nointeract = apply_χ0(res, δ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.8.1" }, "kernelspec": { "name": "julia-1.8", "display_name": "Julia 1.8.1", "language": "julia" } }, "nbformat": 4 }