Ejemplo n.º 1
0
def get_wigner_dmat(quant_2j, alpha, beta, gamma):
    """
    Given quantum number and Euler angles, return the Wigner-D matrix.

    Parameters
    ----------
    quant_2j: int
        Twice of the quantum number j: 2j, for example, quant_2j=1 means j=1/2,
        quant_2j=2 means j=1
    alpha: float number
        The first Euler angle :math:`\\alpha` in radian [0, :math:`2\\pi`].
    beta: float number
        The second Euler angle :math:`\\beta` in radian [0, :math:`\\pi`].
    gamma: float number
        The third Euler angle :math:`\\gamma` in radian [0, :math:`2\\pi`].

    Returns
    -------
    result: 2d complex array, shape(quant_2j+1, quant_2j+1)
        The Wigner D-matrix.
        For :math:`j=1/2`, the orbital order is: +1/2 (spin up), -1/2 (spin down).
        For :math:`j>1/2`, the orbital order is: :math:`-j, -j+1, ..., +j`

    Examples
    --------
    >>> import edrixs
    spin-1/2 D-matrix
    >>> edrixs.get_wigner_dmat(1, 1, 2, 3)
    array([[-0.224845-0.491295j, -0.454649-0.708073j],
           [ 0.454649-0.708073j, -0.224845+0.491295j]])
    j=1 D-matrix
    >>> edrixs.get_wigner_dmat(2, 1, 2, 3)
    array([[-0.190816-0.220931j,  0.347398+0.541041j, -0.294663-0.643849j],
           [ 0.636536-0.090736j, -0.416147+0.j      , -0.636536-0.090736j],
           [-0.294663+0.643849j, -0.347398+0.541041j, -0.190816+0.220931j]])
    """

    from sympy.physics.quantum.spin import Rotation
    from sympy import N, S
    ndim = quant_2j + 1
    result = np.zeros((ndim, ndim), dtype=np.complex)
    # For j=1/2, we use different orbital order: first +1/2, then -1/2
    if quant_2j == 1:
        for i, mi in enumerate(range(quant_2j, -quant_2j-1, -2)):
            for j, mj in enumerate(range(quant_2j, -quant_2j-1, -2)):
                rot = Rotation.D(S(quant_2j)/2, S(mi)/2, S(mj)/2, alpha, beta, gamma)
                result[i, j] = N(rot.doit())
    # For j > 1/2, the order is -j, -j+1, ..., +j
    else:
        for i, mi in enumerate(range(-quant_2j, quant_2j+1, 2)):
            for j, mj in enumerate(range(-quant_2j, quant_2j+1, 2)):
                rot = Rotation.D(S(quant_2j)/2, S(mi)/2, S(mj)/2, alpha, beta, gamma)
                result[i, j] = N(rot.doit())

    return result
Ejemplo n.º 2
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.º 3
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
Ejemplo n.º 4
0
def get_steering_matrix(degreeMax, ksize, M):
    '''
    Returns a tensor of a block diagonal matrix Sr for the M orientations: i.e. a matrix of weights of shape ((degreeMax+1)**2,(degreeMax+1)**2) for each orientation.
    The output Sr has shape (M,(degreeMax+1)**2,(degreeMax+1)**2)).
    (degreeMax+1)**2 is the total number of Ynm, it comes from the sum_n(2n+1)
    degreeMax: maximal SH degree
    ksize: kernel size
    M: number of orientations
    '''
    radius = (ksize - 1) / 2
    radiusAug = int(np.ceil((radius - 1) * np.sqrt(3)) + 1)
    ksizeAug = radiusAug * 2 + 1
    # define search space for angles.
    zyz = get_euler_angles(M)
    _, theta, phi = getSphCoordArrays(ksize)

    Sr = np.zeros((M, (degreeMax + 1)**2, (degreeMax + 1)**2),
                  dtype=np.complex64)
    # scan through angles
    for a in range(zyz.shape[0]):
        alpha, beta, gamma = zyz[a] * pi / 180
        # Import Wigner D matrix directly from simpy
        for n in range(degreeMax + 1):
            for k1 in range(n * 2 + 1):
                m1 = k1 - n
                for k2 in range(n * 2 + 1):
                    m2 = k2 - n
                    Sr[a, n**2 + k1, n**2 + k2] = np.complex(
                        Rotation.D(n, m1, m2, alpha, beta, gamma).doit())

    return tf.constant(Sr)
Ejemplo n.º 5
0
def wignerRotation(V1, l, powerSpec):
    z1 = V1[0]
    t1 = V1[1]
    p1 = V1[2]

    Vr1 = np.array([-tf.ZtoN(z1), t1, p1])

    elDm1 = lambda m1, m2: Rotation.D(2, m2, m1, -t1, p1, 0).doit()
    #elDm2 = lambda m1,m2: Rotation.D(2,m2,m1,-t2,p2,0).doit()

    #corelation = np.zeros((5,5)).astype(complex)

    var = aBarCor(Vr1, l, powerSpec,
                  V1[0])  #var is the <aBar2m1 aBar*2m2> matrix

    MatDm1 = np.zeros((5, 5)).astype(complex)  #The wigner matrix
    #MatDm2 = np.zeros((5,5)).astype(complex)

    for i in range(-2, 3):
        for j in range(-2, 3):
            MatDm1[i + 2][j + 2] = elDm1(i, j)
            #MatDm2[i+2][j+2] = np.conjugate(elDm2(i,j))

    #print("var:\n", var, "\n MatDm1: \n", MatDm1,"\n MatDm2: \n", MatDm2)

    #corelation = np.linalg.multi_dot([MatDm1,var,np.transpose((MatDm2))])#matrix after rotation by the respective
    #wignerD matrices

    #print("Before rotation (A2m bar):\n:", var, "\n After Wigner rotation(A2m):\n", corelation)
    corelation = np.matmul(MatDm1, var)
    return corelation, var, MatDm1
Ejemplo n.º 6
0
def wignerRotation(V1, V2):
    z1 = V1[0]
    t1 = V1[1]
    p1 = V1[2]

    z2 = V2[0]
    t2 = V2[1]
    p2 = V2[2]

    Vr1 = np.array([-tf.ZtoN(z1), t1, p1])
    Vr2 = np.array([-tf.ZtoN(z2), t2, p2])

    elDm1 = lambda m1, m2: sp.N(Rotation.D(2, m2, m1, -p1, t1, 0).doit(
    ))  #using physics convention: phi is the azimuth (in x-y plane)
    elDm2 = lambda m1, m2: sp.N(Rotation.D(2, m2, m1, -p2, t2, 0).doit())

    delR = deltaR(Vr1, Vr2)

    Integrand = np.zeros(
        5)  #store the values of Ils to save computational time
    for i in range(0, len(Integrand), 2):
        Integrand[i] = I(i, delR, z1,
                         z2)  #toDo: pass in delR rather than Vr1 and Vr2;
        #same thing for aBarCor(Vr1 and Vr2 are only used in spherHarm)

    corelation = np.zeros((5, 5)).astype(complex)

    MatDm1 = np.zeros((5, 5)).astype(complex)  #The two wigner matrices
    MatDm2 = np.zeros((5, 5)).astype(complex)

    for i in range(-2, 3):
        for j in range(-2, 3):
            MatDm1[i + 2][j + 2] = elDm1(i, j)
            MatDm2[i + 2][j + 2] = np.conjugate(elDm2(i, j))
            #MatDm1[i+2][j+2] = np.conjugate(elDm1(i,j))
            #MatDm2[i+2][j+2] = elDm2(i,j)

    var = aBarCor(delR, Integrand)  #var is the <aBar2m1 aBar*2m2> matrix

    #print("var:\n", var, "\n MatDm1: \n", MatDm1,"\n MatDm2: \n", MatDm2)

    #corelation = np.linalg.multi_dot([np.transpose(MatDm1),var,(MatDm2)])
    corelation = np.linalg.multi_dot([(MatDm1), var, np.transpose(MatDm2)])

    #print("Before rotation (A2m bar):\n:", var, "\n After Wigner rotation(A2m):\n", corelation)

    return corelation, var, MatDm1, MatDm2
Ejemplo n.º 7
0
 def __prepare_WignerD_alpha0(self):
     s = sympy.S(self._q - 1) / 2
     theta, phi, c = sympy.symbols('theta phi c')
     Ds = sympy.Array([[
         Rotation.D(s, s - i, s - j, 0, -theta, -phi).doit()
         for j in range(self._q)
     ] for i in range(self._q)])
     # Ds = Ds.subs(theta,sympy.acos(c))
     self.__WignerD_alpha0 = sympy.lambdify((theta, phi), Ds, 'numpy')
Ejemplo n.º 8
0
def formulate_wigner_d(transition: StateTransition, node_id: int) -> sp.Expr:
    r"""Compute `~sympy.physics.quantum.spin.WignerD` for a transition node.

    Following :cite:`kutschkeAngularDistributionCookbook1996`, Eq. (10). For a
    two-body decay :math:`1 \to 2, 3`, we get

    .. math:: D^{s_1}_{m_1,\lambda_2-\lambda_3}(-\phi,\theta,0)
        :label: formulate_wigner_d

    with:

    - :math:`s_1` the `Spin.magnitude <qrules.particle.Spin.magnitude>` of the
      decaying state,
    - :math:`m_1` the `~qrules.transition.State.spin_projection` of the
      decaying state,
    - :math:`\lambda_{2}, \lambda_{3}` the helicities of the decay products in
      in the restframe of :math:`1` (can be taken to be their intrinsic
      `~qrules.transition.State.spin_projection` when following a constistent
      boosting procedure),
    - and :math:`\phi` and :math:`\theta` the helicity angles (see also
      :func:`.get_helicity_angle_label`).

    Note that :math:`\lambda_2, \lambda_3` are ordered by their number of
    children, then by their state ID (see :class:`.TwoBodyDecay`).

    See :cite:`kutschkeAngularDistributionCookbook1996`, Eq. (30) for an
    example of Wigner-:math:`D` functions in a *sequential* two-body decay.

    Example
    -------
    >>> import qrules
    >>> reaction = qrules.generate_transitions(
    ...     initial_state=[("J/psi(1S)", [+1])],
    ...     final_state=[("gamma", [-1]), "f(0)(980)"],
    ... )
    >>> transition = reaction.transitions[0]
    >>> formulate_wigner_d(transition, node_id=0)
    WignerD(1, 1, -1, -phi_0, theta_0, 0)

    .. math::
        D^{s_1}_{m_1,\lambda_2-\lambda_3}\left(-\phi,\theta,0\right)
        = D^{1}_{+1,(-1-0)}\left(-\phi_0,\theta_0,0\right)
        = D^{1}_{1,-1}\left(-\phi_0,\theta_0,0\right)
    """
    from sympy.physics.quantum.spin import Rotation as Wigner

    decay = TwoBodyDecay.from_transition(transition, node_id)
    _, phi, theta = _generate_kinematic_variables(transition, node_id)
    return Wigner.D(
        j=sp.Rational(decay.parent.particle.spin),
        m=sp.Rational(decay.parent.spin_projection),
        mp=sp.Rational(decay.children[0].spin_projection -
                       decay.children[1].spin_projection),
        alpha=-phi,
        beta=theta,
        gamma=0,
    )
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()))
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
Ejemplo n.º 11
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
Ejemplo n.º 13
0
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.º 14
0
def WignerRotation(cluster, l, ps):

    z = cluster[0]
    t1 = cluster[1]
    p1 = cluster[2]

    elDm = lambda m1, m2: Rotation.D(l, m1, m2, -t1, p1, 0).doit()
    MatDm = np.zeros((2 * l + 1, 5)).astype(complex)

    for m2 in range(-2, 3):
        for m1 in range(-l, l + 1):
            MatDm[m1 + l][m2 + 2] = elDm(m1, m2)

    temp = CorMatrix(l, z, ps)
    corelation = np.linalg.multi_dot([MatDm, temp])

    return corelation
Ejemplo n.º 15
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.º 16
0
def wignerRotation(V1, l):
    z1 = V1[0]
    t1 = V1[1]
    p1 = V1[2]

    Vr1 = np.array([-tf.ZtoN(z1), t1, p1])

    elDm1 = lambda m1, m2: Rotation.D(2, m2, m1, -p1, t1, 0).doit()

    var = aBarCor(Vr1, l, V1[0])  #var is the <aBar2m1 aBar*2m2> matrix

    MatDm1 = np.zeros((5, 5)).astype(complex)  #The wigner matrix

    for i in range(-2, 3):
        for j in range(-2, 3):
            MatDm1[i + 2][j + 2] = elDm1(i, j)

    corelation = np.matmul(MatDm1, var)
    return corelation, var, MatDm1
Ejemplo n.º 17
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.º 18
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.º 19
0
def test_sympy__physics__quantum__spin__Rotation():
    from sympy.physics.quantum.spin import Rotation
    from sympy import pi
    assert _test_args(Rotation(pi, 0, pi / 2))
Ejemplo n.º 20
0
def test_rotation():
    assert Rotation.d(1, 1, 1, 0) == 1
Ejemplo n.º 21
0
def test_spin():
    lz = JzOp("L")
    ket = JzKet(1, 0)
    bra = JzBra(1, 0)
    cket = JzKetCoupled(1, 0, (1, 2))
    cbra = JzBraCoupled(1, 0, (1, 2))
    cket_big = JzKetCoupled(1, 0, (1, 2, 3))
    cbra_big = JzBraCoupled(1, 0, (1, 2, 3))
    rot = Rotation(1, 2, 3)
    bigd = WignerD(1, 2, 3, 4, 5, 6)
    smalld = WignerD(1, 2, 3, 0, 4, 0)
    assert str(lz) == "Lz"
    ascii_str = """\
L \n\
 z\
"""
    ucode_str = u("""\
L \n\
 z\
""")
    assert pretty(lz) == ascii_str
    assert upretty(lz) == ucode_str
    assert latex(lz) == "L_z"
    sT(lz, "JzOp(Symbol('L'))")
    assert str(J2) == "J2"
    ascii_str = """\
 2\n\
J \
"""
    ucode_str = u("""\
 2\n\
J \
""")
    assert pretty(J2) == ascii_str
    assert upretty(J2) == ucode_str
    assert latex(J2) == r"J^2"
    sT(J2, "J2Op(Symbol('J'))")
    assert str(Jz) == "Jz"
    ascii_str = """\
J \n\
 z\
"""
    ucode_str = u("""\
J \n\
 z\
""")
    assert pretty(Jz) == ascii_str
    assert upretty(Jz) == ucode_str
    assert latex(Jz) == "J_z"
    sT(Jz, "JzOp(Symbol('J'))")
    assert str(ket) == "|1,0>"
    assert pretty(ket) == "|1,0>"
    assert upretty(ket) == u"❘1,0⟩"
    assert latex(ket) == r"{\left|1,0\right\rangle }"
    sT(ket, "JzKet(Integer(1),Integer(0))")
    assert str(bra) == "<1,0|"
    assert pretty(bra) == "<1,0|"
    assert upretty(bra) == u"⟨1,0❘"
    assert latex(bra) == r"{\left\langle 1,0\right|}"
    sT(bra, "JzBra(Integer(1),Integer(0))")
    assert str(cket) == "|1,0,j1=1,j2=2>"
    assert pretty(cket) == "|1,0,j1=1,j2=2>"
    assert upretty(cket) == u"❘1,0,j₁=1,j₂=2⟩"
    assert latex(cket) == r"{\left|1,0,j_{1}=1,j_{2}=2\right\rangle }"
    sT(
        cket,
        "JzKetCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2)),Tuple(Tuple(Integer(1), Integer(2), Integer(1))))",
    )
    assert str(cbra) == "<1,0,j1=1,j2=2|"
    assert pretty(cbra) == "<1,0,j1=1,j2=2|"
    assert upretty(cbra) == u"⟨1,0,j₁=1,j₂=2❘"
    assert latex(cbra) == r"{\left\langle 1,0,j_{1}=1,j_{2}=2\right|}"
    sT(
        cbra,
        "JzBraCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2)),Tuple(Tuple(Integer(1), Integer(2), Integer(1))))",
    )
    assert str(cket_big) == "|1,0,j1=1,j2=2,j3=3,j(1,2)=3>"
    # TODO: Fix non-unicode pretty printing
    # i.e. j1,2 -> j(1,2)
    assert pretty(cket_big) == "|1,0,j1=1,j2=2,j3=3,j1,2=3>"
    assert upretty(cket_big) == u"❘1,0,j₁=1,j₂=2,j₃=3,j₁,₂=3⟩"
    assert (latex(cket_big) ==
            r"{\left|1,0,j_{1}=1,j_{2}=2,j_{3}=3,j_{1,2}=3\right\rangle }")
    sT(
        cket_big,
        "JzKetCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2), Integer(3)),Tuple(Tuple(Integer(1), Integer(2), Integer(3)), Tuple(Integer(1), Integer(3), Integer(1))))",
    )
    assert str(cbra_big) == "<1,0,j1=1,j2=2,j3=3,j(1,2)=3|"
    assert pretty(cbra_big) == u"<1,0,j1=1,j2=2,j3=3,j1,2=3|"
    assert upretty(cbra_big) == u"⟨1,0,j₁=1,j₂=2,j₃=3,j₁,₂=3❘"
    assert (latex(cbra_big) ==
            r"{\left\langle 1,0,j_{1}=1,j_{2}=2,j_{3}=3,j_{1,2}=3\right|}")
    sT(
        cbra_big,
        "JzBraCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2), Integer(3)),Tuple(Tuple(Integer(1), Integer(2), Integer(3)), Tuple(Integer(1), Integer(3), Integer(1))))",
    )
    assert str(rot) == "R(1,2,3)"
    assert pretty(rot) == "R (1,2,3)"
    assert upretty(rot) == u"ℛ (1,2,3)"
    assert latex(rot) == r"\mathcal{R}\left(1,2,3\right)"
    sT(rot, "Rotation(Integer(1),Integer(2),Integer(3))")
    assert str(bigd) == "WignerD(1, 2, 3, 4, 5, 6)"
    ascii_str = """\
 1         \n\
D   (4,5,6)\n\
 2,3       \
"""
    ucode_str = u("""\
 1         \n\
D   (4,5,6)\n\
 2,3       \
""")
    assert pretty(bigd) == ascii_str
    assert upretty(bigd) == ucode_str
    assert latex(bigd) == r"D^{1}_{2,3}\left(4,5,6\right)"
    sT(
        bigd,
        "WignerD(Integer(1), Integer(2), Integer(3), Integer(4), Integer(5), Integer(6))",
    )
    assert str(smalld) == "WignerD(1, 2, 3, 0, 4, 0)"
    ascii_str = """\
 1     \n\
d   (4)\n\
 2,3   \
"""
    ucode_str = u("""\
 1     \n\
d   (4)\n\
 2,3   \
""")
    assert pretty(smalld) == ascii_str
    assert upretty(smalld) == ucode_str
    assert latex(smalld) == r"d^{1}_{2,3}\left(4\right)"
    sT(
        smalld,
        "WignerD(Integer(1), Integer(2), Integer(3), Integer(0), Integer(4), Integer(0))",
    )
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 28 09:39:23 2019

@author: Benjamin Smith
"""

from sympy.physics.quantum.spin import Rotation as r
import sympy as sp
import numpy as np

a, b, c = sp.symbols('a b c')

J = 1
Jmag = int(2 * J + 1)
alpha, beta, gamma = 0, -np.pi / 2, 0
mat = sp.zeros(Jmag, Jmag)
states = np.linspace(-J, J, Jmag, dtype=int)
for i in range(Jmag):
    for j in range(Jmag):
        mat[i, j] = sp.nsimplify(r.D(J, states[i], states[j], a, b, c).doit(),
                                 tolerance=1e-10,
                                 rational=True)

#rot_mat = mat * sp.Matrix([0, 1, 0])
print(mat)
Ejemplo n.º 23
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.º 24
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.º 25
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.º 26
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.º 27
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.º 28
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.º 29
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)
Ejemplo n.º 30
0
def test_rotation_d():
    # Symbolic tests
    alpha, beta, gamma = symbols('alpha beta gamma')
    # j = 1/2
    assert Rotation.D(S(1) / 2,
                      S(1) / 2,
                      S(1) / 2, alpha, beta, gamma).doit() == cos(
                          beta / 2) * exp(-I * alpha / 2) * exp(-I * gamma / 2)
    assert Rotation.D(S(1) / 2,
                      S(1) / 2, -S(1) / 2, alpha, beta,
                      gamma).doit() == -sin(beta / 2) * exp(
                          -I * alpha / 2) * exp(I * gamma / 2)
    assert Rotation.D(S(1) / 2, -S(1) / 2,
                      S(1) / 2, alpha, beta, gamma).doit() == sin(
                          beta / 2) * exp(I * alpha / 2) * exp(-I * gamma / 2)
    assert Rotation.D(S(1) / 2, -S(1) / 2, -S(1) / 2, alpha, beta,
                      gamma).doit() == cos(beta / 2) * exp(
                          I * alpha / 2) * exp(I * gamma / 2)
    # j = 1
    assert Rotation.D(1, 1, 1, alpha, beta,
                      gamma).doit() == (1 + cos(beta)) / 2 * exp(
                          -I * alpha) * exp(-I * gamma)
    assert Rotation.D(1, 1, 0, alpha, beta,
                      gamma).doit() == -sin(beta) / sqrt(2) * exp(-I * alpha)
    assert Rotation.D(
        1, 1, -1, alpha, beta,
        gamma).doit() == (1 - cos(beta)) / 2 * exp(-I * alpha) * exp(I * gamma)
    assert Rotation.D(1, 0, 1, alpha, beta,
                      gamma).doit() == sin(beta) / sqrt(2) * exp(-I * gamma)
    assert Rotation.D(1, 0, 0, alpha, beta, gamma).doit() == cos(beta)
    assert Rotation.D(1, 0, -1, alpha, beta,
                      gamma).doit() == -sin(beta) / sqrt(2) * exp(I * gamma)
    assert Rotation.D(
        1, -1, 1, alpha, beta,
        gamma).doit() == (1 - cos(beta)) / 2 * exp(I * alpha) * exp(-I * gamma)
    assert Rotation.D(1, -1, 0, alpha, beta,
                      gamma).doit() == sin(beta) / sqrt(2) * exp(I * alpha)
    assert Rotation.D(
        1, -1, -1, alpha, beta,
        gamma).doit() == (1 + cos(beta)) / 2 * exp(I * alpha) * exp(I * gamma)
    # j = 3/2
    assert Rotation.D(
        S(3) / 2,
        S(3) / 2,
        S(3) / 2, alpha, beta,
        gamma).doit() == (3 * cos(beta / 2) + cos(3 * beta / 2)) / 4 * exp(
            -3 * I * alpha / 2) * exp(-3 * I * gamma / 2)
    assert Rotation.D(
        S(3) / 2,
        S(3) / 2,
        S(1) / 2, alpha, beta,
        gamma).doit() == sqrt(3) * (-sin(beta / 2) - sin(
            3 * beta / 2)) / 4 * exp(-3 * I * alpha / 2) * exp(-I * gamma / 2)
    assert Rotation.D(
        S(3) / 2,
        S(3) / 2, -S(1) / 2, alpha, beta,
        gamma).doit() == sqrt(3) * (cos(beta / 2) - cos(
            3 * beta / 2)) / 4 * exp(-3 * I * alpha / 2) * exp(I * gamma / 2)
    assert Rotation.D(
        S(3) / 2,
        S(3) / 2, -S(3) / 2, alpha, beta,
        gamma).doit() == (-3 * sin(beta / 2) + sin(3 * beta / 2)) / 4 * exp(
            -3 * I * alpha / 2) * exp(3 * I * gamma / 2)
    assert Rotation.D(
        S(3) / 2,
        S(1) / 2,
        S(3) / 2, alpha, beta, gamma).doit() == sqrt(3) * (sin(beta / 2) + sin(
            3 * beta / 2)) / 4 * exp(-I * alpha / 2) * exp(-3 * I * gamma / 2)
    assert Rotation.D(
        S(3) / 2,
        S(1) / 2,
        S(1) / 2, alpha, beta,
        gamma).doit() == (cos(beta / 2) + 3 * cos(3 * beta / 2)) / 4 * exp(
            -I * alpha / 2) * exp(-I * gamma / 2)
    assert Rotation.D(
        S(3) / 2,
        S(1) / 2, -S(1) / 2, alpha, beta,
        gamma).doit() == (sin(beta / 2) - 3 * sin(3 * beta / 2)) / 4 * exp(
            -I * alpha / 2) * exp(I * gamma / 2)
    assert Rotation.D(
        S(3) / 2,
        S(1) / 2, -S(3) / 2, alpha, beta,
        gamma).doit() == sqrt(3) * (cos(beta / 2) - cos(
            3 * beta / 2)) / 4 * exp(-I * alpha / 2) * exp(3 * I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(1) / 2,
        S(3) / 2, alpha, beta, gamma).doit() == sqrt(3) * (cos(beta / 2) - cos(
            3 * beta / 2)) / 4 * exp(I * alpha / 2) * exp(-3 * I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(1) / 2,
        S(1) / 2, alpha, beta,
        gamma).doit() == (-sin(beta / 2) + 3 * sin(3 * beta / 2)) / 4 * exp(
            I * alpha / 2) * exp(-I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(1) / 2, -S(1) / 2, alpha, beta,
        gamma).doit() == (cos(beta / 2) + 3 * cos(3 * beta / 2)) / 4 * exp(
            I * alpha / 2) * exp(I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(1) / 2, -S(3) / 2, alpha, beta,
        gamma).doit() == sqrt(3) * (-sin(beta / 2) - sin(
            3 * beta / 2)) / 4 * exp(I * alpha / 2) * exp(3 * I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(3) / 2,
        S(3) / 2, alpha, beta,
        gamma).doit() == (3 * sin(beta / 2) - sin(3 * beta / 2)) / 4 * exp(
            3 * I * alpha / 2) * exp(-3 * I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(3) / 2,
        S(1) / 2, alpha, beta, gamma).doit() == sqrt(3) * (cos(beta / 2) - cos(
            3 * beta / 2)) / 4 * exp(3 * I * alpha / 2) * exp(-I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(3) / 2, -S(1) / 2, alpha, beta,
        gamma).doit() == sqrt(3) * (sin(beta / 2) + sin(
            3 * beta / 2)) / 4 * exp(3 * I * alpha / 2) * exp(I * gamma / 2)
    assert Rotation.D(
        S(3) / 2, -S(3) / 2, -S(3) / 2, alpha, beta,
        gamma).doit() == (3 * cos(beta / 2) + cos(3 * beta / 2)) / 4 * exp(
            3 * I * alpha / 2) * exp(3 * I * gamma / 2)
    # j = 2
    assert Rotation.D(
        2, 2, 2, alpha, beta,
        gamma).doit() == (3 + 4 * cos(beta) + cos(2 * beta)) / 8 * exp(
            -2 * I * alpha) * exp(-2 * I * gamma)
    assert Rotation.D(
        2, 2, 1, alpha, beta,
        gamma).doit() == (-2 * sin(beta) - sin(2 * beta)) / 4 * exp(
            -2 * I * alpha) * exp(-I * gamma)
    assert Rotation.D(2, 2, 0, alpha, beta,
                      gamma).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8 * exp(
                          -2 * I * alpha)
    assert Rotation.D(
        2, 2, -1, alpha, beta,
        gamma).doit() == (-2 * sin(beta) + sin(2 * beta)) / 4 * exp(
            -2 * I * alpha) * exp(I * gamma)
    assert Rotation.D(
        2, 2, -2, alpha, beta,
        gamma).doit() == (3 - 4 * cos(beta) + cos(2 * beta)) / 8 * exp(
            -2 * I * alpha) * exp(2 * I * gamma)
    assert Rotation.D(
        2, 1, 2, alpha, beta,
        gamma).doit() == (2 * sin(beta) + sin(2 * beta)) / 4 * exp(
            -I * alpha) * exp(-2 * I * gamma)
    assert Rotation.D(2, 1, 1, alpha, beta,
                      gamma).doit() == (cos(beta) + cos(2 * beta)) / 2 * exp(
                          -I * alpha) * exp(-I * gamma)
    assert Rotation.D(
        2, 1, 0, alpha, beta,
        gamma).doit() == -sqrt(6) * sin(2 * beta) / 4 * exp(-I * alpha)
    assert Rotation.D(2, 1, -1, alpha, beta,
                      gamma).doit() == (cos(beta) - cos(2 * beta)) / 2 * exp(
                          -I * alpha) * exp(I * gamma)
    assert Rotation.D(
        2, 1, -2, alpha, beta,
        gamma).doit() == (-2 * sin(beta) + sin(2 * beta)) / 4 * exp(
            -I * alpha) * exp(2 * I * gamma)
    assert Rotation.D(2, 0, 2, alpha, beta,
                      gamma).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8 * exp(
                          -2 * I * gamma)
    assert Rotation.D(
        2, 0, 1, alpha, beta,
        gamma).doit() == sqrt(6) * sin(2 * beta) / 4 * exp(-I * gamma)
    assert Rotation.D(2, 0, 0, alpha, beta,
                      gamma).doit() == (1 + 3 * cos(2 * beta)) / 4
    assert Rotation.D(
        2, 0, -1, alpha, beta,
        gamma).doit() == -sqrt(6) * sin(2 * beta) / 4 * exp(I * gamma)
    assert Rotation.D(
        2, 0, -2, alpha, beta,
        gamma).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8 * exp(2 * I * gamma)
    assert Rotation.D(
        2, -1, 2, alpha, beta,
        gamma).doit() == (2 * sin(beta) - sin(2 * beta)) / 4 * exp(
            I * alpha) * exp(-2 * I * gamma)
    assert Rotation.D(2, -1, 1, alpha, beta,
                      gamma).doit() == (cos(beta) - cos(2 * beta)) / 2 * exp(
                          I * alpha) * exp(-I * gamma)
    assert Rotation.D(
        2, -1, 0, alpha, beta,
        gamma).doit() == sqrt(6) * sin(2 * beta) / 4 * exp(I * alpha)
    assert Rotation.D(2, -1, -1, alpha, beta,
                      gamma).doit() == (cos(beta) + cos(2 * beta)) / 2 * exp(
                          I * alpha) * exp(I * gamma)
    assert Rotation.D(
        2, -1, -2, alpha, beta,
        gamma).doit() == (-2 * sin(beta) - sin(2 * beta)) / 4 * exp(
            I * alpha) * exp(2 * I * gamma)
    assert Rotation.D(
        2, -2, 2, alpha, beta,
        gamma).doit() == (3 - 4 * cos(beta) + cos(2 * beta)) / 8 * exp(
            2 * I * alpha) * exp(-2 * I * gamma)
    assert Rotation.D(
        2, -2, 1, alpha, beta,
        gamma).doit() == (2 * sin(beta) - sin(2 * beta)) / 4 * exp(
            2 * I * alpha) * exp(-I * gamma)
    assert Rotation.D(
        2, -2, 0, alpha, beta,
        gamma).doit() == sqrt(6) * (1 - cos(2 * beta)) / 8 * exp(2 * I * alpha)
    assert Rotation.D(
        2, -2, -1, alpha, beta,
        gamma).doit() == (2 * sin(beta) + sin(2 * beta)) / 4 * exp(
            2 * I * alpha) * exp(I * gamma)
    assert Rotation.D(
        2, -2, -2, alpha, beta,
        gamma).doit() == (3 + 4 * cos(beta) + cos(2 * beta)) / 8 * exp(
            2 * I * alpha) * exp(2 * I * gamma)
    # Numerical tests
    # j = 1/2
    assert Rotation.D(S(1) / 2,
                      S(1) / 2,
                      S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -I * sqrt(2) / 2
    assert Rotation.D(S(1) / 2,
                      S(1) / 2, -S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -sqrt(2) / 2
    assert Rotation.D(S(1) / 2, -S(1) / 2,
                      S(1) / 2, pi / 2, pi / 2, pi / 2).doit() == sqrt(2) / 2
    assert Rotation.D(S(1) / 2, -S(1) / 2, -S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == I * sqrt(2) / 2
    # j = 1
    assert Rotation.D(1, 1, 1, pi / 2, pi / 2, pi / 2).doit() == -1 / 2
    assert Rotation.D(1, 1, 0, pi / 2, pi / 2,
                      pi / 2).doit() == I * sqrt(2) / 2
    assert Rotation.D(1, 1, -1, pi / 2, pi / 2, pi / 2).doit() == 1 / 2
    assert Rotation.D(1, 0, 1, pi / 2, pi / 2,
                      pi / 2).doit() == -I * sqrt(2) / 2
    assert Rotation.D(1, 0, 0, pi / 2, pi / 2, pi / 2).doit() == 0
    assert Rotation.D(1, 0, -1, pi / 2, pi / 2,
                      pi / 2).doit() == -I * sqrt(2) / 2
    assert Rotation.D(1, -1, 1, pi / 2, pi / 2, pi / 2).doit() == 1 / 2
    assert Rotation.D(1, -1, 0, pi / 2, pi / 2,
                      pi / 2).doit() == I * sqrt(2) / 2
    assert Rotation.D(1, -1, -1, pi / 2, pi / 2, pi / 2).doit() == -1 / 2
    # j = 3/2
    assert Rotation.D(S(3) / 2,
                      S(3) / 2,
                      S(3) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == I * sqrt(2) / 4
    assert Rotation.D(S(3) / 2,
                      S(3) / 2,
                      S(1) / 2, pi / 2, pi / 2, pi / 2).doit() == sqrt(6) / 4
    assert Rotation.D(S(3) / 2,
                      S(3) / 2, -S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -I * sqrt(6) / 4
    assert Rotation.D(S(3) / 2,
                      S(3) / 2, -S(3) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -sqrt(2) / 4
    assert Rotation.D(S(3) / 2,
                      S(1) / 2,
                      S(3) / 2, pi / 2, pi / 2, pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.D(S(3) / 2,
                      S(1) / 2,
                      S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == I * sqrt(2) / 4
    assert Rotation.D(S(3) / 2,
                      S(1) / 2, -S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -sqrt(2) / 4
    assert Rotation.D(S(3) / 2,
                      S(1) / 2, -S(3) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == I * sqrt(6) / 4
    assert Rotation.D(S(3) / 2, -S(1) / 2,
                      S(3) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -I * sqrt(6) / 4
    assert Rotation.D(S(3) / 2, -S(1) / 2,
                      S(1) / 2, pi / 2, pi / 2, pi / 2).doit() == sqrt(2) / 4
    assert Rotation.D(S(3) / 2, -S(1) / 2, -S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -I * sqrt(2) / 4
    assert Rotation.D(S(3) / 2, -S(1) / 2, -S(3) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == sqrt(6) / 4
    assert Rotation.D(S(3) / 2, -S(3) / 2,
                      S(3) / 2, pi / 2, pi / 2, pi / 2).doit() == sqrt(2) / 4
    assert Rotation.D(S(3) / 2, -S(3) / 2,
                      S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == I * sqrt(6) / 4
    assert Rotation.D(S(3) / 2, -S(3) / 2, -S(1) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.D(S(3) / 2, -S(3) / 2, -S(3) / 2, pi / 2, pi / 2,
                      pi / 2).doit() == -I * sqrt(2) / 4
    # j = 2
    assert Rotation.D(2, 2, 2, pi / 2, pi / 2, pi / 2).doit() == 1 / 4
    assert Rotation.D(2, 2, 1, pi / 2, pi / 2, pi / 2).doit() == -I / 2
    assert Rotation.D(2, 2, 0, pi / 2, pi / 2, pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.D(2, 2, -1, pi / 2, pi / 2, pi / 2).doit() == I / 2
    assert Rotation.D(2, 2, -2, pi / 2, pi / 2, pi / 2).doit() == 1 / 4
    assert Rotation.D(2, 1, 2, pi / 2, pi / 2, pi / 2).doit() == I / 2
    assert Rotation.D(2, 1, 1, pi / 2, pi / 2, pi / 2).doit() == 1 / 2
    assert Rotation.D(2, 1, 0, pi / 2, pi / 2, pi / 2).doit() == 0
    assert Rotation.D(2, 1, -1, pi / 2, pi / 2, pi / 2).doit() == 1 / 2
    assert Rotation.D(2, 1, -2, pi / 2, pi / 2, pi / 2).doit() == -I / 2
    assert Rotation.D(2, 0, 2, pi / 2, pi / 2, pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.D(2, 0, 1, pi / 2, pi / 2, pi / 2).doit() == 0
    assert Rotation.D(2, 0, 0, pi / 2, pi / 2, pi / 2).doit() == -1 / 2
    assert Rotation.D(2, 0, -1, pi / 2, pi / 2, pi / 2).doit() == 0
    assert Rotation.D(2, 0, -2, pi / 2, pi / 2, pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.D(2, -1, 2, pi / 2, pi / 2, pi / 2).doit() == -I / 2
    assert Rotation.D(2, -1, 1, pi / 2, pi / 2, pi / 2).doit() == 1 / 2
    assert Rotation.D(2, -1, 0, pi / 2, pi / 2, pi / 2).doit() == 0
    assert Rotation.D(2, -1, -1, pi / 2, pi / 2, pi / 2).doit() == 1 / 2
    assert Rotation.D(2, -1, -2, pi / 2, pi / 2, pi / 2).doit() == I / 2
    assert Rotation.D(2, -2, 2, pi / 2, pi / 2, pi / 2).doit() == 1 / 4
    assert Rotation.D(2, -2, 1, pi / 2, pi / 2, pi / 2).doit() == I / 2
    assert Rotation.D(2, -2, 0, pi / 2, pi / 2, pi / 2).doit() == -sqrt(6) / 4
    assert Rotation.D(2, -2, -1, pi / 2, pi / 2, pi / 2).doit() == -I / 2
    assert Rotation.D(2, -2, -2, pi / 2, pi / 2, pi / 2).doit() == 1 / 4
Ejemplo n.º 31
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.º 32
0
def test_spin():
    lz = JzOp('L')
    ket = JzKet(1, 0)
    bra = JzBra(1, 0)
    cket = JzKetCoupled(1, 0, (1, 2))
    cbra = JzBraCoupled(1, 0, (1, 2))
    cket_big = JzKetCoupled(1, 0, (1, 2, 3))
    cbra_big = JzBraCoupled(1, 0, (1, 2, 3))
    rot = Rotation(1, 2, 3)
    bigd = WignerD(1, 2, 3, 4, 5, 6)
    smalld = WignerD(1, 2, 3, 0, 4, 0)
    assert str(lz) == 'Lz'
    ascii_str = \
"""\
L \n\
 z\
"""
    ucode_str = \
u"""\
L \n\
 z\
"""
    assert pretty(lz) == ascii_str
    assert upretty(lz) == ucode_str
    assert latex(lz) == 'L_z'
    sT(lz, "JzOp(Symbol('L'))")
    assert str(J2) == 'J2'
    ascii_str = \
"""\
 2\n\
J \
"""
    ucode_str = \
u"""\
 2\n\
J \
"""
    assert pretty(J2) == ascii_str
    assert upretty(J2) == ucode_str
    assert latex(J2) == r'J^2'
    sT(J2, "J2Op(Symbol('J'))")
    assert str(Jz) == 'Jz'
    ascii_str = \
"""\
J \n\
 z\
"""
    ucode_str = \
u"""\
J \n\
 z\
"""
    assert pretty(Jz) == ascii_str
    assert upretty(Jz) == ucode_str
    assert latex(Jz) == 'J_z'
    sT(Jz, "JzOp(Symbol('J'))")
    assert str(ket) == '|1,0>'
    assert pretty(ket) == '|1,0>'
    assert upretty(ket) == u'❘1,0⟩'
    assert latex(ket) == r'{\left|1,0\right\rangle }'
    sT(ket, "JzKet(Integer(1),Integer(0))")
    assert str(bra) == '<1,0|'
    assert pretty(bra) == '<1,0|'
    assert upretty(bra) == u'⟨1,0❘'
    assert latex(bra) == r'{\left\langle 1,0\right|}'
    sT(bra, "JzBra(Integer(1),Integer(0))")
    assert str(cket) == '|1,0,j1=1,j2=2>'
    assert pretty(cket) == '|1,0,j1=1,j2=2>'
    assert upretty(cket) == u'❘1,0,j₁=1,j₂=2⟩'
    assert latex(cket) == r'{\left|1,0,j_{1}=1,j_{2}=2\right\rangle }'
    sT(
        cket,
        "JzKetCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2)),Tuple(Tuple(Integer(1), Integer(2), Integer(1))))"
    )
    assert str(cbra) == '<1,0,j1=1,j2=2|'
    assert pretty(cbra) == '<1,0,j1=1,j2=2|'
    assert upretty(cbra) == u'⟨1,0,j₁=1,j₂=2❘'
    assert latex(cbra) == r'{\left\langle 1,0,j_{1}=1,j_{2}=2\right|}'
    sT(
        cbra,
        "JzBraCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2)),Tuple(Tuple(Integer(1), Integer(2), Integer(1))))"
    )
    assert str(cket_big) == '|1,0,j1=1,j2=2,j3=3,j(1,2)=3>'
    # TODO: Fix non-unicode pretty printing
    # i.e. j1,2 -> j(1,2)
    assert pretty(cket_big) == '|1,0,j1=1,j2=2,j3=3,j1,2=3>'
    assert upretty(cket_big) == u'❘1,0,j₁=1,j₂=2,j₃=3,j₁,₂=3⟩'
    assert latex(cket_big) == \
        r'{\left|1,0,j_{1}=1,j_{2}=2,j_{3}=3,j_{1,2}=3\right\rangle }'
    sT(
        cket_big,
        "JzKetCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2), Integer(3)),Tuple(Tuple(Integer(1), Integer(2), Integer(3)), Tuple(Integer(1), Integer(3), Integer(1))))"
    )
    assert str(cbra_big) == '<1,0,j1=1,j2=2,j3=3,j(1,2)=3|'
    assert pretty(cbra_big) == u'<1,0,j1=1,j2=2,j3=3,j1,2=3|'
    assert upretty(cbra_big) == u'⟨1,0,j₁=1,j₂=2,j₃=3,j₁,₂=3❘'
    assert latex(cbra_big) == \
        r'{\left\langle 1,0,j_{1}=1,j_{2}=2,j_{3}=3,j_{1,2}=3\right|}'
    sT(
        cbra_big,
        "JzBraCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(2), Integer(3)),Tuple(Tuple(Integer(1), Integer(2), Integer(3)), Tuple(Integer(1), Integer(3), Integer(1))))"
    )
    assert str(rot) == 'R(1,2,3)'
    assert pretty(rot) == 'R (1,2,3)'
    assert upretty(rot) == u'ℛ (1,2,3)'
    assert latex(rot) == r'\mathcal{R}\left(1,2,3\right)'
    sT(rot, "Rotation(Integer(1),Integer(2),Integer(3))")
    assert str(bigd) == 'WignerD(1, 2, 3, 4, 5, 6)'
    ascii_str = \
"""\
 1         \n\
D   (4,5,6)\n\
 2,3       \
"""
    ucode_str = \
u"""\
 1         \n\
D   (4,5,6)\n\
 2,3       \
"""
    assert pretty(bigd) == ascii_str
    assert upretty(bigd) == ucode_str
    assert latex(bigd) == r'D^{1}_{2,3}\left(4,5,6\right)'
    sT(
        bigd,
        "WignerD(Integer(1), Integer(2), Integer(3), Integer(4), Integer(5), Integer(6))"
    )
    assert str(smalld) == 'WignerD(1, 2, 3, 0, 4, 0)'
    ascii_str = \
"""\
 1     \n\
d   (4)\n\
 2,3   \
"""
    ucode_str = \
u"""\
 1     \n\
d   (4)\n\
 2,3   \
"""
    assert pretty(smalld) == ascii_str
    assert upretty(smalld) == ucode_str
    assert latex(smalld) == r'd^{1}_{2,3}\left(4\right)'
    sT(
        smalld,
        "WignerD(Integer(1), Integer(2), Integer(3), Integer(0), Integer(4), Integer(0))"
    )