Exemple #1
0
def test_create_f():
    i, j, n, m = symbols('i,j,n,m')
    o = Fd(i)
    assert isinstance(o, CreateFermion)
    o = o.subs(i, j)
    assert o.atoms(Symbol) == {j}
    o = Fd(1)
    assert o.apply_operator(FKet([n])) == FKet([1, n])
    assert o.apply_operator(FKet([n])) == -FKet([n, 1])
    o = Fd(n)
    assert o.apply_operator(FKet([])) == FKet([n])

    vacuum = FKet([], fermi_level=4)
    assert vacuum == FKet([], fermi_level=4)

    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 Fd(i).apply_operator(FKet([i, j, k], 4)) == FKet([j, k], 4)
    assert Fd(a).apply_operator(FKet([i, b, k], 4)) == FKet([a, i, b, k], 4)

    assert Dagger(B(p)).apply_operator(q) == q*CreateBoson(p)
    assert repr(Fd(p)) == 'CreateFermion(p)'
    assert srepr(Fd(p)) == "CreateFermion(Symbol('p'))"
    assert latex(Fd(p)) == r'a^\dagger_{p}'
Exemple #2
0
def test_create_f():
    i, j, n, m = symbols('i j n m')
    o = Fd(i)
    assert isinstance(o, CreateFermion)
    o = o.subs(i, j)
    assert o.atoms(Symbol) == set([j])
    o = Fd(1)
    assert o.apply_operator(FKet([n])) == FKet([1,n])
    assert o.apply_operator(FKet([n])) ==-FKet([n,1])
    o = Fd(n)
    assert o.apply_operator(FKet([])) == FKet([n])

    vacuum = FKet([],fermi_level=4)
    assert vacuum == FKet([],fermi_level=4)

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

    assert Fd(i).apply_operator(FKet([i,j,k],4)) == FKet([j,k],4)
    assert Fd(a).apply_operator(FKet([i,b,k],4)) == FKet([a,i,b,k],4)
def test_create_f():
    i, j, n, m = symbols('i,j,n,m')
    o = Fd(i)
    assert isinstance(o, CreateFermion)
    o = o.subs(i, j)
    assert o.atoms(Symbol) == {j}
    o = Fd(1)
    assert o.apply_operator(FKet([n])) == FKet([1, n])
    assert o.apply_operator(FKet([n])) == -FKet([n, 1])
    o = Fd(n)
    assert o.apply_operator(FKet([])) == FKet([n])

    vacuum = FKet([], fermi_level=4)
    assert vacuum == FKet([], fermi_level=4)

    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 Fd(i).apply_operator(FKet([i, j, k], 4)) == FKet([j, k], 4)
    assert Fd(a).apply_operator(FKet([i, b, k], 4)) == FKet([a, i, b, k], 4)
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
Exemple #5
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)))
from sympy import symbols, latex, WildFunction, collect, Rational, simplify
from sympy.physics.secondquant import F, Fd, wicks, AntiSymmetricTensor, substitute_dummies, NO, evaluate deltas

"""
Define Hamiltonian and the second-quantized representation of a three-body Slater determinant.
"""

# Define Hamiltonian
p, q, r, s = symbols("p q r s", dummy=True)
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)
Hamiltonian = f * pr + Rational(1) / Rational(4) * v * pqsr
a, b, c, d, e, f = symbols("a, b, c, d, e, f", above_fermi=True)

# Create teh representatoin
expression = wicks(F(c) * F(b) * F(a) * Hamiltonian * Fd(d) * Fd(e) * Fd(f), keep_only_fully_contracted=True, simplify_kronecker_deltas=True)
expression = evaluate_deltas(expression)
expression = simplify(expression)
print(latex(expression))
Exemple #7
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))
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)
Exemple #9
0
def L2(expr):                                                           
 j1,j2,j3,j4,j5 = symbols('j1,j2,j3,j4,j5' ,below_fermi=True, cls=Dummy)
 b1,b2,b3,b4,b5 = symbols('b1,b2,b3,b4,b5' ,above_fermi=True, cls=Dummy)                          
 if   expr == "IP":                                                             
  L2 = Fraction(1, 2)*AntiSymmetricTensor('l',(j2,j3),(b1,))*Fd(j2)*Fd(j3)*F(b1)                  
  return L2                                                                     
 elif expr == "DIP":                                                            
  L2 = Fraction(1, 6)*AntiSymmetricTensor('l',(j3,j4,j5),(b1,))*Fd(j3)*Fd(j4)*Fd(j5)*F(b1)          
  return L2
 elif expr == "EA":
  L2 = Fraction(1, 2)*AntiSymmetricTensor('l',(j1,),(b2,b3))*Fd(j1)*F(b3)*F(b2)
  return L2
 elif expr == "DEA":
  L2 = Fraction(1, 6)*AntiSymmetricTensor('l',(j1,),(b3,b4,b5))*Fd(j1)*F(b5)*F(b4)*F(b3)
  return L2                                                                   
 elif expr == "EE":
  L2 = Fraction(1, 4)*AntiSymmetricTensor('l',(j2,j3),(b2,b3))*Fd(j2)*Fd(j3)*F(b3)*F(b2)
  return L2
 elif expr == "CCSD":
  L2 = Fraction(1, 4)*AntiSymmetricTensor('l',(j2,j3),(b2,b3))*Fd(j2)*Fd(j3)*F(b3)*F(b2)
  return L2
Exemple #10
0
def TPDM(L, R, flavor):

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

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

    oooo = Fd(i) * Fd(j) * F(l) * F(k)
    cc = BCH.level(oooo, "SD")
    g_oooo = evaluate_deltas(wicks(L * cc * R,
                                   keep_only_fully_contracted=True))
    PermutList = [PermutationOperator(i,j),PermutationOperator(i,k), \
               PermutationOperator(i,l),PermutationOperator(j,k), \
               PermutationOperator(j,l),PermutationOperator(k,l)]
    g_oooo = simplify_index_permutations(g_oooo, PermutList)
    index_rule = {'below': 'mnop', 'above': 'abcde'}
    g_oooo = substitute_dummies(g_oooo,
                                new_indices=True,
                                pretty_indices=index_rule)
    gamma = Symbol('\gamma_{ijkl}')
    final_eq = Eq(gamma, g_oooo)
    display(final_eq)

    ooov = Fd(i) * Fd(j) * F(a) * F(k)
    cc = BCH.level(ooov, "SD")
    g_ooov = evaluate_deltas(wicks(L * cc * R,
                                   keep_only_fully_contracted=True))
    PermutList = [PermutationOperator(i,j),PermutationOperator(i,k), \
               PermutationOperator(j,k)]
    g_ooov = simplify_index_permutations(g_ooov, PermutList)
    index_rule = {'below': 'lmnop', 'above': 'bcdef'}
    g_ooov = substitute_dummies(g_ooov,
                                new_indices=True,
                                pretty_indices=index_rule)
    gamma = Symbol('\gamma_{ijka}')
    final_eq = Eq(gamma, g_oo)
    display(final_eq)

    ooov = Fd(i) * Fd(a) * F(k) * F(j)
    cc = BCH.level(ooov, "SD")
    g_ovoo = evaluate_deltas(wicks(L * cc * R,
                                   keep_only_fully_contracted=True))
    PermutList = [PermutationOperator(i,j),PermutationOperator(i,k), \
               PermutationOperator(j,k)]
    g_ovoo = simplify_index_permutations(g_ovoo, PermutList)
    index_rule = {'below': 'lmnop', 'above': 'bcdef'}
    g_ovoo = substitute_dummies(g_ovoo,
                                new_indices=True,
                                pretty_indices=index_rule)
    gamma = Symbol('\gamma_{iajk}')
    final_eq = Eq(gamma, g_ovoo)
    display(final_eq)

    ovov = Fd(i) * Fd(a) * F(b) * F(j)
    cc = BCH.level(ovov, "SD")
    g_ovov = evaluate_deltas(wicks(L * cc * R,
                                   keep_only_fully_contracted=True))
    PermutList = [PermutationOperator(i, j), PermutationOperator(a, b)]
    g_ovov = simplify_index_permutations(g_ovov, PermutList)
    index_rule = {'below': 'klmno', 'above': 'cdef'}
    g_ovov = substitute_dummies(g_ovov,
                                new_indices=True,
                                pretty_indices=index_rule)
    gamma = Symbol('\gamma_{iajb}')
    final_eq = Eq(gamma, g_ovov)
    display(final_eq)

    ovvv = Fd(i) * Fd(a) * F(c) * F(b)
    cc = BCH.level(ovvv, "SD")
    g_ovvv = evaluate_deltas(wicks(L * cc * R,
                                   keep_only_fully_contracted=True))
    PermutList = [PermutationOperator(a,b),PermutationOperator(a,c), \
               PermutationOperator(b,c)]
    g_ovvv = simplify_index_permutations(g_ovvv, PermutList)
    index_rule = {'below': 'jklmn', 'above': 'defg'}
    g_ovvv = substitute_dummies(g_ovvv,
                                new_indices=True,
                                pretty_indices=index_rule)
    gamma = Symbol('\gamma_{iabc}')
    final_eq = Eq(gamma, g_ovvv)
    display(final_eq)

    oovv = Fd(i) * Fd(j) * F(b) * F(a)
    cc = BCH.level(oovv, "SD")
    g_oovv = evaluate_deltas(wicks(L * cc * R,
                                   keep_only_fully_contracted=True))
    PermutList = [PermutationOperator(i, j), PermutationOperator(a, b)]
    g_oovv = simplify_index_permutations(g_oovv, PermutList)
    index_rule = {'below': 'klmn', 'above': 'cdefg'}
    g_oovv = substitute_dummies(g_oovv,
                                new_indices=True,
                                pretty_indices=index_rule)
    gamma = Symbol('\gamma_{ijab}')
    final_eq = Eq(gamma, g_oovv)
    display(final_eq)
Exemple #11
0
                symbols("p", above_fermi=True, cls=Dummy),
                symbols("q", below_fermi=True, cls=Dummy),
            ),
        ),
        (
            "rho^{a}_{i} = ",
            (
                symbols("p", below_fermi=True, cls=Dummy),
                symbols("q", above_fermi=True, cls=Dummy),
            ),
        ),
        ("rho^{j}_{i} = ", symbols("p, q", below_fermi=True, cls=Dummy)),
    ]

    for label, (p, q) in symbol_list:
        c_pq = Fd(p) * F(q)

        T = sum(get_ccsd_t_operators())
        L = sum(get_ccsd_lambda_operators())

        # Only keep non-zero terms
        rho_eq = eval_equation(c_pq)
        rho_eq += eval_equation(Commutator(c_pq, T))
        rho_eq += eval_equation(L * c_pq)
        comm = Commutator(c_pq, T)
        rho_eq += eval_equation(L * comm)
        comm = Commutator(comm, sum(get_ccsd_t_operators()))
        rho_eq += Rational(1, 2) * eval_equation(L * comm)

        rho = rho_eq.expand()
        rho = evaluate_deltas(rho)
Exemple #12
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)
Exemple #13
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]
Exemple #14
0
from sympy.physics.secondquant import Commutator, F, Fd, wicks, NO
from sympy import symbols, simplify

a = symbols("b0:8")
exp = F(a[1])*F(a[0])*Fd(a[3])*Fd(a[2]) * F(a[4])*F(a[5])*Fd(a[6])*Fd(a[7])


exp = wicks(exp)
print(exp)
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)))
Exemple #16
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)]'
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]
Exemple #18
0
def test_create_f():
    i, j, n, m = symbols('i,j,n,m')
    o = Fd(i)
    assert isinstance(o, CreateFermion)
    o = o.subs(i, j)
    assert o.atoms(Symbol) == {j}
    o = Fd(1)
    assert o.apply_operator(FKet([n])) == FKet([1, n])
    assert o.apply_operator(FKet([n])) == -FKet([n, 1])
    o = Fd(n)
    assert o.apply_operator(FKet([])) == FKet([n])

    vacuum = FKet([], fermi_level=4)
    assert vacuum == FKet([], fermi_level=4)

    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 Fd(i).apply_operator(FKet([i, j, k], 4)) == FKet([j, k], 4)
    assert Fd(a).apply_operator(FKet([i, b, k], 4)) == FKet([a, i, b, k], 4)

    assert Dagger(B(p)).apply_operator(q) == q * CreateBoson(p)
    assert repr(Fd(p)) == 'CreateFermion(p)'
    assert srepr(Fd(p)) == "CreateFermion(Symbol('p'))"
    assert latex(Fd(p)) == r'a^\dagger_{p}'
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
Exemple #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]
    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)))
Exemple #21
0
def test_sympy__physics__secondquant__NO():
    from sympy.physics.secondquant import NO, F, Fd
    assert _test_args(NO(Fd(x) * F(y)))
Exemple #22
0
                                       Commutator, simplify_index_permutations,
                                       PermutationOperator, contraction)
from sympy import (symbols, expand, pprint, Rational, latex, Dummy)

#Link to Second quant documentation: https://docs.sympy.org/latest/modules/physics/secondquant.html

pretty_dummies_dict = {
    'above': 'abcdefgh',
    'below': 'ijklmno',
    'general': 'pqrstu'
}

p, q, r, s = symbols('p,q,r,s', cls=Dummy)

#Setup creation and annihilation operators
ap_dagger = Fd(p)
aq = F(q)
#Perform a contraction
contr = evaluate_deltas(contraction(ap_dagger, aq))
print("Example outputs")
print()
print("contraction(a_p^\dagger a_q): ", latex(contr))
print()

#Setup Hamiltonian, not on normal order form
h = AntiSymmetricTensor('h', (p, ), (q, ))
pq = ap_dagger * aq

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