<jupyter_start><jupyter_text>Hydrogen calculations using `sympy`The `sympy` library does symbolic math.  It also includes several useful things in the [`sympy.physics`](https://docs.sympy.org/latest/modules/physics/index.html) module, like hydrogen and harmonic oscillator wavefunctions.<jupyter_code>from sympy import *
from sympy.physics.hydrogen import *
n = symbols("n")
ell = symbols("ℓ")
m = symbols("m")
r, theta, phi = symbols("r θ ϕ", real=True)
# Unperturbed energy of state n
E_nl(n)
# Wavefunciton of state |n,ℓ,m>
Psi_nlm(n, ell, m, r, phi, theta)
# Check a specfic state to compare
Psi_nlm(3, 1, 0, r, phi, theta)
# define some aliases
z = r * cos(theta)
x = r * sin(theta)*cos(phi)
y = r * sin(theta)*sin(phi)<jupyter_output><empty_output><jupyter_text>Example integralsLet's calculate$$\langle 2,1,0 \vert z \vert 1,0,0\rangle = \int\limits_{r=0}^{\infty} \int\limits_{\phi=0}^{2\pi} \int\limits_{\theta=0}^\pi\phi^*_{2,1,0}\, z\, \phi_{1,0,0}\,r^2\sin\theta\,dr\,d\theta\,d\phi$$<jupyter_code># Set up some integrals
Integral(conjugate(Psi_nlm(2,1,0,r, phi, theta))*z*Psi_nlm(1,0,0,r,phi,theta)*r**2*sin(theta),(phi,0,2*pi),(theta,0,pi),(r,0,oo))
# perform the integration
_.doit()
# approximate this in decimal form
N(_)
_*5.292e-11 # convert from atomic units to SI units
_**2
_21**2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18018018018018017, 'fraction_numerical': 0.03078078078078078, 'mean_word_length': 6.128342245989304, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '536521', 'license': 'MIT', 'n_tokens_mistral': 554, 'n_tokens_neox': 518, 'n_words': 122, 'path': 'HydrogenSympy.ipynb', 'repo_name': 'corcoted/Phys475', 'size': '1332'}