Ejemplo n.º 1
0
def G(l_1, l_2, m_1, m_2, M, alpha, beta):

    # INPUTS: 'l_1': Angular quantum number of atom 1.
    # 'l_2': Angular quantum number of atom 2.
    # 'm_1': Magnetic quantum number of atom 1.
    # 'm_2': Magnetic quantum number of atom 2.
    # 'M': A float which represents the type of symmetry bond we are considering, e.g. M = 0
    # for sigma, M = 1 for pi, M = 2 for delta, etc.
    # 'alpha': Azithmuthal coordinate.
    # 'beta': Polar coordinate.
    # RETURNS: This function returns the relevant coefficient that should be are used in writing the
    # Slater-Koster transformations.

    def tau(m):
        if m >= 0:
            return 1.0
        else:
            return 0.0

    def A(m, alpha):
        if m == 0:
            return np.sqrt(2) / 2
        else:
            return ((-1)**m) * (tau(m) * sp.cos(np.absolute(m) * alpha) +
                                tau(-m) * sin(np.absolute(m) * alpha))

    def B(m, alpha):
        if m == 0:
            return 0.0
        else:
            return ((-1)**m) * (tau(-m) * sp.cos(np.absolute(m) * alpha) -
                                tau(m) * sin(np.absolute(m) * alpha))

    def S(l, m, M, alpha, beta):
        W1 = Rotation.d(l, np.absolute(m), M, beta).doit()
        W2 = Rotation.d(l, np.absolute(m), -M, beta).doit()
        return A(m, alpha) * (((-1)**M) * W1 + W2)

    def T(l, m, M, alpha, beta):
        W1 = Rotation.d(l, np.absolute(m), M, beta).doit()
        W2 = Rotation.d(l, np.absolute(m), -M, beta).doit()
        return B(m, alpha) * ((-1)**M * W1 - W2)

    if M == 0:
        return 2 * A(m_1, alpha) * A(m_2, alpha) * Rotation.d(
            l_1, np.absolute(m_1), 0, beta).doit() * Rotation.d(
                l_2, np.absolute(m_2), 0, beta).doit()
    else:
        return (S(l_1, m_1, M, alpha, beta) * S(l_2, m_2, M, alpha, beta) +
                T(l_1, m_1, M, alpha, beta) * T(l_2, m_2, M, alpha, beta))
Ejemplo n.º 2
0
def wigner_dm0_vector_sympy(ang_momentum_l, angle):
    R_out = np.empty(2 * ang_momentum_l + 1, dtype=np.float64)
    for i in range(2 * ang_momentum_l + 1):
        rotate = Rotation.d(ang_momentum_l, -ang_momentum_l + i, 0,
                            angle).doit()
        R_out[i] = complex(rotate).real
    return R_out
def UnrotCovRel(beta, z1, z2):
    lmax = 8

    xi = np.zeros(lmax - 1).astype(complex)
    for l in range(2, lmax + 1):
        xi[l - 2] = KIntegral(z1, z2, l)
        #print(xi[l-2])

    rel = 0
    for l in range(2, lmax + 1):
        rel += (2 * l + 1) / (4 * np.pi) * xi[l - 2] * sp.N(
            Rotation.d(l, 2, -2, beta).doit())

    var = 0
    for l in range(2, lmax + 1):
        var += (2 * l + 1) / (4 * np.pi) * xi[l - 2] * sp.N(
            Rotation.d(l, 2, 2, beta).doit())

    return var, rel
def dlmmp_sympy(l, m, mp, beta):
    """
    The Wigner-d matrix term d^l_{m,m'}(beta), evaluated using `sympy`.

    Note that the transformation in `sympy` is a **passive** transformation,
    (i.e., it is a rotation of the coordinate system, not of actual points
    in 3D space), so we flip the sign of the angle of rotation when
    comparing to our implementation.
    """
    return np.float(re(Rotation.d(l, m, mp, -beta).doit().evalf()))
Ejemplo n.º 5
0
def wigner_d(l, m, m_prime, beta, wdsympy=False):
    """Computation of Wigner-d-functions for the rotation of a T-matrix
    
    Args:
        l (int):          Degree :math:`l` (1, ..., lmax)
        m (int):          Order :math:`m` (-min(l,mmax),...,min(l,mmax))
        m_prime (int):    Order :math:`m_prime` (-min(l,mmax),...,min(l,mmax))
        beta (float):     Second Euler angle in rad
        wdsympy (bool):   If True, Wigner-d-functions come from the sympy toolbox 
        
    Returns:
        real value of Wigner-d-function
    """
    wig_d = np.zeros(l + 1, dtype=complex)

    if wdsympy == False:

        if beta < 0:
            aa = m
            bb = m_prime
            m = bb
            m_prime = aa

        if m == 0 and m_prime == 0:
            for nn in range(1, l + 1):
                wig_d[nn] = sympy.legendre_poly(nn, np.cos(beta))
        else:
            # recursion formulation (Mishchenko, Scattering, Absorption and Emission of Light by small Particles, p.365 (B.22 - B.24))
            l_min = max(abs(m), abs(m_prime))
            wig_d[l_min - 1] = 0
            if m_prime >= m:
                zeta = 1
            else:
                zeta = (-1)**(m - m_prime)

            wig_d[l_min] = (
                zeta * 2.0**(-l_min) *
                (factorial(2 * l_min) /
                 (factorial(abs(m - m_prime)) * factorial(abs(m + m_prime))))**
                0.5 * (1 - np.cos(beta))**(abs(m - m_prime) / 2) *
                (1 + np.cos(beta))**(abs(m + m_prime) / 2))

            for ll in range(l_min, l):
                wig_d[ll + 1] = (
                    ((2 * ll + 1) *
                     (ll * (ll + 1) * np.cos(beta) - m * m_prime) * wig_d[ll] -
                     (ll + 1) * (ll**2 - m**2)**0.5 *
                     (ll**2 - m_prime**2)**0.5 * wig_d[ll - 1]) /
                    (ll * ((ll + 1)**2 - m**2)**0.5 *
                     ((ll + 1)**2 - m_prime**2)**0.5))

    else:
        wig_d[l] = complex(Rotation.d(l, m, m_prime, beta).doit())

    return wig_d[l].real
def UnrotCovRel(beta, z1, z2):
    lmax = 7  #NOTE: In general, the higher this number the greater the accuracy, but for very small redshift, i.e. z<0.1,
    #covariance for l>2 is so low that beyond l~6, python returns a "nan". Need an if statement in here.

    xi = np.zeros(lmax - 1).astype(complex)
    for l in range(2, lmax + 1):
        xi[l - 2] = KIntegral(z1, z2, l)
        #print(xi[l-2])

    rel = 0
    for l in range(2, lmax + 1):
        rel += (2 * l + 1) / (4 * np.pi) * xi[l - 2] * sp.N(
            Rotation.d(l, 2, -2, beta).doit())

    var = 0
    for l in range(2, lmax + 1):
        var += (2 * l + 1) / (4 * np.pi) * xi[l - 2] * sp.N(
            Rotation.d(l, 2, 2, beta).doit())

    return 526.2668069929152 * var, 526.2668069929152 * rel
def test_wignerd():
    l_test = 5
    m_test = -3
    m_prime_test = 4
    beta_test = 0.64
    wigd = smuthi.utility.math.wigner_d(l_test,
                                        m_test,
                                        m_prime_test,
                                        beta_test,
                                        wdsympy=False)
    wigd_sympy = complex(
        Rotation.d(l_test, m_test, m_prime_test, beta_test).doit()).real
    err = abs((wigd - wigd_sympy) / wigd)
    assert err < 1e-10
Ejemplo n.º 8
0
def AC_aniso(Nmax,a2,Beta,I1,I2):
    '''
        Generates the effect of the anisotropic AC Stark shift for a rigid-rotor
        like molecule.

        This term is calculated differently to all of the others in this work
        and is based off Jesus Aldegunde's FORTRAN 77 code. It iterates over
        N,MN,N',MN' to build a matrix without hyperfine structure then uses
        kronecker products to expand it into all of the hyperfine states.

        input arguments:

        Nmax: maximum rotational quantum number to calculate (int)
        a2: anisotropic polarisability (float)
        Beta: polarisation angle of the laser in Radians (float)
        I1,I2: Nuclear spin of nucleus 1,2 (float)

        returns:
        H: Hamiltonian, (2*Nmax+1)*(2*I1_mag+1)*(2*I2_mag+1)x
           (2*Nmax+1)*(2*I1_mag+1)*(2*I2_mag+1) array.
     '''
    I1shape = int(2*I1+1)
    I2shape = int(2*I2+1)
    shape = numpy.sum(numpy.array([2*x+1 for x in range(0,Nmax+1)]))
    HAC = numpy.zeros((shape,shape),dtype= numpy.complex)
    i=0
    j=0
    for N1 in range(0,Nmax+1):
        for M1 in range(N1,-(N1+1),-1):
            for N2 in range(0,Nmax+1):
                for M2 in range(N2,-(N2+1),-1):
                    M = M2-M1
                    HAC[i,j]= -a2*(Rotation.d(2,M,0,Beta).doit()*(-1)**M2*\
                                numpy.sqrt((2*N1+1)*(2*N2+1))*\
                                wigner_3j(N2,2,N1,0,0,0)*\
                                wigner_3j(N2,2,N1,-M2,M,M1))
                    j+=1
            j=0
            i+=1
    #final check for NaN errors, mostly this is due to division by zero or
    # multiplication by a small prefactor. it is safe to set these terms to 0
    HAC[numpy.isnan(HAC)] =0

    #return the matrix, in the full uncoupled basis.
    return (numpy.kron(HAC,numpy.kron(numpy.identity(I1shape),
            numpy.identity(I2shape))))
Ejemplo n.º 9
0
def wigner_small_d(theta, j, m1, m2):
    """Calculate Wigner small-d function. Needs sympy.
      theta : angle
      j : spin (in units of 1/2, e.g. 1 for spin=1/2)
      m1 and m2 : spin projections (in units of 1/2)

    :param theta: 
    :param j: 
    :param m1: 
    :param m2: 

    """
    from sympy import Rational
    from sympy.abc import x
    from sympy.utilities.lambdify import lambdify
    from sympy.physics.quantum.spin import Rotation as Wigner
    d = Wigner.d(Rational(j, 2), Rational(m1, 2), Rational(m2, 2),
                 x).doit().evalf()
    return lambdify(x, d, "tensorflow")(theta)
Ejemplo n.º 10
0
def test_wignerd():
    j, m, mp, alpha, beta, gamma = symbols('j m mp alpha beta gamma')
    assert Rotation.D(j, m, mp, alpha, beta,
                      gamma) == WignerD(j, m, mp, alpha, beta, gamma)
    assert Rotation.d(j, m, mp, beta) == WignerD(j, m, mp, 0, beta, 0)
Ejemplo n.º 11
0
def test_rotation_small_d():
    # Symbolic tests
    beta = symbols('beta')
    # j = 1/2
    assert Rotation.d(S(1) / 2,
                      S(1) / 2,
                      S(1) / 2, beta).doit() == cos(beta / 2)
    assert Rotation.d(S(1) / 2,
                      S(1) / 2, -S(1) / 2, beta).doit() == -sin(beta / 2)
    assert Rotation.d(S(1) / 2, -S(1) / 2,
                      S(1) / 2, beta).doit() == sin(beta / 2)
    assert Rotation.d(S(1) / 2, -S(1) / 2, -S(1) / 2,
                      beta).doit() == cos(beta / 2)
    # j = 1
    assert Rotation.d(1, 1, 1, beta).doit() == (1 + cos(beta)) / 2
    assert Rotation.d(1, 1, 0, beta).doit() == -sin(beta) / sqrt(2)
    assert Rotation.d(1, 1, -1, beta).doit() == (1 - cos(beta)) / 2
    assert Rotation.d(1, 0, 1, beta).doit() == sin(beta) / sqrt(2)
    assert Rotation.d(1, 0, 0, beta).doit() == cos(beta)
    assert Rotation.d(1, 0, -1, beta).doit() == -sin(beta) / sqrt(2)
    assert Rotation.d(1, -1, 1, beta).doit() == (1 - cos(beta)) / 2
    assert Rotation.d(1, -1, 0, beta).doit() == sin(beta) / sqrt(2)
    assert Rotation.d(1, -1, -1, beta).doit() == (1 + cos(beta)) / 2
    # j = 3/2
    assert Rotation.d(
        S(3) / 2,
        S(3) / 2,
        S(3) / 2, beta).doit() == (3 * cos(beta / 2) + cos(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2,
        S(3) / 2,
        S(1) / 2,
        beta).doit() == sqrt(3) * (-sin(beta / 2) - sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2,
        S(3) / 2, -S(1) / 2,
        beta).doit() == sqrt(3) * (cos(beta / 2) - cos(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2,
        S(3) / 2, -S(3) / 2,
        beta).doit() == (-3 * sin(beta / 2) + sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2,
        S(1) / 2,
        S(3) / 2,
        beta).doit() == sqrt(3) * (sin(beta / 2) + sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2,
        S(1) / 2,
        S(1) / 2, beta).doit() == (cos(beta / 2) + 3 * cos(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2,
        S(1) / 2, -S(1) / 2,
        beta).doit() == (sin(beta / 2) - 3 * sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2,
        S(1) / 2, -S(3) / 2,
        beta).doit() == sqrt(3) * (cos(beta / 2) - cos(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(1) / 2,
        S(3) / 2,
        beta).doit() == sqrt(3) * (cos(beta / 2) - cos(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(1) / 2,
        S(1) / 2, beta).doit() == (-sin(beta / 2) + 3 * sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(1) / 2, -S(1) / 2,
        beta).doit() == (cos(beta / 2) + 3 * cos(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(1) / 2, -S(3) / 2,
        beta).doit() == sqrt(3) * (-sin(beta / 2) - sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(3) / 2,
        S(3) / 2, beta).doit() == (3 * sin(beta / 2) - sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(3) / 2,
        S(1) / 2,
        beta).doit() == sqrt(3) * (cos(beta / 2) - cos(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(3) / 2, -S(1) / 2,
        beta).doit() == sqrt(3) * (sin(beta / 2) + sin(3 * beta / 2)) / 4
    assert Rotation.d(
        S(3) / 2, -S(3) / 2, -S(3) / 2,
        beta).doit() == (3 * cos(beta / 2) + cos(3 * beta / 2)) / 4
    # j = 2
    assert Rotation.d(2, 2, 2,
                      beta).doit() == (3 + 4 * cos(beta) + cos(2 * beta)) / 8
    assert Rotation.d(2, 2, 1,
                      beta).doit() == (-2 * sin(beta) - sin(2 * beta)) / 4
    assert Rotation.d(2, 2, 0,
                      beta).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8
    assert Rotation.d(2, 2, -1,
                      beta).doit() == (-2 * sin(beta) + sin(2 * beta)) / 4
    assert Rotation.d(2, 2, -2,
                      beta).doit() == (3 - 4 * cos(beta) + cos(2 * beta)) / 8
    assert Rotation.d(2, 1, 2,
                      beta).doit() == (2 * sin(beta) + sin(2 * beta)) / 4
    assert Rotation.d(2, 1, 1, beta).doit() == (cos(beta) + cos(2 * beta)) / 2
    assert Rotation.d(2, 1, 0, beta).doit() == -sqrt(6) * sin(2 * beta) / 4
    assert Rotation.d(2, 1, -1, beta).doit() == (cos(beta) - cos(2 * beta)) / 2
    assert Rotation.d(2, 1, -2,
                      beta).doit() == (-2 * sin(beta) + sin(2 * beta)) / 4
    assert Rotation.d(2, 0, 2,
                      beta).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8
    assert Rotation.d(2, 0, 1, beta).doit() == sqrt(6) * sin(2 * beta) / 4
    assert Rotation.d(2, 0, 0, beta).doit() == (1 + 3 * cos(2 * beta)) / 4
    assert Rotation.d(2, 0, -1, beta).doit() == -sqrt(6) * sin(2 * beta) / 4
    assert Rotation.d(2, 0, -2,
                      beta).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8
    assert Rotation.d(2, -1, 2,
                      beta).doit() == (2 * sin(beta) - sin(2 * beta)) / 4
    assert Rotation.d(2, -1, 1, beta).doit() == (cos(beta) - cos(2 * beta)) / 2
    assert Rotation.d(2, -1, 0, beta).doit() == sqrt(6) * sin(2 * beta) / 4
    assert Rotation.d(2, -1, -1,
                      beta).doit() == (cos(beta) + cos(2 * beta)) / 2
    assert Rotation.d(2, -1, -2,
                      beta).doit() == (-2 * sin(beta) - sin(2 * beta)) / 4
    assert Rotation.d(2, -2, 2,
                      beta).doit() == (3 - 4 * cos(beta) + cos(2 * beta)) / 8
    assert Rotation.d(2, -2, 1,
                      beta).doit() == (2 * sin(beta) - sin(2 * beta)) / 4
    assert Rotation.d(2, -2, 0,
                      beta).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8
    assert Rotation.d(2, -2, -1,
                      beta).doit() == (2 * sin(beta) + sin(2 * beta)) / 4
    assert Rotation.d(2, -2, -2,
                      beta).doit() == (3 + 4 * cos(beta) + cos(2 * beta)) / 8
    # Numerical tests
    # j = 1/2
    assert Rotation.d(S(1) / 2,
                      S(1) / 2,
                      S(1) / 2, pi / 2).doit() == sqrt(2) / 2
    assert Rotation.d(S(1) / 2,
                      S(1) / 2, -S(1) / 2, pi / 2).doit() == -sqrt(2) / 2
    assert Rotation.d(S(1) / 2, -S(1) / 2,
                      S(1) / 2, pi / 2).doit() == sqrt(2) / 2
    assert Rotation.d(S(1) / 2, -S(1) / 2, -S(1) / 2,
                      pi / 2).doit() == sqrt(2) / 2
    # j = 1
    assert Rotation.d(1, 1, 1, pi / 2).doit() == 1 / 2
    assert Rotation.d(1, 1, 0, pi / 2).doit() == -sqrt(2) / 2
    assert Rotation.d(1, 1, -1, pi / 2).doit() == 1 / 2
    assert Rotation.d(1, 0, 1, pi / 2).doit() == sqrt(2) / 2
    assert Rotation.d(1, 0, 0, pi / 2).doit() == 0
    assert Rotation.d(1, 0, -1, pi / 2).doit() == -sqrt(2) / 2
    assert Rotation.d(1, -1, 1, pi / 2).doit() == 1 / 2
    assert Rotation.d(1, -1, 0, pi / 2).doit() == sqrt(2) / 2
    assert Rotation.d(1, -1, -1, pi / 2).doit() == 1 / 2
    # j = 3/2
    assert Rotation.d(S(3) / 2,
                      S(3) / 2,
                      S(3) / 2, pi / 2).doit() == sqrt(2) / 4
    assert Rotation.d(S(3) / 2,
                      S(3) / 2,
                      S(1) / 2, pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.d(S(3) / 2,
                      S(3) / 2, -S(1) / 2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(S(3) / 2,
                      S(3) / 2, -S(3) / 2, pi / 2).doit() == -sqrt(2) / 4
    assert Rotation.d(S(3) / 2,
                      S(1) / 2,
                      S(3) / 2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(S(3) / 2,
                      S(1) / 2,
                      S(1) / 2, pi / 2).doit() == -sqrt(2) / 4
    assert Rotation.d(S(3) / 2,
                      S(1) / 2, -S(1) / 2, pi / 2).doit() == -sqrt(2) / 4
    assert Rotation.d(S(3) / 2,
                      S(1) / 2, -S(3) / 2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(S(3) / 2, -S(1) / 2,
                      S(3) / 2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(S(3) / 2, -S(1) / 2,
                      S(1) / 2, pi / 2).doit() == sqrt(2) / 4
    assert Rotation.d(S(3) / 2, -S(1) / 2, -S(1) / 2,
                      pi / 2).doit() == -sqrt(2) / 4
    assert Rotation.d(S(3) / 2, -S(1) / 2, -S(3) / 2,
                      pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.d(S(3) / 2, -S(3) / 2,
                      S(3) / 2, pi / 2).doit() == sqrt(2) / 4
    assert Rotation.d(S(3) / 2, -S(3) / 2,
                      S(1) / 2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(S(3) / 2, -S(3) / 2, -S(1) / 2,
                      pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(S(3) / 2, -S(3) / 2, -S(3) / 2,
                      pi / 2).doit() == sqrt(2) / 4
    # j = 2
    assert Rotation.d(2, 2, 2, pi / 2).doit() == 1 / 4
    assert Rotation.d(2, 2, 1, pi / 2).doit() == -1 / 2
    assert Rotation.d(2, 2, 0, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(2, 2, -1, pi / 2).doit() == -1 / 2
    assert Rotation.d(2, 2, -2, pi / 2).doit() == 1 / 4
    assert Rotation.d(2, 1, 2, pi / 2).doit() == 1 / 2
    assert Rotation.d(2, 1, 1, pi / 2).doit() == -1 / 2
    assert Rotation.d(2, 1, 0, pi / 2).doit() == 0
    assert Rotation.d(2, 1, -1, pi / 2).doit() == 1 / 2
    assert Rotation.d(2, 1, -2, pi / 2).doit() == -1 / 2
    assert Rotation.d(2, 0, 2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(2, 0, 1, pi / 2).doit() == 0
    assert Rotation.d(2, 0, 0, pi / 2).doit() == -1 / 2
    assert Rotation.d(2, 0, -1, pi / 2).doit() == 0
    assert Rotation.d(2, 0, -2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(2, -1, 2, pi / 2).doit() == 1 / 2
    assert Rotation.d(2, -1, 1, pi / 2).doit() == 1 / 2
    assert Rotation.d(2, -1, 0, pi / 2).doit() == 0
    assert Rotation.d(2, -1, -1, pi / 2).doit() == -1 / 2
    assert Rotation.d(2, -1, -2, pi / 2).doit() == -1 / 2
    assert Rotation.d(2, -2, 2, pi / 2).doit() == 1 / 4
    assert Rotation.d(2, -2, 1, pi / 2).doit() == 1 / 2
    assert Rotation.d(2, -2, 0, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.d(2, -2, -1, pi / 2).doit() == 1 / 2
    assert Rotation.d(2, -2, -2, pi / 2).doit() == 1 / 4
Ejemplo n.º 12
0
def test_rotation():
    assert Rotation.d(1, 1, 1, 0) == 1
Ejemplo n.º 13
0
def reference(l, m, k, x):
  return complex(N(Rotation.d(l, m, k, x).doit()))
Ejemplo n.º 14
0
#     y = [0, h, 0]

#     p = np.arange(int(x[1] - x[0]))
#     spec = np.arange(n_points)
#     y[int(x[0]):int(x[0]) + p] = y[0] + (y[1] - y[0]) / (x[1] - x[0]) * (p - x[0])


if __name__ == "__main__":
    value = []
    l = 2
    cos_beta = [-0.5498, 0.230]
    for k, cos_b in enumerate(cos_beta):
        for i in range(2 * l + 1):
            for j in range(2 * l + 1):
                value.append(
                    complex(Rotation.d(l, -l + j, -l + i, np.arccos(cos_b)).doit()).real
                )
    value = np.asarray(value)
    np.save("tests/wigner/l=2_cx=[-0.5498, 0.230]", value)

    value = []
    l = 2
    cos_beta = 0.5
    for i in range(2 * l + 1):
        for j in range(2 * l + 1):
            value.append(
                complex(Rotation.d(l, -l + j, -l + i, np.arccos(cos_beta)).doit()).real
            )
    value = np.asarray(value)
    np.save("tests/wigner/l=2_cx=0.5", value)
Ejemplo n.º 15
0
            val += tmp
    val = f1234 * val
    return val


if __name__ == '__main__':

    from sympy.physics.quantum.spin import Rotation

    s = 1
    mp = 1
    ms = 1
    beta = 1.0
    print '\ntest-1'
    print 'd1,1,1=', 0.5 * (1 + math.cos(beta))
    print 'sympy =', Rotation.d(s, mp, ms, beta).doit()
    print 'myval =', value(s, mp, ms, beta)

    s = 2
    mp = 2
    ms = -1
    beta = 1.0
    print '\ntest-2'
    print 'd2,2,-1=', -0.5 * math.sin(beta) * (1 - math.cos(beta))
    print 'sympy  =', Rotation.d(s, mp, ms, beta).doit()
    print 'myval  =', value(s, mp, ms, beta)

    s = 0.5
    mp = 0.5
    ms = 0.5
    betalst = [1.0, numpy.pi]
Ejemplo n.º 16
0
def test_wignerd():
    j, m, mp, alpha, beta, gamma = symbols('j m mp alpha beta gamma')
    assert Rotation.D(j, m, mp, alpha, beta, gamma) == WignerD(j, m, mp, alpha, beta, gamma)
    assert Rotation.d(j, m, mp, beta) == WignerD(j, m, mp, 0, beta, 0)
Ejemplo n.º 17
0
def test_rotation_small_d():
    # Symbolic tests
    beta = symbols('beta')
    # j = 1/2
    assert Rotation.d(S(1)/2,S(1)/2,S(1)/2,beta).doit() == cos(beta/2)
    assert Rotation.d(S(1)/2,S(1)/2,-S(1)/2,beta).doit() == -sin(beta/2)
    assert Rotation.d(S(1)/2,-S(1)/2,S(1)/2,beta).doit() == sin(beta/2)
    assert Rotation.d(S(1)/2,-S(1)/2,-S(1)/2,beta).doit() == cos(beta/2)
    # j = 1
    assert Rotation.d(1,1,1,beta).doit() == (1+cos(beta))/2
    assert Rotation.d(1,1,0,beta).doit() == -sin(beta)/sqrt(2)
    assert Rotation.d(1,1,-1,beta).doit() == (1-cos(beta))/2
    assert Rotation.d(1,0,1,beta).doit() == sin(beta)/sqrt(2)
    assert Rotation.d(1,0,0,beta).doit() == cos(beta)
    assert Rotation.d(1,0,-1,beta).doit() == -sin(beta)/sqrt(2)
    assert Rotation.d(1,-1,1,beta).doit() == (1-cos(beta))/2
    assert Rotation.d(1,-1,0,beta).doit() == sin(beta)/sqrt(2)
    assert Rotation.d(1,-1,-1,beta).doit() == (1+cos(beta))/2
    # j = 3/2
    assert Rotation.d(S(3)/2,S(3)/2,S(3)/2,beta).doit() == (3*cos(beta/2)+cos(3*beta/2))/4
    assert Rotation.d(S(3)/2,S(3)/2,S(1)/2,beta).doit() == sqrt(3)*(-sin(beta/2)-sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,S(3)/2,-S(1)/2,beta).doit() == sqrt(3)*(cos(beta/2)-cos(3*beta/2))/4
    assert Rotation.d(S(3)/2,S(3)/2,-S(3)/2,beta).doit() == (-3*sin(beta/2)+sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,S(1)/2,S(3)/2,beta).doit() == sqrt(3)*(sin(beta/2)+sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,S(1)/2,S(1)/2,beta).doit() == (cos(beta/2)+3*cos(3*beta/2))/4
    assert Rotation.d(S(3)/2,S(1)/2,-S(1)/2,beta).doit() == (sin(beta/2)-3*sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,S(1)/2,-S(3)/2,beta).doit() == sqrt(3)*(cos(beta/2)-cos(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(1)/2,S(3)/2,beta).doit() == sqrt(3)*(cos(beta/2)-cos(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(1)/2,S(1)/2,beta).doit() == (-sin(beta/2)+3*sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(1)/2,-S(1)/2,beta).doit() == (cos(beta/2)+3*cos(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(1)/2,-S(3)/2,beta).doit() == sqrt(3)*(-sin(beta/2)-sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(3)/2,S(3)/2,beta).doit() == (3*sin(beta/2)-sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(3)/2,S(1)/2,beta).doit() == sqrt(3)*(cos(beta/2)-cos(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(3)/2,-S(1)/2,beta).doit() == sqrt(3)*(sin(beta/2)+sin(3*beta/2))/4
    assert Rotation.d(S(3)/2,-S(3)/2,-S(3)/2,beta).doit() == (3*cos(beta/2)+cos(3*beta/2))/4
    # j = 2
    assert Rotation.d(2,2,2,beta).doit() == (3+4*cos(beta)+cos(2*beta))/8
    assert Rotation.d(2,2,1,beta).doit() == (-2*sin(beta)-sin(2*beta))/4
    assert Rotation.d(2,2,0,beta).doit() == sqrt(6)*(1-cos(2*beta))/8
    assert Rotation.d(2,2,-1,beta).doit() == (-2*sin(beta)+sin(2*beta))/4
    assert Rotation.d(2,2,-2,beta).doit() == (3-4*cos(beta)+cos(2*beta))/8
    assert Rotation.d(2,1,2,beta).doit() == (2*sin(beta)+sin(2*beta))/4
    assert Rotation.d(2,1,1,beta).doit() == (cos(beta)+cos(2*beta))/2
    assert Rotation.d(2,1,0,beta).doit() == -sqrt(6)*sin(2*beta)/4
    assert Rotation.d(2,1,-1,beta).doit() == (cos(beta)-cos(2*beta))/2
    assert Rotation.d(2,1,-2,beta).doit() == (-2*sin(beta)+sin(2*beta))/4
    assert Rotation.d(2,0,2,beta).doit() == sqrt(6)*(1-cos(2*beta))/8
    assert Rotation.d(2,0,1,beta).doit() == sqrt(6)*sin(2*beta)/4
    assert Rotation.d(2,0,0,beta).doit() == (1+3*cos(2*beta))/4
    assert Rotation.d(2,0,-1,beta).doit() == -sqrt(6)*sin(2*beta)/4
    assert Rotation.d(2,0,-2,beta).doit() == sqrt(6)*(1-cos(2*beta))/8
    assert Rotation.d(2,-1,2,beta).doit() == (2*sin(beta)-sin(2*beta))/4
    assert Rotation.d(2,-1,1,beta).doit() == (cos(beta)-cos(2*beta))/2
    assert Rotation.d(2,-1,0,beta).doit() == sqrt(6)*sin(2*beta)/4
    assert Rotation.d(2,-1,-1,beta).doit() == (cos(beta)+cos(2*beta))/2
    assert Rotation.d(2,-1,-2,beta).doit() == (-2*sin(beta)-sin(2*beta))/4
    assert Rotation.d(2,-2,2,beta).doit() == (3-4*cos(beta)+cos(2*beta))/8
    assert Rotation.d(2,-2,1,beta).doit() == (2*sin(beta)-sin(2*beta))/4
    assert Rotation.d(2,-2,0,beta).doit() == sqrt(6)*(1-cos(2*beta))/8
    assert Rotation.d(2,-2,-1,beta).doit() == (2*sin(beta)+sin(2*beta))/4
    assert Rotation.d(2,-2,-2,beta).doit() == (3+4*cos(beta)+cos(2*beta))/8
    # Numerical tests
    # j = 1/2
    assert Rotation.d(S(1)/2,S(1)/2,S(1)/2,pi/2).doit() == sqrt(2)/2
    assert Rotation.d(S(1)/2,S(1)/2,-S(1)/2,pi/2).doit() == -sqrt(2)/2
    assert Rotation.d(S(1)/2,-S(1)/2,S(1)/2,pi/2).doit() == sqrt(2)/2
    assert Rotation.d(S(1)/2,-S(1)/2,-S(1)/2,pi/2).doit() == sqrt(2)/2
    # j = 1
    assert Rotation.d(1,1,1,pi/2).doit() == 1/2
    assert Rotation.d(1,1,0,pi/2).doit() == -sqrt(2)/2
    assert Rotation.d(1,1,-1,pi/2).doit() == 1/2
    assert Rotation.d(1,0,1,pi/2).doit() == sqrt(2)/2
    assert Rotation.d(1,0,0,pi/2).doit() == 0
    assert Rotation.d(1,0,-1,pi/2).doit() == -sqrt(2)/2
    assert Rotation.d(1,-1,1,pi/2).doit() == 1/2
    assert Rotation.d(1,-1,0,pi/2).doit() == sqrt(2)/2
    assert Rotation.d(1,-1,-1,pi/2).doit() == 1/2
    # j = 3/2
    assert Rotation.d(S(3)/2,S(3)/2,S(3)/2,pi/2).doit() == sqrt(2)/4
    assert Rotation.d(S(3)/2,S(3)/2,S(1)/2,pi/2).doit() == -sqrt(6)/4
    assert Rotation.d(S(3)/2,S(3)/2,-S(1)/2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(S(3)/2,S(3)/2,-S(3)/2,pi/2).doit() == -sqrt(2)/4
    assert Rotation.d(S(3)/2,S(1)/2,S(3)/2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(S(3)/2,S(1)/2,S(1)/2,pi/2).doit() == -sqrt(2)/4
    assert Rotation.d(S(3)/2,S(1)/2,-S(1)/2,pi/2).doit() == -sqrt(2)/4
    assert Rotation.d(S(3)/2,S(1)/2,-S(3)/2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(S(3)/2,-S(1)/2,S(3)/2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(S(3)/2,-S(1)/2,S(1)/2,pi/2).doit() == sqrt(2)/4
    assert Rotation.d(S(3)/2,-S(1)/2,-S(1)/2,pi/2).doit() == -sqrt(2)/4
    assert Rotation.d(S(3)/2,-S(1)/2,-S(3)/2,pi/2).doit() == -sqrt(6)/4
    assert Rotation.d(S(3)/2,-S(3)/2,S(3)/2,pi/2).doit() == sqrt(2)/4
    assert Rotation.d(S(3)/2,-S(3)/2,S(1)/2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(S(3)/2,-S(3)/2,-S(1)/2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(S(3)/2,-S(3)/2,-S(3)/2,pi/2).doit() == sqrt(2)/4
    # j = 2
    assert Rotation.d(2,2,2,pi/2).doit() == 1/4
    assert Rotation.d(2,2,1,pi/2).doit() == -1/2
    assert Rotation.d(2,2,0,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(2,2,-1,pi/2).doit() == -1/2
    assert Rotation.d(2,2,-2,pi/2).doit() == 1/4
    assert Rotation.d(2,1,2,pi/2).doit() == 1/2
    assert Rotation.d(2,1,1,pi/2).doit() == -1/2
    assert Rotation.d(2,1,0,pi/2).doit() == 0
    assert Rotation.d(2,1,-1,pi/2).doit() == 1/2
    assert Rotation.d(2,1,-2,pi/2).doit() == -1/2
    assert Rotation.d(2,0,2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(2,0,1,pi/2).doit() == 0
    assert Rotation.d(2,0,0,pi/2).doit() == -1/2
    assert Rotation.d(2,0,-1,pi/2).doit() == 0
    assert Rotation.d(2,0,-2,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(2,-1,2,pi/2).doit() == 1/2
    assert Rotation.d(2,-1,1,pi/2).doit() == 1/2
    assert Rotation.d(2,-1,0,pi/2).doit() == 0
    assert Rotation.d(2,-1,-1,pi/2).doit() == -1/2
    assert Rotation.d(2,-1,-2,pi/2).doit() == -1/2
    assert Rotation.d(2,-2,2,pi/2).doit() == 1/4
    assert Rotation.d(2,-2,1,pi/2).doit() == 1/2
    assert Rotation.d(2,-2,0,pi/2).doit() == sqrt(6)/4
    assert Rotation.d(2,-2,-1,pi/2).doit() == 1/2
    assert Rotation.d(2,-2,-2,pi/2).doit() == 1/4
Ejemplo n.º 18
0
def wigner_dm0_vector_sympy(l, angle):
    R_out = np.empty(2 * l + 1, dtype=np.float64)
    for i in range(2 * l + 1):
        R_out[i] = complex(Rotation.d(l, -l + i, 0, angle).doit()).real
    return R_out
Ejemplo n.º 19
0
 def T(l, m, M, alpha, beta):
     W1 = Rotation.d(l, np.absolute(m), M, beta).doit()
     W2 = Rotation.d(l, np.absolute(m), -M, beta).doit()
     return B(m, alpha) * ((-1)**M * W1 - W2)
Ejemplo n.º 20
0
 def S(l, m, M, alpha, beta):
     W1 = Rotation.d(l, np.absolute(m), M, beta).doit()
     W2 = Rotation.d(l, np.absolute(m), -M, beta).doit()
     return A(m, alpha) * (((-1)**M) * W1 + W2)