Example #1
0
 def _pdf(self, x, dfn, dfd, nc):
     n1, n2 = dfn, dfd
     term = -nc / 2. + nc * n1 * x / (2 * (n2 + n1 * x)) + special.gammaln(
         n1 / 2.) + special.gammaln(1 + n2 / 2.)
     term -= special.gammaln((n1 + n2) / 2.)
     Px = numpy.exp(term)
     Px *= n1**(n1 / 2.) * n2**(n2 / 2.) * x**(n1 / 2. - 1)
     Px *= (n2 + n1 * x)**(-(n1 + n2) / 2.)
     Px *= special.assoc_laguerre(-nc * n1 * x / (2. * (n2 + n1 * x)),
                                  n2 / 2., n1 / 2. - 1)
     Px /= special.beta(n1 / 2., n2 / 2.)
     return Px
Example #2
0
def get_wave_r1(n,l,m,Zm,r):
        x = r
        y = 0 
        z = 0
        X, Z = np.meshgrid(x, z)

        rho = np.linalg.norm((X,y,Z), axis=0) *Zm / n
        Lag = assoc_laguerre(2 * rho, n - l - 1, 2 * l + 1)
        Ylm  = sph_harm(m, l, np.arctan2(y,X), np.arctan2(np.linalg.norm((X,y), axis=0), Z))
        Psi = np.exp(-rho) * np.power((2*rho),l) * Lag * Ylm

        density = np.conjugate(Psi) * Psi
        density = density.real
        return density[0]
def WaveFunction(x, y, z, n, l, m):
    
    # theta is azimuthal angle and phi is polar angle  
    r, phi, theta = CoordinateConverter(x, y, z)
    # a is the Bohr radius in angstroms
    
    a = .529 
    
    spherical = special.sph_harm(m, n, theta, phi)
    
    LaguerreOrder = 2*l + 1
    LaguerrePoint = (2*r)/(n*a)
    laguerre = special.assoc_laguerre(LaguerreOrder, LaguerrePoint)
    radial = sqrt((2/(n*a))**3 * (float(factorial(n-l-1))/(float(2*n*(factorial(n+l))**3))))*exp(-r/(n*a))*((2*r)/(n*a))**l
    
    value = radial * laguerre * spherical
    probability = abs(value)**2
    
    return probability
def compute_R_tilde_for_one_l(
        i_l, ll, n_m, n_r, n_n, m_vect, i_l_zero, n_l_pos,
        e_L_PHI_mat, r_vect, phi_vect,
        r_b, sigma_b, a_param, lambda_param, dr, dphi,
        cos_phi, cos2_phi, z_slices,
        HH, H_N_2_vect, exp_j_dPhi_R_PHI):

    r_part_l_M_R_mat = np.zeros((n_m, n_r))
    R_plus_curr = np.zeros((n_m, n_n), dtype=np.complex)
    R_minus_curr = np.zeros((n_m, n_n), dtype=np.complex)
    for i_m, mm in  enumerate(m_vect):
        print(f'l={i_l-i_l_zero}/{n_l_pos} m={i_m}/{n_m}')
        lag_l_m_R_vect =assoc_laguerre(
                a_param * r_vect*r_vect, n=mm, k=np.abs(ll))
        r_part_l_M_R_mat[i_m, :]  = (
                  dr * r_vect
                * (r_vect/r_b)**(lambda_param*np.abs(ll))
                * lag_l_m_R_vect
                )
        for nn in range(n_n):
            int_dphi_l_n_R_vect = np.zeros(n_r, dtype=np.complex)
            int_dphi_ml_n_R_vect = np.zeros(n_r, dtype=np.complex)
            for i_r, rr in enumerate(r_vect):
                h_n_r_cos_phi = np.interp(rr*cos_phi,
                    z_slices, HH[nn, :])
                exp_c2_r_PHI_vect = np.exp(-a_param*rr*rr
                        *(1-cos2_phi/(2*a_param*sigma_b**2)))
                integrand_part = (exp_c2_r_PHI_vect
                  * h_n_r_cos_phi/H_N_2_vect[nn]
                  * np.conj(e_L_PHI_mat[i_l, :]))
                int_dphi_l_n_R_vect[i_r] = dphi * np.sum(
                    integrand_part
                  * np.conj(exp_j_dPhi_R_PHI[i_r, :]))
                int_dphi_ml_n_R_vect[i_r] = dphi * np.sum(
                    np.conj(integrand_part)
                  * np.conj(exp_j_dPhi_R_PHI[i_r, :]))
            R_plus_curr[i_m, nn] = np.sum(
                    r_part_l_M_R_mat[i_m, :]*
                    int_dphi_l_n_R_vect)
            R_minus_curr[i_m, nn] = np.sum(
                    r_part_l_M_R_mat[i_m, :]*
                    int_dphi_ml_n_R_vect)
    return R_plus_curr, R_minus_curr
Example #5
0
def Om_n_m(eta, n, m, Om0):
    # Calculates the modified Rabi frequency associated with the transition between |g,n> -- |e,n+m>
    # accepts both integer and np.arrays
    # also work for n+m<0
    if type(n) == int:
        if n < 0:
            output = 0

        else:
            t1 = np.exp(-eta**2 / 2)
            t2 = eta**np.abs(m)
            if m == 0:
                t3 = 1
                t4 = np.abs(sp.assoc_laguerre(eta**2, n, np.abs(m)))

            elif m > 0:
                t3 = product_pos_m(n, m)
                t4 = np.abs(sp.assoc_laguerre(eta**2, n, np.abs(m)))

            elif (m < 0) and (n + m >= 0):
                t3 = product_neg_m(n, -m)
                t4 = np.abs(sp.assoc_laguerre(eta**2, n, np.abs(m)))

            elif (m < 0) and (n + m < 0):
                t3 = 1
                t4 = 0

            output = Om0 * t1 * t2 * t3 * t4
    else:
        output = np.zeros(len(n))

        t1 = np.exp(-eta**2 / 2)
        t2 = eta**np.abs(m)
        if m == 0:
            t3 = 1
            t4 = np.abs(sp.assoc_laguerre(eta**2, n[n >= 0], np.abs(m)))
            output[n >= 0] = Om0 * t1 * t2 * t3 * t4

        elif m > 0:
            t3 = product_pos_m(n[n >= 0], m)
            t4 = np.abs(sp.assoc_laguerre(eta**2, n[n >= 0], np.abs(m)))
            output[n >= 0] = Om0 * t1 * t2 * t3 * t4

        elif m < 0:
            t3 = product_neg_m(n[n >= 0], -m)
            t4 = np.abs(sp.assoc_laguerre(eta**2, n[n >= 0], np.abs(m)))
            output_temp = np.zeros(len(n))
            output_temp[n >= 0] = Om0 * t1 * t2 * t3 * t4
            output[n + m >= 0] = output_temp[:len(output[n + m >= 0])]
    return output
def compute_R_for_one_l(
        i_l, ll, n_m, n_r, n_n, m_vect, i_l_zero, n_l_pos,
        e_L_PHI_mat, r_vect, phi_vect,
        r_b, sigma_b, a_param, lambda_param, dr, dphi,
        cos_phi, z_slices, KK, exp_j_dPhi_R_PHI):

    r_part_l_M_R_mat = np.zeros((n_m, n_r))
    R_plus_curr = np.zeros((n_m, n_n), dtype=np.complex)
    R_minus_curr = np.zeros((n_m, n_n), dtype=np.complex)
    for i_m, mm in  enumerate(m_vect):
        print(f'l={i_l-i_l_zero}/{n_l_pos} m={i_m}/{n_m}')
        lag_l_m_R_vect =assoc_laguerre(
                a_param * r_vect*r_vect, n=mm, k=np.abs(ll))
        r_part_l_M_R_mat[i_m, :]  = (
                  dr * r_vect
                * a_param**np.abs(ll)*r_b**(lambda_param*np.abs(ll))
                * r_vect**((2-lambda_param)*np.abs(ll))
                * lag_l_m_R_vect
                * np.exp(-r_vect**2 / (2*sigma_b**2))
                )

        for nn in range(n_n):
            int_dphi_l_n_R_vect = np.zeros(n_r, dtype=np.complex)
            int_dphi_ml_n_R_vect = np.zeros(n_r, dtype=np.complex)
            for i_r, rr in enumerate(r_vect):
                k_n_r_cos_phi = np.interp(rr*cos_phi,
                    z_slices, KK[nn, :])
                integrand_part = k_n_r_cos_phi*e_L_PHI_mat[i_l, :]
                int_dphi_l_n_R_vect[i_r] = dphi * np.sum(
                    exp_j_dPhi_R_PHI[i_r, :]
                  * integrand_part)
                int_dphi_ml_n_R_vect[i_r] = dphi * np.sum(
                    exp_j_dPhi_R_PHI[i_r, :]
                  * np.conj(integrand_part))
            R_plus_curr[i_m, nn] = np.sum(
                    r_part_l_M_R_mat[i_m, :]*
                    int_dphi_l_n_R_vect)
            R_minus_curr[i_m, nn] = np.sum(
                    r_part_l_M_R_mat[i_m, :]*
                    int_dphi_ml_n_R_vect)
    return R_plus_curr, R_minus_curr
Example #7
0
def HFunc(r, theta, phi, n, l, m):
    '''
    Hydrogen wavefunction // a_0 = 1

    INPUT
        r: Radial coordinate
        theta: Polar coordinate
        phi: Azimuthal coordinate
        n: Principle quantum number
        l: Angular momentum quantum number
        m: Magnetic quantum number

    OUTPUT
        Value of wavefunction
    '''

    coeff = np.sqrt((2.0 / n)**3 * spe.factorial(n - l - 1) /
                    (2.0 * n * spe.factorial(n + l)))
    laguerre = spe.assoc_laguerre(2.0 * r / n, n - l - 1, 2 * l + 1)
    sphHarm = spe.sph_harm(m, l, phi,
                           theta)  # Note the different convention from doc

    return coeff * np.exp(-r / n) * (2.0 * r / n)**l * laguerre * sphHarm
def WaveFunction(x, y, z, n, l, m):

    # theta is azimuthal angle and phi is polar angle
    r, phi, theta = CoordinateConverter(x, y, z)
    # a is the Bohr radius in angstroms

    a = .529

    spherical = special.sph_harm(m, n, theta, phi)

    LaguerreOrder = 2 * l + 1
    LaguerrePoint = (2 * r) / (n * a)
    laguerre = special.assoc_laguerre(LaguerreOrder, LaguerrePoint)
    radial = sqrt(
        (2 / (n * a))**3 *
        (float(factorial(n - l - 1)) /
         (float(2 * n * (factorial(n + l))**3)))) * exp(-r /
                                                        (n * a)) * ((2 * r) /
                                                                    (n * a))**l

    value = radial * laguerre * spherical
    probability = abs(value)**2

    return probability
#fig = plt.figure()

for n in qn:
    for l in ql:
        for m in qm:
            if n <= l:
                continue
            if m > l:
                continue
#            ax = fig.add_subplot(1, 1, 1, projection='3d')
            R = np.sqrt(
                (2 / (n * a)) *
                (np.math.factorial(n - l - 1) /
                 (2 * n * np.math.factorial(n + 1))**3)) * np.exp(
                     -r /
                     (n * a)) * (2 * r / (n * a))**l * special.assoc_laguerre(
                         2 * r / (n * a), n - l - 1, 2 * l + 1)
            ep = (-1)**m
            Y = ep * np.sqrt(
                (2 * l + 1) / (4 * np.pi) * special.factorial(l - np.abs(m)) /
                special.factorial(1 + np.abs(m))) * np.exp(
                    1j * m * phi) * special.lpmv(m, l, np.cos(theta))

            Z = np.abs(R * Y)**2
            X, Y = r * np.cos(theta), r * np.sin(theta)

            pylab.pcolor(Y, X, Z, cmap='jet')
            pylab.colorbar()

pylab.show()
Example #10
0
def laguerre(n, l, x):
    return assoc_laguerre(x, n - l - 1, 2 * l + 1)
Example #11
0
def Hydor(request):
    try:
        n = request.GET.get('n', 4)
        l = request.GET.get('l', 1)
        m = request.GET.get('m', 0)
        n, l, m = float(n), float(l), float(m)
        import numpy as np
        import matplotlib.pyplot as plt
        from scipy.special import sph_harm
        from scipy.special import assoc_laguerre
        from pathlib import Path

        my_file = Path(settings.STATIC_ROOT + str(n) + str(l) + str(m) +
                       ".png")
        x = np.linspace(-n**2 * 4, n**2 * 4, 500)
        y = 0  #### the plane locates at y = 0
        z = np.linspace(-n**2 * 4, n**2 * 4, 500)
        X, Z = np.meshgrid(x, z)
        rho = np.linalg.norm((X, y, Z), axis=0) / n
        Lag = assoc_laguerre(2 * rho, n - l - 1, 2 * l + 1)
        Ylm = sph_harm(m, l, np.arctan2(y, X),
                       np.arctan2(np.linalg.norm((X, y), axis=0), Z))
        Psi = np.exp(-rho) * np.power((2 * rho), l) * Lag * Ylm
        density = np.conjugate(Psi) * Psi
        density = density.real
        if not my_file.is_file():
            fig, ax = plt.subplots(figsize=(10, 10))
            ax.imshow(density.real,
                      extent=[
                          -density.max() * 0.2,
                          density.max() * 0.2, -density.max() * 0.2,
                          density.max() * 0.2
                      ],
                      cmap='gist_stern')
            # plt.show()
            fig.set_facecolor('black')
            fig.savefig(settings.STATIC_ROOT + str(n) + str(l) + str(m) +
                        ".png",
                        dpi=300)
            plt.close()
        theta1 = np.linspace(0, 2 * np.pi, 181)
        phi1 = np.linspace(0, np.pi, 91)
        theta_2d, phi_2d = np.meshgrid(theta1, phi1)
        Ylm1 = sph_harm(abs(m), l, theta_2d, phi_2d)
        xyz_2d = np.array([
            np.sin(phi_2d) * np.sin(theta_2d),
            np.sin(phi_2d) * np.cos(theta_2d),
            np.cos(phi_2d)
        ])
        if m < 0:
            Ylm1 = np.sqrt(2) * (-1)**m * Ylm1.imag
        else:
            Ylm1 = np.sqrt(2) * (-1)**m * Ylm1.real
        r = np.abs(Ylm1.real) * xyz_2d

        # plt.plot(r[0][1], r[1][1])
        try:
            T = density * (((4 * np.pi) / 3) * (((np.max(X) + X)**3) -
                                                ((4 * np.pi) / 3 * (X**3))))
            # T = (T - np.min(T)) / (np.max(T) - np.min(T))  # 最值归一化

            T = (T - np.min(T)) / (np.max(T) - np.min(T))
            T = T.tolist()[100:250]
            y = [round(x[249:250][0], 6) * 300 for x in T]
        except:
            y = None
        return JsonResponse({
            'src':
            settings.STATIC_ROOT + str(n) + str(l) + str(m) + ".png",
            'r':
            r.tolist(),
            'y':
            y
        })
    except:
        return JsonResponse({'sorry': 'error'})
Example #12
0
 def Radial(self):
     n, l = self.n, self.l
     norm = np.sqrt((2 / n)**2 * f(n - l - 1) / 2 / n / f(n + l))
     R = np.exp(-self.R / n) * (2 * self.R / n)**l
     L = assoc_laguerre(2 * self.R / n, n - l - 1, 2 * l + 1)
     return norm * R * L
Example #13
0
def laguerre_wave_function(x, zeta, n, l):
    """
    Laguerre function, see [A. E. McCoy and M. A. Caprio, J. Math. Phys. 57, (2016).] for details
    """
    eta = 2.0 * x / zeta
    return np.sqrt(2.0 * gamma(n+1) / (zeta * gamma(n+2*l+3)) ) * 2.0 * eta**l * np.exp(-0.5*eta) * assoc_laguerre(eta, n, 2*l+2) / zeta
Example #14
0
def SHoverlap(a = AtomGaussian(), b = AtomGaussian()):
   
    R = b.centre - a.centre
    radius2 = R.dot(R)
    radius = np.sqrt(radius2)
    xi = a.alpha * b.alpha /(a.alpha + b.alpha)
    lague_x = xi*radius2
    
    Rot = np.zeros([3,3]).astype(complex) 
    Rot[0,0] = -1/np.sqrt(2)
    Rot[1,0] = 1/np.sqrt(2)
    Rot[0,1] = Rot[1,1] = complex(0,1/np.sqrt(2))                                      
    Rot[2,2] = 1
    
    Ax = np.matmul(Rot,a.axis)
    Bx = np.matmul(Rot,b.axis)

    axis_mat = np.outer(Ax,Bx)

    l1 = a.l
    l2 = b.l
    
    m1 = a.m
    m2 = b.m
        
    I_map = np.zeros([3,3]).astype(complex)
    mset = [+1,-1,0]
    for i in range(3):
        for j in range(3):
            m1 = mset[i]
            m2 = mset[j]

            I = 0
            F = 0
                                 
            m = m2 - m1
        
            # for one centre overlap integrals
            if radius == 0:
                if l1 == l2 and  m1 == m2: 
                    I = (-1)**l2 * special.gamma(l2+3/2)* (4*xi)**(l2+3/2) /(2*(2*np.pi)**(3/2))
            else:
            # for two centre overlap integrals
                
                theta   =  np.arccos(R[2]/radius)
                phi     =  np.arctan2(R[1],R[0])
                
                # set the range of theta and phi for 
                if theta < 0:
                    theta = theta + 2*np.pi
                if phi < 0:
                    phi = phi + 2*np.pi
                    
                    # use the selection rule to 
                lset = []
                for value in range(abs(l1-l2),l1+l2+1):
                    if (l1+l2+ value) %2 == 0:
                        lset.append(value)
         
                # Sum I for each L
                for l in lset:    
                    if abs(m) > l: continue
                
                    # Calculate the overlap
                    n             = (l1+l2-l)/2
                    C_A_nl        = 2**n * np.math.factorial(n) * (2*xi)**(n+l+3/2)
                    Laguerre      = special.assoc_laguerre(lague_x, n, l+1/2)
                    SolidHarmonic = radius**l * special.sph_harm(m, l, phi, theta)
                    Psi_xi_R      = np.exp(-lague_x)*Laguerre* SolidHarmonic   
                    gaunt_value   = float((-1.0)**m2 *  gaunt(l2,l1,l,-m2,m1,m))
                    
                    I             += (-1)**n * gaunt_value * C_A_nl * Psi_xi_R
                    
                    #calculate the gradient 
                    overGrad = Gradient(n,l,m,xi,R)
                    moment = np.cross(b.centre,overGrad)
                    overGrad= np.hstack((overGrad,moment))
        
                    F += (-1)**n * gaunt_value * C_A_nl * overGrad
                            
                    '''
                    #calculate the Hessian
                    C_A_l_np      = 2**(n+1) * np.math.factorial(n+1) * (2*xi)**(n+1+l+3/2)
                    Laguerre_np   = special.assoc_laguerre(lague_x, n+1, l+1/2)
                    Psi_xi_R_np   = np.exp(-lague_x)*Laguerre_np* SolidHarmonic
                    
                    K             += (-1)**n * gaunt_value * C_A_l_np * Psi_xi_R_np
                    '''            
            I_map[i,j] = I
    
    result = axis_mat * I_map
    resum = result.sum()

    # Normalized version               
    #S = (-1.0)**l2 * (2*np.pi)**(3/2)* Normalize(1/(4*a.alpha),l1)* Normalize(1/(4*b.alpha),l2)*I
    S = (-1.0)**l2 * (2*np.pi)**(3/2)* resum
    Grad_S = (-1.0)**l2 * (2*np.pi)**(3/2)* F
    #Hess_S = (-1.0)**l2 * (2*np.pi)**(3/2)* K
    return np.real(S), Grad_S