Beispiel #1
0
def test_wigner():
    def tn(a, b):
        return abs((a - b).n(64) < S('1e-64'))
    assert tn(wigner_9j(1,1,1, 1,1,1, 1,1,0 ,prec=64), S(1)/18)
    assert wigner_9j(3,3,2, 3,3,2, 3,3,2) == 3221*sqrt(70)/(246960*sqrt(105)) - 365/(3528*sqrt(70)*sqrt(105))
    assert wigner_6j(5,5,5,5,5,5) == Rational(1,52)
    assert tn(wigner_6j(8,8,8,8,8,8, prec=64), -S(12219)/965770)
Beispiel #2
0
def test_wigner():
    def tn(a, b):
        return (a - b).n(64) < S('1e-64')
    assert tn(wigner_9j(1, 1, 1, 1, 1, 1, 1, 1, 0, prec=64), S(1)/18)
    assert wigner_9j(3, 3, 2, 3, 3, 2, 3, 3, 2) == 3221*sqrt(
        70)/(246960*sqrt(105)) - 365/(3528*sqrt(70)*sqrt(105))
    assert wigner_6j(5, 5, 5, 5, 5, 5) == Rational(1, 52)
    assert tn(wigner_6j(8, 8, 8, 8, 8, 8, prec=64), -S(12219)/965770)
Beispiel #3
0
def safe_wigner_9j(*args):
    """ Wigner 9j symbol, same arguments as in Avoid the ValueError whenever the
     arguments don't fulfill the triangle relation. """
    try:
        return float(wigner_9j(*args, prec=None))
    except ValueError or AttributeError:
        return 0
def dump_w9j(tjmax):
    # note: sympy's wigner_9j is buggy for half-integer arguments
    #       (as of 0.7.6.1)
    import sympy.physics.wigner as spw
    for write in dump_output("symw9j", tjmax):
        for tjs in iter_9tjs(tjmax):
            z = spw.wigner_9j(*(Fraction(tj, 2) for tj in tjs))
            write("\t".join(map(str, tjs + (show_signedsqrtfrac(z),))) + "\n")
Beispiel #5
0
def dump_w9j(tjmax):
    # note: sympy's wigner_9j is buggy for half-integer arguments
    #       (as of 0.7.6.1)
    import sympy.physics.wigner as spw
    for write in dump_output("symw9j", tjmax):
        for tjs in iter_9tjs(tjmax):
            z = spw.wigner_9j(*(Fraction(tj, 2) for tj in tjs))
            write("\t".join(map(str, tjs + (show_signedsqrtfrac(z), ))) + "\n")
def Ysigma(l1, j1, l2, j2, l, s, k):
    """
    < l1, j1 || [Y_l sigma_s]_k || l2, j2 >
    Note: all inputs are not not doubled
    """
    sfact = np.sqrt(2.0)
    if (s == 1): sfact = np.sqrt(6.0)
    return np.sqrt(float(
        (2 * j1 + 1) * (2 * j2 + 1) *
        (2 * k + 1))) * N(wigner_9j(l1, 0.5, j1, l2, 0.5, j2, l, s, k,
                                    prec=8)) * Yl_red(l1, l2, l) * sfact
    def compute_matrix_coeff(i):
        # output submatrix
        tmp_out = np.zeros((len(ell_1), len(ell_1)))

        # i is first matrix index
        L_1, L_2, L_3 = ell_1[i], ell_2[i], ell_3[i]
        pref_1 = np.sqrt((2. * L_1 + 1.) * (2. * L_2 + 1.) * (2. * L_3 + 1.))

        for j in range(len(ell_1)):
            # j is second matrix index
            Lpp_1, Lpp_2, Lpp_3 = ell_1[j], ell_2[j], ell_3[j]
            pref_2 = pref_1 * np.sqrt(
                (2. * Lpp_1 + 1.) * (2. * Lpp_2 + 1.) * (2. * Lpp_3 + 1.))
            # add phase
            pref_2 *= (-1.)**(Lpp_1 + Lpp_2 + Lpp_3)

            for k in range(len(ell_1)):
                # k indexes inner Lambda' term
                Lp_1, Lp_2, Lp_3 = ell_1[k], ell_2[k], ell_3[k]

                # Compute prefactor
                pref = pref_2 * np.sqrt(
                    (2. * Lp_1 + 1.) * (2. * Lp_2 + 1.) *
                    (2. * Lp_3 + 1.)) / (4. * np.pi)**(3. / 2.)

                # Compute 3j couplings
                three_j_piece = np.float64(wigner_3j(L_1, Lp_1, Lpp_1, 0, 0,
                                                     0))
                if three_j_piece == 0: continue
                three_j_piece *= np.float64(
                    wigner_3j(L_2, Lp_2, Lpp_2, 0, 0, 0))
                if three_j_piece == 0: continue
                three_j_piece *= np.float(wigner_3j(L_3, Lp_3, Lpp_3, 0, 0, 0))
                if three_j_piece == 0: continue

                # Compute the 9j component
                nine_j_piece = np.float64(
                    wigner_9j(L_1,
                              Lp_1,
                              Lpp_1,
                              L_2,
                              Lp_2,
                              Lpp_2,
                              L_3,
                              Lp_3,
                              Lpp_3,
                              prec=8))
                if nine_j_piece == 0: continue

                tmp_out[j, k] = pref * three_j_piece * nine_j_piece
        return tmp_out
Beispiel #8
0
 def doit(self, **hints):
     if self.is_symbolic:
         raise ValueError("Coefficients must be numerical")
     return wigner_9j(
         self.j1,
         self.j2,
         self.j12,
         self.j3,
         self.j4,
         self.j34,
         self.j13,
         self.j24,
         self.j,
     )
Beispiel #9
0
def tensor_product(a, b, j, k1, k2, k, a1, b1, j1, n=True, precision=None):
    """
    If you have a matrix element of a product of two tensor operators
    of rank k1 and k2, this product operator has a spherical tensor
    operator component of rank k.
    
    This function describes the reduced matrix element:
    <J,A,B||(T^k1(A) T^k2(B))^k||J1,A1,B1>
    
    see Brown and Carrington 5.169
    """

    output = (sqrt((2 * j + 1) * (2 * k + 1) * (2 * j1 + 1)) *
              wigner_9j(a1, b1, j1, k1, k2, k, a, b, j, precision=precision))

    return formated_output(output, n=n)
Beispiel #10
0
def tensor_product(a, b, j, 
                   k1, k2, k, 
                   a1, b1, j1, 
                   n=True, precision=None):
    """
    If you have a matrix element of a product of two tensor operators
    of rank k1 and k2, this product operator has a spherical tensor
    operator component of rank k.
    
    This function describes the reduced matrix element:
    <J,A,B||(T^k1(A) T^k2(B))^k||J1,A1,B1>
    
    see Brown and Carrington 5.169
    """
    
    output = (sqrt((2 * j + 1) * (2 * k + 1) * (2 * j1 + 1)) *
              wigner_9j(a1, b1, j1, 
                        k1, k2, k, 
                        a,  b,  j, 
                        precision=precision))
    
    return formated_output(output, n=n)
def test_wigner():
    def tn(a, b):
        return (a - b).n(64) < S('1e-64')

    assert tn(wigner_9j(1, 1, 1, 1, 1, 1, 1, 1, 0, prec=64), S(1) / 18)
    assert wigner_9j(
        3, 3, 2, 3, 3, 2, 3, 3,
        2) == 3221 * sqrt(70) / (246960 * sqrt(105)) - 365 / (3528 * sqrt(70) *
                                                              sqrt(105))
    assert wigner_6j(5, 5, 5, 5, 5, 5) == Rational(1, 52)
    assert tn(wigner_6j(8, 8, 8, 8, 8, 8, prec=64), -S(12219) / 965770)
    # regression test for #8747
    half = Rational(1, 2)
    assert wigner_9j(0, 0, 0, 0, half, half, 0, half, half) == half
    assert (wigner_9j(3, 5, 4, 7 * half, 5 * half, 4, 9 * half, 9 * half,
                      0) == -sqrt(Rational(361, 205821000)))
    assert (wigner_9j(1, 4, 3, 5 * half, 4, 5 * half, 5 * half, 2,
                      7 * half) == -sqrt(Rational(3971, 373403520)))
    assert (wigner_9j(4, 9 * half, 5 * half, 2, 4, 4, 5, 7 * half,
                      7 * half) == -sqrt(Rational(3481, 5042614500)))
def test_wigner():
    def tn(a, b):
        return (a - b).n(64) < S('1e-64')
    assert tn(wigner_9j(1, 1, 1, 1, 1, 1, 1, 1, 0, prec=64), S(1)/18)
    assert wigner_9j(3, 3, 2, 3, 3, 2, 3, 3, 2) == 3221*sqrt(
        70)/(246960*sqrt(105)) - 365/(3528*sqrt(70)*sqrt(105))
    assert wigner_6j(5, 5, 5, 5, 5, 5) == Rational(1, 52)
    assert tn(wigner_6j(8, 8, 8, 8, 8, 8, prec=64), -S(12219)/965770)
    # regression test for #8747
    half = Rational(1, 2)
    assert wigner_9j(0, 0, 0, 0, half, half, 0, half, half) == half
    assert (wigner_9j(3, 5, 4,
                      7 * half, 5 * half, 4,
                      9 * half, 9 * half, 0)
            == -sqrt(Rational(361, 205821000)))
    assert (wigner_9j(1, 4, 3,
                      5 * half, 4, 5 * half,
                      5 * half, 2, 7 * half)
            == -sqrt(Rational(3971, 373403520)))
    assert (wigner_9j(4, 9 * half, 5 * half,
                      2, 4, 4,
                      5, 7 * half, 7 * half)
            == -sqrt(Rational(3481, 5042614500)))
Beispiel #13
0
 def doit(self, **hints):
     if self.is_symbolic:
         raise ValueError("Coefficients must be numerical")
     return wigner_9j(self.j1, self.j2, self.j12, self.j3, self.j4, self.j34, self.j13, self.j24, self.j)
Beispiel #14
0
                for k, y in enumerate(it.repeat((jpair[0], jpair[1]),
                                                len(Js))):
                    jjj_wig3j = wigner_3j(y[0], y[1], Js[k], 0, 0, 0).evalf()

                    maxp = max(x[0] + y[0], x[1] + y[1])

                    for ppair in it.product(np.arange(maxp + 1), repeat=2):
                        Ps = return_Ls(ppair[0], ppair[1])

                        for m, z in enumerate(
                                it.repeat((ppair[0], ppair[1]), len(Ps))):
                            wig9j = wigner_9j(x[0],
                                              y[0],
                                              z[0],
                                              x[1],
                                              y[1],
                                              z[1],
                                              Ls[i],
                                              Js[k],
                                              Ps[m],
                                              prec=64)

                            cleb_p0 = clebsch_gordan(z[0], x[0], y[0], 0, 0,
                                                     0).evalf()
                            cleb_p1 = clebsch_gordan(z[1], x[1], y[1], 0, 0,
                                                     0).evalf()
                            cleb_P0 = clebsch_gordan(Ps[m], Ls[i], Js[k], 0, 0,
                                                     0).evalf()

                            if np.abs(ell_wig3j) > 0.0 and np.abs(
                                    jjj_wig3j) > 0.0 and np.abs(wig9j) > 0.0:
                                if np.abs(cleb_p0) > 0.0 and np.abs(
def non_antisimetrized_BB_ME(bra, ket, parameters):

    # Passing of parameters
    n_a, n_b = bra.n1, bra.n2
    n_c, n_d = ket.n1, ket.n2
    l_a, l_b = bra.l1, bra.l2
    l_c, l_d = ket.l1, ket.l2
    j_a, j_b = bra.j1, bra.j2
    j_c, j_d = ket.j1, ket.j2

    J, T = bra.J, bra.T

    # Adjust the oscillator lenght to the reducced mass of the proton
    b_param = parameters[0][0] * np.sqrt(2)

    Sum = 0.
    L_max = min((l_a + l_b), (l_c + l_d))
    L_min = max(abs(l_a - l_b), abs(l_c - l_d))

    for L in range(L_min, L_max + 1):
        for S in range(0, 2):

            try:
                # j atribute are defined as 2*j
                w9j_bra = wigner_9j(l_a,
                                    1 / 2,
                                    j_a / 2,
                                    l_b,
                                    1 / 2,
                                    j_b / 2,
                                    L,
                                    S,
                                    J,
                                    prec=None)  #.evalf()
            except ValueError:
                w9j_bra = 0

            if (abs(w9j_bra) > 1.e-15):
                try:
                    w9j_ket = wigner_9j(l_c,
                                        1 / 2,
                                        j_c / 2,
                                        l_d,
                                        1 / 2,
                                        j_d / 2,
                                        L,
                                        S,
                                        J,
                                        prec=None)  #.evalf()
                except ValueError:
                    w9j_ket = 0

                if (abs(w9j_ket) > 1.e-15):
                    # j atribute are defined as 2*j
                    recoupling = ((2 * S + 1) * (2 * L + 1) * np.sqrt(
                        (j_a + 1) * (j_b + 1) * (j_c + 1) * (j_d + 1)) *
                                  w9j_bra * w9j_ket)

                    # Sum of gaussians and projection operators
                    for i in range(2):

                        mu_param = parameters[i][1]

                        # Radial Part for Gauss Integral (L == lambda)
                        Radial = Moshinsky_Transformation_ME(
                            n_a, l_a, n_b, l_b, n_c, l_c, n_d, l_d, L, b_param,
                            mu_param)

                        #                        print('Radial['+ str(i)+ ']: '+str(Radial))
                        # Exchange Part
                        Exchange_Energy = (
                            parameters[i][2] +  # Wigner
                            (parameters[i][3] * ((-1)**(L))) +  # Majorana
                            (parameters[i][4] * ((-1)**(S))) +  # Barlett
                            (parameters[i][5] * ((-1)**(T))))  # Heisenberg

                        #                        print('Exchange['+ str(i)+ ']: ',Exchange_Energy, '  couping=',recoupling)
                        # Add up
                        Sum += recoupling * Radial * Exchange_Energy

    return Sum
    j8 = map(float, data[:, 7])
    j9 = map(float, data[:, 8])
    W_9j = map(float, data[:, 9])
    errors, non_zero = 0, 0
    tol = 1e-5
    Erroneos, No_erroneos = [], []

    for i in range(len(j1)):
        w_9j, j_1, j_2, j_3, j_4, j_5, j_6, j_7, j_8, j_9 = \
        W_9j[i], j1[i], j2[i], j3[i], j4[i], j5[i], j6[i], j7[i], j8[i], j9[i]
        try:
            w9j_analitic = wigner_9j(j_1,
                                     j_2,
                                     j_3,
                                     j_4,
                                     j_5,
                                     j_6,
                                     j_7,
                                     j_8,
                                     j_9,
                                     prec=None)
        except ValueError:
            w9j_analitic = 0
        if abs(w_9j - w9j_analitic) > tol:
            errors += 1
            non_zero += 1
            #            print(j1, j2, j, m1, m2, m,"cg=",cg," // cg_an=",cg_analitic," //Error")
            Erroneos.append([[j_1, j_2, j_3, j_4, j_5, j_6, j_7, j_8, j_9],
                             w_9j, w9j_analitic])
            raw_input("press any key")
#        else:
#            print(j1, j2, j, m1, m2, m,"cg=",cg," // cg_an=",cg_analitic)
Beispiel #17
0
def wig9j(j1, j2, j3, l1, l2, l3, n1, n2, n3):
    """
    This function redefines the wig9jj in terms of things that I like:
    """
    return float(wigner_9j(j1, j2, j3, l1, l2, l3, n1, n2, n3))