.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "master-tutorial/3_exercises/plot_4_magnetic_field.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_4_magnetic_field.py: Magnetic field ************** .. include:: ../../exercises/4.inc .. GENERATED FROM PYTHON SOURCE LINES 7-11 .. code-block:: Python import numpy as np import magnopy .. GENERATED FROM PYTHON SOURCE LINES 12-14 Exercise 1 ========== .. GENERATED FROM PYTHON SOURCE LINES 15-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, c1=1, c22=1 ) # Create a Hamiltonian spinham = magnopy.SpinHamiltonian(cell=cell, atoms=atoms, convention=convention) # Add nearest neighbor interactions for nu in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]: spinham.add_22( alpha=0, beta=0, nu=nu, parameter=magnopy.converter22.from_iso(iso=-1) ) # Add magnetic field along +y of the value 2.432 Tesla spinham.add_magnetic_field(B=(0, 2.432, 0)) .. GENERATED FROM PYTHON SOURCE LINES 48-52 Exercise 2 ========== First we create base Hamiltonian with no magnetic field present. .. GENERATED FROM PYTHON SOURCE LINES 53-80 .. 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, c1=1, c22=1 ) # Create a Hamiltonian spinham = magnopy.SpinHamiltonian(cell=cell, atoms=atoms, convention=convention) # Add nearest neighbor interactions for nu in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]: spinham.add_22( alpha=0, beta=0, nu=nu, parameter=magnopy.converter22.from_iso(iso=-1) ) .. GENERATED FROM PYTHON SOURCE LINES 81-82 Then we create a Hamiltonian with only magnetic field of the value (0, 0.1, 0) .. GENERATED FROM PYTHON SOURCE LINES 83-88 .. code-block:: Python B_step = spinham.get_empty() B_step.add_magnetic_field(B=(0, 0.1, 0), alphas=[0]) .. GENERATED FROM PYTHON SOURCE LINES 89-90 Finally, we use arithmetics on spin Hamiltonians to get a list of ten Hamiltonians .. GENERATED FROM PYTHON SOURCE LINES 91-97 .. code-block:: Python spinhams = [spinham + (index + 1) * B_step for index in range(10)] for spinham in spinhams: print(spinham.p1[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none [0, array([0. , 0.01157676, 0. ])] [0, array([0. , 0.02315353, 0. ])] [0, array([0. , 0.03473029, 0. ])] [0, array([0. , 0.04630705, 0. ])] [0, array([0. , 0.05788382, 0. ])] [0, array([0. , 0.06946058, 0. ])] [0, array([0. , 0.08103735, 0. ])] [0, array([0. , 0.09261411, 0. ])] [0, array([0. , 0.10419087, 0. ])] [0, array([0. , 0.11576764, 0. ])] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.005 seconds) .. _sphx_glr_download_master-tutorial_3_exercises_plot_4_magnetic_field.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_4_magnetic_field.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_4_magnetic_field.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_4_magnetic_field.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_