.. 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_5_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_school-tutorials_trilmax-2025_1_python-library_plot_5_energy.py: Classical Energy **************** .. admonition:: Tutorial tasks * Compute classical energy of one of the Hamiltonians from the previous tasks. * Change the convention of the spin Hamiltonian and re-compute the energy. Does it change? * Use the set of Hamiltonians from :ref:`trilmax-2025_spinham_arithmetics`. Optimize the spin direction for the full Hamiltonian. Use them to compute energy contributions of every term. * (extra) Create a Hamiltonian of the ferromagnet with an easy magnetic axis. Find out numerically the value of the magnetic field that is applied perpendicular to the easy axis, which fully orients the spins along the magnetic field. Classical energy of the spin Hamiltonian is implemented in a separate class. .. GENERATED FROM PYTHON SOURCE LINES 21-28 .. code-block:: Python import magnopy spinham = magnopy.examples.cubic_ferro_nn(S=1, J_21=(-1, 0, 1)) energy = magnopy.Energy(spinham=spinham) .. GENERATED FROM PYTHON SOURCE LINES 29-30 This object can be used to simply compute the energy for some set of spin directions .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. code-block:: Python print(energy(spin_directions=[[1, 0, 0]])) print(energy(spin_directions=[[0, 1, 0]])) print(energy(spin_directions=[[0, 0, 1]])) .. rst-class:: sphx-glr-script-out .. code-block:: none -4.0 -3.0 -2.0 .. GENERATED FROM PYTHON SOURCE LINES 36-38 or to optimize spin directions within unit cell and get the configuration of some local minima .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python optimized_sd = energy.optimize() .. rst-class:: sphx-glr-script-out .. code-block:: none ─────┬─────────────┬─────────────┬───────────── step │ E_0 │ delta E_0 │ max torque ─────┴─────────────┴─────────────┴───────────── 1 -3.8144091 0.5227305 0.7795155 2 -3.9177110 0.1033019 0.6757774 3 -3.9701722 0.0524612 0.3862030 4 -3.9996792 0.0295069 0.0361254 5 -3.9998632 0.0001840 0.0281246 6 -3.9999656 0.0001025 0.0117617 7 -3.9999929 0.0000273 0.0069941 8 -3.9999954 0.0000024 0.0046177 9 -3.9999977 0.0000023 0.0042198 10 -3.9999992 0.0000015 0.0019175 11 -3.9999996 0.0000005 0.0016791 12 -4.0000000 0.0000003 0.0003172 13 -4.0000000 0.0000000 0.0002358 14 -4.0000000 0.0000000 0.0000697 15 -4.0000000 0.0000000 0.0000598 16 -4.0000000 0.0000000 0.0000160 17 -4.0000000 0.0000000 0.0000126 18 -4.0000000 0.0000000 0.0000033 ─────────────────────────────────────────────── .. GENERATED FROM PYTHON SOURCE LINES 42-43 see :py:class:`magnopy.Energy` for more details. .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python print(optimized_sd) print(energy(optimized_sd)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 1.00000000e+00 -1.43745602e-06 -4.01553907e-07]] -3.9999999999976126 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.038 seconds) .. _sphx_glr_download_school-tutorials_trilmax-2025_1_python-library_plot_5_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_5_energy.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_5_energy.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_5_energy.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_