You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

458 lines
37 KiB

<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>grogupy.utilities &mdash; grogupy 1.0.0 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=e59714d7" />
<link rel="stylesheet" type="text/css" href="../../_static/sphinx-design.min.css?v=95c83b7e" />
<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=8d563738"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/design-tabs.js?v=f930bc37"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home">
grogupy
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Getting started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Quickstart</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cite.html">Citing grogupy</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">User Guide</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../tutorials/index.html">Tutorials</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Advanced usage</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../implementation/modules.html">src</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../implementation/grogupy.html">grogupy package</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../implementation/environment.html">Environment variables</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../dev/index.html">Contributing to grogupy</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Extras</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../changelog/index.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../bibliography.html">Bibliography</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">grogupy</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
<li class="breadcrumb-item active">grogupy.utilities</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for grogupy.utilities</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright (c) [2024] []</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in all</span>
<span class="c1"># copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<span class="c1"># SOFTWARE.</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.special</span> <span class="kn">import</span> <span class="n">roots_legendre</span>
<span class="kn">from</span> <span class="nn">sisl.io.siesta</span> <span class="kn">import</span> <span class="n">eigSileSiesta</span>
<span class="c1"># Pauli matrices</span>
<span class="n">tau_x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="n">tau_y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="n">j</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="n">j</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="n">tau_z</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="n">tau_0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<div class="viewcode-block" id="commutator">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.commutator">[docs]</a>
<span class="k">def</span> <span class="nf">commutator</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Shorthand for commutator.</span>
<span class="sd"> Commutator of two matrices in the mathematical sense.</span>
<span class="sd"> Args:</span>
<span class="sd"> a : np.array_like</span>
<span class="sd"> The first matrix</span>
<span class="sd"> b : np.array_like</span>
<span class="sd"> The second matrix</span>
<span class="sd"> Returns:</span>
<span class="sd"> np.array_like</span>
<span class="sd"> The commutator of a and b</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">a</span> <span class="o">@</span> <span class="n">b</span> <span class="o">-</span> <span class="n">b</span> <span class="o">@</span> <span class="n">a</span></div>
<span class="c1"># define some useful functions</span>
<div class="viewcode-block" id="hsk">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.hsk">[docs]</a>
<span class="k">def</span> <span class="nf">hsk</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">ss</span><span class="p">,</span> <span class="n">sc_off</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Speed up Hk and Sk generation.</span>
<span class="sd"> Calculates the Hamiltonian and the Overlap matrix at a given k point. It is faster that the sisl version.</span>
<span class="sd"> Args:</span>
<span class="sd"> H : np.array_like</span>
<span class="sd"> Hamiltonian in spin box form</span>
<span class="sd"> ss : np.array_like</span>
<span class="sd"> Overlap matrix in spin box form</span>
<span class="sd"> sc_off : list</span>
<span class="sd"> supercell indexes of the Hamiltonian</span>
<span class="sd"> k : tuple, optional</span>
<span class="sd"> The k point where the matrices are set up. Defaults to (0, 0, 0)</span>
<span class="sd"> Returns:</span>
<span class="sd"> np.array_like</span>
<span class="sd"> Hamiltonian at the given k point</span>
<span class="sd"> np.array_like</span>
<span class="sd"> Overlap matrix at the given k point</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># this two conversion lines are from the sisl source</span>
<span class="n">k</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)</span>
<span class="n">k</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,)</span>
<span class="c1"># this generates the list of phases</span>
<span class="n">phases</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="n">j</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">k</span> <span class="o">@</span> <span class="n">sc_off</span><span class="o">.</span><span class="n">T</span><span class="p">)</span>
<span class="c1"># phases applied to the hamiltonian</span>
<span class="n">HK</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">einsum</span><span class="p">(</span><span class="s2">&quot;abc,a-&gt;bc&quot;</span><span class="p">,</span> <span class="n">H</span><span class="p">,</span> <span class="n">phases</span><span class="p">)</span>
<span class="n">SK</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">einsum</span><span class="p">(</span><span class="s2">&quot;abc,a-&gt;bc&quot;</span><span class="p">,</span> <span class="n">ss</span><span class="p">,</span> <span class="n">phases</span><span class="p">)</span>
<span class="k">return</span> <span class="n">HK</span><span class="p">,</span> <span class="n">SK</span></div>
<div class="viewcode-block" id="make_kset">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.make_kset">[docs]</a>
<span class="k">def</span> <span class="nf">make_kset</span><span class="p">(</span><span class="n">dirs</span><span class="o">=</span><span class="s2">&quot;xyz&quot;</span><span class="p">,</span> <span class="n">NUMK</span><span class="o">=</span><span class="mi">20</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Simple k-grid generator to sample the Brillouin zone.</span>
<span class="sd"> Depending on the value of the dirs</span>
<span class="sd"> argument k sampling in 1,2 or 3 dimensions is generated.</span>
<span class="sd"> If dirs argument does not contain either of x, y or z</span>
<span class="sd"> a kset of a single k-pont at the origin is returned. The total number of k points is the NUMK**(dimensions)</span>
<span class="sd"> Args:</span>
<span class="sd"> dirs : str, optional</span>
<span class="sd"> Directions of the k points in the Brillouin zone. They are the three lattice vectors. Defaults to &quot;xyz&quot;</span>
<span class="sd"> NUMK : int, optional</span>
<span class="sd"> The number of k points in a direction. Defaults to 20</span>
<span class="sd"> Returns:</span>
<span class="sd"> np.array_like</span>
<span class="sd"> An array of k points that uniformly sample the Brillouin zone in the given directions</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># if there is no xyz in dirs return the Gamma point</span>
<span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">d</span> <span class="ow">in</span> <span class="n">dirs</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="s2">&quot;xyz&quot;</span><span class="p">])):</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="n">kran</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">dirs</span><span class="p">)</span> <span class="o">*</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">NUMK</span><span class="p">,</span> <span class="n">endpoint</span><span class="o">=</span><span class="kc">False</span><span class="p">)]</span>
<span class="n">mg</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">meshgrid</span><span class="p">(</span><span class="o">*</span><span class="n">kran</span><span class="p">)</span>
<span class="n">dirsdict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">dirs</span><span class="p">):</span>
<span class="n">dirsdict</span><span class="p">[</span><span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="n">mg</span><span class="p">[</span><span class="n">d</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="s2">&quot;xyz&quot;</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">d</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">):</span>
<span class="n">dirsdict</span><span class="p">[</span><span class="n">d</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span> <span class="o">*</span> <span class="n">dirsdict</span><span class="p">[</span><span class="n">dirs</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
<span class="n">kset</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">dirsdict</span><span class="p">[</span><span class="n">d</span><span class="p">]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="s2">&quot;xyz&quot;</span><span class="p">])</span><span class="o">.</span><span class="n">T</span>
<span class="k">return</span> <span class="n">kset</span></div>
<div class="viewcode-block" id="make_contour">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.make_contour">[docs]</a>
<span class="k">def</span> <span class="nf">make_contour</span><span class="p">(</span><span class="n">emin</span><span class="o">=-</span><span class="mi">20</span><span class="p">,</span> <span class="n">emax</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">enum</span><span class="o">=</span><span class="mi">42</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="mi">150</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;A more sophisticated contour generator.</span>
<span class="sd"> Calculates the parameters for the complex contour integral. It uses the</span>
<span class="sd"> Legendre-Gauss quadrature method. It returns a class that contains</span>
<span class="sd"> the information for the contour integral.</span>
<span class="sd"> Args:</span>
<span class="sd"> emin : int, optional</span>
<span class="sd"> Energy minimum of the contour. Defaults to -20</span>
<span class="sd"> emax : float, optional</span>
<span class="sd"> Energy maximum of the contour. Defaults to 0.0, so the Fermi level</span>
<span class="sd"> enum : int, optional</span>
<span class="sd"> Number of sample points along the contour. Defaults to 42</span>
<span class="sd"> p : int, optional</span>
<span class="sd"> Shape parameter that describes the distribution of the sample points. Defaults to 150</span>
<span class="sd"> Returns:</span>
<span class="sd"> ccont</span>
<span class="sd"> Contains all the information for the contour integral</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">x</span><span class="p">,</span> <span class="n">wl</span> <span class="o">=</span> <span class="n">roots_legendre</span><span class="p">(</span><span class="n">enum</span><span class="p">)</span>
<span class="n">R</span> <span class="o">=</span> <span class="p">(</span><span class="n">emax</span> <span class="o">-</span> <span class="n">emin</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="c1"># radius</span>
<span class="n">z0</span> <span class="o">=</span> <span class="p">(</span><span class="n">emax</span> <span class="o">+</span> <span class="n">emin</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="c1"># center point</span>
<span class="n">y1</span> <span class="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">p</span><span class="p">)</span> <span class="c1"># lower bound</span>
<span class="n">y2</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1"># upper bound</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">(</span><span class="n">y2</span> <span class="o">-</span> <span class="n">y1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">x</span> <span class="o">+</span> <span class="p">(</span><span class="n">y2</span> <span class="o">+</span> <span class="n">y1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
<span class="n">phi</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">y</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="n">p</span> <span class="c1"># angle parameter</span>
<span class="n">ze</span> <span class="o">=</span> <span class="n">z0</span> <span class="o">+</span> <span class="n">R</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="mi">1</span><span class="n">j</span> <span class="o">*</span> <span class="n">phi</span><span class="p">)</span> <span class="c1"># complex points for path</span>
<span class="n">we</span> <span class="o">=</span> <span class="o">-</span><span class="p">(</span><span class="n">y2</span> <span class="o">-</span> <span class="n">y1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">y</span><span class="p">)</span> <span class="o">/</span> <span class="n">p</span> <span class="o">*</span> <span class="mi">1</span><span class="n">j</span> <span class="o">*</span> <span class="p">(</span><span class="n">ze</span> <span class="o">-</span> <span class="n">z0</span><span class="p">)</span> <span class="o">*</span> <span class="n">wl</span>
<span class="c1"># just an empty container class</span>
<span class="k">class</span> <span class="nc">ccont</span><span class="p">:</span>
<span class="k">pass</span>
<span class="n">cont</span> <span class="o">=</span> <span class="n">ccont</span><span class="p">()</span>
<span class="n">cont</span><span class="o">.</span><span class="n">R</span> <span class="o">=</span> <span class="n">R</span>
<span class="n">cont</span><span class="o">.</span><span class="n">z0</span> <span class="o">=</span> <span class="n">z0</span>
<span class="n">cont</span><span class="o">.</span><span class="n">ze</span> <span class="o">=</span> <span class="n">ze</span>
<span class="n">cont</span><span class="o">.</span><span class="n">we</span> <span class="o">=</span> <span class="n">we</span>
<span class="n">cont</span><span class="o">.</span><span class="n">enum</span> <span class="o">=</span> <span class="n">enum</span>
<span class="k">return</span> <span class="n">cont</span></div>
<div class="viewcode-block" id="tau_u">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.tau_u">[docs]</a>
<span class="k">def</span> <span class="nf">tau_u</span><span class="p">(</span><span class="n">u</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Pauli matrix in direction u.</span>
<span class="sd"> Returns the vector u in the basis of the Pauli matrices.</span>
<span class="sd"> Args:</span>
<span class="sd"> u : list or np.array_like</span>
<span class="sd"> The direction</span>
<span class="sd"> Returns:</span>
<span class="sd"> np.array_like</span>
<span class="sd"> Arbitrary direction in the base of the Pauli matrices</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># u is force to be of unit length</span>
<span class="n">u</span> <span class="o">=</span> <span class="n">u</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>
<span class="k">return</span> <span class="n">u</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">tau_x</span> <span class="o">+</span> <span class="n">u</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">tau_y</span> <span class="o">+</span> <span class="n">u</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">tau_z</span></div>
<span class="c1">#</span>
<div class="viewcode-block" id="crossM">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.crossM">[docs]</a>
<span class="k">def</span> <span class="nf">crossM</span><span class="p">(</span><span class="n">u</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Definition for the cross-product matrix.</span>
<span class="sd"> It acts as a cross product with vector u.</span>
<span class="sd"> Args:</span>
<span class="sd"> u : list or np.array_like</span>
<span class="sd"> The second vector in the cross product</span>
<span class="sd"> Returns:</span>
<span class="sd"> np.array_like</span>
<span class="sd"> The matrix that represents teh cross product with a vector</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="n">u</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">u</span><span class="p">[</span><span class="mi">1</span><span class="p">]],</span> <span class="p">[</span><span class="n">u</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="n">u</span><span class="p">[</span><span class="mi">0</span><span class="p">]],</span> <span class="p">[</span><span class="o">-</span><span class="n">u</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">u</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">0</span><span class="p">]])</span></div>
<div class="viewcode-block" id="RotM">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.RotM">[docs]</a>
<span class="k">def</span> <span class="nf">RotM</span><span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">eps</span><span class="o">=</span><span class="mf">1e-10</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Definition of rotation matrix with angle theta around direction u.</span>
<span class="sd"> Args:</span>
<span class="sd"> theta : float</span>
<span class="sd"> The angle of rotation</span>
<span class="sd"> u : np.array_like</span>
<span class="sd"> The rotation axis</span>
<span class="sd"> eps : float, optional</span>
<span class="sd"> Cutoff for small elements in the resulting matrix. Defaults to 1e-10</span>
<span class="sd"> Returns:</span>
<span class="sd"> np.array_like</span>
<span class="sd"> The rotation matrix</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">u</span> <span class="o">=</span> <span class="n">u</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>
<span class="n">M</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span> <span class="o">*</span> <span class="n">crossM</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>
<span class="o">+</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">))</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">u</span><span class="p">)</span>
<span class="p">)</span>
<span class="c1"># kill off small numbers</span>
<span class="n">M</span><span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">M</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">eps</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="k">return</span> <span class="n">M</span></div>
<div class="viewcode-block" id="RotMa2b">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.RotMa2b">[docs]</a>
<span class="k">def</span> <span class="nf">RotMa2b</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">eps</span><span class="o">=</span><span class="mf">1e-10</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Definition of rotation matrix rotating unit vector a to unit vector b.</span>
<span class="sd"> Function returns array R such that R @ a = b holds.</span>
<span class="sd"> Args:</span>
<span class="sd"> a : np.array_like</span>
<span class="sd"> First vector</span>
<span class="sd"> b : np.array_like</span>
<span class="sd"> Second vector</span>
<span class="sd"> eps : float, optional</span>
<span class="sd"> Cutoff for small elements in the resulting matrix. Defaults to 1e-10</span>
<span class="sd"> Returns:</span>
<span class="sd"> np.array_like</span>
<span class="sd"> The rotation matrix with the above property</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">a</span> <span class="o">@</span> <span class="n">b</span>
<span class="n">M</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="n">crossM</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">+</span> <span class="n">crossM</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">@</span> <span class="n">crossM</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">c</span><span class="p">)</span>
<span class="c1"># kill off small numbers</span>
<span class="n">M</span><span class="p">[</span><span class="nb">abs</span><span class="p">(</span><span class="n">M</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">eps</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="k">return</span> <span class="n">M</span></div>
<div class="viewcode-block" id="read_siesta_emin">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.read_siesta_emin">[docs]</a>
<span class="k">def</span> <span class="nf">read_siesta_emin</span><span class="p">(</span><span class="n">eigfile</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;It reads the lowest energy level from the siesta run.</span>
<span class="sd"> It uses the .EIG file from siesta that contains the eigenvalues.</span>
<span class="sd"> Args:</span>
<span class="sd"> eigfile : str</span>
<span class="sd"> The path to the .EIG file</span>
<span class="sd"> Returns:</span>
<span class="sd"> float</span>
<span class="sd"> The energy minimum</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># read the file</span>
<span class="n">eigs</span> <span class="o">=</span> <span class="n">eigSileSiesta</span><span class="p">(</span><span class="n">eigfile</span><span class="p">)</span><span class="o">.</span><span class="n">read_data</span><span class="p">()</span>
<span class="k">return</span> <span class="n">eigs</span><span class="o">.</span><span class="n">min</span><span class="p">()</span></div>
<div class="viewcode-block" id="int_de_ke">
<a class="viewcode-back" href="../../implementation/grogupy.utilities.html#grogupy.utilities.int_de_ke">[docs]</a>
<span class="k">def</span> <span class="nf">int_de_ke</span><span class="p">(</span><span class="n">traced</span><span class="p">,</span> <span class="n">we</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;It numerically integrates the traced matrix.</span>
<span class="sd"> It is a wrapper from numpy.trapz and it contains the</span>
<span class="sd"> relevant constants to calculate the energy integral from</span>
<span class="sd"> equation 93 or 96.</span>
<span class="sd"> Args:</span>
<span class="sd"> traced : np.array_like</span>
<span class="sd"> The trace of a matrix or a matrix product</span>
<span class="sd"> we : float</span>
<span class="sd"> The weight of a point on the contour</span>
<span class="sd"> Returns:</span>
<span class="sd"> float</span>
<span class="sd"> The energy calculated from the integral formula</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">trapz</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">imag</span><span class="p">(</span><span class="n">traced</span> <span class="o">*</span> <span class="n">we</span><span class="p">))</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2024, grogupy.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>