.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "master-tutorial/3_exercises/plot_3_spinham.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_3_exercises_plot_3_spinham.py: Spin Hamiltonian **************** .. include:: ../../exercises/3.inc .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python import numpy as np import magnopy .. GENERATED FROM PYTHON SOURCE LINES 13-15 Exercise 1 ========== .. GENERATED FROM PYTHON SOURCE LINES 16-47 .. code-block:: Python # Cubic cell with a = 1 cell = np.eye(3) # One atom per unit cell # located in the center of the unit cell atoms = dict( names=["Fe"], positions=[[0.5, 0.5, 0.5]], spins=[2.5], g_factors=[2], ) # Choose convention convention = magnopy.Convention(multiple_counting=True, spin_normalized=False, c22=1) # Create a Hamiltonian spinham = magnopy.SpinHamiltonian(cell=cell, atoms=atoms, convention=convention) # Add nearest neighbor parameter # Choose 1D chain along the first lattice vector parameter = magnopy.converter22.from_iso(iso=1) spinham.add_22(alpha=0, beta=0, nu=(1, 0, 0), parameter=parameter) # Add next-nearest neighbor parameter of opposite sign and slightly smaller absolute value spinham.add_22(alpha=0, beta=0, nu=(2, 0, 0), parameter=-0.95 * parameter) _, pe2 = magnopy.experimental.plot_spinham(spinham=spinham, _sphinx_gallery_fix=True) pe2.show(axes_visible=False, legend_position="left") .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 48-50 Exercise 2 ========== .. GENERATED FROM PYTHON SOURCE LINES 51-57 .. code-block:: Python # Create two modified conventions mod_conv_1 = convention.get_modified(multiple_counting=False) mod_conv_2 = convention.get_modified(c22=-1) .. GENERATED FROM PYTHON SOURCE LINES 58-60 First, display the parameters in the original convention: they have the same values as the one we passed to :py:meth:`magnopy.SpinHamiltonian.add_22` function .. GENERATED FROM PYTHON SOURCE LINES 61-67 .. code-block:: Python for alpha, beta, nu, parameter in spinham.p22: print( f"{spinham.atoms.names[alpha]} -> {spinham.atoms.names[beta]} at {nu}\n{parameter}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none Fe -> Fe at (1, 0, 0) [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] Fe -> Fe at (2, 0, 0) [[-0.95 -0. -0. ] [-0. -0.95 -0. ] [-0. -0. -0.95]] Fe -> Fe at (-1, 0, 0) [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] Fe -> Fe at (-2, 0, 0) [[-0.95 -0. -0. ] [-0. -0.95 -0. ] [-0. -0. -0.95]] .. GENERATED FROM PYTHON SOURCE LINES 68-71 Next we disable multiple counting. As there are twice as less parameters in the Hamiltonian in the new convention, then values of the parameters shall be two times larger to preserve physical properties of the model (for example classical energy). .. GENERATED FROM PYTHON SOURCE LINES 72-80 .. code-block:: Python spinham.convention = mod_conv_1 for alpha, beta, nu, parameter in spinham.p22: print( f"{spinham.atoms.names[alpha]} -> {spinham.atoms.names[beta]} at {nu}\n{parameter}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none Fe -> Fe at (1, 0, 0) [[2. 0. 0.] [0. 2. 0.] [0. 0. 2.]] Fe -> Fe at (2, 0, 0) [[-1.9 -0. -0. ] [-0. -1.9 -0. ] [-0. -0. -1.9]] .. GENERATED FROM PYTHON SOURCE LINES 81-83 Finally, we change the sign in front of the two spins & two sites term. The parameter shall change their sign to preserve physical properties of the model. .. GENERATED FROM PYTHON SOURCE LINES 84-92 .. code-block:: Python spinham.convention = mod_conv_2 for alpha, beta, nu, parameter in spinham.p22: print( f"{spinham.atoms.names[alpha]} -> {spinham.atoms.names[beta]} at {nu}\n{parameter}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none Fe -> Fe at (1, 0, 0) [[-1. -0. -0.] [-0. -1. -0.] [-0. -0. -1.]] Fe -> Fe at (2, 0, 0) [[0.95 0. 0. ] [0. 0.95 0. ] [0. 0. 0.95]] Fe -> Fe at (-1, 0, 0) [[-1. -0. -0.] [-0. -1. -0.] [-0. -0. -1.]] Fe -> Fe at (-2, 0, 0) [[0.95 0. 0. ] [0. 0.95 0. ] [0. 0. 0.95]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.071 seconds) .. _sphx_glr_download_master-tutorial_3_exercises_plot_3_spinham.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_3_spinham.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_3_spinham.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_3_spinham.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_