Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8963ca2

Browse files
Added Quantum Pattern Visualizer Project
1 parent 92e703d commit 8963ca2

File tree

2 files changed

+233
-0
lines changed

2 files changed

+233
-0
lines changed

‎Q/Quantum-Pattern-Visualizer/README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
### **Quantum Number Pattern Visualizer**
2+
3+
#### **Project Overview:**
4+
5+
The **Quantum Number Pattern Visualizer** is a Python-based tool designed to visualize the probability distributions of atomic orbitals, based on quantum numbers in quantum mechanics. Using mathematical models like spherical harmonics and radial wavefunctions, the visualizer generates 3D plots of wavefunction probability densities, representing where an electron is most likely to be found around an atom.
6+
7+
This tool provides insights into the abstract concepts of quantum mechanics, making it easier to understand the shapes and distributions of atomic orbitals for different quantum numbers.
8+
9+
---
10+
11+
### **Features:**
12+
13+
- Visualizes 3D probability distributions of atomic orbitals based on the quantum numbers \( n \), \( l \), and \( m \).
14+
- Uses color mapping to represent the probability distribution, with higher probabilities indicated by darker colors.
15+
- The user can input quantum numbers to generate and observe different orbitals, including \( s \), \( p \), \( d \), and higher orbitals.
16+
- Interactive 3D scatter plot, which allows users to rotate and explore the distribution.
17+
- A color bar that indicates the intensity of the wavefunction.
18+
19+
---
20+
21+
### **How it Works:**
22+
23+
#### **Quantum Numbers:**
24+
25+
1. **Principal Quantum Number (n)**: Governs the size of the orbital. Larger values of \( n \) correspond to orbitals that are farther from the nucleus.
26+
27+
- Example values: 1, 2, 3, ...
28+
29+
2. **Angular Momentum Quantum Number (l)**: Defines the shape of the orbital. For a given \( n \), \( l \) can take values from 0 to \( n-1 \).
30+
31+
- Example values: 0 (s), 1 (p), 2 (d), ...
32+
33+
3. **Magnetic Quantum Number (m)**: Determines the orientation of the orbital. For a given \( l \), \( m \) can take values from \( -l \) to \( +l \).
34+
- Example values: \( -l \), \( 0 \), \( +l \)
35+
36+
#### **Mathematical Foundation:**
37+
38+
- The **radial wavefunction** describes the probability distribution as a function of the distance from the nucleus.
39+
- The **angular wavefunction** is based on spherical harmonics and describes the distribution as a function of angles \( \theta \) and \( \phi \).
40+
- The product of the radial and angular wavefunctions gives the total wavefunction \( \psi \), and the absolute square \( |\psi|^2 \) represents the probability density for finding an electron in a given region.
41+
42+
---
43+
44+
### **Installation Instructions:**
45+
46+
#### **1. Prerequisites:**
47+
48+
- Python 3.x installed on your system.
49+
- The following Python packages are required:
50+
- **NumPy**: For numerical calculations.
51+
- **SciPy**: For special functions like spherical harmonics and Laguerre polynomials.
52+
- **Matplotlib**: For 3D plotting and visualization.
53+
54+
#### **2. Install Required Packages:**
55+
56+
Run the following command in your terminal to install the required packages:
57+
58+
```bash
59+
pip install numpy scipy matplotlib
60+
```
61+
62+
#### **3. Clone the Repository:**
63+
64+
### **How to Run:**
65+
66+
1. **Run the Python script:**
67+
68+
```bash
69+
python visualizer.py
70+
```
71+
72+
2. **Input Quantum Numbers:**
73+
74+
When prompted, input values for the principal quantum number \( n \), angular momentum quantum number \( l \), and magnetic quantum number \( m \).
75+
76+
- Example:
77+
- Enter principal quantum number \( n \): `2`
78+
- Enter angular momentum quantum number \( l \): `1`
79+
- Enter magnetic quantum number \( m \): `0`
80+
81+
3. **Observe the Visualization:**
82+
83+
- A 3D plot will be generated showing the probability distribution of the orbital corresponding to the input quantum numbers. You can rotate and zoom in on the plot to explore the shape of the orbital.
84+
85+
---
86+
87+
### **Project Structure:**
88+
89+
```
90+
Quantum-Number-Pattern-Visualizer/
91+
92+
├── visualizer.py # Main script for running the visualizer
93+
├── README.md # Project documentation
94+
├── requirements.txt # Required Python packages
95+
96+
```
97+
98+
---
99+
100+
### **Key Functions in `visualizer.py`:**
101+
102+
- **`radial_wavefunction(n, l, r)`**:
103+
104+
- Computes the radial part of the wavefunction using associated Laguerre polynomials.
105+
106+
- **`angular_wavefunction(l, m, theta, phi)`**:
107+
108+
- Computes the angular part of the wavefunction using spherical harmonics.
109+
110+
- **`wavefunction(n, l, m, r, theta, phi)`**:
111+
112+
- Combines the radial and angular components to compute the total wavefunction.
113+
114+
- **`generate_grid(size_r, size_theta, size_phi)`**:
115+
116+
- Generates a 3D grid in spherical coordinates for plotting.
117+
118+
- **`spherical_to_cartesian(r, theta, phi)`**:
119+
120+
- Converts spherical coordinates to Cartesian coordinates for 3D visualization.
121+
122+
- **`plot_wavefunction(n, l, m)`**:
123+
- Plots the 3D scatter plot showing the probability distribution of the wavefunction based on the quantum numbers.
124+
125+
---
126+
127+
### **Sample Usage:**
128+
129+
Here’s how the output will vary for different quantum numbers:
130+
131+
#### **For \( n = 2, l = 1, m = 0 \):**
132+
133+
- You will see a probability distribution corresponding to a \( p \)-orbital, which has a characteristic dumbbell shape.
134+
135+
#### **For \( n = 3, l = 2, m = 1 \):**
136+
137+
- The visualization will represent a more complex \( d \)-orbital with distinct regions of probability density.
138+
139+
---
140+
141+
### **Customization:**
142+
143+
- **Grid Size**: You can change the grid resolution by adjusting the `size_r`, `size_theta`, and `size_phi` parameters in the `generate_grid()` function for finer or coarser visualizations.
144+
- **Transparency and Color Mapping**: The transparency (`alpha`) and color scheme (`cmap`) used in the scatter plot can be customized for different visual effects.
145+
146+
---
147+
148+
### **Known Issues:**
149+
150+
- **Performance**: The 3D scatter plot can become computationally expensive for larger grids. Reducing the grid size (using `generate_grid(size_r=30, size_theta=30, size_phi=30)`) can improve performance without significantly affecting the visualization quality.
151+
152+
### **Contact:**
153+
154+
For any questions or feedback, feel free to reach at:
155+
156+
- **Email**: aswinpkumar03@gmail.com
157+
- **GitHub**: [AswinPKumar01](https://github.com/AswinPKumar01)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
from mpl_toolkits.mplot3d import Axes3D
4+
from scipy.special import sph_harm, assoc_laguerre
5+
import math
6+
7+
# Constants
8+
pi = np.pi
9+
10+
# Function to compute radial part of wavefunction (R_nl)
11+
def radial_wavefunction(n, l, r):
12+
rho = 2 * r / n
13+
norm = np.sqrt((2 / n) ** 3 * math.factorial(n - l - 1) / (2 * n * math.factorial(n + l)))
14+
laguerre = assoc_laguerre(rho, n - l - 1, 2 * l + 1)
15+
radial = norm * np.exp(-rho / 2) * rho ** l * laguerre
16+
return radial
17+
18+
# Function to compute angular part of wavefunction (Y_lm)
19+
def angular_wavefunction(l, m, theta, phi):
20+
return sph_harm(m, l, phi, theta)
21+
22+
# Full wavefunction R_nl * Y_lm
23+
def wavefunction(n, l, m, r, theta, phi):
24+
R = radial_wavefunction(n, l, r)
25+
Y = angular_wavefunction(l, m, theta, phi)
26+
psi = R * Y
27+
return np.abs(psi) ** 2 # Probability distribution
28+
29+
# Generate a spherical grid
30+
def generate_grid(size_r=50, size_theta=50, size_phi=50):
31+
r = np.linspace(0, 20, size_r)
32+
theta = np.linspace(0, pi, size_theta)
33+
phi = np.linspace(0, 2 * pi, size_phi)
34+
r, theta, phi = np.meshgrid(r, theta, phi)
35+
return r, theta, phi
36+
37+
# Convert spherical coordinates to cartesian for plotting
38+
def spherical_to_cartesian(r, theta, phi):
39+
x = r * np.sin(theta) * np.cos(phi)
40+
y = r * np.sin(theta) * np.sin(phi)
41+
z = r * np.cos(theta)
42+
return x, y, z
43+
44+
# Plot the probability distribution with a scatter plot for 3D visualization
45+
def plot_wavefunction(n, l, m):
46+
r, theta, phi = generate_grid(size_r=30, size_theta=30, size_phi=30) # Reduced grid size for speed
47+
psi_squared = wavefunction(n, l, m, r, theta, phi)
48+
49+
x, y, z = spherical_to_cartesian(r, theta, phi)
50+
51+
fig = plt.figure()
52+
ax = fig.add_subplot(111, projection='3d')
53+
ax.set_title(f'Quantum Numbers n={n}, l={l}, m={m}')
54+
55+
# Use scatter plot to visualize the 3D probability distribution
56+
ax.scatter(x, y, z, c=psi_squared.ravel(), cmap='viridis', marker='o', alpha=0.5)
57+
58+
# Improve performance by removing axes for a cleaner look
59+
ax.set_xticks([])
60+
ax.set_yticks([])
61+
ax.set_zticks([])
62+
63+
fig.colorbar(ax.scatter(x, y, z, c=psi_squared.ravel(), cmap='viridis', marker='o', alpha=0.5), ax=ax, shrink=0.5, aspect=5) # Add color bar to indicate intensity
64+
plt.show()
65+
66+
# Input quantum numbers n, l, m
67+
def main():
68+
print("Quantum Number Pattern Visualizer")
69+
n = int(input("Enter principal quantum number n (1, 2, 3, ...): "))
70+
l = int(input(f"Enter angular momentum quantum number l (0, 1, 2, ..., n-1): "))
71+
m = int(input(f"Enter magnetic quantum number m (-l, ..., 0, ..., +l): "))
72+
73+
plot_wavefunction(n, l, m)
74+
75+
if __name__ == "__main__":
76+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /