Quantum
Quest

Algorithms, Math, and Physics

Visualizing quantum elegance: the hydrogen atom orbitals

To conclude my journey on the analysis of the hydrogen atom, as detailed in my previous posts (here and here), I have focused on a computational approach to visualize the hydrogen atom’s orbitals. This blog aims to elucidate the steps and the Python code I employed to transform abstract quantum mechanical equations into tangible visual representations.

The Schrödinger equation for hydrogen yields solutions—wavefunctions—that are characterized by quantum numbers n, l, and m. These wavefunctions, comprised of radial and angular components, describe the probability distribution of an electron around the nucleus.

Implementing the code

My visualization approach calculates these components and then plots their probability densities. Below is an outline of the essential functions in my Python script:

Converting cartesian to spherical coordinates

Given the natural expression of wavefunctions in spherical coordinates, a conversion from cartesian coordinates is necessary.


def cartesian2spherical(x, y, z):
    xy2 = x**2 + y**2
    r = np.sqrt(xy2 + z**2)
    theta = np.arctan2(np.sqrt(xy2), z)
    phi = np.arctan2(y, x)
    phi[phi < 0] += np.pi * 2
    return r, theta, phi

Calculating the radial wavefunction

This function computes the radial component of the wavefunction, utilizing associated Laguerre polynomials—a solution to the radial Schrödinger equation for hydrogen.


def radial_wavefunction(r, n, l, a_0):
    rho = 2 * r / (n * a_0)
    normalization = np.sqrt((2 / (n * a_0))**3 * np.math.factorial(n - l - 1) / (2 * n * np.math.factorial(n + l)))
    radial_part = np.exp(-rho / 2) * rho**l * sp.assoc_laguerre(rho, n - l - 1, 2 * l + 1)
    return normalization * radial_part

Determining the angular wavefunction

The angular part is determined using spherical harmonics, which are functions of the angular momentum quantum numbers l and m.


def angular_wavefunction(theta, phi, m, l):
    return sp.sph_harm(m, l, phi, theta)

Visualizing the probability density

The visualization process is facilitated by the make_plot function, which constructs a meshgrid in Cartesian coordinates, converts these points to spherical coordinates, calculates the wavefunction for each point, and plots the probability density.


import matplotlib.pyplot as plt
import numpy as np

def make_plot(outfile: str):
    fig = plt.figure(figsize=(6, 6))
    # L depends from the principal quantum number
    X, Z = np.mgrid[-L:L:1000 * 1j, -L:L:1000 * 1j]
    Y = np.zeros_like(X)  # Y=0 for the XZ plane
    r_t_p = cartesian2spherical(X, Y, Z)
    wavefunction = radial_wavefunction(r_t_p[0], p.n, p.l, p.a0) \
        * angular_wavefunction(r_t_p[1], r_t_p[2], p.m, p.l)
    # Probability density
    # Using X and Z for plotting
    ax.pcolormesh(X, Z, np.abs(wavefunction)**2, cmap='inferno')

Conclusion

The transition from mathematical equations to visual representations illuminates the probabilistic nature of electron positions within the hydrogen atom, reflecting the core principles of quantum mechanics. These visualizations serve not only as educational tools but also as a testament to the power of computational physics.

You can find the resulting images here.