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 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.º 3
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.º 4
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.º 5
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.º 6
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,
    )
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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
# -*- 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)
import numpy as np
from sympy.physics.quantum.spin import Rotation as R
import sympy as sp

sp.init_printing()
from matplotlib import pyplot as plt

alpha, beta, gamma = sp.symbols('alpha beta gamma')
J = 1
m = 1
mp = 1
Rot = sp.zeros(3, 3)
for i, m in enumerate(range(-1, 2)):
    for j, mp in enumerate(range(-1, 2)):
        val = R.D(J, m, mp, alpha, beta, gamma).doit()
        Rot[i, j] = val
#        print(val)

## For sigma light rotated along the polar angle
N = 101
angles = np.linspace(0, 2 * np.pi, N)
states = np.zeros((N, 3))  #might have to be complex
state_init = np.array([[1, 0, 0]]).T
for i, ang in enumerate(angles):
    rotMat = Rot.subs(alpha, 0).subs(gamma, 0).subs(beta, ang)
    newval = rotMat * state_init
    states[i, :] = newval.T

degrees = angles * 180 / np.pi
plt.figure()
Ejemplo n.º 13
0
    for lam2 in [-S(1) / 2, S(1) / 2]:
        lam_l = lam2 - lam1
        for lam in [1]:
            coeffs += [
                Symbol('A_' + str(J_L) + '_' + str(lam) + '_' + str(lam1) +
                       '_' + str(lam2),
                       real=True)
            ]
            phases += [
                Symbol('d_' + str(J_L) + '_' + str(lam) + '_' + str(lam1) +
                       '_' + str(lam2),
                       real=True)
            ]
            A = coeffs[-1]
            '''A = coeffs[-1] * exp(I*phases[-1])'''
            B = Rotation.D(J_K, lam, 0, 0, thetaK, 0)
            C = Rotation.D(J_L, lam, lam_l, phi, thetaL, -phi)
            amp += A * B * C
            print
            print amp.doit()
            print

amp1 = amp.doit().expand(complex=True)
amp1_st = amp.doit().expand(complex=True).conjugate()
amp_sq = amp1 * amp1_st
print simplify(amp_sq.expand())
'''
print amp1
print
print amp1_st
print