a bunch of things and proper documentation and build

class-solution
Daniel Pozsar 3 months ago
parent 7403710cf5
commit cd6e293d23

3
.gitignore vendored

@ -24,3 +24,6 @@ tmp*
# Mac stuff # Mac stuff
*.DS_Store* *.DS_Store*
# PYPI test tokens
.pypirc

@ -1,34 +1,71 @@
# Relativistic magnetic interactions from non-orthogonal basis sets # Relativistic magnetic interactions from non-orthogonal basis sets
More on the theoretical background can be seen on [arXiv](https://arxiv.org/abs/2309.02558).
# TODO # TODO
- Definition of magnetic entities: - Parallel or serial energy integral to reduce memory overhead
* Through simple sequence o forbitals in the unit cell - Check the symmetrization of the Hamiltonian and overlap matrix to make them hermitian
* Through atom specification - Check if exchange field has scalar part
* Through atom and orbital specification - Add more tests
- Separation of TR and TRB components of the Hamiltonian, Identification of the exchange field. - Run tests on different magnetic materials and compare it to Grogu Matlab.
- Definition of commutator expressions, old projection matrix elements - Ehm MAKE IT WORK SOMEHOW :'(
- Efficient calculation of Green's functions
- Calculation of energy and momentum resolved derivatives
- Parallel BZ and serial energy integral
# Building wheel # Building wheel
See detailed documentation on [PYPI](https://packaging.python.org/en/latest/tutorials/packaging-projects/). See detailed documentation on [PYPI](https://packaging.python.org/en/latest/tutorials/packaging-projects/).
- First you need some API Tokens for Test PYPI ,to be able to upload. You can read about it [here](https://test.pypi.org/help/#apitoken). I own the current project, so you have to contact me.
Use the following commands for a quick setup: Use the following commands for a quick setup:
- Build wheel - Build wheel
``` ```
python -m build python -m build
```
- Push to PYPI test repository
```
python -m twine upload --repository testpypi dist/*
``` ```
Build wheel: # Usage
Push to pypi(testpypi for beginners): python3 -m twine upload --repository testpypi dist/* ## For end users
Download and install from [PYPI](https://test.pypi.org/project/grogu-magn/) test repository.
Ehhez kellenek tokenek: ```
You will be prompted for a username and password. For the username, use __token__. For the password, use the token value, including the pypi- prefix. python3 -m pip install --index-url https://test.pypi.org/simple/ grogu_magn
```
## For developers
Végfelhasználóknak (egyelőre testpypi): python3 -m pip install --index-url https://test.pypi.org/simple/ example-package-YOUR-USERNAME-HERE - Clone repository from Gitea
```
git clone https://gitea.vo.elte.hu/et209d/grogu.git
```
- Create .venv (for example with VsCode)
* Use python 3.9.6
* install dependencies from:
* requirements.txt
* requirements-dev.txt
* /docs/requirements.txt
- Install and run pre-commit
```
pre-commit install
pre-commit run --all-files
```
To build the documentation navigate to the `docs/source` folder and run `make clean` and `make html`. After this the html page can be found in `docs/source/_build/html`.
```
cd docs/source
make clean
make html
```

@ -1,4 +1,4 @@
# Sphinx build info version 1 # Sphinx build info version 1
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done. # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 0f8ff1598a5b65221fc2ef8f29fdbeac config: d8f86c3651bae6bbb2cfa348920c9196
tags: 645f666f9bcd5a90fca523b33c5a78b7 tags: 645f666f9bcd5a90fca523b33c5a78b7

@ -13,7 +13,7 @@
<script src="../../_static/jquery.js?v=5d32c60e"></script> <script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../../_static/documentation_options.js?v=d45e8c67"></script> <script src="../../_static/documentation_options.js?v=d45e8c67"></script>
<script src="../../_static/doctools.js?v=9bcbadda"></script> <script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/js/theme.js"></script> <script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" /> <link rel="index" title="Index" href="../../genindex.html" />
@ -89,15 +89,22 @@
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</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="c1"># SOFTWARE.</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">product</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</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">scipy.special</span> <span class="kn">import</span> <span class="n">roots_legendre</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">permutations</span><span class="p">,</span> <span class="n">product</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>
<span class="c1"># define some useful functions</span> <span class="c1"># define some useful functions</span>
<div class="viewcode-block" id="hsk"> <div class="viewcode-block" id="hsk">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.hsk">[docs]</a> <a class="viewcode-back" href="../../grogu.html#grogu.useful.hsk">[docs]</a>
<span class="k">def</span> <span class="nf">hsk</span><span class="p">(</span><span class="n">dh</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="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;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> One way to speed up Hk and Sk generation</span> <span class="sd"> One way to speed up Hk and Sk generation</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
@ -105,13 +112,12 @@
<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"># are from the sisl source</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"># are from the sisl source</span>
<span class="c1"># this generates the list of phases</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="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">dh</span><span class="o">.</span><span class="n">rcell</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="n">dh</span><span class="o">.</span><span class="n">cell</span><span class="p">),</span> <span class="n">dh</span><span class="o">.</span><span class="n">sc</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="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="n">HKU</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,c-&gt;ab&quot;</span><span class="p">,</span> <span class="n">dh</span><span class="o">.</span><span class="n">hup</span><span class="p">,</span> <span class="n">phases</span><span class="p">)</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">HKD</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,c-&gt;ab&quot;</span><span class="p">,</span> <span class="n">dh</span><span class="o">.</span><span class="n">hdo</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="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,c-&gt;ab&quot;</span><span class="p">,</span> <span class="n">dh</span><span class="o">.</span><span class="n">sov</span><span class="p">,</span> <span class="n">phases</span><span class="p">)</span>
<span class="k">return</span> <span class="n">HKU</span><span class="p">,</span> <span class="n">HKD</span><span class="p">,</span> <span class="n">SK</span></div> <span class="k">return</span> <span class="n">HK</span><span class="p">,</span> <span class="n">SK</span></div>
@ -175,80 +181,190 @@
<div class="viewcode-block" id="make_atran"> <div class="viewcode-block" id="commutator">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.make_atran">[docs]</a> <a class="viewcode-back" href="../../grogu.html#grogu.useful.commutator">[docs]</a>
<span class="k">def</span> <span class="nf">make_atran</span><span class="p">(</span><span class="n">nauc</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">dist</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span> <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="s2">&quot;Shorthand for commutator&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>
<div class="viewcode-block" id="tau_u">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.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;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Simple pair generator. Depending on the value of the dirs</span> <span class="sd"> Pauli matrix in direction u.</span>
<span class="sd"> argument 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 single pair is returend.</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</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="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="c1"># u is force to be of unit length</span>
<span class="k">return</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="p">[</span><span class="mi">1</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="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="n">dran</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">arange</span><span class="p">(</span><span class="o">-</span><span class="n">dist</span><span class="p">,</span> <span class="n">dist</span> <span class="o">+</span> <span class="mi">1</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">dran</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">ucran</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="c1">#</span>
<span class="n">atran</span> <span class="o">=</span> <span class="p">[]</span> <div class="viewcode-block" id="crossM">
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">product</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">nauc</span><span class="p">),</span> <span class="n">repeat</span><span class="o">=</span><span class="mi">2</span><span class="p">)):</span> <a class="viewcode-back" href="../../grogu.html#grogu.useful.crossM">[docs]</a>
<span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">ucran</span><span class="p">:</span> <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="k">if</span> <span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">i</span> <span class="o">-</span> <span class="n">j</span><span class="p">)</span> <span class="o">+</span> <span class="nb">sum</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">u</span><span class="p">)))</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="n">atran</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">u</span><span class="p">)))</span> <span class="sd"> Definition for the cross-product matrix.</span>
<span class="sd"> Acting as a cross product with vector u.</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>
<span class="k">return</span> <span class="n">atran</span></div>
<div class="viewcode-block" id="RotM">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.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;</span>
<span class="sd"> Definition of rotation matrix with angle theta around direction u.</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="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="c1"># kill off small numbers</span>
<span class="k">return</span> <span class="n">M</span></div>
<div class="viewcode-block" id="add">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.add">[docs]</a>
<span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;The sum of two numbers for testing.</span>
<span class="sd"> This function adds to numbers together. I only created this for testing documentation and examples.</span> <div class="viewcode-block" id="RotMa2b">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.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;</span>
<span class="sd"> 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"> &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="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="c1"># kill off small numbers</span>
<span class="k">return</span> <span class="n">M</span></div>
<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> x : float</span>
<span class="sd"> First number</span>
<span class="sd"> y : float</span>
<span class="sd"> Second number added to `x`</span>
<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> sum : int</span>
<span class="sd"> The sum of the inputs</span>
<span class="sd"> See Also</span> <div class="viewcode-block" id="spin_tracer">
<span class="sd"> --------</span> <a class="viewcode-back" href="../../grogu.html#grogu.useful.spin_tracer">[docs]</a>
<span class="sd"> numpy.add : Adds more than two numbers.</span> <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;</span>
<span class="sd"> Spin tracer utility.</span>
<span class="sd"> This akes 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"> &quot;&quot;&quot;</span>
<span class="sd"> Notes</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="sd"> -----</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="sd"> We can create some latex notes here [1]_ :</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="sd"> .. math:: a + b = c</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="sd"> References</span> <span class="k">return</span> <span class="n">M_o</span></div>
<span class="sd"> ----------</span>
<span class="sd"> .. [1] https://numpydoc.readthedocs.io/en/latest/format.html</span>
<span class="sd"> Examples</span>
<span class="sd"> --------</span>
<span class="sd"> &gt;&gt;&gt; add(1, 2)</span>
<span class="sd"> 3</span>
<div class="viewcode-block" id="parse_magnetic_entity">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.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;</span>
<span class="sd"> Function to define orbital indeces of a given magnetic entity.</span>
<span class="sd"> dh: a sisl Hamiltonian object</span>
<span class="sd"> atom: an integer or list of integers, defining atom (or atoms) in the unicell forming the magnetic entity</span>
<span class="sd"> l: integer, defining the angular momentum channel</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="blow_up_orbindx">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.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;</span>
<span class="sd"> Function to blow up orbital indeces to make SPIN BOX indices.</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span></div> <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">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></div>
<div class="viewcode-block" id="calculate_exchange_tensor">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.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="n">o1</span><span class="p">,</span> <span class="n">o2</span><span class="p">,</span> <span class="n">o3</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"># o1=x, o2=y, o3=z</span>
<span class="c1"># dict(o=np.array([1, 0, 0]), vw=[np.array([0, 1, 0]), np.array([0, 0, 1])]),</span>
<span class="c1"># dict(o=np.array([0, 1, 0]), vw=[np.array([1, 0, 0]), np.array([0, 0, 1])]),</span>
<span class="c1"># dict(o=np.array([0, 0, 1]), vw=[np.array([1, 0, 0]), np.array([0, 1, 0])]),</span>
<span class="n">J_ii</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">o2</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">o3</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">o1</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span> <span class="c1"># xx, yy, zz</span>
<span class="n">J_S</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.5</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">o3</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">o3</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">o2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">o2</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">o1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">o1</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span> <span class="c1"># yz, zx, xy</span>
<span class="n">D</span> <span class="o">=</span> <span class="mf">0.5</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">o1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">o1</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">o2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="n">o2</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">o3</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">o3</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span> <span class="c1"># x, y, z</span>
<span class="k">return</span> <span class="n">J_ii</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="mi">3</span><span class="p">,</span> <span class="n">D</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">J_ii</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="n">J_ii</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="mi">3</span><span class="p">,</span> <span class="n">J_S</span><span class="p">])</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span></div>
<div class="viewcode-block" id="print_atomic_indices">
<a class="viewcode-back" href="../../grogu.html#grogu.useful.print_atomic_indices">[docs]</a>
<span class="k">def</span> <span class="nf">print_atomic_indices</span><span class="p">(</span><span class="n">pair</span><span class="p">,</span> <span class="n">magnetic_entities</span><span class="p">,</span> <span class="n">dh</span><span class="p">):</span>
<span class="n">atomic_indices</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">atoms</span> <span class="o">=</span> <span class="n">magnetic_entities</span><span class="p">[</span><span class="n">pair</span><span class="p">[</span><span class="s2">&quot;ai&quot;</span><span class="p">]]</span>
<span class="k">if</span> <span class="s2">&quot;l&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;l&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;all&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;atom&quot;</span><span class="p">],</span> <span class="nb">int</span><span class="p">):</span>
<span class="n">atomic_indices</span> <span class="o">+=</span> <span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;[</span><span class="si">{</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">]</span><span class="si">{</span><span class="n">dh</span><span class="o">.</span><span class="n">atoms</span><span class="p">[</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">tag</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;l&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">)&quot;</span>
<span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">atoms</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">atomic_indices</span> <span class="o">+=</span> <span class="p">[</span>
<span class="sa">f</span><span class="s2">&quot;[</span><span class="si">{</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">]</span><span class="si">{</span><span class="n">dh</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="s1">&#39;atom&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">tag</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">atom</span><span class="p">[</span><span class="s1">&#39;l&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">)&quot;</span>
<span class="k">for</span> <span class="n">atom</span> <span class="ow">in</span> <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;atom&quot;</span><span class="p">]</span>
<span class="p">]</span>
<span class="n">atoms</span> <span class="o">=</span> <span class="n">magnetic_entities</span><span class="p">[</span><span class="n">pair</span><span class="p">[</span><span class="s2">&quot;aj&quot;</span><span class="p">]]</span>
<span class="k">if</span> <span class="s2">&quot;l&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;l&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;all&quot;</span>
<span class="n">atomic_indices</span> <span class="o">+=</span> <span class="s2">&quot; &quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;atom&quot;</span><span class="p">],</span> <span class="nb">int</span><span class="p">):</span>
<span class="n">atomic_indices</span> <span class="o">+=</span> <span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;[</span><span class="si">{</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">]</span><span class="si">{</span><span class="n">dh</span><span class="o">.</span><span class="n">atoms</span><span class="p">[</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">tag</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;l&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">)&quot;</span>
<span class="p">)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">atoms</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">atomic_indices</span> <span class="o">+=</span> <span class="p">[</span>
<span class="sa">f</span><span class="s2">&quot;[</span><span class="si">{</span><span class="n">atoms</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">]</span><span class="si">{</span><span class="n">dh</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="s1">&#39;atom&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">tag</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">atom</span><span class="p">[</span><span class="s1">&#39;l&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">)&quot;</span>
<span class="k">for</span> <span class="n">atom</span> <span class="ow">in</span> <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;atom&quot;</span><span class="p">]</span>
<span class="p">]</span>
<span class="n">atomic_indices</span> <span class="o">+=</span> <span class="sa">f</span><span class="s2">&quot; </span><span class="si">{</span><span class="n">pair</span><span class="p">[</span><span class="s1">&#39;Ruc&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2"> d [Ang] Not yet.&quot;</span>
<span class="k">return</span> <span class="n">atomic_indices</span></div>
</pre></div> </pre></div>

@ -13,7 +13,7 @@
<script src="../_static/jquery.js?v=5d32c60e"></script> <script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=d45e8c67"></script> <script src="../_static/documentation_options.js?v=d45e8c67"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script> <script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/js/theme.js"></script> <script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" /> <link rel="index" title="Index" href="../genindex.html" />

@ -1,5 +1,12 @@
/* /*
* basic.css
* ~~~~~~~~~
*
* Sphinx stylesheet -- basic theme. * Sphinx stylesheet -- basic theme.
*
* :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/ */
/* -- main layout ----------------------------------------------------------- */ /* -- main layout ----------------------------------------------------------- */
@ -108,11 +115,15 @@ img {
/* -- search page ----------------------------------------------------------- */ /* -- search page ----------------------------------------------------------- */
ul.search { ul.search {
margin-top: 10px; margin: 10px 0 0 20px;
padding: 0;
} }
ul.search li { ul.search li {
padding: 5px 0; padding: 5px 0 5px 20px;
background-image: url(file.png);
background-repeat: no-repeat;
background-position: 0 7px;
} }
ul.search li a { ul.search li a {

@ -1,5 +1,12 @@
/* /*
* doctools.js
* ~~~~~~~~~~~
*
* Base JavaScript utilities for all Sphinx HTML documentation. * Base JavaScript utilities for all Sphinx HTML documentation.
*
* :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/ */
"use strict"; "use strict";

@ -1,6 +1,13 @@
/* /*
* language_data.js
* ~~~~~~~~~~~~~~~~
*
* This script contains the language-specific data used by searchtools.js, * This script contains the language-specific data used by searchtools.js,
* namely the list of stopwords, stemmer, scorer and splitter. * namely the list of stopwords, stemmer, scorer and splitter.
*
* :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/ */
var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]; var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"];

@ -1,5 +1,12 @@
/* /*
* searchtools.js
* ~~~~~~~~~~~~~~~~
*
* Sphinx JavaScript utilities for the full-text search. * Sphinx JavaScript utilities for the full-text search.
*
* :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/ */
"use strict"; "use strict";
@ -13,7 +20,7 @@ if (typeof Scorer === "undefined") {
// and returns the new score. // and returns the new score.
/* /*
score: result => { score: result => {
const [docname, title, anchor, descr, score, filename, kind] = result const [docname, title, anchor, descr, score, filename] = result
return score return score
}, },
*/ */
@ -40,14 +47,6 @@ if (typeof Scorer === "undefined") {
}; };
} }
// Global search result kind enum, used by themes to style search results.
class SearchResultKind {
static get index() { return "index"; }
static get object() { return "object"; }
static get text() { return "text"; }
static get title() { return "title"; }
}
const _removeChildren = (element) => { const _removeChildren = (element) => {
while (element && element.lastChild) element.removeChild(element.lastChild); while (element && element.lastChild) element.removeChild(element.lastChild);
}; };
@ -65,13 +64,9 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY; const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY;
const contentRoot = document.documentElement.dataset.content_root; const contentRoot = document.documentElement.dataset.content_root;
const [docName, title, anchor, descr, score, _filename, kind] = item; const [docName, title, anchor, descr, score, _filename] = item;
let listItem = document.createElement("li"); let listItem = document.createElement("li");
// Add a class representing the item's type:
// can be used by a theme's CSS selector for styling
// See SearchResultKind for the class names.
listItem.classList.add(`kind-${kind}`);
let requestUrl; let requestUrl;
let linkUrl; let linkUrl;
if (docBuilder === "dirhtml") { if (docBuilder === "dirhtml") {
@ -120,10 +115,8 @@ const _finishSearch = (resultCount) => {
"Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories." "Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories."
); );
else else
Search.status.innerText = Documentation.ngettext( Search.status.innerText = _(
"Search finished, found one page matching the search query.", "Search finished, found ${resultCount} page(s) matching the search query."
"Search finished, found ${resultCount} pages matching the search query.",
resultCount,
).replace('${resultCount}', resultCount); ).replace('${resultCount}', resultCount);
}; };
const _displayNextItem = ( const _displayNextItem = (
@ -145,7 +138,7 @@ const _displayNextItem = (
else _finishSearch(resultCount); else _finishSearch(resultCount);
}; };
// Helper function used by query() to order search results. // Helper function used by query() to order search results.
// Each input is an array of [docname, title, anchor, descr, score, filename, kind]. // Each input is an array of [docname, title, anchor, descr, score, filename].
// Order the results by score (in opposite order of appearance, since the // Order the results by score (in opposite order of appearance, since the
// `_displayNextItem` function uses pop() to retrieve items) and then alphabetically. // `_displayNextItem` function uses pop() to retrieve items) and then alphabetically.
const _orderResultsByScoreThenName = (a, b) => { const _orderResultsByScoreThenName = (a, b) => {
@ -255,7 +248,6 @@ const Search = {
searchSummary.classList.add("search-summary"); searchSummary.classList.add("search-summary");
searchSummary.innerText = ""; searchSummary.innerText = "";
const searchList = document.createElement("ul"); const searchList = document.createElement("ul");
searchList.setAttribute("role", "list");
searchList.classList.add("search"); searchList.classList.add("search");
const out = document.getElementById("search-results"); const out = document.getElementById("search-results");
@ -326,7 +318,7 @@ const Search = {
const indexEntries = Search._index.indexentries; const indexEntries = Search._index.indexentries;
// Collect multiple result groups to be sorted separately and then ordered. // Collect multiple result groups to be sorted separately and then ordered.
// Each is an array of [docname, title, anchor, descr, score, filename, kind]. // Each is an array of [docname, title, anchor, descr, score, filename].
const normalResults = []; const normalResults = [];
const nonMainIndexResults = []; const nonMainIndexResults = [];
@ -345,7 +337,6 @@ const Search = {
null, null,
score + boost, score + boost,
filenames[file], filenames[file],
SearchResultKind.title,
]); ]);
} }
} }
@ -363,7 +354,6 @@ const Search = {
null, null,
score, score,
filenames[file], filenames[file],
SearchResultKind.index,
]; ];
if (isMain) { if (isMain) {
normalResults.push(result); normalResults.push(result);
@ -485,7 +475,6 @@ const Search = {
descr, descr,
score, score,
filenames[match[0]], filenames[match[0]],
SearchResultKind.object,
]); ]);
}; };
Object.keys(objects).forEach((prefix) => Object.keys(objects).forEach((prefix) =>
@ -596,7 +585,6 @@ const Search = {
null, null,
score, score,
filenames[file], filenames[file],
SearchResultKind.text,
]); ]);
} }
return results; return results;

@ -13,7 +13,7 @@
<script src="_static/jquery.js?v=5d32c60e"></script> <script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=d45e8c67"></script> <script src="_static/documentation_options.js?v=d45e8c67"></script>
<script src="_static/doctools.js?v=9bcbadda"></script> <script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script> <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script> <script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="#" /> <link rel="index" title="Index" href="#" />
@ -71,16 +71,35 @@
<h1 id="index">Index</h1> <h1 id="index">Index</h1>
<div class="genindex-jumpbox"> <div class="genindex-jumpbox">
<a href="#A"><strong>A</strong></a> <a href="#B"><strong>B</strong></a>
| <a href="#C"><strong>C</strong></a>
| <a href="#G"><strong>G</strong></a> | <a href="#G"><strong>G</strong></a>
| <a href="#H"><strong>H</strong></a> | <a href="#H"><strong>H</strong></a>
| <a href="#M"><strong>M</strong></a> | <a href="#M"><strong>M</strong></a>
| <a href="#P"><strong>P</strong></a>
| <a href="#R"><strong>R</strong></a>
| <a href="#S"><strong>S</strong></a>
| <a href="#T"><strong>T</strong></a>
</div> </div>
<h2 id="A">A</h2> <h2 id="B">B</h2>
<table style="width: 100%" class="indextable genindextable"><tr> <table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul> <td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.add">add() (in module grogu.useful)</a> <li><a href="grogu.html#grogu.useful.blow_up_orbindx">blow_up_orbindx() (in module grogu.useful)</a>
</li>
</ul></td>
</tr></table>
<h2 id="C">C</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.calculate_exchange_tensor">calculate_exchange_tensor() (in module grogu.useful)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.commutator">commutator() (in module grogu.useful)</a>
</li>
<li><a href="grogu.html#grogu.useful.crossM">crossM() (in module grogu.useful)</a>
</li> </li>
</ul></td> </ul></td>
</tr></table> </tr></table>
@ -132,8 +151,6 @@
<h2 id="M">M</h2> <h2 id="M">M</h2>
<table style="width: 100%" class="indextable genindextable"><tr> <table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul> <td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.make_atran">make_atran() (in module grogu.useful)</a>
</li>
<li><a href="grogu.html#grogu.useful.make_contour">make_contour() (in module grogu.useful)</a> <li><a href="grogu.html#grogu.useful.make_contour">make_contour() (in module grogu.useful)</a>
</li> </li>
<li><a href="grogu.html#grogu.useful.make_kset">make_kset() (in module grogu.useful)</a> <li><a href="grogu.html#grogu.useful.make_kset">make_kset() (in module grogu.useful)</a>
@ -154,6 +171,46 @@
</ul></td> </ul></td>
</tr></table> </tr></table>
<h2 id="P">P</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.parse_magnetic_entity">parse_magnetic_entity() (in module grogu.useful)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.print_atomic_indices">print_atomic_indices() (in module grogu.useful)</a>
</li>
</ul></td>
</tr></table>
<h2 id="R">R</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.RotM">RotM() (in module grogu.useful)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.RotMa2b">RotMa2b() (in module grogu.useful)</a>
</li>
</ul></td>
</tr></table>
<h2 id="S">S</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.spin_tracer">spin_tracer() (in module grogu.useful)</a>
</li>
</ul></td>
</tr></table>
<h2 id="T">T</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="grogu.html#grogu.useful.tau_u">tau_u() (in module grogu.useful)</a>
</li>
</ul></td>
</tr></table>
</div> </div>

@ -14,9 +14,8 @@
<script src="_static/jquery.js?v=5d32c60e"></script> <script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=d45e8c67"></script> <script src="_static/documentation_options.js?v=d45e8c67"></script>
<script src="_static/doctools.js?v=9bcbadda"></script> <script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script> <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="_static/js/theme.js"></script> <script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" /> <link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" /> <link rel="search" title="Search" href="search.html" />
@ -50,11 +49,19 @@
<li class="toctree-l3"><a class="reference internal" href="#module-grogu.example">grogu.example module</a></li> <li class="toctree-l3"><a class="reference internal" href="#module-grogu.example">grogu.example module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-grogu.jij">grogu.jij module</a></li> <li class="toctree-l3"><a class="reference internal" href="#module-grogu.jij">grogu.jij module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-grogu.useful">grogu.useful module</a><ul> <li class="toctree-l3"><a class="reference internal" href="#module-grogu.useful">grogu.useful module</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.add"><code class="docutils literal notranslate"><span class="pre">add()</span></code></a></li> <li class="toctree-l4"><a class="reference internal" href="#grogu.useful.RotM"><code class="docutils literal notranslate"><span class="pre">RotM()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.RotMa2b"><code class="docutils literal notranslate"><span class="pre">RotMa2b()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.blow_up_orbindx"><code class="docutils literal notranslate"><span class="pre">blow_up_orbindx()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.calculate_exchange_tensor"><code class="docutils literal notranslate"><span class="pre">calculate_exchange_tensor()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.commutator"><code class="docutils literal notranslate"><span class="pre">commutator()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.crossM"><code class="docutils literal notranslate"><span class="pre">crossM()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.hsk"><code class="docutils literal notranslate"><span class="pre">hsk()</span></code></a></li> <li class="toctree-l4"><a class="reference internal" href="#grogu.useful.hsk"><code class="docutils literal notranslate"><span class="pre">hsk()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.make_atran"><code class="docutils literal notranslate"><span class="pre">make_atran()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.make_contour"><code class="docutils literal notranslate"><span class="pre">make_contour()</span></code></a></li> <li class="toctree-l4"><a class="reference internal" href="#grogu.useful.make_contour"><code class="docutils literal notranslate"><span class="pre">make_contour()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.make_kset"><code class="docutils literal notranslate"><span class="pre">make_kset()</span></code></a></li> <li class="toctree-l4"><a class="reference internal" href="#grogu.useful.make_kset"><code class="docutils literal notranslate"><span class="pre">make_kset()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.parse_magnetic_entity"><code class="docutils literal notranslate"><span class="pre">parse_magnetic_entity()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.print_atomic_indices"><code class="docutils literal notranslate"><span class="pre">print_atomic_indices()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.spin_tracer"><code class="docutils literal notranslate"><span class="pre">spin_tracer()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#grogu.useful.tau_u"><code class="docutils literal notranslate"><span class="pre">tau_u()</span></code></a></li>
</ul> </ul>
</li> </li>
<li class="toctree-l3"><a class="reference internal" href="#module-grogu">Module contents</a></li> <li class="toctree-l3"><a class="reference internal" href="#module-grogu">Module contents</a></li>
@ -103,62 +110,46 @@
<section id="module-grogu.useful"> <section id="module-grogu.useful">
<span id="grogu-useful-module"></span><h2>grogu.useful module<a class="headerlink" href="#module-grogu.useful" title="Link to this heading"></a></h2> <span id="grogu-useful-module"></span><h2>grogu.useful module<a class="headerlink" href="#module-grogu.useful" title="Link to this heading"></a></h2>
<dl class="py function"> <dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.add"> <dt class="sig sig-object py" id="grogu.useful.RotM">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">add</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#add"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.add" title="Link to this definition"></a></dt> <span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">RotM</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">theta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">u</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-10</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#RotM"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.RotM" title="Link to this definition"></a></dt>
<dd><p>The sum of two numbers for testing.</p> <dd><p>Definition of rotation matrix with angle theta around direction u.</p>
<p>This function adds to numbers together. I only created this for testing documentation and examples.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>float</em>) First number</p></li>
<li><p><strong>y</strong> (<em>float</em>) Second number added to <cite>x</cite></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>sum</strong> The sum of the inputs</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>int</p>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.add</span></code></dt><dd><p>Adds more than two numbers.</p>
</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>We can create some latex notes here <a class="footnote-reference brackets" href="#id2" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> :</p>
<div class="math notranslate nohighlight">
\[a + b = c\]</div>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id2" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>
<p><a class="reference external" href="https://numpydoc.readthedocs.io/en/latest/format.html">https://numpydoc.readthedocs.io/en/latest/format.html</a></p>
</aside>
</aside>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">add</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="go">3</span>
</pre></div>
</div>
</dd></dl> </dd></dl>
<dl class="py function"> <dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.hsk"> <dt class="sig sig-object py" id="grogu.useful.RotMa2b">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">hsk</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dh</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">(0,</span> <span class="pre">0,</span> <span class="pre">0)</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#hsk"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.hsk" title="Link to this definition"></a></dt> <span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">RotMa2b</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-10</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#RotMa2b"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.RotMa2b" title="Link to this definition"></a></dt>
<dd><p>One way to speed up Hk and Sk generation</p> <dd><p>Definition of rotation matrix rotating unit vector a to unit vector b.
Function returns array R such that R&#64;a = b holds.</p>
</dd></dl> </dd></dl>
<dl class="py function"> <dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.make_atran"> <dt class="sig sig-object py" id="grogu.useful.blow_up_orbindx">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">make_atran</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">nauc</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dirs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'xyz'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dist</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#make_atran"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.make_atran" title="Link to this definition"></a></dt> <span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">blow_up_orbindx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">orb_indices</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#blow_up_orbindx"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.blow_up_orbindx" title="Link to this definition"></a></dt>
<dd><p>Simple pair generator. Depending on the value of the dirs <dd><p>Function to blow up orbital indeces to make SPIN BOX indices.</p>
argument sampling in 1,2 or 3 dimensions is generated. </dd></dl>
If dirs argument does not contain either of x,y or z
a single pair is returend.</p> <dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.calculate_exchange_tensor">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">calculate_exchange_tensor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pair</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#calculate_exchange_tensor"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.calculate_exchange_tensor" title="Link to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.commutator">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">commutator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#commutator"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.commutator" title="Link to this definition"></a></dt>
<dd><p>Shorthand for commutator</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.crossM">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">crossM</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">u</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#crossM"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.crossM" title="Link to this definition"></a></dt>
<dd><p>Definition for the cross-product matrix.
Acting as a cross product with vector u.</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.hsk">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">hsk</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">H</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ss</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sc_off</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">(0,</span> <span class="pre">0,</span> <span class="pre">0)</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#hsk"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.hsk" title="Link to this definition"></a></dt>
<dd><p>One way to speed up Hk and Sk generation</p>
</dd></dl> </dd></dl>
<dl class="py function"> <dl class="py function">
@ -176,6 +167,39 @@ If dirs argument does not contain either of x,y or z
a kset of a single k-pont at the origin is returend.</p> a kset of a single k-pont at the origin is returend.</p>
</dd></dl> </dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.parse_magnetic_entity">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">parse_magnetic_entity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dh</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">atom</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">l</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#parse_magnetic_entity"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.parse_magnetic_entity" title="Link to this definition"></a></dt>
<dd><p>Function to define orbital indeces of a given magnetic entity.
dh: a sisl Hamiltonian object
atom: an integer or list of integers, defining atom (or atoms) in the unicell forming the magnetic entity
l: integer, defining the angular momentum channel</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.print_atomic_indices">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">print_atomic_indices</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pair</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">magnetic_entities</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dh</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#print_atomic_indices"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.print_atomic_indices" title="Link to this definition"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.spin_tracer">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">spin_tracer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">M</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#spin_tracer"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.spin_tracer" title="Link to this definition"></a></dt>
<dd><p>Spin tracer utility.
This akes an operator with the orbital-spin sequence:
orbital 1 up,
orbital 1 down,
orbital 2 up,
orbital 2 down,
that is in the SPIN-BOX representation,
and extracts orbital dependent Pauli traces.</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="grogu.useful.tau_u">
<span class="sig-prename descclassname"><span class="pre">grogu.useful.</span></span><span class="sig-name descname"><span class="pre">tau_u</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">u</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/grogu/useful.html#tau_u"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#grogu.useful.tau_u" title="Link to this definition"></a></dt>
<dd><p>Pauli matrix in direction u.</p>
</dd></dl>
</section> </section>
<section id="module-grogu"> <section id="module-grogu">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-grogu" title="Link to this heading"></a></h2> <span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-grogu" title="Link to this heading"></a></h2>

@ -14,9 +14,8 @@
<script src="_static/jquery.js?v=5d32c60e"></script> <script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=d45e8c67"></script> <script src="_static/documentation_options.js?v=d45e8c67"></script>
<script src="_static/doctools.js?v=9bcbadda"></script> <script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script> <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="_static/js/theme.js"></script> <script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" /> <link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" /> <link rel="search" title="Search" href="search.html" />

@ -14,9 +14,8 @@
<script src="_static/jquery.js?v=5d32c60e"></script> <script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=d45e8c67"></script> <script src="_static/documentation_options.js?v=d45e8c67"></script>
<script src="_static/doctools.js?v=9bcbadda"></script> <script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script> <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="_static/js/theme.js"></script> <script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" /> <link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" /> <link rel="search" title="Search" href="search.html" />
@ -84,11 +83,19 @@
<li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu.example">grogu.example module</a></li> <li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu.example">grogu.example module</a></li>
<li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu.jij">grogu.jij module</a></li> <li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu.jij">grogu.jij module</a></li>
<li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu.useful">grogu.useful module</a><ul> <li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu.useful">grogu.useful module</a><ul>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.add"><code class="docutils literal notranslate"><span class="pre">add()</span></code></a></li> <li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.RotM"><code class="docutils literal notranslate"><span class="pre">RotM()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.RotMa2b"><code class="docutils literal notranslate"><span class="pre">RotMa2b()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.blow_up_orbindx"><code class="docutils literal notranslate"><span class="pre">blow_up_orbindx()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.calculate_exchange_tensor"><code class="docutils literal notranslate"><span class="pre">calculate_exchange_tensor()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.commutator"><code class="docutils literal notranslate"><span class="pre">commutator()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.crossM"><code class="docutils literal notranslate"><span class="pre">crossM()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.hsk"><code class="docutils literal notranslate"><span class="pre">hsk()</span></code></a></li> <li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.hsk"><code class="docutils literal notranslate"><span class="pre">hsk()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.make_atran"><code class="docutils literal notranslate"><span class="pre">make_atran()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.make_contour"><code class="docutils literal notranslate"><span class="pre">make_contour()</span></code></a></li> <li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.make_contour"><code class="docutils literal notranslate"><span class="pre">make_contour()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.make_kset"><code class="docutils literal notranslate"><span class="pre">make_kset()</span></code></a></li> <li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.make_kset"><code class="docutils literal notranslate"><span class="pre">make_kset()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.parse_magnetic_entity"><code class="docutils literal notranslate"><span class="pre">parse_magnetic_entity()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.print_atomic_indices"><code class="docutils literal notranslate"><span class="pre">print_atomic_indices()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.spin_tracer"><code class="docutils literal notranslate"><span class="pre">spin_tracer()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="grogu.html#grogu.useful.tau_u"><code class="docutils literal notranslate"><span class="pre">tau_u()</span></code></a></li>
</ul> </ul>
</li> </li>
<li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu">Module contents</a></li> <li class="toctree-l2"><a class="reference internal" href="grogu.html#module-grogu">Module contents</a></li>

@ -2,6 +2,6 @@
# Project: Grogu # Project: Grogu
# Version: # Version:
# The remainder of this file is compressed using zlib. # The remainder of this file is compressed using zlib.
xÚ•M xΪ•“MnΓ Fχ>R»uΤv™t)jΖxbσ'fPνΫ΄u¤H);τρή0 b<>~H",{λϋdPΌ<50>aMv#[σT²φY΄MIq2υ_ώ¬Ο<C2AC>fα)™J|χαω°:§δkοΔλΦΊΓ[WatΖΙ¤<><C2A4>vύ\a*0*`”8«ά€Ρ<CEA1>55Όµ‰<C2B5>λ¤θ‰j¦2<C2A6>TA[<5B>P*οΨ§X«M„\α<04><EFBFBD>Βΰ<CE92>µθXσRγGνρΩlηηΣ
Â@ …÷=E@·Ýz‚à$ÎĶv~Êü€½½3MÕŠv^¾÷™TÎVº~«­ŒŠ` UVVuÐjÁZ¹„²`•n¨»DýË_ëßlôt‰j&¾B)³å<12><08>5°™š>èÚ·3h<33>-<2D>084sMš`£kk=…2<>täVá™Õ<>ƒ].9}À¤ôLâ:-VT¼Gr…^BR£&0¯T¤C|Ù ëËGƒ<47>{¾!ïÂÇóӣİw¢˜$üˆ>ô¡Nó6Á:Q¿YcÏû‡üÞ; ©B§ <EFBFBD>δ
¨ k.Κ<>dzΐ£Λέΰ,<2C>ϋ½<CF8B><0E>h3tM/<2F>x_—¥ςλ½Ί@Ώ•ΚRP ΨόΌZ@½Θi²y°¶Τδ<CEA4>t§ƒ°΄?E<”―Xz)<>¶g\£STΝ¦Βƒ<CE92>ΗΗ<!<21>ρV,Yq>Λώq½ο7ϊ©―

@ -13,7 +13,7 @@
<script src="_static/jquery.js?v=5d32c60e"></script> <script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=d45e8c67"></script> <script src="_static/documentation_options.js?v=d45e8c67"></script>
<script src="_static/doctools.js?v=9bcbadda"></script> <script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script> <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script> <script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" /> <link rel="index" title="Index" href="genindex.html" />

@ -14,7 +14,7 @@
<script src="_static/jquery.js?v=5d32c60e"></script> <script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=d45e8c67"></script> <script src="_static/documentation_options.js?v=d45e8c67"></script>
<script src="_static/doctools.js?v=9bcbadda"></script> <script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script> <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script> <script src="_static/js/theme.js"></script>
<script src="_static/searchtools.js"></script> <script src="_static/searchtools.js"></script>

File diff suppressed because one or more lines are too long

@ -220,7 +220,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.12.7" "version": "3.9.6"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -3,48 +3,52 @@ requires = ["hatchling"]
build-backend = "hatchling.build" build-backend = "hatchling.build"
[project] [project]
name = "grogu" name = "grogu_magn"
version = "0.0.1" version = "0.0.3"
authors = [ authors = [
{ name="Laszlo Oroszlany", email="laszlo.oroszlany@ttk.elte.hu" },
{ name="Daniel Pozsar", email="danielpozsar@student.elte.hu" }, { name="Daniel Pozsar", email="danielpozsar@student.elte.hu" },
{ name="Laszlo Oroszlany", email="laszlo.oroszlany@ttk.elte.hu" },
] ]
description = "Relativistic magnetic interactions from non-orthogonal basis sets" description = "Relativistic magnetic interactions from non-orthogonal basis sets"
readme = "README.md" readme = "README.md"
kewords = [ kewords = [
"DFT", "DFT",
"physics", "physics",
"grogu" "grogu",
"magnetic interactions",
] ]
requires-python = ">=3.9" requires-python = ">=3.9"
dependencies = [ dependencies = [
"numpy", "numpy==1.24.4",
"scipy", "scipy",
"sisl", "sisl==0.14.3",
"netcdf4==1.6.2",
"openmpi", "openmpi",
"mpi4py", "mpi4py",
"argparse",
] ]
classifiers = [ classifiers = [
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Programming Language :: Python", "Programming Language :: Python",
"Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering :: Physics", "Topic :: Scientific/Engineering :: Physics",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
"Operating System :: OS Independent", "Operating System :: OS Independent",
] ]
[project.scripts]
grogu = "grogu:main"
[project.urls] [project.urls]
Homepage = "https://github.com/pypa/sampleproject" Homepage = "https://gitea.vo.elte.hu/et209d/grogu"
Documentation = "https://readthedocs.org" Documentation = "https://gitea.vo.elte.hu/et209d/grogu"
Repository = "https://github.com/me/spam.git" Repository = "https://gitea.vo.elte.hu/et209d/grogu"
Issues = "https://github.com/pypa/sampleproject/issues" Issues = "https://gitea.vo.elte.hu/et209d/grogu"
[tool.pytest.ini_options] [tool.pytest.ini_options]
pythonpath = [ pythonpath = [
"src/grogu/" "src/grogu_magn/"
] ]
addopts = [ addopts = [
"--import-mode=importlib", "--import-mode=importlib",

@ -14,6 +14,5 @@ pytest
pytest-randomly pytest-randomly
pytest-cov pytest-cov
isort isort
sphinx
tqdm tqdm
matplotlib matplotlib

@ -1,5 +1,4 @@
# Package dependencies # Package dependencies
argparse
numpy==1.24.4 numpy==1.24.4
scipy scipy
sisl==0.14.3 sisl==0.14.3

@ -0,0 +1,526 @@
from useful import *
def main():
import os
from sys import stdout
from timeit import default_timer as timer
from tqdm import tqdm
os.environ["OMP_NUM_THREADS"] = "1" # export OMP_NUM_THREADS=4
os.environ["OPENBLAS_NUM_THREADS"] = "1" # export OPENBLAS_NUM_THREADS=4
os.environ["MKL_NUM_THREADS"] = "1" # export MKL_NUM_THREADS=6
os.environ["VECLIB_MAXIMUM_THREADS"] = "1" # export VECLIB_MAXIMUM_THREADS=4
os.environ["NUMEXPR_NUM_THREADS"] = "1" # export NUMEXPR_NUM_THREADS=6
import warnings
import numpy as np
import sisl
from mpi4py import MPI
from numpy.linalg import inv
start_time = timer()
# this cell mimicks an input file
fdf = sisl.get_sile("../../lat3_791/Fe3GeTe2.fdf")
# this information needs to be given at the input!!
scf_xcf_orientation = np.array([0, 0, 1]) # z
# list of reference directions for around which we calculate the derivatives
# o is the quantization axis, v and w are two axes perpendicular to it
# at this moment the user has to supply o,v,w on the input.
# we can have some default for this
ref_xcf_orientations = [
dict(o=np.array([1, 0, 0]), vw=[np.array([0, 1, 0]), np.array([0, 0, 1])]),
dict(o=np.array([0, 1, 0]), vw=[np.array([1, 0, 0]), np.array([0, 0, 1])]),
dict(o=np.array([0, 0, 1]), vw=[np.array([1, 0, 0]), np.array([0, 1, 0])]),
]
# human readable definition of magnetic entities
# magnetic_entities = [
# dict(atom=0, ),
# dict(atom=1, ),
# dict(atom=2, ),
# dict(atom=3, l=2),
# dict(atom=4, l=2),
# dict(atom=5, l=2),
# ]
# pairs = [
# dict(ai=3, aj=4, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV
# dict(ai=3, aj=5, Ruc=np.array([0, 0, 0])), # these should all be around -41.9 in the isotropic part
# dict(ai=4, aj=5, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=0, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=1, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=2, Ruc=np.array([0, 0, 0])),
# ]
magnetic_entities = [
dict(atom=3, l=2),
dict(atom=4, l=2),
dict(atom=5, l=2),
]
# pair information
pairs = [
dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV
dict(
ai=0, aj=2, Ruc=np.array([0, 0, 0])
), # these should all be around -41.9 in the isotropic part
dict(ai=1, aj=2, Ruc=np.array([0, 0, 0])),
dict(ai=0, aj=1, Ruc=np.array([-1, 0, 0])),
dict(ai=0, aj=2, Ruc=np.array([-1, 0, 0])),
dict(ai=0, aj=1, Ruc=np.array([1, 0, 0])),
dict(ai=0, aj=2, Ruc=np.array([1, 0, 0])),
dict(ai=0, aj=1, Ruc=np.array([0, -1, 0])),
dict(ai=0, aj=2, Ruc=np.array([0, -1, 0])),
dict(ai=0, aj=1, Ruc=np.array([0, 1, 0])),
dict(ai=0, aj=2, Ruc=np.array([0, 1, 0])),
dict(ai=1, aj=2, Ruc=np.array([-1, 0, 0])),
]
# Brilloun zone sampling and Green function contour integral
kset = 20
kdirs = "xy"
ebot = -30
eset = 50
esetp = 1000
# MPI parameters
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
root_node = 0
if rank == root_node:
print("Number of nodes in the parallel cluster: ", size)
simulation_parameters = dict(
path="Not yet specified.",
scf_xcf_orientation=scf_xcf_orientation,
ref_xcf_orientations=ref_xcf_orientations,
kset=kset,
kdirs=kdirs,
ebot=ebot,
eset=eset,
esetp=esetp,
parallel_size=size,
)
# digestion of the input
# read in hamiltonian
dh = fdf.read_hamiltonian()
try:
simulation_parameters["geom"] = fdf.read_geometry()
except:
print("Error reading geometry.")
# unit cell index
uc_in_sc_idx = dh.lattice.sc_index([0, 0, 0])
setup_time = timer()
NO = dh.no # shorthand for number of orbitals in the unit cell
# preprocessing Hamiltonian and overlap matrix elements
h11 = dh.tocsr(dh.M11r)
h11 += dh.tocsr(dh.M11i) * 1.0j
h11 = h11.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
h22 = dh.tocsr(dh.M22r)
h22 += dh.tocsr(dh.M22i) * 1.0j
h22 = h22.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
h12 = dh.tocsr(dh.M12r)
h12 += dh.tocsr(dh.M12i) * 1.0j
h12 = h12.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
h21 = dh.tocsr(dh.M21r)
h21 += dh.tocsr(dh.M21i) * 1.0j
h21 = h21.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
sov = (
dh.tocsr(dh.S_idx)
.toarray()
.reshape(NO, dh.n_s, NO)
.transpose(0, 2, 1)
.astype("complex128")
)
# Reorganization of Hamiltonian and overlap matrix elements to SPIN BOX representation
U = np.vstack(
[np.kron(np.eye(NO, dtype=int), [1, 0]), np.kron(np.eye(NO, dtype=int), [0, 1])]
)
# This is the permutation that transforms ud1ud2 to u12d12
# That is this transforms FROM SPIN BOX to ORBITAL BOX => U
# the inverse transformation is U.T u12d12 to ud1ud2
# That is FROM ORBITAL BOX to SPIN BOX => U.T
# From now on everything is in SPIN BOX!!
hh, ss = np.array(
[
U.T
@ np.block([[h11[:, :, i], h12[:, :, i]], [h21[:, :, i], h22[:, :, i]]])
@ U
for i in range(dh.lattice.nsc.prod())
]
), np.array(
[
U.T
@ np.block(
[[sov[:, :, i], sov[:, :, i] * 0], [sov[:, :, i] * 0, sov[:, :, i]]]
)
@ U
for i in range(dh.lattice.nsc.prod())
]
)
# symmetrizing Hamiltonian and overlap matrix to make them hermitian
for i in range(dh.lattice.sc_off.shape[0]):
j = dh.lattice.sc_index(-dh.lattice.sc_off[i])
h1, h1d = hh[i], hh[j]
hh[i], hh[j] = (h1 + h1d.T.conj()) / 2, (h1d + h1.T.conj()) / 2
s1, s1d = ss[i], ss[j]
ss[i], ss[j] = (s1 + s1d.T.conj()) / 2, (s1d + s1.T.conj()) / 2
# identifying TRS and TRB parts of the Hamiltonian
TAUY = np.kron(np.eye(NO), tau_y)
hTR = np.array([TAUY @ hh[i].conj() @ TAUY for i in range(dh.lattice.nsc.prod())])
hTRS = (hh + hTR) / 2
hTRB = (hh - hTR) / 2
# extracting the exchange field
traced = [spin_tracer(hTRB[i]) for i in range(dh.lattice.nsc.prod())] # equation 77
XCF = np.array(
[
np.array([f["x"] for f in traced]),
np.array([f["y"] for f in traced]),
np.array([f["z"] for f in traced]),
]
) # equation 77
# Check if exchange field has scalar part
max_xcfs = abs(np.array(np.array([f["c"] for f in traced]))).max()
if max_xcfs > 1e-12:
warnings.warn(
f"Exchange field has non negligible scalar part. Largest value is {max_xcfs}"
)
H_and_XCF_time = timer()
# for every site we have to store 3 Greens function (and the associated _tmp-s) in the 3 reference directions
for i, mag_ent in enumerate(magnetic_entities):
parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes
magnetic_entities[i]["orbital_indeces"] = parsed
magnetic_entities[i]["spin_box_indeces"] = blow_up_orbindx(
parsed
) # calculate spin box indexes
spin_box_shape = len(
mag_ent["spin_box_indeces"]
) # calculate size for Greens function generation
mag_ent["energies"] = (
[]
) # we will store the second order energy derivations here
mag_ent["Gii"] = [] # Greens function
mag_ent["Gii_tmp"] = [] # Greens function for parallelization
mag_ent["Vu1"] = [
list([]) for _ in range(len(ref_xcf_orientations))
] # These will be the perturbed potentials from eq. 100
mag_ent["Vu2"] = [list([]) for _ in range(len(ref_xcf_orientations))]
for i in ref_xcf_orientations:
mag_ent["Gii"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128")
) # Greens functions for every quantization axis
mag_ent["Gii_tmp"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128")
)
# for every site we have to store 2x3 Greens function (and the associated _tmp-s)
# in the 3 reference directions, because G_ij and G_ji are both needed
for pair in pairs:
spin_box_shape_i, spin_box_shape_j = len(
magnetic_entities[pair["ai"]]["spin_box_indeces"]
), len(
magnetic_entities[pair["aj"]]["spin_box_indeces"]
) # calculate size for Greens function generation
pair["energies"] = [] # we will store the second order energy derivations here
pair["Gij"] = [] # Greens function
pair["Gji"] = []
pair["Gij_tmp"] = [] # Greens function for parallelization
pair["Gji_tmp"] = []
pair["Vij"] = [
list([]) for _ in range(len(ref_xcf_orientations))
] # These will be the perturbed potentials from eq. 100
pair["Vji"] = [list([]) for _ in range(len(ref_xcf_orientations))]
for i in ref_xcf_orientations:
pair["Gij"].append(
np.zeros((eset, spin_box_shape_i, spin_box_shape_j), dtype="complex128")
)
pair["Gij_tmp"].append(
np.zeros((eset, spin_box_shape_i, spin_box_shape_j), dtype="complex128")
) # Greens functions for every quantization axis
pair["Gji"].append(
np.zeros((eset, spin_box_shape_j, spin_box_shape_i), dtype="complex128")
)
pair["Gji_tmp"].append(
np.zeros((eset, spin_box_shape_j, spin_box_shape_i), dtype="complex128")
)
site_and_pair_dictionaries_time = timer()
kset = make_kset(dirs=kdirs, NUMK=kset) # generate k space sampling
wkset = np.ones(len(kset)) / len(kset) # generate weights for k points
kpcs = np.array_split(kset, size) # split the k points based on MPI size
kpcs[root_node] = tqdm(kpcs[root_node], desc="k loop", file=stdout)
k_set_time = timer()
# this will contain all the data needed to calculate the energy variations upon rotation
hamiltonians = []
# iterate over the reference directions (quantization axes)
for i, orient in enumerate(ref_xcf_orientations):
# obtain rotated exchange field
R = RotMa2b(scf_xcf_orientation, orient["o"])
rot_XCF = np.einsum("ij,jklm->iklm", R, XCF)
rot_H_XCF = sum(
[np.kron(rot_XCF[i], tau) for i, tau in enumerate([tau_x, tau_y, tau_z])]
)
rot_H_XCF_uc = rot_H_XCF[uc_in_sc_idx]
# obtain total Hamiltonian with the rotated exchange field
rot_H = hTRS + rot_H_XCF # equation 76
hamiltonians.append(
dict(orient=orient["o"], H=rot_H, rotations=[])
) # store orientation and rotated Hamiltonian
for u in orient[
"vw"
]: # these are the infinitezimal rotations (for now) perpendicular to the quantization axis
Tu = np.kron(np.eye(NO, dtype=int), tau_u(u)) # section 2.H
Vu1 = 1j / 2 * commutator(rot_H_XCF_uc, Tu) # equation 100
Vu2 = 1 / 8 * commutator(commutator(Tu, rot_H_XCF_uc), Tu) # equation 100
for mag_ent in magnetic_entities:
mag_ent["Vu1"][i].append(
Vu1[:, mag_ent["spin_box_indeces"]][mag_ent["spin_box_indeces"], :]
) # fill up the perturbed potentials (for now) based on the on-site projections
mag_ent["Vu2"][i].append(
Vu2[:, mag_ent["spin_box_indeces"]][mag_ent["spin_box_indeces"], :]
)
for pair in pairs:
ai = magnetic_entities[pair["ai"]][
"spin_box_indeces"
] # get the pair orbital sizes from the magnetic entities
aj = magnetic_entities[pair["aj"]]["spin_box_indeces"]
pair["Vij"][i].append(
Vu1[:, ai][aj, :]
) # fill up the perturbed potentials (for now) based on the on-site projections
pair["Vji"][i].append(Vu1[:, aj][ai, :])
reference_rotations_time = timer()
if rank == root_node:
print("Number of magnetic entities being calculated: ", len(magnetic_entities))
print(
"We have to calculate the Greens function for three reference direction and we are going to calculate 15 energy integrals per site."
)
print(f"The shape of the Hamiltonian and the Greens function is {NO}x{NO}.")
comm.Barrier()
# ----------------------------------------------------------------------
# make energy contour
# we are working in eV now !
# and sisil shifts E_F to 0 !
cont = make_contour(emin=ebot, enum=eset, p=esetp)
eran = cont.ze
# ----------------------------------------------------------------------
# sampling the integrand on the contour and the BZ
for k in kpcs[rank]:
wk = wkset[rank] # weight of k point in BZ integral
for i, hamiltonian_orientation in enumerate(
hamiltonians
): # iterate over reference directions
# calculate Greens function
H = hamiltonian_orientation["H"]
HK, SK = hsk(H, ss, dh.sc_off, k)
Gk = inv(SK * eran.reshape(eset, 1, 1) - HK)
# store the Greens function slice of the magnetic entities (for now) based on the on-site projections
for mag_ent in magnetic_entities:
mag_ent["Gii_tmp"][i] += (
Gk[:, mag_ent["spin_box_indeces"]][..., mag_ent["spin_box_indeces"]]
* wk
)
for pair in pairs:
# add phase shift based on the cell difference
phase = np.exp(1j * 2 * np.pi * k @ pair["Ruc"].T)
# get the pair orbital sizes from the magnetic entities
ai = magnetic_entities[pair["ai"]]["spin_box_indeces"]
aj = magnetic_entities[pair["aj"]]["spin_box_indeces"]
# store the Greens function slice of the magnetic entities (for now) based on the on-site projections
pair["Gij_tmp"][i] += Gk[:, ai][..., aj] * phase * wk
pair["Gji_tmp"][i] += Gk[:, aj][..., ai] * phase * wk
# summ reduce partial results of mpi nodes
for i in range(len(hamiltonians)):
for mag_ent in magnetic_entities:
comm.Reduce(mag_ent["Gii_tmp"][i], mag_ent["Gii"][i], root=root_node)
for pair in pairs:
comm.Reduce(pair["Gij_tmp"][i], pair["Gij"][i], root=root_node)
comm.Reduce(pair["Gji_tmp"][i], pair["Gji"][i], root=root_node)
green_function_inversion_time = timer()
if rank == root_node:
# iterate over the magnetic entities
for tracker, mag_ent in enumerate(magnetic_entities):
# iterate over the quantization axes
for i, Gii in enumerate(mag_ent["Gii"]):
storage = []
# iterate over the first and second order local perturbations
for Vu1, Vu2 in zip(mag_ent["Vu1"][i], mag_ent["Vu2"][i]):
# The Szunyogh-Lichtenstein formula
traced = np.trace(
(Vu2 @ Gii + 0.5 * Gii @ Vu1 @ Gii), axis1=1, axis2=2
)
# evaluation of the contour integral
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the magnetic entities dictionary with the energies
mag_ent["energies"].append(storage)
# iterate over the pairs
for tracker, pair in enumerate(pairs):
# iterate over the quantization axes
for i, (Gij, Gji) in enumerate(zip(pair["Gij"], pair["Gji"])):
site_i = magnetic_entities[pair["ai"]]
site_j = magnetic_entities[pair["aj"]]
storage = []
# iterate over the first order local perturbations in all possible orientations for the two sites
for Vui in site_i["Vu1"][i]:
for Vuj in site_j["Vu1"][i]:
# The Szunyogh-Lichtenstein formula
traced = np.trace((Vui @ Gij @ Vuj @ Gji), axis1=1, axis2=2)
# evaluation of the contour integral
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the pairs dictionary with the energies
pairs[tracker]["energies"].append(storage)
end_time = timer()
print(
"############################### GROGU OUTPUT ###################################"
)
print(
"================================================================================"
)
print("Input file: ")
print(simulation_parameters["path"])
print(
"Number of nodes in the parallel cluster: ",
simulation_parameters["parallel_size"],
)
print(
"================================================================================"
)
try:
print("Cell [Ang]: ")
print(simulation_parameters["geom"].cell)
except:
print("Geometry could not be read.")
print(
"================================================================================"
)
print("DFT axis: ")
print(simulation_parameters["scf_xcf_orientation"])
print("Quantization axis and perpendicular rotation directions:")
for ref in ref_xcf_orientations:
print(ref["o"], " --» ", ref["vw"])
print(
"================================================================================"
)
print("number of k points: ", simulation_parameters["kset"])
print("k point directions: ", simulation_parameters["kdirs"])
print(
"================================================================================"
)
print("Parameters for the contour integral:")
print("Ebot: ", simulation_parameters["ebot"])
print("Eset: ", simulation_parameters["eset"])
print("Esetp: ", simulation_parameters["esetp"])
print(
"================================================================================"
)
print("Atomic informations: ")
print("")
print("")
print("Not yet specified.")
print("")
print("")
print(
"================================================================================"
)
print("Exchange [meV]")
print(
"--------------------------------------------------------------------------------"
)
print("Atom1 Atom2 [i j k] d [Ang]")
print(
"--------------------------------------------------------------------------------"
)
for pair in pairs:
J_iso, J_S, D = calculate_exchange_tensor(pair)
J_iso = J_iso * sisl.unit_convert("eV", "meV")
J_S = J_S * sisl.unit_convert("eV", "meV")
D = D * sisl.unit_convert("eV", "meV")
print(print_atomic_indices(pair, magnetic_entities, dh))
print("Isotropic: ", J_iso)
print("DMI: ", D)
print("Symmetric-anisotropy: ", J_S)
print("")
print(
"================================================================================"
)
print("Runtime information: ")
print("Total runtime: ", end_time - start_time)
print(
"--------------------------------------------------------------------------------"
)
print("Initial setup: ", setup_time - start_time)
print(
f"Hamiltonian conversion and XC field extraction: {H_and_XCF_time - setup_time:.3f} s"
)
print(
f"Pair and site datastructure creatrions: {site_and_pair_dictionaries_time - H_and_XCF_time:.3f} s"
)
print(
f"k set cration and distribution: {k_set_time - site_and_pair_dictionaries_time:.3f} s"
)
print(f"Rotating XC potential: {reference_rotations_time - k_set_time:.3f} s")
print(
f"Greens function inversion: {green_function_inversion_time - reference_rotations_time:.3f} s"
)
print(
f"Calculate energies and magnetic components: {end_time - green_function_inversion_time:.3f} s"
)
if __name__ == "__main__":
main()

@ -31,7 +31,7 @@ if __name__ == "__main__":
from mpi4py import MPI from mpi4py import MPI
from scipy.special import roots_legendre from scipy.special import roots_legendre
from grogu.useful import hsk, make_atran, make_contour, make_kset from grogu_magn.useful import hsk, make_atran, make_contour, make_kset
start = timer() start = timer()

File diff suppressed because one or more lines are too long

@ -1,515 +0,0 @@
import os
from sys import stdout
from timeit import default_timer as timer
from tqdm import tqdm
os.environ["OMP_NUM_THREADS"] = "1" # export OMP_NUM_THREADS=4
os.environ["OPENBLAS_NUM_THREADS"] = "1" # export OPENBLAS_NUM_THREADS=4
os.environ["MKL_NUM_THREADS"] = "1" # export MKL_NUM_THREADS=6
os.environ["VECLIB_MAXIMUM_THREADS"] = "1" # export VECLIB_MAXIMUM_THREADS=4
os.environ["NUMEXPR_NUM_THREADS"] = "1" # export NUMEXPR_NUM_THREADS=6
import warnings
import numpy as np
import sisl
from mpi4py import MPI
from numpy.linalg import inv
from grogu.useful import *
start_time = timer()
# this cell mimicks an input file
fdf = sisl.get_sile("./lat3_791/Fe3GeTe2.fdf")
# this information needs to be given at the input!!
scf_xcf_orientation = np.array([0, 0, 1]) # z
# list of reference directions for around which we calculate the derivatives
# o is the quantization axis, v and w are two axes perpendicular to it
# at this moment the user has to supply o,v,w on the input.
# we can have some default for this
ref_xcf_orientations = [
dict(o=np.array([1, 0, 0]), vw=[np.array([0, 1, 0]), np.array([0, 0, 1])]),
dict(o=np.array([0, 1, 0]), vw=[np.array([1, 0, 0]), np.array([0, 0, 1])]),
dict(o=np.array([0, 0, 1]), vw=[np.array([1, 0, 0]), np.array([0, 1, 0])]),
]
# human readable definition of magnetic entities
# magnetic_entities = [
# dict(atom=0, ),
# dict(atom=1, ),
# dict(atom=2, ),
# dict(atom=3, l=2),
# dict(atom=4, l=2),
# dict(atom=5, l=2),
# ]
# pairs = [
# dict(ai=3, aj=4, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV
# dict(ai=3, aj=5, Ruc=np.array([0, 0, 0])), # these should all be around -41.9 in the isotropic part
# dict(ai=4, aj=5, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=0, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=1, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=2, Ruc=np.array([0, 0, 0])),
# ]
magnetic_entities = [
dict(atom=3, l=2),
dict(atom=4, l=2),
dict(atom=5, l=2),
]
# pair information
pairs = [
dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV
dict(
ai=0, aj=2, Ruc=np.array([0, 0, 0])
), # these should all be around -41.9 in the isotropic part
dict(ai=1, aj=2, Ruc=np.array([0, 0, 0])),
dict(ai=0, aj=1, Ruc=np.array([-1, 0, 0])),
dict(ai=0, aj=2, Ruc=np.array([-1, 0, 0])),
dict(ai=0, aj=1, Ruc=np.array([1, 0, 0])),
dict(ai=0, aj=2, Ruc=np.array([1, 0, 0])),
dict(ai=0, aj=1, Ruc=np.array([0, -1, 0])),
dict(ai=0, aj=2, Ruc=np.array([0, -1, 0])),
dict(ai=0, aj=1, Ruc=np.array([0, 1, 0])),
dict(ai=0, aj=2, Ruc=np.array([0, 1, 0])),
dict(ai=1, aj=2, Ruc=np.array([-1, 0, 0])),
]
# Brilloun zone sampling and Green function contour integral
kset = 20
kdirs = "xy"
ebot = -30
eset = 50
esetp = 1000
# MPI parameters
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
root_node = 0
if rank == root_node:
print("Number of nodes in the parallel cluster: ", size)
simulation_parameters = dict(
path="Not yet specified.",
scf_xcf_orientation=scf_xcf_orientation,
ref_xcf_orientations=ref_xcf_orientations,
kset=kset,
kdirs=kdirs,
ebot=ebot,
eset=eset,
esetp=esetp,
parallel_size=size,
)
# digestion of the input
# read in hamiltonian
dh = fdf.read_hamiltonian()
try:
simulation_parameters["geom"] = fdf.read_geometry()
except:
print("Error reading geometry.")
# unit cell index
uc_in_sc_idx = dh.lattice.sc_index([0, 0, 0])
setup_time = timer()
NO = dh.no # shorthand for number of orbitals in the unit cell
# preprocessing Hamiltonian and overlap matrix elements
h11 = dh.tocsr(dh.M11r)
h11 += dh.tocsr(dh.M11i) * 1.0j
h11 = h11.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
h22 = dh.tocsr(dh.M22r)
h22 += dh.tocsr(dh.M22i) * 1.0j
h22 = h22.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
h12 = dh.tocsr(dh.M12r)
h12 += dh.tocsr(dh.M12i) * 1.0j
h12 = h12.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
h21 = dh.tocsr(dh.M21r)
h21 += dh.tocsr(dh.M21i) * 1.0j
h21 = h21.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype("complex128")
sov = (
dh.tocsr(dh.S_idx)
.toarray()
.reshape(NO, dh.n_s, NO)
.transpose(0, 2, 1)
.astype("complex128")
)
# Reorganization of Hamiltonian and overlap matrix elements to SPIN BOX representation
U = np.vstack(
[np.kron(np.eye(NO, dtype=int), [1, 0]), np.kron(np.eye(NO, dtype=int), [0, 1])]
)
# This is the permutation that transforms ud1ud2 to u12d12
# That is this transforms FROM SPIN BOX to ORBITAL BOX => U
# the inverse transformation is U.T u12d12 to ud1ud2
# That is FROM ORBITAL BOX to SPIN BOX => U.T
# From now on everything is in SPIN BOX!!
hh, ss = np.array(
[
U.T @ np.block([[h11[:, :, i], h12[:, :, i]], [h21[:, :, i], h22[:, :, i]]]) @ U
for i in range(dh.lattice.nsc.prod())
]
), np.array(
[
U.T
@ np.block([[sov[:, :, i], sov[:, :, i] * 0], [sov[:, :, i] * 0, sov[:, :, i]]])
@ U
for i in range(dh.lattice.nsc.prod())
]
)
# symmetrizing Hamiltonian and overlap matrix to make them hermitian
for i in range(dh.lattice.sc_off.shape[0]):
j = dh.lattice.sc_index(-dh.lattice.sc_off[i])
h1, h1d = hh[i], hh[j]
hh[i], hh[j] = (h1 + h1d.T.conj()) / 2, (h1d + h1.T.conj()) / 2
s1, s1d = ss[i], ss[j]
ss[i], ss[j] = (s1 + s1d.T.conj()) / 2, (s1d + s1.T.conj()) / 2
# identifying TRS and TRB parts of the Hamiltonian
TAUY = np.kron(np.eye(NO), tau_y)
hTR = np.array([TAUY @ hh[i].conj() @ TAUY for i in range(dh.lattice.nsc.prod())])
hTRS = (hh + hTR) / 2
hTRB = (hh - hTR) / 2
# extracting the exchange field
traced = [spin_tracer(hTRB[i]) for i in range(dh.lattice.nsc.prod())] # equation 77
XCF = np.array(
[
np.array([f["x"] for f in traced]),
np.array([f["y"] for f in traced]),
np.array([f["z"] for f in traced]),
]
) # equation 77
# Check if exchange field has scalar part
max_xcfs = abs(np.array(np.array([f["c"] for f in traced]))).max()
if max_xcfs > 1e-12:
warnings.warn(
f"Exchange field has non negligible scalar part. Largest value is {max_xcfs}"
)
H_and_XCF_time = timer()
# for every site we have to store 3 Greens function (and the associated _tmp-s) in the 3 reference directions
for i, mag_ent in enumerate(magnetic_entities):
parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes
magnetic_entities[i]["orbital_indeces"] = parsed
magnetic_entities[i]["spin_box_indeces"] = blow_up_orbindx(
parsed
) # calculate spin box indexes
spin_box_shape = len(
mag_ent["spin_box_indeces"]
) # calculate size for Greens function generation
mag_ent["energies"] = [] # we will store the second order energy derivations here
mag_ent["Gii"] = [] # Greens function
mag_ent["Gii_tmp"] = [] # Greens function for parallelization
mag_ent["Vu1"] = [
list([]) for _ in range(len(ref_xcf_orientations))
] # These will be the perturbed potentials from eq. 100
mag_ent["Vu2"] = [list([]) for _ in range(len(ref_xcf_orientations))]
for i in ref_xcf_orientations:
mag_ent["Gii"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128")
) # Greens functions for every quantization axis
mag_ent["Gii_tmp"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128")
)
# for every site we have to store 2x3 Greens function (and the associated _tmp-s)
# in the 3 reference directions, because G_ij and G_ji are both needed
for pair in pairs:
spin_box_shape_i, spin_box_shape_j = len(
magnetic_entities[pair["ai"]]["spin_box_indeces"]
), len(
magnetic_entities[pair["aj"]]["spin_box_indeces"]
) # calculate size for Greens function generation
pair["energies"] = [] # we will store the second order energy derivations here
pair["Gij"] = [] # Greens function
pair["Gji"] = []
pair["Gij_tmp"] = [] # Greens function for parallelization
pair["Gji_tmp"] = []
pair["Vij"] = [
list([]) for _ in range(len(ref_xcf_orientations))
] # These will be the perturbed potentials from eq. 100
pair["Vji"] = [list([]) for _ in range(len(ref_xcf_orientations))]
for i in ref_xcf_orientations:
pair["Gij"].append(
np.zeros((eset, spin_box_shape_i, spin_box_shape_j), dtype="complex128")
)
pair["Gij_tmp"].append(
np.zeros((eset, spin_box_shape_i, spin_box_shape_j), dtype="complex128")
) # Greens functions for every quantization axis
pair["Gji"].append(
np.zeros((eset, spin_box_shape_j, spin_box_shape_i), dtype="complex128")
)
pair["Gji_tmp"].append(
np.zeros((eset, spin_box_shape_j, spin_box_shape_i), dtype="complex128")
)
site_and_pair_dictionaries_time = timer()
kset = make_kset(dirs=kdirs, NUMK=kset) # generate k space sampling
wkset = np.ones(len(kset)) / len(kset) # generate weights for k points
kpcs = np.array_split(kset, size) # split the k points based on MPI size
kpcs[root_node] = tqdm(kpcs[root_node], desc="k loop", file=stdout)
k_set_time = timer()
# this will contain all the data needed to calculate the energy variations upon rotation
hamiltonians = []
# iterate over the reference directions (quantization axes)
for i, orient in enumerate(ref_xcf_orientations):
# obtain rotated exchange field
R = RotMa2b(scf_xcf_orientation, orient["o"])
rot_XCF = np.einsum("ij,jklm->iklm", R, XCF)
rot_H_XCF = sum(
[np.kron(rot_XCF[i], tau) for i, tau in enumerate([tau_x, tau_y, tau_z])]
)
rot_H_XCF_uc = rot_H_XCF[uc_in_sc_idx]
# obtain total Hamiltonian with the rotated exchange field
rot_H = hTRS + rot_H_XCF # equation 76
hamiltonians.append(
dict(orient=orient["o"], H=rot_H, rotations=[])
) # store orientation and rotated Hamiltonian
for u in orient[
"vw"
]: # these are the infinitezimal rotations (for now) perpendicular to the quantization axis
Tu = np.kron(np.eye(NO, dtype=int), tau_u(u)) # section 2.H
Vu1 = 1j / 2 * commutator(rot_H_XCF_uc, Tu) # equation 100
Vu2 = 1 / 8 * commutator(commutator(Tu, rot_H_XCF_uc), Tu) # equation 100
for mag_ent in magnetic_entities:
mag_ent["Vu1"][i].append(
Vu1[:, mag_ent["spin_box_indeces"]][mag_ent["spin_box_indeces"], :]
) # fill up the perturbed potentials (for now) based on the on-site projections
mag_ent["Vu2"][i].append(
Vu2[:, mag_ent["spin_box_indeces"]][mag_ent["spin_box_indeces"], :]
)
for pair in pairs:
ai = magnetic_entities[pair["ai"]][
"spin_box_indeces"
] # get the pair orbital sizes from the magnetic entities
aj = magnetic_entities[pair["aj"]]["spin_box_indeces"]
pair["Vij"][i].append(
Vu1[:, ai][aj, :]
) # fill up the perturbed potentials (for now) based on the on-site projections
pair["Vji"][i].append(Vu1[:, aj][ai, :])
reference_rotations_time = timer()
if rank == root_node:
print("Number of magnetic entities being calculated: ", len(magnetic_entities))
print(
"We have to calculate the Greens function for three reference direction and we are going to calculate 15 energy integrals per site."
)
print(f"The shape of the Hamiltonian and the Greens function is {NO}x{NO}.")
comm.Barrier()
# ----------------------------------------------------------------------
# make energy contour
# we are working in eV now !
# and sisil shifts E_F to 0 !
cont = make_contour(emin=ebot, enum=eset, p=esetp)
eran = cont.ze
# ----------------------------------------------------------------------
# sampling the integrand on the contour and the BZ
for k in kpcs[rank]:
wk = wkset[rank] # weight of k point in BZ integral
for i, hamiltonian_orientation in enumerate(
hamiltonians
): # iterate over reference directions
# calculate Greens function
H = hamiltonian_orientation["H"]
HK, SK = hsk(H, ss, dh.sc_off, k)
Gk = inv(SK * eran.reshape(eset, 1, 1) - HK)
# store the Greens function slice of the magnetic entities (for now) based on the on-site projections
for mag_ent in magnetic_entities:
mag_ent["Gii_tmp"][i] += (
Gk[:, mag_ent["spin_box_indeces"]][..., mag_ent["spin_box_indeces"]]
* wk
)
for pair in pairs:
# add phase shift based on the cell difference
phase = np.exp(1j * 2 * np.pi * k @ pair["Ruc"].T)
# get the pair orbital sizes from the magnetic entities
ai = magnetic_entities[pair["ai"]]["spin_box_indeces"]
aj = magnetic_entities[pair["aj"]]["spin_box_indeces"]
# store the Greens function slice of the magnetic entities (for now) based on the on-site projections
pair["Gij_tmp"][i] += Gk[:, ai][..., aj] * phase * wk
pair["Gji_tmp"][i] += Gk[:, aj][..., ai] * phase * wk
# summ reduce partial results of mpi nodes
for i in range(len(hamiltonians)):
for mag_ent in magnetic_entities:
comm.Reduce(mag_ent["Gii_tmp"][i], mag_ent["Gii"][i], root=root_node)
for pair in pairs:
comm.Reduce(pair["Gij_tmp"][i], pair["Gij"][i], root=root_node)
comm.Reduce(pair["Gji_tmp"][i], pair["Gji"][i], root=root_node)
green_function_inversion_time = timer()
if rank == root_node:
# iterate over the magnetic entities
for tracker, mag_ent in enumerate(magnetic_entities):
# iterate over the quantization axes
for i, Gii in enumerate(mag_ent["Gii"]):
storage = []
# iterate over the first and second order local perturbations
for Vu1, Vu2 in zip(mag_ent["Vu1"][i], mag_ent["Vu2"][i]):
# The Szunyogh-Lichtenstein formula
traced = np.trace((Vu2 @ Gii + 0.5 * Gii @ Vu1 @ Gii), axis1=1, axis2=2)
# evaluation of the contour integral
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the magnetic entities dictionary with the energies
mag_ent["energies"].append(storage)
# iterate over the pairs
for tracker, pair in enumerate(pairs):
# iterate over the quantization axes
for i, (Gij, Gji) in enumerate(zip(pair["Gij"], pair["Gji"])):
site_i = magnetic_entities[pair["ai"]]
site_j = magnetic_entities[pair["aj"]]
storage = []
# iterate over the first order local perturbations in all possible orientations for the two sites
for Vui in site_i["Vu1"][i]:
for Vuj in site_j["Vu1"][i]:
# The Szunyogh-Lichtenstein formula
traced = np.trace((Vui @ Gij @ Vuj @ Gji), axis1=1, axis2=2)
# evaluation of the contour integral
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the pairs dictionary with the energies
pairs[tracker]["energies"].append(storage)
end_time = timer()
print(
"############################### GROGU OUTPUT ###################################"
)
print(
"================================================================================"
)
print("Input file: ")
print(simulation_parameters["path"])
print(
"Number of nodes in the parallel cluster: ",
simulation_parameters["parallel_size"],
)
print(
"================================================================================"
)
try:
print("Cell [Ang]: ")
print(simulation_parameters["geom"].cell)
except:
print("Geometry could not be read.")
print(
"================================================================================"
)
print("DFT axis: ")
print(simulation_parameters["scf_xcf_orientation"])
print("Quantization axis and perpendicular rotation directions:")
for ref in ref_xcf_orientations:
print(ref["o"], " --» ", ref["vw"])
print(
"================================================================================"
)
print("number of k points: ", simulation_parameters["kset"])
print("k point directions: ", simulation_parameters["kdirs"])
print(
"================================================================================"
)
print("Parameters for the contour integral:")
print("Ebot: ", simulation_parameters["ebot"])
print("Eset: ", simulation_parameters["eset"])
print("Esetp: ", simulation_parameters["esetp"])
print(
"================================================================================"
)
print("Atomic informations: ")
print("")
print("")
print("Not yet specified.")
print("")
print("")
print(
"================================================================================"
)
print("Exchange [meV]")
print(
"--------------------------------------------------------------------------------"
)
print("Atom1 Atom2 [i j k] d [Ang]")
print(
"--------------------------------------------------------------------------------"
)
for pair in pairs:
J_iso, J_S, D = calculate_exchange_tensor(pair)
J_iso = J_iso * sisl.unit_convert("eV", "meV")
J_S = J_S * sisl.unit_convert("eV", "meV")
D = D * sisl.unit_convert("eV", "meV")
print(print_atomic_indices(pair, magnetic_entities, dh))
print("Isotropic: ", J_iso)
print("DMI: ", D)
print("Symmetric-anisotropy: ", J_S)
print("")
print(
"================================================================================"
)
print("Runtime information: ")
print("Total runtime: ", end_time - start_time)
print(
"--------------------------------------------------------------------------------"
)
print("Initial setup: ", setup_time - start_time)
print(
f"Hamiltonian conversion and XC field extraction: {H_and_XCF_time - setup_time:.3f} s"
)
print(
f"Pair and site datastructure creatrions: {site_and_pair_dictionaries_time - H_and_XCF_time:.3f} s"
)
print(
f"k set cration and distribution: {k_set_time - site_and_pair_dictionaries_time:.3f} s"
)
print(f"Rotating XC potential: {reference_rotations_time - k_set_time:.3f} s")
print(
f"Greens function inversion: {green_function_inversion_time - reference_rotations_time:.3f} s"
)
print(
f"Calculate energies and magnetic components: {end_time - green_function_inversion_time:.3f} s"
)
Loading…
Cancel
Save