Пример #1
0
def test_single_nj_rotation_to_wigner_rotation():
    R_in_2 = np.asarray(
        [0 + 0.5j, 0, 0 + 0.1j, 0, 0 - 0.5j],
        dtype=np.complex128,
    )
    R_in_4 = np.asarray(
        [0 - 0.2j, 0, 0 + 0.5j, 0, 0 + 0.1j, 0, 0 - 0.5j, 0, 0 + 0.2j],
        dtype=np.complex128,
    )
    for ang_l, R_in in zip([2, 4], [R_in_2, R_in_4]):
        n_ = ang_l + 1
        for _ in range(10):
            euler_angle = np.random.rand(
                3) * np.pi / 2  # positive quadrant only.
            euler_angle[-1] = 0.0
            cos_angle = np.cos(euler_angle)
            cos_alpha = np.asarray([cos_angle[0]])
            cos_beta = np.asarray([cos_angle[1]])

            # single rotation
            R_out = clib.single_wigner_rotation(ang_l, euler_angle, R_in)
            R_out_2 = clib.__wigner_rotation_2(ang_l, cos_alpha, cos_beta,
                                               R_in).ravel()

            np.testing.assert_almost_equal(
                R_out[:n_],
                R_out_2,
                decimal=8,
                err_msg=f"Error l={ang_l}, index={_}")
def test_single_2j_rotation_00():
    ang_momentum_l = 2
    R_in = np.asarray([0 + 0.5j, 0, 0 + 0.1j, 0, 0 - 0.5j], dtype=np.complex128)
    indexes = np.arange(5) - 2.0

    for _ in range(10):
        euler_angle = np.random.rand(3) * 2.0 * np.pi

        # single rotation
        R_out = clib.single_wigner_rotation(ang_momentum_l, euler_angle, R_in)

        exp_im_alpha = np.exp(-1j * indexes * euler_angle[0])
        R_out_p = R_in * exp_im_alpha
        wigner = clib.wigner_d_matrices(ang_momentum_l, np.asarray([euler_angle[1]]))
        R_out_p = np.dot(wigner.reshape(5, 5), R_out_p)
        exp_im_gamma = np.exp(-1j * indexes * euler_angle[2])
        R_out_p *= exp_im_gamma

        np.testing.assert_almost_equal(R_out, R_out_p, decimal=8)