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.

349 lines
31 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!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.magnetism &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.magnetism</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.magnetism</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>
<div class="viewcode-block" id="blow_up_orbindx">
<a class="viewcode-back" href="../../implementation/grogupy.magnetism.html#grogupy.magnetism.blow_up_orbindx">[docs]</a>
<span class="k">def</span> <span class="nf">blow_up_orbindx</span><span class="p">(</span><span class="n">orb_indices</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Function to blow up orbital indices to make SPIN BOX indices.</span>
<span class="sd"> Args:</span>
<span class="sd"> orb_indices : np.array_like</span>
<span class="sd"> These are the indices in ORBITAL BOX</span>
<span class="sd"> Returns:</span>
<span class="sd"> orb_indices : np.array_like</span>
<span class="sd"> These are the indices in SPIN BOX</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">orb_indices</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">2</span> <span class="o">*</span> <span class="n">o</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">o</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">orb_indices</span><span class="p">])</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span>
<span class="k">return</span> <span class="n">orb_indices</span></div>
<div class="viewcode-block" id="spin_tracer">
<a class="viewcode-back" href="../../implementation/grogupy.magnetism.html#grogupy.magnetism.spin_tracer">[docs]</a>
<span class="k">def</span> <span class="nf">spin_tracer</span><span class="p">(</span><span class="n">M</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Spin tracer utility.</span>
<span class="sd"> This takes an operator with the orbital-spin sequence:</span>
<span class="sd"> orbital 1 up,</span>
<span class="sd"> orbital 1 down,</span>
<span class="sd"> orbital 2 up,</span>
<span class="sd"> orbital 2 down,</span>
<span class="sd"> that is in the SPIN-BOX representation,</span>
<span class="sd"> and extracts orbital dependent Pauli traces.</span>
<span class="sd"> Args:</span>
<span class="sd"> M : np.array_like</span>
<span class="sd"> Traceable matrix</span>
<span class="sd"> Returns:</span>
<span class="sd"> dict</span>
<span class="sd"> It contains the traced matrix with &quot;x&quot;, &quot;y&quot;, &quot;z&quot; and &quot;c&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">M11</span> <span class="o">=</span> <span class="n">M</span><span class="p">[</span><span class="mi">0</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="mi">2</span><span class="p">]</span>
<span class="n">M12</span> <span class="o">=</span> <span class="n">M</span><span class="p">[</span><span class="mi">0</span><span class="p">::</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">::</span><span class="mi">2</span><span class="p">]</span>
<span class="n">M21</span> <span class="o">=</span> <span class="n">M</span><span class="p">[</span><span class="mi">1</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="mi">2</span><span class="p">]</span>
<span class="n">M22</span> <span class="o">=</span> <span class="n">M</span><span class="p">[</span><span class="mi">1</span><span class="p">::</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">::</span><span class="mi">2</span><span class="p">]</span>
<span class="n">M_o</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
<span class="n">M_o</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">M12</span> <span class="o">+</span> <span class="n">M21</span>
<span class="n">M_o</span><span class="p">[</span><span class="s2">&quot;y&quot;</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="p">(</span><span class="n">M12</span> <span class="o">-</span> <span class="n">M21</span><span class="p">)</span>
<span class="n">M_o</span><span class="p">[</span><span class="s2">&quot;z&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">M11</span> <span class="o">-</span> <span class="n">M22</span>
<span class="n">M_o</span><span class="p">[</span><span class="s2">&quot;c&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">M11</span> <span class="o">+</span> <span class="n">M22</span>
<span class="k">return</span> <span class="n">M_o</span></div>
<div class="viewcode-block" id="parse_magnetic_entity">
<a class="viewcode-back" href="../../implementation/grogupy.magnetism.html#grogupy.magnetism.parse_magnetic_entity">[docs]</a>
<span class="k">def</span> <span class="nf">parse_magnetic_entity</span><span class="p">(</span><span class="n">dh</span><span class="p">,</span> <span class="n">atom</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">l</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Function to define orbital indexes of a given magnetic entity.</span>
<span class="sd"> Args:</span>
<span class="sd"> dh : sisl.physics.Hamiltonian</span>
<span class="sd"> Hamiltonian from sisl</span>
<span class="sd"> atom : integer or list of integers, optional</span>
<span class="sd"> Defining atom (or atoms) in the unit cell forming the magnetic entity. Defaults to None</span>
<span class="sd"> l : integer, optional</span>
<span class="sd"> Defining the angular momentum channel. Defaults to None</span>
<span class="sd"> Returns:</span>
<span class="sd"> list</span>
<span class="sd"> The orbital indexes of the given magnetic entity</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># case where we deal with more than one atom defining the magnetic entity</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">atom</span><span class="p">)</span> <span class="o">==</span> <span class="nb">list</span><span class="p">:</span>
<span class="n">dat</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">atom</span><span class="p">:</span>
<span class="n">a_orb_idx</span> <span class="o">=</span> <span class="n">dh</span><span class="o">.</span><span class="n">geometry</span><span class="o">.</span><span class="n">a2o</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="nb">all</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span>
<span class="nb">type</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span>
<span class="p">):</span> <span class="c1"># if specified we restrict to given l angular momentum channel inside each atom</span>
<span class="n">a_orb_idx</span> <span class="o">=</span> <span class="n">a_orb_idx</span><span class="p">[[</span><span class="n">o</span><span class="o">.</span><span class="n">l</span> <span class="o">==</span> <span class="n">l</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">dh</span><span class="o">.</span><span class="n">geometry</span><span class="o">.</span><span class="n">atoms</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">.</span><span class="n">orbitals</span><span class="p">]]</span>
<span class="n">dat</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">a_orb_idx</span><span class="p">)</span>
<span class="n">orbital_indeces</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">(</span><span class="n">dat</span><span class="p">)</span>
<span class="c1"># case where we deal with a singel atom magnetic entity</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">atom</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span><span class="p">:</span>
<span class="n">orbital_indeces</span> <span class="o">=</span> <span class="n">dh</span><span class="o">.</span><span class="n">geometry</span><span class="o">.</span><span class="n">a2o</span><span class="p">(</span><span class="n">atom</span><span class="p">,</span> <span class="nb">all</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span>
<span class="nb">type</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="o">==</span> <span class="nb">int</span>
<span class="p">):</span> <span class="c1"># if specified we restrict to given l angular momentum channel</span>
<span class="n">orbital_indeces</span> <span class="o">=</span> <span class="n">orbital_indeces</span><span class="p">[</span>
<span class="p">[</span><span class="n">o</span><span class="o">.</span><span class="n">l</span> <span class="o">==</span> <span class="n">l</span> <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">dh</span><span class="o">.</span><span class="n">geometry</span><span class="o">.</span><span class="n">atoms</span><span class="p">[</span><span class="n">atom</span><span class="p">]</span><span class="o">.</span><span class="n">orbitals</span><span class="p">]</span>
<span class="p">]</span>
<span class="k">return</span> <span class="n">orbital_indeces</span> <span class="c1"># numpy array containing integers labeling orbitals associated to a magnetic entity.</span></div>
<div class="viewcode-block" id="calculate_anisotropy_tensor">
<a class="viewcode-back" href="../../implementation/grogupy.magnetism.html#grogupy.magnetism.calculate_anisotropy_tensor">[docs]</a>
<span class="k">def</span> <span class="nf">calculate_anisotropy_tensor</span><span class="p">(</span><span class="n">mag_ent</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Calculates the renormalized anisotropy tensor from the energies.</span>
<span class="sd"> It uses the grogu convention for output.</span>
<span class="sd"> Args:</span>
<span class="sd"> mag_ent : dict</span>
<span class="sd"> An element from the magnetic entities</span>
<span class="sd"> Returns:</span>
<span class="sd"> K : np.array_like</span>
<span class="sd"> elements of the anisotropy tensor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># get the energies</span>
<span class="n">energies</span> <span class="o">=</span> <span class="n">mag_ent</span><span class="p">[</span><span class="s2">&quot;energies&quot;</span><span class="p">]</span>
<span class="c1"># calculate the diagonal tensor elements</span>
<span class="n">Kxx</span> <span class="o">=</span> <span class="n">energies</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">energies</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">Kyy</span> <span class="o">=</span> <span class="n">energies</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="o">-</span> <span class="n">energies</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">Kzz</span> <span class="o">=</span> <span class="mi">0</span>
<span class="c1"># perform consistency check</span>
<span class="n">calculated_diff</span> <span class="o">=</span> <span class="n">Kyy</span> <span class="o">-</span> <span class="n">Kxx</span>
<span class="n">expected_diff</span> <span class="o">=</span> <span class="n">energies</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">energies</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="n">consistency_check</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">calculated_diff</span> <span class="o">-</span> <span class="n">expected_diff</span><span class="p">)</span>
<span class="k">return</span> <span class="n">Kxx</span><span class="p">,</span> <span class="n">Kyy</span><span class="p">,</span> <span class="n">Kzz</span><span class="p">,</span> <span class="n">consistency_check</span></div>
<div class="viewcode-block" id="calculate_exchange_tensor">
<a class="viewcode-back" href="../../implementation/grogupy.magnetism.html#grogupy.magnetism.calculate_exchange_tensor">[docs]</a>
<span class="k">def</span> <span class="nf">calculate_exchange_tensor</span><span class="p">(</span><span class="n">pair</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Calculates the exchange tensor from the energies.</span>
<span class="sd"> It produces the isotropic exchange, the relevant elements</span>
<span class="sd"> from the Dzyaloshinskii-Morilla (Dm) tensor, the symmetric-anisotropy</span>
<span class="sd"> and the complete exchange tensor.</span>
<span class="sd"> Args:</span>
<span class="sd"> pair : dict</span>
<span class="sd"> An element from the pairs</span>
<span class="sd"> Returns:</span>
<span class="sd"> J_iso : float</span>
<span class="sd"> Isotropic exchange (Tr[J] / 3)</span>
<span class="sd"> J_S : np.array_like</span>
<span class="sd"> Symmetric-anisotropy (J_S = J - J_iso * I &gt; Jxx, Jyy, Jxy, Jxz, Jyz)</span>
<span class="sd"> D : np.array_like</span>
<span class="sd"> DM elements (Dx, Dy, Dz)</span>
<span class="sd"> J : np.array_like</span>
<span class="sd"> Complete exchange tensor flattened (Jxx, Jxy, Jxz, Jyx, Jyy, Jyz, Jzx, Jzy, Jzz)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># energies from rotations</span>
<span class="n">energies</span> <span class="o">=</span> <span class="n">pair</span><span class="p">[</span><span class="s2">&quot;energies&quot;</span><span class="p">]</span>
<span class="c1"># Initialize output arrays</span>
<span class="n">J</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="n">D</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="c1"># J matrix calculations</span>
<span class="c1"># J(1,1) = mean([DEij(2,2,2), DEij(2,2,3)])</span>
<span class="n">J</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="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="n">energies</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="c1"># J(1,2) = -mean([DEij(1,2,3), DEij(2,1,3)])</span>
<span class="n">J</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="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">energies</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="n">J</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="o">=</span> <span class="n">J</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="c1"># J(1,3) = -mean([DEij(1,2,2), DEij(2,1,2)])</span>
<span class="n">J</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="n">energies</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="n">J</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">J</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="c1"># J(2,2) = mean([DEij(2,2,1), DEij(1,1,3)])</span>
<span class="n">J</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="n">energies</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="c1"># J(2,3) = -mean([DEij(1,2,1), DEij(2,1,1)])</span>
<span class="n">J</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</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">energies</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="n">J</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">J</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="c1"># J(3,3) = mean([DEij(1,1,1), DEij(1,1,2)])</span>
<span class="n">J</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</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">energies</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="c1"># D vector calculations</span>
<span class="c1"># D(1) = mean([DEij(1,2,1), -DEij(2,1,1)])</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">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</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="o">-</span><span class="n">energies</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="c1"># D(2) = mean([DEij(2,1,2), -DEij(1,2,2)])</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">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="o">-</span><span class="n">energies</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="c1"># D(3) = mean([DEij(1,2,3), -DEij(2,1,3)])</span>
<span class="n">D</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">([</span><span class="n">energies</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="o">-</span><span class="n">energies</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="n">J_iso</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">trace</span><span class="p">(</span><span class="n">J</span><span class="p">)</span> <span class="o">/</span> <span class="mi">3</span>
<span class="c1"># based on the grogu output pdf</span>
<span class="c1"># traceless symmetric exchange matrix:</span>
<span class="c1"># Jxx, Jyy, Jxy, Jxz, Jyz</span>
<span class="n">J_S</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">J</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="o">-</span> <span class="n">J_iso</span><span class="p">,</span> <span class="n">J</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">J_iso</span><span class="p">,</span> <span class="n">J</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">J</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">J</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>
<span class="k">return</span> <span class="n">J_iso</span><span class="p">,</span> <span class="n">J_S</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">J</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>