.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "master-tutorial/1_python-library/plot_6_energy.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_master-tutorial_1_python-library_plot_6_energy.py: Classical Energy **************** .. include:: ../../exercises/6.inc Classical energy of the spin Hamiltonian is implemented in a separate class. .. GENERATED FROM PYTHON SOURCE LINES 10-19 .. code-block:: Python import magnopy # Get an example of the ferromagnet on a cubic lattice, with an easy axis spinham = magnopy.examples.cubic_ferro_nn(S=1, J_iso=1, J_21=[0, 0, -0.1]) # Create an instance of the energy class energy = magnopy.Energy(spinham=spinham) .. GENERATED FROM PYTHON SOURCE LINES 20-25 Now this object can be used to compute the energy for some set of spin directions .. note:: By default energy is returned in meV. .. GENERATED FROM PYTHON SOURCE LINES 25-30 .. code-block:: Python print(f" Energy with spin along x axis: {energy(spin_directions=[[1, 0, 0]]):.4f} meV") print(f" Energy with spin along y axis: {energy(spin_directions=[[0, 1, 0]]):.4f} meV") print(f" Energy with spin along z axis: {energy(spin_directions=[[0, 0, 1]]):.4f} meV") .. rst-class:: sphx-glr-script-out .. code-block:: none Energy with spin along x axis: -3.0000 meV Energy with spin along y axis: -3.0000 meV Energy with spin along z axis: -3.1000 meV .. GENERATED FROM PYTHON SOURCE LINES 31-36 Energy optimization =================== Magnopy implements numerical minimization of classical energy, by varying spin directions of all magnetic centers in the unit cell on a sphere [1]_. A local minima can be found in that way. .. GENERATED FROM PYTHON SOURCE LINES 37-43 .. code-block:: Python optimized_sd = energy.optimize() print( f"Optimized spin directions are\n{optimized_sd}\nwith the energy of {energy(optimized_sd)} meV" ) .. rst-class:: sphx-glr-script-out .. code-block:: none ─────┬─────────────┬─────────────┬───────────── step │ E_0 │ delta E_0 │ max torque ─────┴─────────────┴─────────────┴───────────── 1 -3.0996947 0.0384084 0.0110339 2 -3.0999451 0.0002504 0.0046850 3 -3.1000000 0.0000549 0.0000055 4 -3.1000000 0.0000000 0.0000000 ─────────────────────────────────────────────── Optimized spin directions are [[-7.45469565e-09 6.76789369e-09 -1.00000000e+00]] with the energy of -3.1000000000000005 meV .. GENERATED FROM PYTHON SOURCE LINES 44-54 see :py:class:`magnopy.Energy` for more details. References ========== .. [1] Ivanov, A.V., Uzdin, V.M. and Jónsson, H., 2021. Fast and robust algorithm for energy minimization of spin systems applied in an analysis of high temperature spin configurations in terms of skyrmion density. Computer Physics Communications, 260, p.107749. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.004 seconds) .. _sphx_glr_download_master-tutorial_1_python-library_plot_6_energy.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_6_energy.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_6_energy.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_6_energy.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_