-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathangular.py
36 lines (28 loc) · 1.04 KB
/
angular.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from typing import Callable
import scipy.integrate as integrate
import numpy as np
import math
import warnings
warnings.filterwarnings("ignore")
from .wave_func import Y
def angular_matrix_element(
l1: int, m1: int, l2: int, m2: int, op: Callable = lambda theta, phi: 1
) -> float:
"""
Matrix element of an operator (written in the coordinate of theta and phi) <l1,m1|op(theta, phi)|l2,m2>
by integrating using the spherical harmonics.
:param l1: orbital quantum number of the bra
:param m1: magnetic quantum number of the bra
:param l2: orbital quantum number of the ket
:param m2: magnetic quantum number of the ket
:param op: the operator (a function of `theta` and `phi`)
:return: the matrix element
"""
def integrand(theta, phi):
bra = np.conj(Y(l1, m1, theta, phi))
ket = Y(l2, m2, theta, phi)
return bra * op(theta, phi) * ket * np.sin(theta)
res, _ = integrate.nquad(
lambda theta, phi: integrand(theta, phi), [[0, math.pi], [0, 2 * math.pi]]
)
return res