def test_Ynm_c(): th, ph = Symbol("theta", real=True), Symbol("phi", real=True) from sympy.abc import n, m assert Ynm_c( n, m, th, ph) == (-1)**(2 * m) * exp(-2 * I * m * ph) * Ynm(n, m, th, ph)
def Psi_nlm(n, l, m, r, phi, theta, Z=1): """ Returns the Hydrogen wave function psi_{nlm}. It's the product of the radial wavefunction R_{nl} and the spherical harmonic Y_{l}^{m}. n, l, m quantum numbers 'n', 'l' and 'm' r radial coordinate phi azimuthal angle theta polar angle Z atomic number (1 for Hydrogen, 2 for Helium, ...) Everything is in Hartree atomic units. Examples ======== >>> from sympy.physics.hydrogen import Psi_nlm >>> from sympy import Symbol >>> r=Symbol("r", real=True, positive=True) >>> phi=Symbol("phi", real=True) >>> theta=Symbol("theta", real=True) >>> Z=Symbol("Z", positive=True, integer=True, nonzero=True) >>> Psi_nlm(1,0,0,r,phi,theta,Z) Z**(3/2)*exp(-Z*r)/sqrt(pi) >>> Psi_nlm(2,1,1,r,phi,theta,Z) -Z**(5/2)*r*exp(I*phi)*exp(-Z*r/2)*sin(theta)/(8*sqrt(pi)) Integrating the absolute square of a hydrogen wavefunction psi_{nlm} over the whole space leads 1. The normalization of the hydrogen wavefunctions Psi_nlm is: >>> from sympy import integrate, conjugate, pi, oo, sin >>> wf=Psi_nlm(2,1,1,r,phi,theta,Z) >>> abs_sqrd=wf*conjugate(wf) >>> jacobi=r**2*sin(theta) >>> integrate(abs_sqrd*jacobi, (r,0,oo), (phi,0,2*pi), (theta,0,pi)) 1 """ # sympify arguments n, l, m, r, phi, theta, Z = S(n), S(l), S(m), S(r), S(phi), S(theta), S(Z) # check if values for n,l,m make physically sense if n.is_integer and n<1: raise ValueError("'n' must be positive integer") if l.is_integer and not (n > l): raise ValueError("'n' must be greater than 'l'") if m.is_integer and not (abs(m)<=l): raise ValueError("|'m'| must be less or equal 'l'") # return the hydrogen wave function return R_nl(n, l, r, Z)*Ynm(l,m,theta,phi).expand(func=True)
def Y_ell_m_ell(ell: int, m_ell: int): """ Return the spherical harmonic function :param ell: kinetic momentum (int) :param m_ell: quantum number m_ell (int) :return: (sympy object) """ from sympy.functions.special.spherical_harmonics import Ynm theta, phi = sp.Symbol("theta", real=True), sp.Symbol("phi", real=True) # return sp.FU['TR8'](Ynm(ell, m_ell, theta, phi).expand(func=True)) # return Ynm(ell, m_ell, theta, phi) return Ynm(ell, m_ell, theta, phi).expand(func=True)
def test_Znm(): # https://en.wikipedia.org/wiki/Solid_harmonics#List_of_lowest_functions th, ph = Symbol("theta", real=True), Symbol("phi", real=True) assert Znm(0, 0, th, ph) == Ynm(0, 0, th, ph) assert Znm(1, -1, th, ph) == ( -sqrt(2) * I * (Ynm(1, 1, th, ph) - exp(-2 * I * ph) * Ynm(1, 1, th, ph)) / 2 ) assert Znm(1, 0, th, ph) == Ynm(1, 0, th, ph) assert Znm(1, 1, th, ph) == ( sqrt(2) * (Ynm(1, 1, th, ph) + exp(-2 * I * ph) * Ynm(1, 1, th, ph)) / 2 ) assert Znm(0, 0, th, ph).expand(func=True) == 1 / (2 * sqrt(pi)) assert Znm(1, -1, th, ph).expand(func=True) == ( sqrt(3) * I * sin(th) * exp(I * ph) / (4 * sqrt(pi)) - sqrt(3) * I * sin(th) * exp(-I * ph) / (4 * sqrt(pi)) ) assert Znm(1, 0, th, ph).expand(func=True) == sqrt(3) * cos(th) / (2 * sqrt(pi)) assert Znm(1, 1, th, ph).expand(func=True) == ( -sqrt(3) * sin(th) * exp(I * ph) / (4 * sqrt(pi)) - sqrt(3) * sin(th) * exp(-I * ph) / (4 * sqrt(pi)) ) assert Znm(2, -1, th, ph).expand(func=True) == ( sqrt(15) * I * sin(th) * exp(I * ph) * cos(th) / (4 * sqrt(pi)) - sqrt(15) * I * sin(th) * exp(-I * ph) * cos(th) / (4 * sqrt(pi)) ) assert Znm(2, 0, th, ph).expand(func=True) == 3 * sqrt(5) * cos(th) ** 2 / ( 4 * sqrt(pi) ) - sqrt(5) / (4 * sqrt(pi)) assert Znm(2, 1, th, ph).expand(func=True) == ( -sqrt(15) * sin(th) * exp(I * ph) * cos(th) / (4 * sqrt(pi)) - sqrt(15) * sin(th) * exp(-I * ph) * cos(th) / (4 * sqrt(pi)) )
def dot_rot_grad_Ynm(j, p, l, m, theta, phi): r""" Returns dot product of rotational gradients of spherical harmonics. Explanation =========== This function returns the right hand side of the following expression: .. math :: \vec{R}Y{_j^{p}} \cdot \vec{R}Y{_l^{m}} = (-1)^{m+p} \sum\limits_{k=|l-j|}^{l+j}Y{_k^{m+p}} * \alpha_{l,m,j,p,k} * \frac{1}{2} (k^2-j^2-l^2+k-j-l) Arguments ========= j, p, l, m .... indices in spherical harmonics (expressions or integers) theta, phi .... angle arguments in spherical harmonics Example ======= >>> from sympy import symbols >>> from sympy.physics.wigner import dot_rot_grad_Ynm >>> theta, phi = symbols("theta phi") >>> dot_rot_grad_Ynm(3, 2, 2, 0, theta, phi).doit() 3*sqrt(55)*Ynm(5, 2, theta, phi)/(11*sqrt(pi)) """ j = sympify(j) p = sympify(p) l = sympify(l) m = sympify(m) theta = sympify(theta) phi = sympify(phi) k = Dummy("k") def alpha(l, m, j, p, k): return sqrt((2*l+1)*(2*j+1)*(2*k+1)/(4*pi)) * \ Wigner3j(j, l, k, S.Zero, S.Zero, S.Zero) * \ Wigner3j(j, l, k, p, m, -m-p) return (S.NegativeOne)**(m+p) * Sum(Ynm(k, m+p, theta, phi) * alpha(l,m,j,p,k) / 2 \ *(k**2-j**2-l**2+k-j-l), (k, abs(l-j), l+j))
def psi(n: int, l: int, ml: int, Z: int = 1): check(n, l, ml, Z) a0, r, θ, φ = symbols("a_0 r θ φ") ρ = 2 * r / (n * a0) R = ( sqrt(2 * Z / n / a0) ** 3 * factorial(n - l - 1) / (2 * n * factorial(n + l)) * exp(-ρ / 2) * ρ ** l ) lag = L(2 * l + 1, n - l - 1, ρ) Y = Ynm(ml, l, θ, φ) if l else 1 return 1 / sqrt(π) * R * lag * Y
def timeit_Ynm_xy(): Ynm(1, 1, x, y)
def test_Ynm(): # http://en.wikipedia.org/wiki/Spherical_harmonics th, ph = Symbol("theta", real=True), Symbol("phi", real=True) from sympy.abc import n,m assert Ynm(0, 0, th, ph).expand(func=True) == 1/(2*sqrt(pi)) assert Ynm(1, -1, th, ph) == -exp(-2*I*ph)*Ynm(1, 1, th, ph) assert Ynm(1, -1, th, ph).expand(func=True) == sqrt(6)*sin(th)*exp(-I*ph)/(4*sqrt(pi)) assert Ynm(1, 0, th, ph).expand(func=True) == sqrt(3)*cos(th)/(2*sqrt(pi)) assert Ynm(1, 1, th, ph).expand(func=True) == -sqrt(6)*sin(th)*exp(I*ph)/(4*sqrt(pi)) assert Ynm(2, 0, th, ph).expand(func=True) == 3*sqrt(5)*cos(th)**2/(4*sqrt(pi)) - sqrt(5)/(4*sqrt(pi)) assert Ynm(2, 1, th, ph).expand(func=True) == -sqrt(30)*sin(th)*exp(I*ph)*cos(th)/(4*sqrt(pi)) assert Ynm(2, -2, th, ph).expand(func=True) == (-sqrt(30)*exp(-2*I*ph)*cos(th)**2/(8*sqrt(pi)) + sqrt(30)*exp(-2*I*ph)/(8*sqrt(pi))) assert Ynm(2, 2, th, ph).expand(func=True) == (-sqrt(30)*exp(2*I*ph)*cos(th)**2/(8*sqrt(pi)) + sqrt(30)*exp(2*I*ph)/(8*sqrt(pi))) assert diff(Ynm(n, m, th, ph), th) == (m*cot(th)*Ynm(n, m, th, ph) + sqrt((-m + n)*(m + n + 1))*exp(-I*ph)*Ynm(n, m + 1, th, ph)) assert diff(Ynm(n, m, th, ph), ph) == I*m*Ynm(n, m, th, ph) assert conjugate(Ynm(n, m, th, ph)) == (-1)**(2*m)*exp(-2*I*m*ph)*Ynm(n, m, th, ph) assert Ynm(n, m, -th, ph) == Ynm(n, m, th, ph) assert Ynm(n, m, th, -ph) == exp(-2*I*m*ph)*Ynm(n, m, th, ph) assert Ynm(n, -m, th, ph) == (-1)**m*exp(-2*I*m*ph)*Ynm(n, m, th, ph)
def Psi_nlm(n, l, m, r, phi, theta, Z=1): """ Returns the Hydrogen wave function psi_{nlm}. It's the product of the radial wavefunction R_{nl} and the spherical harmonic Y_{l}^{m}. Parameters ========== n : integer Principal Quantum Number which is an integer with possible values as 1, 2, 3, 4,... l : integer ``l`` is the Angular Momentum Quantum Number with values ranging from 0 to ``n-1``. m : integer ``m`` is the Magnetic Quantum Number with values ranging from ``-l`` to ``l``. r : radial coordinate phi : azimuthal angle theta : polar angle Z : atomic number (1 for Hydrogen, 2 for Helium, ...) Everything is in Hartree atomic units. Examples ======== >>> from sympy.physics.hydrogen import Psi_nlm >>> from sympy import Symbol >>> r=Symbol("r", positive=True) >>> phi=Symbol("phi", real=True) >>> theta=Symbol("theta", real=True) >>> Z=Symbol("Z", positive=True, integer=True, nonzero=True) >>> Psi_nlm(1,0,0,r,phi,theta,Z) Z**(3/2)*exp(-Z*r)/sqrt(pi) >>> Psi_nlm(2,1,1,r,phi,theta,Z) -Z**(5/2)*r*exp(I*phi)*exp(-Z*r/2)*sin(theta)/(8*sqrt(pi)) Integrating the absolute square of a hydrogen wavefunction psi_{nlm} over the whole space leads 1. The normalization of the hydrogen wavefunctions Psi_nlm is: >>> from sympy import integrate, conjugate, pi, oo, sin >>> wf=Psi_nlm(2,1,1,r,phi,theta,Z) >>> abs_sqrd=wf*conjugate(wf) >>> jacobi=r**2*sin(theta) >>> integrate(abs_sqrd*jacobi, (r,0,oo), (phi,0,2*pi), (theta,0,pi)) 1 """ # sympify arguments n, l, m, r, phi, theta, Z = map(S, [n, l, m, r, phi, theta, Z]) # check if values for n,l,m make physically sense if n.is_integer and n < 1: raise ValueError("'n' must be positive integer") if l.is_integer and not (n > l): raise ValueError("'n' must be greater than 'l'") if m.is_integer and not (abs(m) <= l): raise ValueError("|'m'| must be less or equal 'l'") # return the hydrogen wave function return R_nl(n, l, r, Z) * Ynm(l, m, theta, phi).expand(func=True)