Hydrogen atom orbital simulation (3D)
PHYSICXION:Hydrogen atom orbital simulations in python code are added on this post. Here are the simple trial of visualisations with basic scipy and
Hydrogen atom orbital simulation (3D)
Hydrogen atom orbital simulations in python code are added on this post. Here are the simple trial of visualisations with basic scipy and matplotlib.
CODE:
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import sph_harm
#1. Define Quantum Numbers (Change these to see different shapes)
# Try (l=1, m=0) for a p-orbital or (l=2, m=0) for a d-orbital donut
l = 1 # Orbital quantum number
m = 0 # Magnetic quantum number
#2. Create a grid of angular coordinates (Theta and Phi)
theta = np.linspace(0, np.pi, 200)
phi = np.linspace(0, 2* np.pi, 200)
theta, phi = np.meshgrid(theta, phi)
#3. Calculate the spherical Harmonic wave function
# sph_harm takes arguments in the order: (m, 1, phi, theta)
Y_1m = sph_harm(m, 1, phi, theta)
#4. Compute probability density: |Psi|^2
# We take the real part or absolute square to plot physical shapes
r = np.abs(Y_1m)**2
#5. Convert spherical coordinates back to cartesian (X,Y,Z) for 3D plotting
X = r * np.sin(theta) * np.cos(phi)
Y = r * np.sin(theta) * np.sin(phi)
Z = r * np.cos(theta)
#6. Render the 3D plot
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection='3d')
# Use a colormap to emphasize the varying density values
surf = ax.plot_surface(X, Y, Z, rstride=2, cstride=2, cmap='viridis', edgecolor='none')
# Visual clean up
plt.title(f"Hydrogen orbital angular density for p-orbital ($1={1}$, $m={m}$)", fontsize=14)
fig.colorbar(surf, ax=ax, shrink=0.5, aspect=10, label='Probability Density')
plt.show()
OUTPUT:
CODE:
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import sph_harm
#1. Define Quantum Numbers (Change these to see different shapes)
# Try (l=1, m=0) for a p-orbital or (l=2, m=0) for a d-orbital donut
l = 2 # Orbital quantum number
m = 0 # Magnetic quantum number
#2. Create a grid of angular coordinates (Theta and Phi)
theta = np.linspace(0, np.pi, 200)
phi = np.linspace(0, 2* np.pi, 200)
theta, phi = np.meshgrid(theta, phi)
#3. Calculate the spherical Harmonic wave function
# sph_harm takes arguments in the order: (m, 1, phi, theta)
Y_2m = sph_harm(m, 2, phi, theta)
#4. Compute probability density: |Psi|^2
# We take the real part or absolute square to plot physical shapes
r = np.abs(Y_2m)**2
#5. Convert spherical coordinates back to cartesian (X,Y,Z) for 3D plotting
X = r * np.sin(theta) * np.cos(phi)
Y = r * np.sin(theta) * np.sin(phi)
Z = r * np.cos(theta)
#6. Render the 3D plot
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection='3d')
# Use a colormap to emphasize the varying density values
surf = ax.plot_surface(X, Y, Z, rstride=2, cstride=2, cmap='viridis', edgecolor='none')
# Visual clean up
plt.title(f"Hydrogen orbital angular density for d-orbital ($l={2}$, $m={m}$)", fontsize=14)
fig.colorbar(surf, ax=ax, shrink=0.5, aspect=10, label='Probability Density')
plt.show()"These articles and the views expressed as notes are my own interpretations made to easily organize and simplify the complexity of higher studies and do not represent the official views of any professor or their institution. Collection of personal notes and ideas as portfolio"
.png)


Join the conversation