Python Program To Generate Spherical Harmonic
Python Program To Generate Spherical Harmonic
2513
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
3
2 + 1 ( − | |)!
( , )= (cos ) ( ≥ 0)
4 ( + | |)!
| |
( + | |)! (1 − ) 1 − cos 4
(cos ) = | |
| | − , | | + + 1; | | + 1;
( − | |)! 2 | |! 2
| |
(| | − )( ) (| | + + 1)(
5
1 − cos )
| | − , | | + + 1; | | + 1; =
2 (| | + 1)( ) !
2 ( + 1) 1 6
+ − − ( , )=0
With boundary conditions ( , 0) = 0 and ( , 0) = ∞ . For these boundary conditions only integer values of n,
principle quantum number, are allowed. Furthermore, the value of orbital quantum number l must be less than
principle quantum number n. Number of nodes in the solution other than origin is n-l-1.We can calculate the radial
function for the state with quantum number n,l by using equation 7.
7
2 ( − − 1)! 2 2
( , )=
2 [( + )!]
2 ( + )! 2 8
= ( + )! (−1)
( − − 1 − )! (2 + 1 + )! !
Now by using equation 3-8, total wave function can be written as [11-13].
9
2 ( − − 1)! 2 ( + )! 2
= (−1)
2 [( + )!] ( − − 1 − )! (2 + 1 + )! !
| |/
2 + 1 ( − | |)! ( + | |)! 1 −
( + )!
4 ( + | |)! ( − | |)! 2| | | |!
| |
(| | − )( ) (| | + + 1)( )
×
(| | + 1)( ) !
3.METHODOLOGY
= arccos 11
+ +
= tan 12
2514
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
We can determine the explicit forms of associated Laguerre Polynomials, radial probability distribution and
Hypergeometric function for Associated Legendre Polynomials into Cartesian coordinates and with the help of
them; we can transform total wave function into Cartesian coordinate [14]
13
( )! ( )( | |)!
( , , )= )!]
× × × × ×
[( ( | |)!
| |
( | |)! ( ) ( )!
( + )! × | |( | |)!| |!
× × ∑ ( )!( )! !
×
| | (| | )( ) ×(| | )( )
×∑ ×
(| | )( )× !×
ℎ , 14
| |
+ | |/
× = 1− ×
+ +
| | | |
− | |
= + × + +
| | | |
15
( )! ( )( | |)!
Ψ ( , , )= )!]
× × × × ( + )! ×
[( ( | |)!
( | |)! | | ( ) ( )!
| |( | |)!| |!
× + | |
× ∑ ( )!( )! !
× ×
| | | |
| | (| | )( ) ×(| | )( )
∑ × × + +
(| | )( )× !× | |
The notations in lower subscript are pochhammer symbols e.g. (m-n) (k) etc.
16
Ψ (1,0,0) =0.707106781186548√2 ÷√
17
Ψ (2,0,0) = √2 0.25 − 0.125 + + ÷ (√ )
18
Ψ (2,1,0) = 0.125√2 ÷ (√ )
Ψ (3,0,0) = 19
2515
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
21
Ψ (3,2,0) = √2(−0.00356389 − 0.00356389 + 0.00712778 ) ÷ (√ )
Ψ(4,0,0) = √2 0.0884 − 0.06629 + + + 0.0110485 ( + + ) − 0.00046 ( + 22
+ ) ÷ (√ )
Ψ(4,1,0) = 0.61237√2 0.080687 − 0.02017 + + +0.0010086 + 0.0010086 + 23
0.0010086 ) ÷(√ )
+ + + + − 2.0( + + ) ÷(√ + + )
0.0015441 − + + ( + + ) − 0.0010294( + + ) ) ÷
(√ ( + + ))
Ψ(5,0,0) = √2 0.063246 − 0.050596 + + + 0.0101193 ( + + )− 26
0.0006746 ( + + ) + 1.349 × 10 ( + + ) ) ÷ (√ )
Ψ(5,1,0) =0.61237√2 0.0584 − 0.01753 + + + 0.0014 ( + + ) − 27
3.1159 × 10 ( + + ) ÷ (√ )
2.03986 ⋅ 10 ) ÷ (√ + + )
2.5 − + + ( + + ) + 7.5 − + + ( + + ) −
5.0 ( + + ) ÷ (√ ( + + ))
( ) + 1.5776 ⋅ 10 ( 30
Ψ(5,4,0)= √2 3.60599 ⋅ 10 + + − + + + +
) + 6.310485 ⋅ 10 − + + ( + + ) + 8.11348 ×
( ) − 3.24539 ⋅ 10 (
10 − + + + + + + ) ÷
(√ ( + + ) )
Ψ(6,0,0) = 31
√2 0.04811 − 0.040094 + + + 0.00891 ( + + ) − 0.0007425 ( +
+ ) + 2.474924 ⋅ 10 ( + + ) − 2.74992 ⋅ 10 ( + + ) ÷
(√ )
Ψ(6,1,0) = 0.61237√2 0.04473 − 0.01491 + + + 0.001491 ( + + )− 32
5.522 ⋅ 10 ( + + ) + 6.574 ⋅ 10 ( + + ) ÷ (√ )
2516
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
4.6482 ⋅ 10 ( + + ) ÷(√ + + )
× 10 + 2.68364 ⋅ 10 + 2.68364 ⋅ 10 ) ÷ (√ ( + + ))
Ψ(6,4,0) = 1.061 35
√2 3.6005 ⋅ 10 − 1.20016 ⋅ 10 + + 10.0 ( + + ) + 4.375 −
+ + ( + + ) + 17.5 − + + ( + + ) + 22.5 ( −
+ + ( 36 + + ) − 9.0( + + ) ÷ (√ ( + +
) )
Ψ(6,5,0) = √2 6.36482 ⋅ 10 ( + + ) + 3.34153 ⋅ 10 − + + ( + + 36
) + 1.670765 ⋅ 10 − + + ( + + ) + 2.97025 × 10 −
+ + ( + + ) + 2.2277 ⋅ 10 − + + ( + + ) −
5.940496 ⋅ 10 ( + + ) ÷ (√ ( + + ) )
Ψ(7,0,0) = 37
√2 0.0382 − 0.032726 + + + 0.007792 ( + + ) − 0.0007421 ( +
+ ) + 3.180356 ⋅ 10 ( + + ) − 6.05782× 10 ( + + ) + 4.120967 ⋅
10 ( + + ) ÷ (√ )
Ψ(7,1,0)=0.61237√2 0.035627 − 0.0127241 + + + 0.001454 ( + + )− 38
6.9247 ⋅ 10 ( + + ) + 1.413197 ⋅ 10 ( + + ) − 1.00943 ⋅ 10 ( + +
) ÷ (√ )
9.4800157 ⋅ 10 ( + + ) + 7.52382 ⋅ 10 ( + + ) ÷
(√ + + )
Ψ(7,2,0)0.790569√2 3.0 ( + + ) + 1.5 − + + + + − 2.0( + + 40
10 ( + + ) + 7.52382 ⋅ 10 ( + + ) ÷ (√ + + )
Ψ(7,3,0)= 0.9354√2 0.00014689 − 1.573868 ⋅ 10 + + + 4.99641 ⋅ 10 ( + 41
+ ) − 4.7584828 ⋅ 10 ( + + ) 6.0 ( + + ) +
2.5( − + + ( + + ) + 7.5 − + + ( + + ) −
2517
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
5.0 ( + + ) ÷ (√ ( + + ))
Ψ(7,4,0)=1.06066√2 3.34859 ⋅ 10 − 1.913478 ⋅ 10 + + + 2.48504 ⋅ 10 + 42
2.48504 ⋅ 10 + 2.48504 ⋅ 10 ) 10.0 ( + + ) +
4.375( − + + ( + + ) + 17.5 − + + ( + + ) +
22.5 − + + ( + + ) − 9.0( + + ) ) ÷ (√ ( +
+ ) )
Ψ(7,5,0) =1.1726√2 4.26095 ⋅ 10 − 1.014512 ⋅ 10 + + (15.0 ( + + 43
) +7.875 − + + ( + + ) + 39.375 − + + ( + +
) + 70.0( − + + ( + + ) + 52.5 − + + ( + + ) −
14.0( + + ) ÷ (√ ( + + ) )
+ ) + 3.1071014 ⋅ 10 − + + ( + + ) + 7.061594 ⋅ 10 −
+ + ( + + ) + 7.532367 ⋅ 10 − + + ( + + ) +
3.7662 ⋅ 10 − + + ( + + ) − 7.173683 ⋅
( + + ) ÷ (√ ( + + ) )
4.73052736312624 ⋅ 10 ( + + ) ÷ (√ )
Ψ(8,1,0)= 46
0.61237√2 0.0292316983341714 − 0.0109618868753143 + +
+ 0.00137023585941429 ( + + ) − 7.61242144119047
⋅ 10 ( + + ) + 2.03904145746173 ⋅ 10 ( + + )
− 2.54880182182717 ⋅ 10 ( + + ) + 1.1800008434385
1
⋅ 10 ( + + ) ÷ (√ )
2.0( + + )
0.00283034702074012 − 0.000589655629320859 + + +
4.21182592372042 × 10 ( + + ) − 1.31619560116263 ⋅ × 10 ( + +
) + 1.82804944605921 ⋅ 10 ( + + ) − 9.14024723029606 ⋅ 10 ( + +
) ÷ (√ + + )
2518
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
) ÷ (√ ( + + ))
Ψ(8,4,0)= 49
1.06066017177982√2 3.00566019839111 ⋅ 10 − 2.25424514879333 ⋅
10 + + + 5.12328442907575 ⋅ 10 ( + + ) − 3.55783640908038 ⋅
10 ( + + ) (10.0 ( + + ) + 4.375 − + + ( + + ) +
17.5 − + + ( + + ) + 22.5 − + + ( + + ) −
9.0( + + ) ÷ (√ ( + + ) )
Ψ(8,5,0)= 50
1.17260393995586√2 4.2659868006405 ⋅ 10 − 1.77749450026687 ⋅
10 + + +1.70912932717969 ⋅ 10 + 1.70912932717969 ⋅ 10 +
1.70912932717969 ⋅ 10 )(15.0 ( + + ) + 7.875 − + + ( + +
) + 39.375 − + + ( + + ) + 70.0 − + + ( + +
20.0( + + ) ÷ (√ ( + + ) )
+ + ( + + ) + 1.33001057808236 ⋅ 10 − + + ( + +
) + 1.18706748905136 ⋅ 10 − + + ( + + ) + 1.6487×10 −
+ + ( + + ) + 1.19905806974885 ⋅ 10 − + + ( + +
) + 4.31660905109585 ⋅ 10 − + + ( + + ) − 6.16658435870836 ⋅
10 ( + + ) ) ÷ (√ ( + + ) )
Ψ(9,0,0) = 53
√2 0.0261891400439462 − 0.0232792355946188 + + +
0.00603535737638266 ( + + )−
0.000670595264042518 ( + + ) + 3.72552924468066 ⋅ 10 ( + + ) −
1.10386051694242 ⋅ 10 ( + + ) + 1.75215955070225 ⋅ 10 ( + + ) −
1.39060281801766 ⋅ 10 ( + + ) + 4.29198400622734 ⋅ 10 ( +
+ ) ÷ (√ )
Ψ(9,1,0)= 54
0.612372435695794√2 0.0245384688888866 − 0.00954273790123367 + + +
0.00127236505349782 ( + + ) − 7.85410526850508 ⋅ 10 ( + + ) +
2.49336675190637 ⋅ 10 ( + + ) − 4.15561125317729 ⋅ 10 ( + + ) +
3.42025617545456 ⋅ 10 ( + + ) − 1.08579561125542 ⋅ 10 ( + +
2519
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
) ÷ (√ )
8.66165256432085 ⋅ 10 ( + + ) ÷ (√ + + )
6.12471326451312 ⋅ 10 ( + + ) ÷ (√ ( + + )
2520
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
2521
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
Appendix A R=1
p=sm.pi
Python code
Q=sm.sqrt(1/(2*p))
#Wave function generator
U=sm.sqrt((((2/n)**3)))*sm.sqrt((((mt.fa
def wave_generator(): ctorial(n-l-
1))/((2*n)*(mt.factorial(n+l)**3)))))*(Fract
x=sm.Symbol('x') ion(2/n)**l)*sm.exp(-
rho/2)*(r/a)**l*sm.sqrt(1/(a**3))
a=sm.Symbol('a')
H=sm.sqrt((((2*l+1)*(mt.factorial(l-
y=sm.Symbol('y') np.abs(m))))/(2*(mt.factorial(l+np.abs(m))))
))
n=int(input("n="))
o=Q*U*H*sm.exp(-
l=int(input("l=")) rho/2)*Q*((r/a)**l)*sm.sqrt(1/(a**3))
limit=int(input("limit=")) if R!=0:
z=sm.Symbol('z') R=(((hammer(t,i)*hammer(b,i))/(ha
mmer(c,i)*2**i*mt.factorial(i))))*(((1-
r=sm.Symbol('r') d)))**i
d=z/(sm.sqrt(x**2+y**2+z**2)) Z=Z+R
r=sm.sqrt(x**2+y**2+z**2) k=((mt.factorial(np.abs(m)+l)/((mt.facto
rial(l-
theta=sm.Symbol("theta") np.abs(m)))*(2**np.abs(m)*mt.factorial(np.ab
s(m))))))*Z
def hammer(l,s):
p=2*l+1
g=1
q=n-l-1
if g!=0:
F=0
for i in np.arange(0,s):
for i in np.arange(0,q+1):
b=i+l
h=((mt.factorial(q+p)*(((-
g=g*b 1)**i)*(mt.factorial(p+q)/((mt.factorial(q-
i)*mt.factorial(p+i)*mt.factorial(i)))))))*(
return g rho**i)
t=np.abs(m)-l #print(h)
b=np.abs(m)+l+1 F=h+F
c=np.abs(m)+1 O=sm.sqrt(((((2/n)**3)))*((((mt.factoria
l(n-l-
rho=(2*r)/(n*a) 1))/((2*n)*(mt.factorial(n+l)**3))))))*((2/n
)**l)
f=n+l+np.abs(m)
T=simplify(F*O)
Z=0
2522
Kousar Shaheen et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2513 – 2523
G=T*sm.exp(- sm.init_printing(use_latex=True)
rho/2)*(r/a)**l*sm.sqrt(1/(a**3))
print(wave_generator())
I1=simplify(G*k*H*Q*(-m/np.abs(m))**(-
m)*(x+(m/np.abs(m))*1.j*y)**np.abs(m)*sm.sqr
t((x**2+y**2+z**2))**(-np.abs(m)))
print(f"Ψ({n},{l},{m})=")
display(simplify(I1))
I=simplify(G*k*H*Q*(sm.sqrt((1-
d**2)**(np.abs(m)))))
print(f"Ψ({n},{l},{m})**2=")
display(simplify(I**2))
EQ=lambdify((x,z,y,a),I,numpy)
y=1
a=0.529
x=np.linspace(-limit,limit,500)
z=np.linspace(-
limit,limit,500)[:,np.newaxis]
hi=np.abs((EQ(x,z,y,a)))
plt.imshow(hi**1,origin='lower',extent=[
-1,1,-1,1],cmap='hot')
#plt.imshow(hi**2,origin='lower',extent=
[-limit,limit,-limit,limit],cmap='hot')
plt.xlabel(f"({n},{l},{m})",fontsize=50)
plt.colorbar()
import numpy
import numpy as np
import sympy as sm
import math as mt
#%matplotlib qt5
2523