.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "school-tutorials/trilmax-2025/1_python-library/plot_7_lswt.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_school-tutorials_trilmax-2025_1_python-library_plot_7_lswt.py: Linear Spin Wave theory *********************** .. admonition:: Tutorial tasks * Use one of the spin Hamiltonians from the previous tutorial and compute all terms of the magnon Hamiltonian. * Compute magnon dispersion of a simple ferromagnet. * Compute magnon dispersion of a simple antiferromagnet. All methods of linear spin-wave theory are grouped under the :py:class:`magnopy.LSWT` class. Two objects are required to create it * Spin Hamiltonian * Directions of spins in the ground state .. GENERATED FROM PYTHON SOURCE LINES 20-28 .. code-block:: Python import numpy as np import magnopy spinham = magnopy.examples.cubic_ferro_nn(S=1, J_21=(0, 0, -0.5)) lswt = magnopy.LSWT(spinham=spinham, spin_directions=[[0, 0, 1]]) .. GENERATED FROM PYTHON SOURCE LINES 29-33 Once created it can be used to compute terms of the magnon Hamiltonian Correction to the classical energy ================================== .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python print(lswt.E_2) .. rst-class:: sphx-glr-script-out .. code-block:: none -3.5 .. GENERATED FROM PYTHON SOURCE LINES 37-39 Coefficients of the one-operator terms ====================================== .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: Python print(lswt.O) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.+0.j] .. GENERATED FROM PYTHON SOURCE LINES 43-45 Magnon energies =============== .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python print(lswt.omega(k=[0, 0, 0])) .. rst-class:: sphx-glr-script-out .. code-block:: none [1.+0.j] .. GENERATED FROM PYTHON SOURCE LINES 49-58 Parallelization =============== Typically one wants to compute magnon energies for a set of k-points. Often for a rather large set of k-points. Magnopy offers simple interface to parallelize the calculations over the k-points using multiprocessing. See :py:func:`magnopy.multiprocess_over_k` for details. For example, to compute magnon energies for the set of k-points (that are given as absolute coordinates in reciprocal space) utilizing two processes use .. GENERATED FROM PYTHON SOURCE LINES 58-69 .. code-block:: Python kpoints = np.linspace([0, 0, 0], [1, 0, 0], 1000) results = magnopy.multiprocess_over_k( kpoints=kpoints, relative=False, function=lswt.omega, number_processors=2, ) .. GENERATED FROM PYTHON SOURCE LINES 70-71 Note that ``results[i]`` is equivalent to ``lswt.omega(k=kpoints[i], relative=False)``. .. GENERATED FROM PYTHON SOURCE LINES 71-77 .. code-block:: Python print(results[42]) print(lswt.omega(k=kpoints[42], relative=False)) .. rst-class:: sphx-glr-script-out .. code-block:: none [1.00176727+0.j] [1.00176727+0.j] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.241 seconds) .. _sphx_glr_download_school-tutorials_trilmax-2025_1_python-library_plot_7_lswt.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_7_lswt.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_7_lswt.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_7_lswt.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_