Esempio n. 1
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]
Esempio n. 2
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
Esempio n. 3
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)]"
    )
Esempio n. 4
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)
Esempio n. 5
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))
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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
Esempio n. 9
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)))
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
0
def main():
    print()
    print("Calculates the Coupled-Cluster energy- and amplitude equations")
    print("See 'An Introduction to Coupled Cluster Theory' by")
    print("T. Daniel Crawford and Henry F. Schaefer III")
    print(
        "Reference to a Lecture Series: http://vergil.chemistry.gatech.edu/notes/sahan-cc-2010.pdf"
    )
    print()

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

    H = f * pr + Rational(1, 4) * v * pqsr
    print("Using the hamiltonian:", latex(H))

    print("Calculating 4 nested commutators")
    C = Commutator

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 1...")
    comm1 = wicks(C(H, T))
    comm1 = evaluate_deltas(comm1)
    comm1 = substitute_dummies(comm1)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 2...")
    comm2 = wicks(C(comm1, T))
    comm2 = evaluate_deltas(comm2)
    comm2 = substitute_dummies(comm2)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 3...")
    comm3 = wicks(C(comm2, T))
    comm3 = evaluate_deltas(comm3)
    comm3 = substitute_dummies(comm3)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 4...")
    comm4 = wicks(C(comm3, T))
    comm4 = evaluate_deltas(comm4)
    comm4 = substitute_dummies(comm4)

    print("construct Hausdorff expansion...")
    eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24
    eq = eq.expand()
    eq = evaluate_deltas(eq)
    eq = substitute_dummies(eq,
                            new_indices=True,
                            pretty_indices=pretty_dummies_dict)
    print("*********************")
    print()

    print("extracting CC equations from full Hbar")
    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    print()
    print("CC Energy:")
    print(
        latex(wicks(eq, simplify_dummies=True,
                    keep_only_fully_contracted=True)))

    # print("HERE")
    # print("HERE")
    # print("HERE")
    # print(pycode(wicks(eq, simplify_dummies=True,
    #     keep_only_fully_contracted=True)))
    # with open("cc_energy.py", "w") as f:
    # f.
    with open("ccsd.jl", "w") as f:
        eq_energy = wicks(eq,
                          simplify_dummies=True,
                          keep_only_fully_contracted=True)
        f.write(julia_code(eq_energy))

    print()
    print("CC T1:")
    eqT1 = wicks(NO(Fd(i) * F(a)) * eq,
                 simplify_kronecker_deltas=True,
                 keep_only_fully_contracted=True)
    eqT1 = substitute_dummies(eqT1)
    print(latex(eqT1))
    print()
    print("CC T2:")
    eqT2 = wicks(NO(Fd(i) * Fd(j) * F(b) * F(a)) * eq,
                 simplify_dummies=True,
                 keep_only_fully_contracted=True,
                 simplify_kronecker_deltas=True)
    # P = PermutationOperator
    # eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)])
    print(latex(eqT2))
    print(latex(simplify(eqT2)))
Esempio n. 13
0
def test_sympy__physics__secondquant__NO():
    from sympy.physics.secondquant import NO, F, Fd
    assert _test_args(NO(Fd(x) * F(y)))
Esempio n. 14
0
def main():
    print()
    print("Calculates the Coupled-Cluster energy- and amplitude equations")
    print("See 'An Introduction to Coupled Cluster Theory' by")
    print("T. Daniel Crawford and Henry F. Schaefer III")
    print("http://www.ccc.uga.edu/lec_top/cc/html/review.html")
    print()

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

    H = f*pr + Rational(1, 4)*v*pqsr
    print("Using the hamiltonian:", latex(H))

    print("Calculating 4 nested commutators")
    C = Commutator

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 1...")
    comm1 = wicks(C(H, T))
    comm1 = evaluate_deltas(comm1)
    comm1 = substitute_dummies(comm1)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 2...")
    comm2 = wicks(C(comm1, T))
    comm2 = evaluate_deltas(comm2)
    comm2 = substitute_dummies(comm2)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 3...")
    comm3 = wicks(C(comm2, T))
    comm3 = evaluate_deltas(comm3)
    comm3 = substitute_dummies(comm3)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 4...")
    comm4 = wicks(C(comm3, T))
    comm4 = evaluate_deltas(comm4)
    comm4 = substitute_dummies(comm4)

    print("construct Hausdoff expansion...")
    eq = H + comm1 + comm2/2 + comm3/6 + comm4/24
    eq = eq.expand()
    eq = evaluate_deltas(eq)
    eq = substitute_dummies(eq, new_indices=True,
            pretty_indices=pretty_dummies_dict)
    print("*********************")
    print()

    print("extracting CC equations from full Hbar")
    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    print()
    print("CC Energy:")
    print(latex(wicks(eq, simplify_dummies=True,
        keep_only_fully_contracted=True)))
    print()
    print("CC T1:")
    eqT1 = wicks(NO(Fd(i)*F(a))*eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True)
    eqT1 = substitute_dummies(eqT1)
    print(latex(eqT1))
    print()
    print("CC T2:")
    eqT2 = wicks(NO(Fd(i)*Fd(j)*F(b)*F(a))*eq, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True)
    P = PermutationOperator
    eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)])
    print(latex(eqT2))
Esempio n. 15
0
def test_substitute_dummies_NO_operator():
    i, j = symbols("i j", cls=Dummy)
    assert (
        substitute_dummies(att(i, j) * NO(Fd(i) * F(j)) - att(j, i) * NO(Fd(j) * F(i)))
        == 0
    )
Esempio n. 16
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)
    )
Esempio n. 17
0
    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)


p, q, r, s = symbols('p,q,r,s', cls=Dummy)
#Setup Hamiltonian on normal ordered form
E0 = symbols('Eref', real=True, constant=True)  #Reference energy

f = AntiSymmetricTensor('f', (p, ), (q, ))
pq = NO((Fd(p) * F(q)))
Fock = f * pq  #F is reserved by sympy

V = AntiSymmetricTensor('V', (p, q), (r, s))
pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r))

HI = Rational(1, 4) * V * pqsr

HN = E0 + F + HI

i, j, k, l = symbols('i,j,k,l', below_fermi=True)
a, b, c, d = symbols('a,b,c,d', above_fermi=True)

print("Compute CCD energy and amplitude equations term by term")
#BCH: HN + [HN,T] + 0.5*[[HN,T],T] + 1/6 * [[[HN,T],T],T] + 1/24 * [[[[HN,T],T],T],T]
Esempio n. 18
0
def LVECTORS(L0, L1, L2, flavor):
    display(
        Markdown(
            rf""" Computing left sigma amplitudes for {flavor} (skipping summation for dummy variables)"""
        ))

    p, q, r, s = symbols('p,q,r,s', cls=Dummy)
    f = AntiSymmetricTensor('f', (p, ), (q, ))
    pr = NO((Fd(p) * F(q)))
    v = AntiSymmetricTensor('v', (p, q), (r, s))
    pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r))
    ham = f * pr + Rational(1, 4) * v * pqsr

    cc = BCH.level(ham, "SD")
    E_cc = evaluate_deltas(wicks(cc, keep_only_fully_contracted=True))

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

    if flavor == "IP":
        sig11 = evaluate_deltas(
            wicks(L1 * (cc - E_cc) * F(i), keep_only_fully_contracted=True))
        index_rule = {'below': 'jklmno', 'above': 'abcdefg'}
        sig11 = substitute_dummies(sig11,
                                   new_indices=True,
                                   pretty_indices=index_rule)
    if flavor == "EA":
        sig11 = evaluate_deltas(
            wicks(L1 * (cc - E_cc) * Fd(a), keep_only_fully_contracted=True))
        index_rule = {'below': 'ijklmno', 'above': 'bcdefg'}
        sig11 = substitute_dummies(sig11,
                                   new_indices=True,
                                   pretty_indices=index_rule)
    if flavor == "DIP":
        PermutList = [PermutationOperator(i, j)]
        sig11 = evaluate_deltas(
            wicks(L1 * (cc - E_cc) * F(j) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'klmno', 'above': 'abcdefg'}
        sig11 = substitute_dummies(sig11,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig11 = simplify_index_permutations(sig11, PermutList)
    if flavor == "DEA":
        PermutList = [PermutationOperator(a, b)]
        sig11 = evaluate_deltas(
            wicks(L1 * (cc - E_cc) * Fd(a) * Fd(b),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'ijklmno', 'above': 'cdefg'}
        sig11 = substitute_dummies(sig11,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig11 = simplify_index_permutations(sig11, PermutList)

    sigma_11 = Symbol('(L_{1}(\overline{H}_{SS}-E_{cc}))')
    final_eq = Eq(sigma_11, sig11)
    display(final_eq)

    if flavor == "IP":
        PermutList = [PermutationOperator(i, j)]
        sig12 = evaluate_deltas(
            wicks((L2 * cc) * F(i), keep_only_fully_contracted=True))
        index_rule = {'below': 'jklmno', 'above': 'abcdefg'}
        sig12 = substitute_dummies(sig12,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig12 = simplify_index_permutations(sig12, PermutList)
    if flavor == "EA":
        PermutList = [PermutationOperator(a, b)]
        sig12 = evaluate_deltas(
            wicks((L2 * cc) * Fd(a), keep_only_fully_contracted=True))
        index_rule = {'below': 'ijklmno', 'above': 'bcdefg'}
        sig12 = substitute_dummies(sig12,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig12 = simplify_index_permutations(sig12, PermutList)
    if flavor == "DIP":
        PermutList = [
            PermutationOperator(i, j),
            PermutationOperator(j, k),
            PermutationOperator(i, k)
        ]
        sig12 = evaluate_deltas(
            wicks(L2 * cc * F(j) * F(i), keep_only_fully_contracted=True))
        index_rule = {'below': 'klmno', 'above': 'abcdefg'}
        sig12 = substitute_dummies(sig12,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig12 = simplify_index_permutations(sig12, PermutList)
    if flavor == "DEA":
        PermutList = [
            PermutationOperator(a, b),
            PermutationOperator(b, c),
            PermutationOperator(a, c)
        ]
        sig12 = evaluate_deltas(
            wicks((L2 * cc) * Fd(a) * Fd(b), keep_only_fully_contracted=True))
        index_rule = {'below': 'ijklmno', 'above': 'cdefg'}
        sig12 = substitute_dummies(sig12,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig12 = simplify_index_permutations(sig12, PermutList)

    sigma_12 = Symbol('(L_{2}\overline{H}_{DS})')
    final_eq = Eq(sigma_12, sig12)
    display(final_eq)

    if flavor == "IP":
        sig21 = evaluate_deltas(
            wicks((L1 * cc) * Fd(a) * F(j) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'klmno', 'above': 'bcdefgh'}
        sig21 = substitute_dummies(sig21,
                                   new_indices=True,
                                   pretty_indices=index_rule)
    if flavor == "EA":
        sig21 = evaluate_deltas(
            wicks((L1 * cc) * Fd(a) * Fd(b) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'jklmno', 'above': 'cdefgh'}
        sig21 = substitute_dummies(sig21,
                                   new_indices=True,
                                   pretty_indices=index_rule)
    if flavor == "DIP":
        PermutList = [PermutationOperator(i, j)]
        sig21 = evaluate_deltas(
            wicks(L1 * cc * Fd(a) * F(k) * F(j) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'lmno', 'above': 'bcdefgh'}
        sig21 = substitute_dummies(sig21,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig21 = simplify_index_permutations(sig21, PermutList)
    if flavor == "DEA":
        PermutList = [PermutationOperator(a, b)]
        sig21 = evaluate_deltas(
            wicks((L1 * cc) * Fd(a) * Fd(b) * Fd(c) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'jklmno', 'above': 'defgh'}
        sig21 = substitute_dummies(sig21,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig21 = simplify_index_permutations(sig21, PermutList)

    sigma_21 = Symbol('(L_{1}\overline{H}_{SD})')
    final_eq = Eq(sigma_21, sig21)
    display(final_eq)

    if flavor == "IP":
        PermutList = [PermutationOperator(i, j)]
        sig22 = evaluate_deltas(
            wicks(L2 * (cc - E_cc) * Fd(a) * F(j) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'klmno', 'above': 'bcdefgh'}
        sig22 = substitute_dummies(sig22,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig22 = simplify_index_permutations(sig22, PermutList)
    if flavor == "EA":
        PermutList = [PermutationOperator(a, b)]
        sig22 = evaluate_deltas(
            wicks(L2 * (cc - E_cc) * Fd(a) * Fd(b) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'jklmno', 'above': 'cdefgh'}
        sig22 = substitute_dummies(sig22,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig22 = simplify_index_permutations(sig22, PermutList)
    if flavor == "DIP":
        PermutList = [
            PermutationOperator(i, j),
            PermutationOperator(j, k),
            PermutationOperator(i, k)
        ]
        sig22 = evaluate_deltas(
            wicks(L2 * (cc - E_cc) * Fd(a) * F(k) * F(j) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'lmno', 'above': 'bcdefgh'}
        sig22 = substitute_dummies(sig22,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig22 = simplify_index_permutations(sig22, PermutList)
    if flavor == "DEA":
        PermutList = [
            PermutationOperator(a, b),
            PermutationOperator(b, c),
            PermutationOperator(a, c)
        ]
        sig22 = evaluate_deltas(
            wicks(L2 * (cc - E_cc) * Fd(a) * Fd(b) * Fd(c) * F(i),
                  keep_only_fully_contracted=True))
        index_rule = {'below': 'jklmno', 'above': 'defgh'}
        sig22 = substitute_dummies(sig22,
                                   new_indices=True,
                                   pretty_indices=index_rule)
        sig22 = simplify_index_permutations(sig22, PermutList)

    sigma_22 = Symbol('(L_{2}(\overline{H}_{DD}-E_{cc}))')
    final_eq = Eq(sigma_22, sig22)
    display(final_eq)
Esempio n. 19
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)))
Esempio n. 20
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]
Esempio n. 21
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))
Esempio n. 22
0
Eref = evaluate_deltas(wicks(H, keep_only_fully_contracted=True))
Eref = substitute_dummies(Eref,
                          new_indices=True,
                          pretty_indices=pretty_dummies_dict)

print("Eref: ", latex(Eref))
print()
print("Normal ordered Hamiltonian")
print(latex(H_N))
print()

#Setup Hamiltonian on normal ordered form
E0 = symbols('Eref', real=True, constant=True)  #Reference energy

f = AntiSymmetricTensor('f', (p, ), (q, ))
pq = NO(ap_dagger * aq)

V = AntiSymmetricTensor('V', (p, q), (r, s))
pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r))

HI = Rational(1, 4) * V * pqsr
Fock = f * pq  #F is reserved by sympy

HN = E0 + Fock + HI

#Compute <c|F|Phi_i^a>

#Define indices above and below Fermi level
i, j, k, l = symbols('i,j,k,l', below_fermi=True)
a, b, c, d = symbols('a,b,c,d', above_fermi=True)