Beispiel #1
0
    def testP1op(self):
        op = one_p("Hp", name2="Hq")
        bra = braP1("nm")
        ex = apply_wick(bra * op)
        ex.resolve()
        out = AExpression(Ex=ex)

        x = Idx(0, "nm", fermion=False)
        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x], "Hq"),
                             Tensor([x], "")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))

        ket = ketP1("nm")
        ex = apply_wick(op * ket)
        ex.resolve()
        out = AExpression(Ex=ex)
        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x], "Hp"),
                             Tensor([x], "")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))
Beispiel #2
0
    def testEP11op(self):
        op = ep11("Hp", ["occ", "vir"], ["nm"], name2="Hq")
        bra = braP1E1("nm", "occ", "vir")
        ex = apply_wick(bra * op)
        ex.resolve()
        out = AExpression(Ex=ex)

        x = Idx(0, "nm", fermion=False)
        a = Idx(0, "vir")
        i = Idx(0, "occ")
        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x, a, i], ""),
                             Tensor([x, a, i], "Hq")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))

        ket = ketP1E1("nm", "occ", "vir")
        ex = apply_wick(op * ket)
        ex.resolve()
        out = AExpression(Ex=ex)

        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x, i, a], "Hp"),
                             Tensor([x, i, a], "")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))
Beispiel #3
0
    def test_projector(self):
        O1 = one_e("f", ["occ", "vir"])
        O2 = one_e("g", ["occ", "vir"])
        ref1 = apply_wick(O1)
        ref2 = apply_wick(O2)
        ref1.resolve()
        ref2.resolve()
        ref = AExpression(Ex=ref1 * ref2)

        P = Expression([Term(1, [], [], [Projector()], [])])
        out1 = apply_wick(O1 * P * O2)
        out1.resolve()
        out = AExpression(Ex=out1)
        self.assertTrue(ref.pmatch(out))
Beispiel #4
0
    def testEdea1(self):
        bra = braEdea1("vir", "vir")
        ket = ketEdea1("vir", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        a = Idx(0, "vir")
        b = Idx(1, "vir")
        c = Idx(2, "vir")
        d = Idx(3, "vir")
        tensors = [Tensor([a, b], ""), Tensor([c, d], "")]
        tr1 = Term(1, [], tensors, [], [Delta(a, c), Delta(b, d)])
        tr2 = Term(-1, [], tensors, [], [Delta(a, d), Delta(b, c)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))
Beispiel #5
0
    def testEdip1(self):
        bra = braEdip1("occ", "occ")
        ket = ketEdip1("occ", "occ")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        i = Idx(0, "occ")
        j = Idx(1, "occ")
        k = Idx(2, "occ")
        l = Idx(3, "occ")
        tensors = [Tensor([i, j], ""), Tensor([k, l], "")]
        tr1 = Term(1, [], tensors, [], [Delta(i, k), Delta(j, l)])
        tr2 = Term(-1, [], tensors, [], [Delta(i, l), Delta(j, k)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))
Beispiel #6
0
    def testP2op(self):
        op = two_p("H")
        bra = braP1("nm")
        ket = ketP1("nm")
        ex = apply_wick(bra * op * ket)
        ex.resolve()
        out = AExpression(Ex=ex)

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        sym = TensorSym([(0, 1), (1, 0)], [1, 1])
        tensors = [
            Tensor([x], ""),
            Tensor([x, y], "H", sym=sym),
            Tensor([y], "")
        ]
        tr1 = ATerm(scalar=1, sums=[], tensors=tensors)
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))
Beispiel #7
0
    def testP2(self):
        bra = braP2("nm")
        ket = ketP2("nm")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        u = Idx(2, "nm", fermion=False)
        v = Idx(3, "nm", fermion=False)
        tensors = [Tensor([x, y], ""), Tensor([u, v], "")]
        tr1 = Term(1, [], tensors, [], [Delta(x, u), Delta(y, v)])
        tr2 = Term(1, [], tensors, [], [Delta(x, v), Delta(y, u)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = P2("A", ["nm"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        sym = TensorSym([(0, 1), (1, 0)], [1, 1])
        ext = Tensor([x, y], "")
        t1 = Tensor([x, y], "A", sym=sym)
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, t1])
        self.assertTrue(at1 == aout.terms[0])
Beispiel #8
0
    def testE1(self):
        bra = braE1("occ", "vir")
        ket = ketE1("occ", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        j = Idx(1, "occ")
        b = Idx(1, "vir")
        tr1 = Term(1, [],
                   [Tensor([a, i], ""), Tensor([j, b], "")], [],
                   [Delta(i, j), Delta(a, b)])
        ref = Expression([tr1])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = E1("A", ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([a, i], "")
        ten = Tensor([a, i], "A")
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, ten])
        self.assertTrue(len(aout.terms) == 1)
        self.assertTrue(at1 == aout.terms[0])
Beispiel #9
0
    def testEea2(self):
        bra = braEea2("occ", "vir", "vir")
        ket = ketEea2("occ", "vir", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        b = Idx(1, "vir")
        k = Idx(2, "occ")
        c = Idx(2, "vir")
        d = Idx(3, "vir")
        tensors = [Tensor([i, a, b], ""), Tensor([c, d, k], "")]
        tr1 = Term(1, [], tensors, [], [Delta(i, k), Delta(a, c), Delta(b, d)])
        tr2 = Term(
            -1, [], tensors, [],
            [Delta(i, k), Delta(a, d), Delta(b, c)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = Eea2("A", ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([a, b, i], "")
        ten = Tensor([a, b, i], "A", sym=get_sym_ea2())
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, ten])
        self.assertTrue(len(aout.terms) == 1)
        self.assertTrue(at1.pmatch(aout.terms[0]))
Beispiel #10
0
    def testP1E1(self):
        bra = braP1E1("nm", "occ", "vir")
        ket = ketP1E1("nm", "occ", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        i = Idx(0, "occ")
        a = Idx(0, "vir")
        j = Idx(1, "occ")
        b = Idx(1, "vir")
        tensors = [Tensor([x, i, a], ""), Tensor([y, b, j], "")]
        tr1 = Term(1, [], tensors, [], [Delta(x, y), Delta(i, j), Delta(a, b)])
        ref = Expression([tr1])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = EPS1("A", ["nm"], ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([x, a, i], "")
        t1 = Tensor([x, a, i], "A")
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, t1])
        self.assertTrue(at1 == aout.terms[0])
Beispiel #11
0
 def test_p2(self):
     H = two_p("w")
     bra = braP2("nm")
     S2 = P2("S2old", ["nm"])
     HT = commute(H, S2)
     HTT = commute(HT, S2)
     S = bra*(H + HT + 0.5*HTT)
     out = apply_wick(S)
     out.resolve()
     final = AExpression(Ex=out)
     out = str(final) + "\n"
     ref = get_ref("p2_test.out")
     self.assertTrue(ref == out)
Beispiel #12
0
    def testP2E1(self):
        bra = braP2E1("nm", "nm", "occ", "vir")
        op = EPS2("A", ["nm"], ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        a = Idx(0, "vir")
        i = Idx(0, "occ")
        sym = TensorSym([(0, 1, 2, 3), (1, 0, 2, 3)], [1, 1])
        aout = AExpression(Ex=out)
        ext = Tensor([x, y, a, i], "")
        t1 = Tensor([x, y, a, i], "A", sym=sym)
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, t1])
        self.assertTrue(at1 == aout.terms[0])
Beispiel #13
0
    def test_merge_external(self):
        bra = braE1("occ", "vir")
        ket = ketE1("occ", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)
        aterm = aout.terms[0]
        aterm.merge_external()

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        j = Idx(1, "occ")
        b = Idx(1, "vir")
        tensors = [
            Tensor([a, i, j, b], ""),
            tensor_from_delta(Delta(i, j)),
            tensor_from_delta(Delta(a, b))
        ]
        aref = ATerm(scalar=1, sums=[], tensors=tensors)
        self.assertTrue(aterm == aref)
Beispiel #14
0
    def test_connected(self):
        H1 = one_e("f", ["occ", "vir"], norder=True)
        H2 = two_e("I", ["occ", "vir"], norder=True)

        H = H1 + H2
        bra = braE2("occ", "vir", "occ", "vir")
        C0 = E0("c")
        C1 = E1("c", ["occ"], ["vir"])
        C2 = E2("c", ["occ"], ["vir"])
        ket = C0 + C1 + C2

        HC = H * ket
        S = bra * HC
        out = apply_wick(S)
        out.resolve()
        final = AExpression(Ex=out)
        out = [at.connected() for at in final.terms]
        ref = [True] * 19
        ref[0] = ref[1] = ref[2] = ref[3] = False
        self.assertTrue(ref == out)
Beispiel #15
0
    def test_ccsd_T1(self):
        H1 = one_e("f", ["occ", "vir"], norder=True)
        H2 = two_e("I", ["occ", "vir"], norder=True)
        H = H1 + H2

        bra = braE1("occ", "vir")
        T1 = E1("t", ["occ"], ["vir"])
        T2 = E2("t", ["occ"], ["vir"])
        T = T1 + T2

        HT = commute(H, T)
        HTT = commute(HT, T)
        HTTT = commute(commute(commute(H2, T1), T1), T1)

        S = bra*(H + HT + Fraction('1/2')*HTT + Fraction('1/6')*HTTT)
        out = apply_wick(S)
        out.resolve()
        final = AExpression(Ex=out)
        out = str(final) + "\n"
        ref = get_ref("ccsd_T1.out")
        self.assertTrue(ref == out)
Beispiel #16
0
    def testP1(self):
        bra = braP1("nm")
        ket = ketP1("nm")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        tensors = [Tensor([x], ""), Tensor([y], "")]
        tr1 = Term(1, [], tensors, [], [Delta(x, y)])
        ref = Expression([tr1])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = P1("A", ["nm"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([x], "")
        ten = Tensor([x], "A")
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, ten])
        self.assertTrue(at1 == aout.terms[0])
Beispiel #17
0
T2 = E2("t", ["occ"], ["vir"])
T = T1 + T2

HT = commute(H, T)
HTT = commute(HT, T)
HTTT = commute(HTT, T)
HTTTT = commute(HTTT, T)

Hbar = H + HT + Fraction('1/2') * HTT + Fraction('1/6') * HTTT

# ov piece
ket = ketE1("occ", "vir")
S = Hbar * ket
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
final.sort_tensors()
final = final.get_connected()
print("F_{ov} = ")
print(final)

# vv piece
ket = ketEea1("vir")
bra = braEea1("vir")
S = bra * Hbar * ket
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
final.sort_tensors()
final = final.get_connected()
print("F_{vv} = ")
Beispiel #18
0
L = L1 + L2

ket = ketE1("occ", "vir")

HT = commute(H, T)
HTT = commute(HT, T)
HTTT = commute(HTT, T)
HTTTT = commute(HTTT, T)
Hbar = H + HT + Fraction('1/2') * HTT
Hbar += Fraction('1/6') * HTTT + Fraction('1/24') * HTTTT

# Pieces not proportaional to lambda
S = Hbar * ket
out = apply_wick(S)
out.resolve()
ex = AExpression(Ex=out)
ex = ex.get_connected()
ex.sort_tensors()
print(ex)
print("")

# Connected pieces proportional to Lambda
S1 = L * S
out1 = apply_wick(S1)
out1.resolve()
ex1 = AExpression(Ex=out1)
ex1 = ex1.get_connected()
ex1.sort_tensors()

# Subtract those terms that sum to zero
S2 = L * ket * Hbar
Beispiel #19
0
L = L1 + L2

ket = ketE2("occ", "vir", "occ", "vir")

HT = commute(H, T)
HTT = commute(HT, T)
HTTT = commute(HTT, T)
HTTTT = commute(HTTT, T)
Hbar = H + HT + Fraction('1/2')*HTT
Hbar += Fraction('1/6')*HTTT + Fraction('1/24')*HTTTT

# Pieces not proportaional to lambda
S = Hbar*ket
out = apply_wick(S)
out.resolve()
ex = AExpression(Ex=out)
ex = ex.get_connected()
ex.sort_tensors()
print(ex)
print("")

# Connected pieces proportional to Lambda
S = L*S
out = apply_wick(S)
out.resolve()
ex = AExpression(Ex=out)
ex = ex.get_connected()
ex.sort_tensors()
print(ex)
print("")
Beispiel #20
0
from fractions import Fraction
from wick.expression import AExpression
from wick.wick import apply_wick
from wick.convenience import one_e, two_e, E1, E2, braE1, commute

H1 = one_e("f", ["occ", "vir"], norder=True)
H2 = two_e("I", ["occ", "vir"], norder=True)
H = H1 + H2

bra = braE1("occ", "vir")
T1 = E1("t", ["occ"], ["vir"])
T2 = E2("t", ["occ"], ["vir"])
T = T1 + T2

HT = commute(H, T)
HTT = commute(HT, T)
HTTT = commute(commute(commute(H2, T1), T1), T1)

S = bra * (H + HT + Fraction('1/2') * HTT + Fraction('1/6') * HTTT)
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
print(final._print_einsum('T1'))
Beispiel #21
0
H1 = one_e("f", ["occ", "vir"], norder=True)
H2 = two_e("I", ["occ", "vir"], norder=True)
H = H1 + H2

bra = braEip1("occ")
T1 = E1("t", ["occ"], ["vir"])
T2 = E2("t", ["occ"], ["vir"])

R1 = Eip1("r", ["occ"])
R2 = Eip2("r", ["occ"], ["vir"])

T = T1 + T2
R = R1 + R2
HT = commute(H, T)
HTT = commute(HT, T)
HTTT = commute(HTT, T)
HTTTT = commute(HTTT, T)
Hbar = H + HT + Fraction('1/2') * HTT

S0 = Hbar
E0 = apply_wick(S0)
E0.resolve()

Hbar += Fraction('1/6') * HTTT + Fraction('1/24') * HTTTT
S = bra * (Hbar - E0) * R

out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
print(final)
Beispiel #22
0
T = T1 + T2

HT = commute(H, T)
HTT = commute(HT, T)
HTTT = commute(HTT, T)
HTTTT = commute(HTTT, T)
Hbar = H + HT + Fraction('1/2')*HTT
Hbar += Fraction('1/6')*HTTT + Fraction('1/24')*HTTTT

# vovvvo piece
ket = ketEea2("occ", "vir", "vir")
bra = braEea2("occ", "vir", "vir")
S = bra*Hbar*ket
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
final.sort_tensors()
final = final.get_connected()
final.transpose((0, 3, 1, 4, 5, 2))
print("W_{vovvvo} = ")
print(final)

# oovovo piece
ket = ketEip2("occ", "occ", "vir")
bra = braEip2("occ", "occ", "vir")
S = -1*bra*Hbar*ket
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
final.sort_tensors()
final = final.get_connected()
Beispiel #23
0
from wick.expression import AExpression
from wick.wick import apply_wick
from wick.convenience import one_e, two_e, braE1, ketE1, braE2, ketE2

H1 = one_e("f", ["occ", "vir"], norder=True)
H2 = two_e("I", ["occ", "vir"], norder=True)
H = H1 + H2

# first derivative wrt X*
bra = braE1("occ", "vir")
S = bra * H
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
final.sort_tensors()
print("dE/dX* =")
print(final)

# first derivative wrt X
ket = ketE1("occ", "vir")
S = H * ket
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
final.sort_tensors()
final.transpose((1, 0))
print("dE/dX =")
print(final)

print("")
# second derivative wrt X*X*
Beispiel #24
0
L1 = E1("L", ["vir"], ["occ"])
L2 = E2("L", ["vir"], ["occ"])
L = L1 + L2

# ov block
operators = [FOperator(a, True), FOperator(i, False)]
pvo = Expression([Term(1, [], [Tensor([i, a], "")], operators, [])])

PT = commute(pvo, T)
PTT = commute(PT, T)
mid = pvo + PT + Fraction('1/2') * PTT
full = L * mid
out = apply_wick(full)
out.resolve()
final = AExpression(Ex=out)
print("P_{ov} = ")
print(final)

# vv block
operators = [FOperator(a, True), FOperator(b, False)]
pvv = Expression([Term(1, [], [Tensor([b, a], "")], operators, [])])

PT = commute(pvv, T)
PTT = commute(PT, T)
mid = pvv + PT + Fraction('1/2') * PTT
full = L * mid
out = apply_wick(full)
out.resolve()
final = AExpression(Ex=out)
final.sort_tensors()