예제 #1
0
파일: DM.py 프로젝트: sgulania/SQ2EOM
def OPDM(L, R, flavor):

    display(
        Markdown(
            rf""" Computing OPDM for {flavor} (skipping summation for dummy variables)"""
        ))

    i, j = symbols('i,j', below_fermi=True)
    a, b = symbols('a,b', above_fermi=True)

    PermutList = [PermutationOperator(i, j), PermutationOperator(a, b)]

    oo = Fd(i) * F(j)
    cc = BCH.level(oo, "SD")
    g_oo = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True))
    g_oo = simplify_index_permutations(g_oo, PermutList)
    index_rule = {'below': 'klmno', 'above': 'abcde'}
    g_oo = substitute_dummies(g_oo,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_{ij}')
    final_eq = Eq(gamma, g_oo)
    display(final_eq)

    ov = Fd(i) * F(a)
    cc = BCH.level(ov, "SD")
    g_ov = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True))
    g_ov = simplify_index_permutations(g_ov, PermutList)
    index_rule = {'below': 'jklmn', 'above': 'bcdef'}
    g_ov = substitute_dummies(g_ov,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_{ia}')
    final_eq = Eq(gamma, g_ov)
    display(final_eq)

    vo = Fd(a) * F(i)
    cc = BCH.level(vo, "SD")
    g_vo = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True))
    g_vo = simplify_index_permutations(g_vo, PermutList)
    index_rule = {'below': 'jklmn', 'above': 'bcdef'}
    g_vo = substitute_dummies(g_vo,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_{ai}')
    final_eq = Eq(gamma, g_vo)
    display(final_eq)

    vv = Fd(a) * F(b)
    cc = BCH.level(vv, "SD")
    g_vv = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True))
    g_vv = simplify_index_permutations(g_vv, PermutList)
    index_rule = {'below': 'ijklm', 'above': 'cdefg'}
    g_vv = substitute_dummies(g_vv,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_{ab}')
    final_eq = Eq(gamma, g_vv)
    display(final_eq)
def main():
    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    H1, H2 = getHamiltonian()
    eq_H1 = computeHausdorff(H1)  #e^(-T)H1e^T
    eq_H2 = computeHausdorff(H2)
    print("CC energy:")
    Energy = wicks(eq_H1 + eq_H2,
                   simplify_dummies=True,
                   keep_only_fully_contracted=True,
                   simplify_kronecker_deltas=True)
    Energy = substitute_dummies(Energy,
                                new_indices=True,
                                pretty_indices=pretty_dummies_dict)
    print(latex(Energy))
    print()
    """
    print("CC dE_H1/(dLia):")
    eqH1T1 = wicks(Fd(i)*F(a)*eq_H1, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True)
    P = PermutationOperator
    eqH1T1 = simplify_index_permutations(eqH1T1, [P(a, b), P(i, j)])
    eqH1T1 = substitute_dummies(eqH1T1,new_indices=True, pretty_indices=pretty_dummies_dict)
    print(latex(eqH1T1))
    print() 

	print("CC dE_H2/(dLia):")
	eqH2T1 = wicks(Fd(i)*F(a)*eq_H2, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True)
	P = PermutationOperator
	eqH2T1 = simplify_index_permutations(eqH2T1, [P(a, b), P(i, j)])
	eqH2T1 = substitute_dummies(eqH2T1,new_indices=True, pretty_indices=pretty_dummies_dict)
	print(latex(eqH2T1))
	print()
    """

    print("CC dE_H1/(dLijab):")
    eqH1T2 = wicks(Fd(j) * F(b) * Fd(i) * F(a) * eq_H1,
                   simplify_dummies=True,
                   keep_only_fully_contracted=True,
                   simplify_kronecker_deltas=True)
    P = PermutationOperator
    eqH1T2 = simplify_index_permutations(eqH1T2, [P(a, b), P(i, j)])
    eqH1T2 = substitute_dummies(eqH1T2,
                                new_indices=True,
                                pretty_indices=pretty_dummies_dict)
    print(latex(eqH1T2))
    print()

    print("CC dE_H2/(dLijab):")
    eqH2T2 = wicks(Fd(j) * F(b) * Fd(i) * F(a) * eq_H2,
                   simplify_dummies=True,
                   keep_only_fully_contracted=True,
                   simplify_kronecker_deltas=True)
    P = PermutationOperator
    eqH2T2 = simplify_index_permutations(eqH2T2, [P(i, j), P(a, b)])
    eqH2T2 = substitute_dummies(eqH2T2,
                                new_indices=True,
                                pretty_indices=pretty_dummies_dict)
    print(latex(eqH2T2))
    print()
def get_doubles_cluster_operator():
    i, j = symbols("i, j", below_fermi=True, cls=Dummy)
    a, b = symbols("a, b", above_fermi=True, cls=Dummy)

    t = AntiSymmetricTensor("t", (a, b), (i, j))
    t = t * Fd(a) * F(i) * Fd(b) * F(j)

    return [Rational(1, 4) * t]
예제 #4
0
def OPTDM(Lf1, Rf1, Lf2, Rf2, flavor1, flavor2):

    display(
        Markdown(
            rf""" Computing Dyson OPTDM between {flavor1} $\rightarrow$ {flavor2} (skipping summation for dummy variables)"""
        ))

    i = symbols('i', below_fermi=True)
    a = symbols('a', above_fermi=True)

    index_rule = {'below': 'jklmn', 'above': 'bcde'}

    oo = Fd(i)
    cc = BCH.level(oo, "SD")
    g_oo = evaluate_deltas(
        wicks(Lf2 * cc * Rf1, keep_only_fully_contracted=True))
    g_oo = substitute_dummies(g_oo,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_i^{R}')
    final_eq = Eq(gamma, g_oo)
    display(final_eq)

    ov = Fd(a)
    cc = BCH.level(ov, "SD")
    g_ov = evaluate_deltas(
        wicks(Lf2 * cc * Rf1, keep_only_fully_contracted=True))
    index_rule = {'below': 'jklmn', 'above': 'bcdef'}
    g_ov = substitute_dummies(g_ov,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_a^{R}')
    final_eq = Eq(gamma, g_ov)
    display(final_eq)

    vo = F(i)
    cc = BCH.level(vo, "SD")
    g_vo = evaluate_deltas(
        wicks(Lf1 * cc * Rf2, keep_only_fully_contracted=True))
    index_rule = {'below': 'jklmn', 'above': 'bcdef'}
    g_vo = substitute_dummies(g_vo,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_i^{L}')
    final_eq = Eq(gamma, g_vo)
    display(final_eq)

    vv = F(a)
    cc = BCH.level(vv, "SD")
    g_vv = evaluate_deltas(
        wicks(Lf1 * cc * Rf2, keep_only_fully_contracted=True))
    index_rule = {'below': 'ijklm', 'above': 'cdefg'}
    g_vv = substitute_dummies(g_vv,
                              new_indices=True,
                              pretty_indices=index_rule)
    gamma = Symbol('\gamma_a^{L}')
    final_eq = Eq(gamma, g_vv)
    display(final_eq)
def getHamiltonian():
    p, q, r, s = symbols('p,q,r,s', cls=Dummy)
    h = AntiSymmetricTensor('h', (p, ), (q, ))
    pq = Fd(p) * F(q)
    u = AntiSymmetricTensor('u', (p, r), (q, s))
    pqsr = Fd(p) * Fd(r) * F(s) * F(q)
    H1 = h * pq
    H2 = Rational(1, 4) * u * pqsr
    return (H1, H2)
def get_two_body_equation(equation_h, equation_u):
    two_body_eq = wicks(
        Fd(j) * F(b) * Fd(i) * F(a) * equation_u, **wicks_kwargs)

    p = PermutationOperator
    two_body_eq = simplify_index_permutations(two_body_eq, [p(i, j), p(a, b)])
    two_body_eq = substitute_dummies(two_body_eq, **sub_kwargs)

    return two_body_eq
def get_one_body_equation(equation_h, equation_u):
    one_body_eq = wicks(
        Fd(j) * F(b) * Fd(i) * F(a) * equation_h, **wicks_kwargs)

    p = PermutationOperator
    one_body_eq = simplify_index_permutations(one_body_eq, [p(a, b), p(i, j)])
    one_body_eq = substitute_dummies(one_body_eq, **sub_kwargs)

    return one_body_eq
def get_hamiltonian():
    p, q, r, s = symbols("p, q, r, s", cls=Dummy)
    h = AntiSymmetricTensor("h", (p, ), (q, ))
    u = AntiSymmetricTensor("u", (p, r), (q, s))

    h = h * Fd(p) * F(q)
    u = u * Fd(p) * Fd(r) * F(s) * F(q)

    return h, Rational(1, 4) * u
예제 #9
0
def test_commutation():
    n, m = symbols("n,m", above_fermi=True)
    c = Commutator(B(0), Bd(0))
    assert c == 1
    c = Commutator(Bd(0), B(0))
    assert c == -1
    c = Commutator(B(n), Bd(0))
    assert c == KroneckerDelta(n, 0)
    c = Commutator(B(0), Bd(0))
    e = simplify(apply_operators(c * BKet([n])))
    assert e == BKet([n])
    c = Commutator(B(0), B(1))
    e = simplify(apply_operators(c * BKet([n, m])))
    assert e == 0

    c = Commutator(F(m), Fd(m))
    assert c == +1 - 2 * NO(Fd(m) * F(m))
    c = Commutator(Fd(m), F(m))
    assert c.expand() == -1 + 2 * NO(Fd(m) * F(m))

    C = Commutator
    X, Y, Z = symbols('X,Y,Z', commutative=False)
    assert C(C(X, Y), Z) != 0
    assert C(C(X, Z), Y) != 0
    assert C(Y, C(X, Z)) != 0

    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    p, q, r, s = symbols('p,q,r,s')
    D = KroneckerDelta

    assert C(Fd(a), F(i)) == -2 * NO(F(i) * Fd(a))
    assert C(Fd(j), NO(Fd(a) * F(i))).doit(wicks=True) == -D(j, i) * Fd(a)
    assert C(Fd(a) * F(i), Fd(b) * F(j)).doit(wicks=True) == 0
예제 #10
0
def main():

    base = sys.argv[0]
    filename = os.path.splitext(base)[0]
    fo = open(filename + '.tex', "w")

    fo.write("\documentclass{article}\n")
    fo.write("\usepackage[fleqn]{amsmath}\n")
    fo.write("\usepackage{latexsym, amsfonts}\n")
    fo.write("\usepackage{pdflscape}\n")
    fo.write(r'\parindent=0pt\relax')
    fo.write("\n")
    fo.write(r'\begin{document}')
    fo.write("\n")
    fo.write(r'\begin{landscape}')
    fo.write("\n")

    # Hamiltonian
    p, q, r, s = symbols('p,q,r,s', cls=Dummy)
    f = AntiSymmetricTensor('f', (p, ), (q, ))
    pr = Fd(p) * F(q)
    v = AntiSymmetricTensor('v', (p, q), (r, s))
    pqsr = Fd(p) * Fd(q) * F(s) * F(r)

    H = f * pr + Rational(1, 4) * v * pqsr
    # Print Hamiltonian
    fo.write("The spin orbital hamiltonian:\n")
    Equation2Tex(latex(H), fo)

    # Exciation and de-excitation operators
    i, j = symbols('i,j', below_fermi=True)
    a, b = symbols('a,b', above_fermi=True)
    ia = Fd(a) * F(i)
    jb = Fd(j) * F(b)

    C = Commutator
    #First com
    comm1 = C(H, ia)
    comm2 = C(jb, comm1)
    fo.write("Evaluating operators:\n")
    Equation2Tex(latex(comm2), fo)

    comm2 = comm2.doit()
    comm2 = comm2.expand()
    #comm2= Permute_Str(comm2)
    comm2 = Permute_Op(comm2)

    Equation2Tex(latex(comm2), fo)

    #finish writing
    fo.write("\end{landscape}\n")
    fo.write("\end{document}\n")
    fo.close()
    os.system("pdflatex " + filename + '.tex')
예제 #11
0
def test_limit_subs():
    for F in (Sum, Product, Integral):
        assert F(a * exp(a), (a, -2, 2)) == F(a * exp(a),
                                              (a, -b, b)).subs(b, 2)
        assert F(a, (a, F(b, (b, 1, 2)), 4)).subs(F(b, (b, 1, 2)), c) == \
            F(a, (a, c, 4))
        assert F(x, (x, 1, x + y)).subs(x, 1) == F(x, (x, 1, y + 1))
예제 #12
0
def get_CC_operators():
    """
    Returns a tuple (T1,T2) of unique operators.
    """
    i = symbols('i', below_fermi=True, cls=Dummy)
    a = symbols('a', above_fermi=True, cls=Dummy)
    t_ai = AntiSymmetricTensor('t', (a,), (i,))
    ai = NO(Fd(a)*F(i))
    i, j = symbols('i,j', below_fermi=True, cls=Dummy)
    a, b = symbols('a,b', above_fermi=True, cls=Dummy)
    t_abij = AntiSymmetricTensor('t', (a, b), (i, j))
    abji = NO(Fd(a)*Fd(b)*F(j)*F(i))

    T1 = t_ai*ai
    T2 = Rational(1, 4)*t_abij*abji
    return (T1, T2)
예제 #13
0
def get_ccsd_t_operators(ast_symb="t"):
    i = symbols("i", below_fermi=True, cls=Dummy)
    a = symbols("a", above_fermi=True, cls=Dummy)

    t_ai = AntiSymmetricTensor(ast_symb, (a, ), (i, ))
    c_ai = NO(Fd(a) * F(i))

    i, j = symbols("i, j", below_fermi=True, cls=Dummy)
    a, b = symbols("a, b", above_fermi=True, cls=Dummy)

    t_abij = AntiSymmetricTensor(ast_symb, (a, b), (i, j))
    c_abij = NO(Fd(a) * Fd(b) * F(j) * F(i))

    T_1 = t_ai * c_ai
    T_2 = Rational(1, 4) * t_abij * c_abij

    return (T_1, T_2)
예제 #14
0
def get_ccsd_lambda_operators(ast_symb="l"):
    i = symbols("i", below_fermi=True, cls=Dummy)
    a = symbols("a", above_fermi=True, cls=Dummy)

    l_ia = AntiSymmetricTensor(ast_symb, (i, ), (a, ))
    c_ia = NO(Fd(i) * F(a))

    i, j = symbols("i, j", below_fermi=True, cls=Dummy)
    a, b = symbols("a, b", above_fermi=True, cls=Dummy)

    l_ijab = AntiSymmetricTensor(ast_symb, (i, j), (a, b))
    c_ijab = NO(Fd(i) * Fd(j) * F(b) * F(a))

    L_1 = l_ia * c_ia
    L_2 = Rational(1, 4) * l_ijab * c_ijab

    return (L_1, L_2)
예제 #15
0
def test_is_commutative():
    from sympy.physics.secondquant import NO, F, Fd
    m = Symbol('m', commutative=False)
    for f in (Sum, Product, Integral):
        assert f(z, (z, 1, 1)).is_commutative is True
        assert f(z * y, (z, 1, 6)).is_commutative is True
        assert f(m * x, (x, 1, 2)).is_commutative is False

        assert f(NO(Fd(x) * F(y)) * z, (z, 1, 2)).is_commutative is False
예제 #16
0
def test_contraction():
    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    p, q, r, s = symbols('p,q,r,s')
    assert contraction(Fd(i), F(j)) == KroneckerDelta(i, j)
    assert contraction(F(a), Fd(b)) == KroneckerDelta(a, b)
    assert contraction(F(a), Fd(i)) == 0
    assert contraction(Fd(a), F(i)) == 0
    assert contraction(F(i), Fd(a)) == 0
    assert contraction(Fd(i), F(a)) == 0
    assert contraction(Fd(i), F(p)) == KroneckerDelta(i, p)
    restr = evaluate_deltas(contraction(Fd(p), F(q)))
    assert restr.is_only_below_fermi
    restr = evaluate_deltas(contraction(F(p), Fd(q)))
    assert restr.is_only_above_fermi
예제 #17
0
def test_contraction():
    i, j, k, l = symbols("i,j,k,l", below_fermi=True)
    a, b, c, d = symbols("a,b,c,d", above_fermi=True)
    p, q, r, s = symbols("p,q,r,s")
    assert contraction(Fd(i), F(j)) == KroneckerDelta(i, j)
    assert contraction(F(a), Fd(b)) == KroneckerDelta(a, b)
    assert contraction(F(a), Fd(i)) == 0
    assert contraction(Fd(a), F(i)) == 0
    assert contraction(F(i), Fd(a)) == 0
    assert contraction(Fd(i), F(a)) == 0
    assert contraction(Fd(i), F(p)) == KroneckerDelta(i, p)
    restr = evaluate_deltas(contraction(Fd(p), F(q)))
    assert restr.is_only_below_fermi
    restr = evaluate_deltas(contraction(F(p), Fd(q)))
    assert restr.is_only_above_fermi
    raises(ContractionAppliesOnlyToFermions, lambda: contraction(B(a), Fd(b)))
예제 #18
0
def L1(expr):                                                           
 j1,j2,j3 = symbols('j1,j2,j3' ,below_fermi=True, cls=Dummy)                          
 b1,b2,b3 = symbols('b1,b2,b3' ,above_fermi=True, cls=Dummy)

 if   expr == "IP":                                                             
  L1 = Fraction(1, 1)*AntiSymmetricTensor('l',(j1,),())*Fd(j1)
  return L1                                                                     
 elif expr == "DIP":                                                            
  L1 = Fraction(1, 2)*AntiSymmetricTensor('l',(j1,j2),())*Fd(j1)*Fd(j2)          
  return L1
 elif expr == "EA":
  L1 = Fraction(1, 1)*AntiSymmetricTensor('l',(),(b1,))*F(b1)
  return L1
 elif expr == "DEA":
  L1 = Fraction(1, 2)*AntiSymmetricTensor('l',(),(b1,b2))*F(b2)*F(b1)
  return L1                                                                   
 elif expr == "EE":
  L1 = Fraction(1, 1)*AntiSymmetricTensor('l',(j1,),(b1,))*Fd(j1)*F(b1)
  return L1
 elif expr == "CCSD":
  L1 = Fraction(1, 1)*AntiSymmetricTensor('l',(j1,),(b1,))*Fd(j1)*F(b1)
  return L1
예제 #19
0
def R1(expr):                                                           

 i1,i2,i3 = symbols('i1,i2,i3' ,below_fermi=True, cls=Dummy)                          
 a1,a2,a3 = symbols('a1,a2,i3' ,above_fermi=True, cls=Dummy)

 if   expr == "IP":                                                             
  R1 = Fraction(1, 1)*AntiSymmetricTensor('r',(),(i1,))*(F(i1))                                                            
  return R1                                                                     
 elif expr == "DIP":                                                            
  R1 = Fraction(1, 2)*AntiSymmetricTensor('r',(),(i1,i2))*F(i2)*F(i1)          
  return R1
 elif expr == "EA":
  R1 = Fraction(1, 1)*AntiSymmetricTensor('r',(a1,),())*Fd(a1)
  return R1
 elif expr == "DEA":
  R1 = Fraction(1, 2)*AntiSymmetricTensor('r',(a1,a2),())*NO(Fd(a1)*Fd(a2))
  return R1                                                                   
 elif expr == "EE":
  R1 = Fraction(1, 1)*AntiSymmetricTensor('r',(a1,),(i1,))*Fd(a1)*F(i1)
  return R1
 elif expr == "CCSD":
  R1 = 0
  return R1
예제 #20
0
def R2(expr):                                                           
 i1,i2,i3,i4,i5 = symbols('i1,i2,i3,i4,i5' ,below_fermi=True, cls=Dummy)
 a1,a2,a3,a4,a5 = symbols('a1,a2,a3,a4,a5' ,above_fermi=True, cls=Dummy)                          
 if   expr == "IP":                                                             
  R2 = Fraction(1, 2)*AntiSymmetricTensor('r',(a1,),(i2,i3))*Fd(a1)*F(i3)*F(i2)                  
  return R2                                                                     
 elif expr == "DIP":                                                            
  R2 = Fraction(1, 6)*AntiSymmetricTensor('r',(a1,),(i3,i4,i5))*Fd(a1)*F(i5)*F(i4)*F(i3)          
  return R2
 elif expr == "EA":
  R2 = Fraction(1, 2)*AntiSymmetricTensor('r',(a2,a3),(i1,))*Fd(a2)*Fd(a3)*F(i1)
  return R2
 elif expr == "DEA":
  R2 = Fraction(1, 6)*AntiSymmetricTensor('r',(a3,a4,a5),(i1,))*NO(Fd(a3)*Fd(a4)*Fd(a5)*F(i1))
  return R2                                                                   
 elif expr == "EE":
  R2 = Fraction(1, 4)*AntiSymmetricTensor('r',(a2,a3),(i2,i3))*Fd(a2)*Fd(a3)*F(i3)*F(i2)
  return R2
 elif expr == "CCSD":
  R2 = 0
  return R2
예제 #21
0
def test_annihilate_f():
    i, j, n, m = symbols('i,j,n,m')
    o = F(i)
    assert isinstance(o, AnnihilateFermion)
    o = o.subs(i, j)
    assert o.atoms(Symbol) == {j}
    o = F(1)
    assert o.apply_operator(FKet([1, n])) == FKet([n])
    assert o.apply_operator(FKet([n, 1])) == -FKet([n])
    o = F(n)
    assert o.apply_operator(FKet([n])) == FKet([])

    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    p, q, r, s = symbols('p,q,r,s')
    assert F(i).apply_operator(FKet([i, j, k], 4)) == 0
    assert F(a).apply_operator(FKet([i, b, k], 4)) == 0
    assert F(l).apply_operator(FKet([i, j, k], 3)) == 0
    assert F(l).apply_operator(FKet([i, j, k], 4)) == FKet([l, i, j, k], 4)
예제 #22
0
def test_fully_contracted():
    i, j, k, l = symbols('i j k l', below_fermi=True)
    a, b, c, d = symbols('a b c d', above_fermi=True)
    p, q, r, s = symbols('p q r s', cls=Dummy)

    Fock = (AntiSymmetricTensor('f', (p, ), (q, )) * NO(Fd(p) * F(q)))
    V = (AntiSymmetricTensor('v', (p, q),
                             (r, s)) * NO(Fd(p) * Fd(q) * F(s) * F(r))) / 4

    Fai = wicks(NO(Fd(i) * F(a)) * Fock,
                keep_only_fully_contracted=True,
                simplify_kronecker_deltas=True)
    assert Fai == AntiSymmetricTensor('f', (a, ), (i, ))
    Vabij = wicks(NO(Fd(i) * Fd(j) * F(b) * F(a)) * V,
                  keep_only_fully_contracted=True,
                  simplify_kronecker_deltas=True)
    assert Vabij == AntiSymmetricTensor('v', (a, b), (i, j))
예제 #23
0
def test_get_subNO():
    p, q, r = symbols("p,q,r")
    assert NO(F(p) * F(q) * F(r)).get_subNO(1) == NO(F(p) * F(r))
    assert NO(F(p) * F(q) * F(r)).get_subNO(0) == NO(F(q) * F(r))
    assert NO(F(p) * F(q) * F(r)).get_subNO(2) == NO(F(p) * F(q))
예제 #24
0
def test_substitute_dummies_SQ_operator():
    i, j = symbols("i j", cls=Dummy)
    assert substitute_dummies(att(i, j) * Fd(i) * F(j) - att(j, i) * Fd(j) * F(i)) == 0
예제 #25
0
def test_sorting():
    i, j = symbols("i,j", below_fermi=True)
    a, b = symbols("a,b", above_fermi=True)
    p, q = symbols("p,q")

    # p, q
    assert _sort_anticommuting_fermions([Fd(p), F(q)]) == ([Fd(p), F(q)], 0)
    assert _sort_anticommuting_fermions([F(p), Fd(q)]) == ([Fd(q), F(p)], 1)

    # i, p
    assert _sort_anticommuting_fermions([F(p), Fd(i)]) == ([F(p), Fd(i)], 0)
    assert _sort_anticommuting_fermions([Fd(i), F(p)]) == ([F(p), Fd(i)], 1)
    assert _sort_anticommuting_fermions([Fd(p), Fd(i)]) == ([Fd(p), Fd(i)], 0)
    assert _sort_anticommuting_fermions([Fd(i), Fd(p)]) == ([Fd(p), Fd(i)], 1)
    assert _sort_anticommuting_fermions([F(p), F(i)]) == ([F(i), F(p)], 1)
    assert _sort_anticommuting_fermions([F(i), F(p)]) == ([F(i), F(p)], 0)
    assert _sort_anticommuting_fermions([Fd(p), F(i)]) == ([F(i), Fd(p)], 1)
    assert _sort_anticommuting_fermions([F(i), Fd(p)]) == ([F(i), Fd(p)], 0)

    # a, p
    assert _sort_anticommuting_fermions([F(p), Fd(a)]) == ([Fd(a), F(p)], 1)
    assert _sort_anticommuting_fermions([Fd(a), F(p)]) == ([Fd(a), F(p)], 0)
    assert _sort_anticommuting_fermions([Fd(p), Fd(a)]) == ([Fd(a), Fd(p)], 1)
    assert _sort_anticommuting_fermions([Fd(a), Fd(p)]) == ([Fd(a), Fd(p)], 0)
    assert _sort_anticommuting_fermions([F(p), F(a)]) == ([F(p), F(a)], 0)
    assert _sort_anticommuting_fermions([F(a), F(p)]) == ([F(p), F(a)], 1)
    assert _sort_anticommuting_fermions([Fd(p), F(a)]) == ([Fd(p), F(a)], 0)
    assert _sort_anticommuting_fermions([F(a), Fd(p)]) == ([Fd(p), F(a)], 1)

    # i, a
    assert _sort_anticommuting_fermions([F(i), Fd(j)]) == ([F(i), Fd(j)], 0)
    assert _sort_anticommuting_fermions([Fd(j), F(i)]) == ([F(i), Fd(j)], 1)
    assert _sort_anticommuting_fermions([Fd(a), Fd(i)]) == ([Fd(a), Fd(i)], 0)
    assert _sort_anticommuting_fermions([Fd(i), Fd(a)]) == ([Fd(a), Fd(i)], 1)
    assert _sort_anticommuting_fermions([F(a), F(i)]) == ([F(i), F(a)], 1)
    assert _sort_anticommuting_fermions([F(i), F(a)]) == ([F(i), F(a)], 0)
예제 #26
0
def test_NO():
    i, j, k, l = symbols("i j k l", below_fermi=True)
    a, b, c, d = symbols("a b c d", above_fermi=True)
    p, q, r, s = symbols("p q r s", cls=Dummy)

    assert NO(Fd(p) * F(q) + Fd(a) * F(b)) == NO(Fd(p) * F(q)) + NO(Fd(a) * F(b))
    assert NO(Fd(i) * NO(F(j) * Fd(a))) == NO(Fd(i) * F(j) * Fd(a))
    assert NO(1) == 1
    assert NO(i) == i
    assert NO(Fd(a) * Fd(b) * (F(c) + F(d))) == NO(Fd(a) * Fd(b) * F(c)) + NO(
        Fd(a) * Fd(b) * F(d)
    )

    assert NO(Fd(a) * F(b))._remove_brackets() == Fd(a) * F(b)
    assert NO(F(j) * Fd(i))._remove_brackets() == F(j) * Fd(i)

    assert NO(Fd(p) * F(q)).subs(Fd(p), Fd(a) + Fd(i)) == NO(Fd(a) * F(q)) + NO(
        Fd(i) * F(q)
    )
    assert NO(Fd(p) * F(q)).subs(F(q), F(a) + F(i)) == NO(Fd(p) * F(a)) + NO(
        Fd(p) * F(i)
    )

    expr = NO(Fd(p) * F(q))._remove_brackets()
    assert wicks(expr) == NO(expr)

    assert NO(Fd(a) * F(b)) == -NO(F(b) * Fd(a))

    no = NO(Fd(a) * F(i) * F(b) * Fd(j))
    l1 = [ind for ind in no.iter_q_creators()]
    assert l1 == [0, 1]
    l2 = [ind for ind in no.iter_q_annihilators()]
    assert l2 == [3, 2]
    no = NO(Fd(a) * Fd(i))
    assert no.has_q_creators == 1
    assert no.has_q_annihilators == -1
    assert str(no) == ":CreateFermion(a)*CreateFermion(i):"
    assert repr(no) == "NO(CreateFermion(a)*CreateFermion(i))"
    assert latex(no) == r"\left\{a^\dagger_{a} a^\dagger_{i}\right\}"
    raises(NotImplementedError, lambda: NO(Bd(p) * F(q)))
예제 #27
0
def test_wicks():
    p, q, r, s = symbols("p,q,r,s", above_fermi=True)

    # Testing for particles only

    str = F(p) * Fd(q)
    assert wicks(str) == NO(F(p) * Fd(q)) + KroneckerDelta(p, q)
    str = Fd(p) * F(q)
    assert wicks(str) == NO(Fd(p) * F(q))

    str = F(p) * Fd(q) * F(r) * Fd(s)
    nstr = wicks(str)
    fasit = NO(
        KroneckerDelta(p, q) * KroneckerDelta(r, s)
        + KroneckerDelta(p, q) * AnnihilateFermion(r) * CreateFermion(s)
        + KroneckerDelta(r, s) * AnnihilateFermion(p) * CreateFermion(q)
        - KroneckerDelta(p, s) * AnnihilateFermion(r) * CreateFermion(q)
        - AnnihilateFermion(p)
        * AnnihilateFermion(r)
        * CreateFermion(q)
        * CreateFermion(s)
    )
    assert nstr == fasit

    assert (p * q * nstr).expand() == wicks(p * q * str)
    assert (nstr * p * q * 2).expand() == wicks(str * p * q * 2)

    # Testing CC equations particles and holes
    i, j, k, l = symbols("i j k l", below_fermi=True, cls=Dummy)
    a, b, c, d = symbols("a b c d", above_fermi=True, cls=Dummy)
    p, q, r, s = symbols("p q r s", cls=Dummy)

    assert wicks(F(a) * NO(F(i) * F(j)) * Fd(b)) == NO(
        F(a) * F(i) * F(j) * Fd(b)
    ) + KroneckerDelta(a, b) * NO(F(i) * F(j))
    assert wicks(F(a) * NO(F(i) * F(j) * F(k)) * Fd(b)) == NO(
        F(a) * F(i) * F(j) * F(k) * Fd(b)
    ) - KroneckerDelta(a, b) * NO(F(i) * F(j) * F(k))

    expr = wicks(Fd(i) * NO(Fd(j) * F(k)) * F(l))
    assert expr == -KroneckerDelta(i, k) * NO(Fd(j) * F(l)) - KroneckerDelta(j, l) * NO(
        Fd(i) * F(k)
    ) - KroneckerDelta(i, k) * KroneckerDelta(j, l) + KroneckerDelta(i, l) * NO(
        Fd(j) * F(k)
    ) + NO(
        Fd(i) * Fd(j) * F(k) * F(l)
    )
    expr = wicks(F(a) * NO(F(b) * Fd(c)) * Fd(d))
    assert expr == -KroneckerDelta(a, c) * NO(F(b) * Fd(d)) - KroneckerDelta(b, d) * NO(
        F(a) * Fd(c)
    ) - KroneckerDelta(a, c) * KroneckerDelta(b, d) + KroneckerDelta(a, d) * NO(
        F(b) * Fd(c)
    ) + NO(
        F(a) * F(b) * Fd(c) * Fd(d)
    )
예제 #28
0
def test_annihilate_f():
    i, j, n, m = symbols("i,j,n,m")
    o = F(i)
    assert isinstance(o, AnnihilateFermion)
    o = o.subs(i, j)
    assert o.atoms(Symbol) == {j}
    o = F(1)
    assert o.apply_operator(FKet([1, n])) == FKet([n])
    assert o.apply_operator(FKet([n, 1])) == -FKet([n])
    o = F(n)
    assert o.apply_operator(FKet([n])) == FKet([])

    i, j, k, l = symbols("i,j,k,l", below_fermi=True)
    a, b, c, d = symbols("a,b,c,d", above_fermi=True)
    p, q, r, s = symbols("p,q,r,s")
    assert F(i).apply_operator(FKet([i, j, k], 4)) == 0
    assert F(a).apply_operator(FKet([i, b, k], 4)) == 0
    assert F(l).apply_operator(FKet([i, j, k], 3)) == 0
    assert F(l).apply_operator(FKet([i, j, k], 4)) == FKet([l, i, j, k], 4)
    assert str(F(p)) == "f(p)"
    assert repr(F(p)) == "AnnihilateFermion(p)"
    assert srepr(F(p)) == "AnnihilateFermion(Symbol('p'))"
    assert latex(F(p)) == "a_{p}"
예제 #29
0
def test_commutation():
    n, m = symbols("n,m", above_fermi=True)
    c = Commutator(B(0), Bd(0))
    assert c == 1
    c = Commutator(Bd(0), B(0))
    assert c == -1
    c = Commutator(B(n), Bd(0))
    assert c == KroneckerDelta(n, 0)
    c = Commutator(B(0), B(0))
    assert c == 0
    c = Commutator(B(0), Bd(0))
    e = simplify(apply_operators(c * BKet([n])))
    assert e == BKet([n])
    c = Commutator(B(0), B(1))
    e = simplify(apply_operators(c * BKet([n, m])))
    assert e == 0

    c = Commutator(F(m), Fd(m))
    assert c == +1 - 2 * NO(Fd(m) * F(m))
    c = Commutator(Fd(m), F(m))
    assert c.expand() == -1 + 2 * NO(Fd(m) * F(m))

    C = Commutator
    X, Y, Z = symbols("X,Y,Z", commutative=False)
    assert C(C(X, Y), Z) != 0
    assert C(C(X, Z), Y) != 0
    assert C(Y, C(X, Z)) != 0

    i, j, k, l = symbols("i,j,k,l", below_fermi=True)
    a, b, c, d = symbols("a,b,c,d", above_fermi=True)
    p, q, r, s = symbols("p,q,r,s")
    D = KroneckerDelta

    assert C(Fd(a), F(i)) == -2 * NO(F(i) * Fd(a))
    assert C(Fd(j), NO(Fd(a) * F(i))).doit(wicks=True) == -D(j, i) * Fd(a)
    assert C(Fd(a) * F(i), Fd(b) * F(j)).doit(wicks=True) == 0

    c1 = Commutator(F(a), Fd(a))
    assert Commutator.eval(c1, c1) == 0
    c = Commutator(Fd(a) * F(i), Fd(b) * F(j))
    assert latex(c) == r"\left[a^\dagger_{a} a_{i},a^\dagger_{b} a_{j}\right]"
    assert (
        repr(c)
        == "Commutator(CreateFermion(a)*AnnihilateFermion(i),CreateFermion(b)*AnnihilateFermion(j))"
    )
    assert (
        str(c)
        == "[CreateFermion(a)*AnnihilateFermion(i),CreateFermion(b)*AnnihilateFermion(j)]"
    )
예제 #30
0
def test_equality():
    # if this fails remove special handling below
    raises(ValueError, lambda: Sum(x, x))
    r = symbols('x', real=True)
    for F in (Sum, Product, Integral):
        try:
            assert F(x, x) != F(y, y)
            assert F(x, (x, 1, 2)) != F(x, x)
            assert F(x, (x, x)) != F(x, x)  # or else they print the same
            assert F(1, x) != F(1, y)
        except ValueError:
            pass
        assert F(a, (x, 1, 2)) != F(a, (x, 1, 3))
        assert F(a, (x, 1, 2)) != F(b, (x, 1, 2))
        assert F(x, (x, 1, 2)) != F(r, (r, 1, 2))
        assert F(1, (x, 1, x)) != F(1, (y, 1, x))
        assert F(1, (x, 1, x)) != F(1, (y, 1, y))

    # issue 5265
    assert Sum(x, (x, 1, x)).subs(x, a) == Sum(x, (x, 1, a))