Your first spin Hamiltonian¶
Create one electronic spin $S=1/2$ in a magnetic field along $z$.
$$ H=-g\mu_B B_zS_z. $$
Fields are in T and energies in meV. Spin operators are dimensionless. For positive $g$ and $B_z$, $|+1/2\rangle$ is the ground state.
import plotly.io as pio
from spinfinity import SpinSys, hamil, plotting
pio.renderers.default = "plotly_mimetype+notebook"
# Use "fixed" for compact plots, or "no" to suppress display.
plotting.set_display_mode("responsive")
spin = SpinSys([0.5])
spin.B = [0.0, 0.0, 0.5] # T
spin.BTip = [0.0, 0.0, 0.0] # T
spin.gfactorvector = [2.0]
Solve the Hamiltonian¶
calc_EigStates stores results on spin; it does not return them. Use rebuildH=True to construct the Hamiltonian from the current parameters.
E_sort contains unshifted energies, E_All is shifted to the ground state, and E_All_inGHz expresses those energy differences as ordinary frequencies.
hamil.calc_EigStates(spin, rebuildH=True)
print("Hamiltonian (meV):")
print(spin.H)
print("Unshifted energies (meV):", spin.E_sort)
print("Relative energies (meV):", spin.E_All)
frequency = spin.E_All_inGHz[1] - spin.E_All_inGHz[0]
print(f"Transition frequency: {frequency:.3f} GHz")
for state in spin.states:
print(state)
Hamiltonian (meV): [[-0.02894191+0.j 0. +0.j] [ 0. +0.j 0.02894191+0.j]] Unshifted energies (meV): [-0.02894191 0.02894191] Relative energies (meV): [0. 0.05788382] Transition frequency: 13.996 GHz |0> (E = 0.0) = +1.000+0.000j|0.5> |1> (E = 0.0579) = +1.000+0.000j|-0.5>
Inspect the eigenstates¶
The local basis is ordered from $+S$ to $-S$. Columns of eigVectors contain eigenvectors. Squared coefficients give product-basis probabilities, not thermal occupations.
The package plotting function displays automatically. We temporarily suppress that display, adjust the returned figure to the website column, and display it once.
hamil.plot_EigenMatrix(spin);
Change a parameter and rebuild¶
Changing spin.B alone does not update cached results. Rebuild and diagonalize again. Doubling this field doubles the spin-half transition frequency.
spin.B = [0.0, 0.0, 1.0]
hamil.calc_EigStates(spin, rebuildH=True)
frequency = spin.E_All_inGHz[1] - spin.E_All_inGHz[0]
print(f"Transition frequency at 1 T: {frequency:.3f} GHz")
Transition frequency at 1 T: 27.992 GHz
Zeeman diagram¶
The response of the spin system to the external magnetic field is best visible via a Zeeman diagramm
hamil.plot_ZeemanDiagramm(spin);