import numpy as np
import matplotlib.pyplot as plt
# Set the global font size
plt.rcParams['font.size'] = 14
# Enable LaTeX rendering
plt.rcParams['text.usetex'] = True
# Optionally, configure the font family to match your LaTeX document
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = 'Computer Modern'
# Example LaTeX preambles can be set for more advanced customization
plt.rcParams['text.latex.preamble'] = r'\usepackage{amsmath} \usepackage{physics}'
# --- Physical Constants (in SI units) ---
h = 6.62607015e-34 # Planck's constant (J·s)
mu_B = 9.2740100783e-24 # Bohr magneton (J/T)
g_J = 2.00231930436256 # Electron g-factor
g_I_proton = 5.585694702 # Proton g-factor
# --- Hydrogen Ground State Parameters ---
delta_E_hz = 1420.405751768e6 # Hyperfine splitting frequency (Hz)
delta_E_joules = h * delta_E_hz # Hyperfine splitting energy (Joules)
I = 0.5 # Nuclear spin for Hydrogen
# --- Magnetic Field Range (Tesla) ---
B_field = np.linspace(0, 0.2, 500) # From 0 to 0.2 Tesla
# --- Breit-Rabi Parameter 'x' ---
# The parameter x is defined as: x = (g_J * mu_B - g_I * mu_N) * B / delta_E
# Often, the g_I*mu_N term is neglected as it's much smaller, but let's use the full expression
# x = (g_J * mu_B * B_field) / delta_E_joules
# A more common form of x uses the total magnetic moments to be more accurate
x = (g_J*mu_B + g_I_proton*mu_B/1836.15) * B_field / delta_E_joules
# --- Breit-Rabi Formula Calculation ---
# For I = 1/2 and S = 1/2, the states are F=1, F=0
# The formula is E = -delta_E / 4 +- delta_E/2 * sqrt(1 + 2*mF*x + x^2)
# The '+' is for F=1, the '-' is for F=0, but this is only for the mF=0 states.
# We must use the general formula from the beginning.
# The general Breit-Rabi formula is:
# E_mF = -(delta_E/2) * (1/(2I+1)) +- (delta_E/2)*sqrt(1+x^2 + 4mF*x) for I=1/2
# Let's use the full formula for the four energy levels
# F=1, m_F=+1 state:
E1_plus1 = +delta_E_joules/4 + (delta_E_joules/2)*x
# F=1, m_F=0 state:
E1_0 = -delta_E_joules/4 + (delta_E_joules/2)*np.sqrt(1 + x**2)
# F=0, m_F=0 state:
E0_0 = -delta_E_joules/4 - (delta_E_joules/2)*np.sqrt(1 + x**2)
# F=1, m_F=-1 state:
E1_minus1 = delta_E_joules/4 - (delta_E_joules/2)*x
# --- Plotting ---
plt.figure(figsize=(10, 7))
# Plot the energy levels, converting to GHz for the y-axis
plt.plot(B_field * 1000, E1_plus1 / h / 1e9, label=r'$F=1, m_F=+1$', color='red', linewidth=3)
plt.plot(B_field * 1000, E1_0 / h / 1e9, label=r'$F=1, m_F=0$', color='blue', linewidth=3)
plt.plot(B_field * 1000, E0_0 / h / 1e9, label=r'$F=0, m_F=0$', color='purple', linewidth=3)
plt.plot(B_field * 1000, E1_minus1 / h / 1e9, label=r'$F=1, m_F=-1$', color='green', linewidth=3)
plt.text(75, 1.2, r'$(M_J=\tfrac{1}{2},M_I=\tfrac{1}{2})$', fontsize=18, color='red', rotation=14)
plt.text(72, 0.68, r'$(M_J=\tfrac{1}{2},M_I=-\tfrac{1}{2})$', fontsize=18, color='blue', rotation=12)
plt.text(72, -0.88, r'$(M_J=-\tfrac{1}{2},M_I=\tfrac{1}{2})$', fontsize=18, color='green', rotation=-14)
plt.text(69, -1.74, r'$(M_J=-\tfrac{1}{2},M_I=-\tfrac{1}{2})$', fontsize=18, color='purple', rotation=-11.5)
plt.text(2, 0.5, r'$(F=1,M_F=1)$', fontsize=18, color='red', rotation=14)
plt.text(15, 0.2, r'$(F=1,M_F=0)$', fontsize=18, color='blue', rotation=0)
plt.text(2, -0.25, r'$(F=1,M_F=-1)$', fontsize=18, color='green', rotation=-14)
plt.text(2, -0.97, r'$(F=0,M_F=0)$', fontsize=18, color='purple', rotation=0)
plt.axvline(x=10 , color='gray', linestyle='--', linewidth=0.8,
label=r'low field region')
plt.axvline(x=53 , color='gray', linestyle='--', linewidth=0.8,
label=r'high field region')
plt.text(1, 1.2, r'low field', fontsize=18, rotation=90)
plt.text(5, 1.2, r'$\ket{F M_F}$', fontsize=18, rotation=90)
plt.text(15, 1.85, r'transition region', fontsize=18)
plt.text(15, 1.6, r'(mixed states)', fontsize=18)
plt.text(55, 1.85, r'high field (Paschen--Back)', fontsize=18)
plt.text(55, 1.6, r'$\ket{J M_J; I M_I}$', fontsize=18)
plt.xlabel('Magnetic Field B (mT)')
plt.ylabel('Energy shift (GHz)')
plt.grid(False)
#plt.legend()
plt.xlim(0, 100.0)
plt.ylim(-2.0, 2.0)
plt.show()