Skip to content

Commit

Permalink
Deploying to gh-pages from @ 2fd7647 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
utksi committed Jan 17, 2025
1 parent 97ff4f4 commit 78d0ab5
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/jupyter/blog.ipynb.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion feed.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://utksi.github.io/feed.xml" rel="self" type="application/atom+xml"/><link href="https://utksi.github.io/" rel="alternate" type="text/html" hreflang="en"/><updated>2025-01-17T13:46:22+00:00</updated><id>https://utksi.github.io/feed.xml</id><title type="html">blank</title><subtitle>Worklog and thoughts </subtitle><entry><title type="html">ELF, with wannier functions</title><link href="https://utksi.github.io/blog/2024/wannier_elf/" rel="alternate" type="text/html" title="ELF, with wannier functions"/><published>2024-12-12T02:14:00+00:00</published><updated>2024-12-12T02:14:00+00:00</updated><id>https://utksi.github.io/blog/2024/wannier_elf</id><content type="html" xml:base="https://utksi.github.io/blog/2024/wannier_elf/"><![CDATA[<ul> <li> <p>This is not complete - in the sense that it is something, but no one yet knows if it is useful to have.</p> </li> <li> <p>For a primer on wannier functions: please see <a href="https://arxiv.org/abs/2312.10769">this</a>.</p> </li> <li> <p>In the event reading the following is not really needed, the implementation is available here: <a href="https://github.com/utksi/wannier_elf">Wannier-ELF</a></p> </li> </ul> <hr/> <h3 id="what-and-why"><strong>What, and Why?</strong></h3> <p>The Electron Localization Function (ELF) is a valuable tool in computational chemistry and condensed matter physics for visualizing and understanding electron localization in atoms, molecules, and solids.</p> <p>Speaking informally, if one knows the degree of electron localization, a more generalized (as opposed to localized :D) perspective of bonding in the material of interest should be obtained. It is somewhat easier to think of this when looking at the math:</p> <p>The standard expression for ELF involves the kinetic energy densities:</p> \[\text{ELF}(\mathbf{r}) = \dfrac{1}{1 + \left( \dfrac{ t_P(\mathbf{r}) }{ t_h(\mathbf{r}) } \right)^2}\] <ul> <li>\(t_P(\mathbf{r}) = t(\mathbf{r}) - t_W(\mathbf{r})\): Pauli kinetic energy density.</li> <li>\(t(\mathbf{r})\): Total kinetic energy density.</li> <li>\(t_W(\mathbf{r})\): von Weizsäcker kinetic energy density.</li> <li>\(t_h(\mathbf{r})\): Kinetic energy density of a homogeneous electron gas.</li> </ul> <p>Essentially, it is a three-dimensional scalar field that <strong>tracks the variation in KE density</strong> (Total - Von-Weizsäcker term) at some point \(\mathbf{\vec{r}}\) in the cell, compared to if one had a homogeneous electron gas with the same electron density, for which the gradient term: \(\nabla n(\mathbf{r})\) should be exactly zero.</p> <p>This ratio: \(\dfrac{ t_P(\mathbf{r}) }{ t_h(\mathbf{r}) }\) is also sometimes called the <strong>localization index</strong> : \(\chi (r)\).</p> <p>Given \(n(\mathbf{r})\): the electron density.</p> <ol> <li><strong>von Weizsäcker Kinetic Energy Density (\(t_W(\mathbf{r})\))</strong></li> </ol> \[t_W(\mathbf{r}) = \dfrac{1}{8} \dfrac{|\nabla n(\mathbf{r})|^2}{n(\mathbf{r})}\] <ol> <li><strong>Pauli Kinetic Energy Density (\(t_P(\mathbf{r})\))</strong></li> </ol> \[t_P(\mathbf{r}) = t(\mathbf{r}) - t_W(\mathbf{r})\] <ol> <li><strong>Homogeneous Electron Gas Kinetic Energy Density (\(t_h(\mathbf{r})\))</strong></li> </ol> \[t_h(\mathbf{r}) = \dfrac{3}{5} (3\pi^2)^{2/3} [n(\mathbf{r})]^{5/3}\] <hr/> <h3 id="vaspcastep-expressions-for-elf">VASP/CASTEP expressions for ELF</h3> <p>If you’re reading this, then it’s highly likely that you already know that ELF fields can be written very easily after a obtaining charge density in VASP/CASTEP.</p> <p>And, in CASTEP and VASP, the ELF is calculated using an expression involving the Laplacian of the Kohn-Sham orbitals and electron density:</p> \[D(\mathbf{r}) = -2A \sum_i \psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r}) + \dfrac{A}{2} \nabla^2 n(\mathbf{r}) - \dfrac{A}{4n(\mathbf{r})} \left( \nabla n(\mathbf{r}) \right)^2\] <ul> <li>\(A = \dfrac{\hbar^2}{2m}\): Constant involving Planck’s constant \(\hbar\) and electron mass \(m\).</li> <li>The terms represent: <ul> <li><strong>First Term</strong>: Kinetic energy density of the non-interacting Kohn-Sham system.</li> <li><strong>Second Term</strong>: “Correlation correction.”</li> <li><strong>Third Term</strong>: Kinetic energy density of an ideal Bose gas at the same density.</li> </ul> </li> </ul> <p>The ELF is then calculated as:</p> \[\text{ELF}(\mathbf{r}) = \dfrac{1}{1 + \left( \dfrac{ D(\mathbf{r}) }{ D_0(\mathbf{r}) } \right)^2}\] <p>In the \(\texttt{VASP}\) source code, \(D = T + T_{corr.} - T_{bos.}\) could be found, which is the same thing.</p> <p>The numerator in the localization index now looks a bit different here, and the first guess should be that this of course looks like this because the normal expression has been broken down into direct, cross and divergence terms - and one would be correct!</p> <p>I still find it a tiny bit cathartic to show this explicitly (doing my part against entropy).</p> <h4 id="reconciling-the-expressions"><strong>Reconciling the Expressions</strong></h4> <h5 id="step-1-relate-the-first-term-to-total-kinetic-energy-density"><strong>Step 1: Relate the First Term to Total Kinetic Energy Density</strong></h5> <p>The first term in the CASTEP/VASP expression:</p> \[-2A \sum_i \psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r})\] <p>Using the identity:</p> \[\psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r}) = \nabla \cdot \left( \psi_i^*(\mathbf{r}) \nabla \psi_i(\mathbf{r}) \right) - |\nabla \psi_i(\mathbf{r})|^2\] <p>Substitute back:</p> \[-2A \sum_i \psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r}) = 2A \sum_i |\nabla \psi_i(\mathbf{r})|^2 - 2A \sum_i \nabla \cdot \left( \psi_i^*(\mathbf{r}) \nabla \psi_i(\mathbf{r}) \right)\] <p>Note that the first term on the right-hand-side is twice the total kinetic energy density.</p> \[2 t(\mathbf{r}) = 2A \sum_i |\nabla \psi_i(\mathbf{r})|^2\] <h5 id="step-2-relate-the-second-and-third-terms-to-von-weizsäcker-kinetic-energy-density"><strong>Step 2: Relate the Second and Third Terms to von Weizsäcker Kinetic Energy Density</strong></h5> <p>The second term:</p> \[\dfrac{A}{2} \nabla^2 n(\mathbf{r}) = A \nabla \cdot \left( \dfrac{1}{2} \nabla n(\mathbf{r}) \right)\] <p>The third term:</p> \[- \dfrac{A}{4n(\mathbf{r})} \left( \nabla n(\mathbf{r}) \right)^2 = -2 t_W(\mathbf{r})\] <p>since:</p> \[t_W(\mathbf{r}) = \dfrac{1}{8} \dfrac{|\nabla n(\mathbf{r})|^2}{n(\mathbf{r})} = \dfrac{A}{4n(\mathbf{r})} |\nabla n(\mathbf{r})|^2\] <h5 id="step-3-combine-terms"><strong>Step 3: Combine Terms</strong></h5> <p>The total expression becomes:</p> \[D(\mathbf{r}) = 2 t(\mathbf{r}) - 2 t_W(\mathbf{r}) - 2A \sum_i \nabla \cdot \left( \psi_i^*(\mathbf{r}) \nabla \psi_i(\mathbf{r}) \right) + A \nabla \cdot \left( \dfrac{1}{2} \nabla n(\mathbf{r}) \right)\] <p>Group divergence terms:</p> \[D(\mathbf{r}) = 2 \left[ t(\mathbf{r}) - t_W(\mathbf{r}) \right] + \text{Divergence Terms}\] <p>Thus, we see that:</p> \[D(\mathbf{r}) = 2 t_P(\mathbf{r}) + \text{Divergence Terms}\] <h4 id="equivalence"><strong>Equivalence</strong></h4> <ul> <li>The CASTEP/VASP expression for \(D(\mathbf{r})\) essentially represents twice the Pauli kinetic energy density \(2 t_P(\mathbf{r})\), up to divergence terms.</li> <li>The divergence terms may cancel out or integrate to zero under appropriate boundary conditions but can be significant locally.</li> </ul> <hr/> <h3 id="scalar-fields-with-wannier-functions">Scalar fields with Wannier functions</h3> <p>The first step would be to recognize that we’re working with <em>Maximally localized</em> wannier functions. As as result, the phase is consistent.</p> <p>To that end, the solution should be simple.</p> <p>Given a scalar field \(w_n(r)\):</p> \[n(\mathbf{r}) = \sum_n^{\text{occ}} |\tilde{w}_n(\mathbf{r})|^2\] <p>And, calculate the kinetic energy density terms in the same way.</p> <p>Note that, at the end, we need \(D_h(r)\) and \(D(r) = \tau - \tau_w(r)\).</p> <hr/> <h3 id="density-and-density-gradient-from-w_nr">Density and density-gradient from \(w_n(r)\)</h3> <p>In terms of implementation, the electron density and its gradient can be constructed as:</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1"># Process the wannier function.
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://utksi.github.io/feed.xml" rel="self" type="application/atom+xml"/><link href="https://utksi.github.io/" rel="alternate" type="text/html" hreflang="en"/><updated>2025-01-17T15:59:54+00:00</updated><id>https://utksi.github.io/feed.xml</id><title type="html">blank</title><subtitle>Worklog and thoughts </subtitle><entry><title type="html">ELF, with wannier functions</title><link href="https://utksi.github.io/blog/2024/wannier_elf/" rel="alternate" type="text/html" title="ELF, with wannier functions"/><published>2024-12-12T02:14:00+00:00</published><updated>2024-12-12T02:14:00+00:00</updated><id>https://utksi.github.io/blog/2024/wannier_elf</id><content type="html" xml:base="https://utksi.github.io/blog/2024/wannier_elf/"><![CDATA[<ul> <li> <p>This is not complete - in the sense that it is something, but no one yet knows if it is useful to have.</p> </li> <li> <p>For a primer on wannier functions: please see <a href="https://arxiv.org/abs/2312.10769">this</a>.</p> </li> <li> <p>In the event reading the following is not really needed, the implementation is available here: <a href="https://github.com/utksi/wannier_elf">Wannier-ELF</a></p> </li> </ul> <hr/> <h3 id="what-and-why"><strong>What, and Why?</strong></h3> <p>The Electron Localization Function (ELF) is a valuable tool in computational chemistry and condensed matter physics for visualizing and understanding electron localization in atoms, molecules, and solids.</p> <p>Speaking informally, if one knows the degree of electron localization, a more generalized (as opposed to localized :D) perspective of bonding in the material of interest should be obtained. It is somewhat easier to think of this when looking at the math:</p> <p>The standard expression for ELF involves the kinetic energy densities:</p> \[\text{ELF}(\mathbf{r}) = \dfrac{1}{1 + \left( \dfrac{ t_P(\mathbf{r}) }{ t_h(\mathbf{r}) } \right)^2}\] <ul> <li>\(t_P(\mathbf{r}) = t(\mathbf{r}) - t_W(\mathbf{r})\): Pauli kinetic energy density.</li> <li>\(t(\mathbf{r})\): Total kinetic energy density.</li> <li>\(t_W(\mathbf{r})\): von Weizsäcker kinetic energy density.</li> <li>\(t_h(\mathbf{r})\): Kinetic energy density of a homogeneous electron gas.</li> </ul> <p>Essentially, it is a three-dimensional scalar field that <strong>tracks the variation in KE density</strong> (Total - Von-Weizsäcker term) at some point \(\mathbf{\vec{r}}\) in the cell, compared to if one had a homogeneous electron gas with the same electron density, for which the gradient term: \(\nabla n(\mathbf{r})\) should be exactly zero.</p> <p>This ratio: \(\dfrac{ t_P(\mathbf{r}) }{ t_h(\mathbf{r}) }\) is also sometimes called the <strong>localization index</strong> : \(\chi (r)\).</p> <p>Given \(n(\mathbf{r})\): the electron density.</p> <ol> <li><strong>von Weizsäcker Kinetic Energy Density (\(t_W(\mathbf{r})\))</strong></li> </ol> \[t_W(\mathbf{r}) = \dfrac{1}{8} \dfrac{|\nabla n(\mathbf{r})|^2}{n(\mathbf{r})}\] <ol> <li><strong>Pauli Kinetic Energy Density (\(t_P(\mathbf{r})\))</strong></li> </ol> \[t_P(\mathbf{r}) = t(\mathbf{r}) - t_W(\mathbf{r})\] <ol> <li><strong>Homogeneous Electron Gas Kinetic Energy Density (\(t_h(\mathbf{r})\))</strong></li> </ol> \[t_h(\mathbf{r}) = \dfrac{3}{5} (3\pi^2)^{2/3} [n(\mathbf{r})]^{5/3}\] <hr/> <h3 id="vaspcastep-expressions-for-elf">VASP/CASTEP expressions for ELF</h3> <p>If you’re reading this, then it’s highly likely that you already know that ELF fields can be written very easily after a obtaining charge density in VASP/CASTEP.</p> <p>And, in CASTEP and VASP, the ELF is calculated using an expression involving the Laplacian of the Kohn-Sham orbitals and electron density:</p> \[D(\mathbf{r}) = -2A \sum_i \psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r}) + \dfrac{A}{2} \nabla^2 n(\mathbf{r}) - \dfrac{A}{4n(\mathbf{r})} \left( \nabla n(\mathbf{r}) \right)^2\] <ul> <li>\(A = \dfrac{\hbar^2}{2m}\): Constant involving Planck’s constant \(\hbar\) and electron mass \(m\).</li> <li>The terms represent: <ul> <li><strong>First Term</strong>: Kinetic energy density of the non-interacting Kohn-Sham system.</li> <li><strong>Second Term</strong>: “Correlation correction.”</li> <li><strong>Third Term</strong>: Kinetic energy density of an ideal Bose gas at the same density.</li> </ul> </li> </ul> <p>The ELF is then calculated as:</p> \[\text{ELF}(\mathbf{r}) = \dfrac{1}{1 + \left( \dfrac{ D(\mathbf{r}) }{ D_0(\mathbf{r}) } \right)^2}\] <p>In the \(\texttt{VASP}\) source code, \(D = T + T_{corr.} - T_{bos.}\) could be found, which is the same thing.</p> <p>The numerator in the localization index now looks a bit different here, and the first guess should be that this of course looks like this because the normal expression has been broken down into direct, cross and divergence terms - and one would be correct!</p> <p>I still find it a tiny bit cathartic to show this explicitly (doing my part against entropy).</p> <h4 id="reconciling-the-expressions"><strong>Reconciling the Expressions</strong></h4> <h5 id="step-1-relate-the-first-term-to-total-kinetic-energy-density"><strong>Step 1: Relate the First Term to Total Kinetic Energy Density</strong></h5> <p>The first term in the CASTEP/VASP expression:</p> \[-2A \sum_i \psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r})\] <p>Using the identity:</p> \[\psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r}) = \nabla \cdot \left( \psi_i^*(\mathbf{r}) \nabla \psi_i(\mathbf{r}) \right) - |\nabla \psi_i(\mathbf{r})|^2\] <p>Substitute back:</p> \[-2A \sum_i \psi_i^*(\mathbf{r}) \nabla^2 \psi_i(\mathbf{r}) = 2A \sum_i |\nabla \psi_i(\mathbf{r})|^2 - 2A \sum_i \nabla \cdot \left( \psi_i^*(\mathbf{r}) \nabla \psi_i(\mathbf{r}) \right)\] <p>Note that the first term on the right-hand-side is twice the total kinetic energy density.</p> \[2 t(\mathbf{r}) = 2A \sum_i |\nabla \psi_i(\mathbf{r})|^2\] <h5 id="step-2-relate-the-second-and-third-terms-to-von-weizsäcker-kinetic-energy-density"><strong>Step 2: Relate the Second and Third Terms to von Weizsäcker Kinetic Energy Density</strong></h5> <p>The second term:</p> \[\dfrac{A}{2} \nabla^2 n(\mathbf{r}) = A \nabla \cdot \left( \dfrac{1}{2} \nabla n(\mathbf{r}) \right)\] <p>The third term:</p> \[- \dfrac{A}{4n(\mathbf{r})} \left( \nabla n(\mathbf{r}) \right)^2 = -2 t_W(\mathbf{r})\] <p>since:</p> \[t_W(\mathbf{r}) = \dfrac{1}{8} \dfrac{|\nabla n(\mathbf{r})|^2}{n(\mathbf{r})} = \dfrac{A}{4n(\mathbf{r})} |\nabla n(\mathbf{r})|^2\] <h5 id="step-3-combine-terms"><strong>Step 3: Combine Terms</strong></h5> <p>The total expression becomes:</p> \[D(\mathbf{r}) = 2 t(\mathbf{r}) - 2 t_W(\mathbf{r}) - 2A \sum_i \nabla \cdot \left( \psi_i^*(\mathbf{r}) \nabla \psi_i(\mathbf{r}) \right) + A \nabla \cdot \left( \dfrac{1}{2} \nabla n(\mathbf{r}) \right)\] <p>Group divergence terms:</p> \[D(\mathbf{r}) = 2 \left[ t(\mathbf{r}) - t_W(\mathbf{r}) \right] + \text{Divergence Terms}\] <p>Thus, we see that:</p> \[D(\mathbf{r}) = 2 t_P(\mathbf{r}) + \text{Divergence Terms}\] <h4 id="equivalence"><strong>Equivalence</strong></h4> <ul> <li>The CASTEP/VASP expression for \(D(\mathbf{r})\) essentially represents twice the Pauli kinetic energy density \(2 t_P(\mathbf{r})\), up to divergence terms.</li> <li>The divergence terms may cancel out or integrate to zero under appropriate boundary conditions but can be significant locally.</li> </ul> <hr/> <h3 id="scalar-fields-with-wannier-functions">Scalar fields with Wannier functions</h3> <p>The first step would be to recognize that we’re working with <em>Maximally localized</em> wannier functions. As as result, the phase is consistent.</p> <p>To that end, the solution should be simple.</p> <p>Given a scalar field \(w_n(r)\):</p> \[n(\mathbf{r}) = \sum_n^{\text{occ}} |\tilde{w}_n(\mathbf{r})|^2\] <p>And, calculate the kinetic energy density terms in the same way.</p> <p>Note that, at the end, we need \(D_h(r)\) and \(D(r) = \tau - \tau_w(r)\).</p> <hr/> <h3 id="density-and-density-gradient-from-w_nr">Density and density-gradient from \(w_n(r)\)</h3> <p>In terms of implementation, the electron density and its gradient can be constructed as:</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1"># Process the wannier function.
</span><span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">wf</span> <span class="ow">in</span> <span class="nf">enumerate</span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">wannier_data</span><span class="p">):</span>
<span class="n">self</span><span class="p">.</span><span class="n">logger</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span>
<span class="sa">f</span><span class="sh">"</span><span class="s">Processing Wannier function </span><span class="si">{</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s">/</span><span class="si">{</span><span class="nf">len</span><span class="p">(</span><span class="n">self</span><span class="p">.</span><span class="n">wannier_data</span><span class="p">)</span><span class="si">}</span><span class="sh">"</span>
Expand Down
Loading

0 comments on commit 78d0ab5

Please sign in to comment.