Example #1
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])
Example #2
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]))
Example #3
0
 def test_ilist(self):
     s = 1.0
     i = Idx("i", "occ")
     j = Idx("j", "occ")
     sums = [Sigma(i), Sigma(j)]
     tensors = [Tensor([i, j], 'f')]
     operators = [FOperator(i, True), FOperator(j, False)]
     t1 = Term(s, sums, tensors, operators, [])
     ilist = t1.ilist()
     iref = [i, j]
     self.assertTrue(set(iref) == set(ilist))
Example #4
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))
Example #5
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])
Example #6
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))
Example #7
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])
Example #8
0
    def test_resolve3(self):
        I1 = Idx(0, "o1")
        I2 = Idx(1, "o1")
        operators = [FOperator(I1, True), FOperator(I2, False)]
        out = Term(
            1, [Sigma(I1), Sigma(I2)],
            [Tensor([I1, I2], "T")],
            operators, [Delta(I1, I2)])
        out.resolve()

        roperators = [FOperator(I1, True), FOperator(I1, False)]
        ref = Term(
            1, [Sigma(I1)],
            [Tensor([I1, I1], "T")],
            roperators, [])

        self.assertTrue(ref == out)
Example #9
0
    def test_resolve0(self):
        I1 = Idx(0, "o1")
        I2 = Idx(1, "o1")
        I3 = Idx(0, "o2")
        operators = [FOperator(I1, True), FOperator(I3, False)]
        out = Term(
            1, [Sigma(I3)],
            [Tensor([I1, I3], "T")],
            operators, [Delta(I1, I2)])

        out.resolve()

        ref = Term(
            1, [Sigma(I3)],
            [Tensor([I1, I3], "T")],
            operators, [Delta(I1, I2)])

        self.assertTrue(ref == out)
Example #10
0
 def test_scalar_mul(self):
     s = 1.0
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     sums = [Sigma(i), Sigma(j)]
     tensors = [Tensor([i, j], 'f')]
     operators = [FOperator(i, True), FOperator(j, False)]
     t = Term(s, sums, tensors, operators, [])
     t1 = 3.14 * t
     t2 = t * 3.14
     self.assertTrue(t1 == t2)
Example #11
0
    def test_mul(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        a = Idx(0, "vir")
        b = Idx(1, "vir")
        sum1 = [Sigma(i), Sigma(j)]
        ten1 = [Tensor([i, j], 'f')]
        ops1 = [FOperator(i, True), FOperator(j, False)]
        t1 = Term(1.0, sum1, ten1, ops1, [])
        sum2 = [Sigma(a), Sigma(b)]
        ten2 = [Tensor([a, b], 'f')]
        ops2 = [FOperator(a, True), FOperator(b, False)]
        t2 = Term(1.0, sum2, ten2, ops2, [])

        sum3 = sum2 + sum1
        ten3 = ten1 + ten2
        ops3 = ops1 + ops2
        ref = Term(1.0, sum3, ten3, ops3, [])

        out = t1 * t2
        self.assertTrue(ref == out)
Example #12
0
    def test_mul2(self):
        s = 1.0
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        sums = [Sigma(i), Sigma(j)]
        tensors = [Tensor([i, j], 'f')]
        operators = [FOperator(i, True), FOperator(j, False)]
        t1 = Term(s, sums, tensors, operators, [])

        t3 = t1 * t1
        k = Idx(2, "occ")
        l = Idx(3, "occ")
        sums = [Sigma(i), Sigma(j), Sigma(k), Sigma(l)]
        tensors = [Tensor([i, j], 'f'), Tensor([k, l], 'f')]
        operators = [
            FOperator(i, True),
            FOperator(j, False),
            FOperator(k, True),
            FOperator(l, False)
        ]
        ttest = Term(s, sums, tensors, operators, [])
        self.assertTrue(t3 == ttest)
Example #13
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))
Example #14
0
    def test_resolve_chain(self):
        I1 = Idx(0, "v1")
        I2 = Idx(0, "o1")
        I3 = Idx(1, "v1")
        I4 = Idx(1, "o1")
        operators = [
            FOperator(I1, True), FOperator(I2, True),
            FOperator(I4, False), FOperator(I3, False)]
        out = Term(
            1, [Sigma(I2), Sigma(I3), Sigma(I4)],
            [Tensor([I1, I2, I3, I4], "T")],
            operators, [Delta(I1, I3), Delta(I2, I4)])
        out.resolve()

        roperators = [
            FOperator(I1, True), FOperator(I2, True),
            FOperator(I2, False), FOperator(I1, False)]
        ref = Term(
            1, [Sigma(I2)],
            [Tensor([I1, I2, I1, I2], "T")],
            roperators, [])

        self.assertTrue(ref == out)
Example #15
0
    def test_str(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        sums = [Sigma(i)]
        tensors = [Tensor([i, j], "X")]
        operators = [FOperator(i, False)]
        e1 = Term(1, sums, tensors, operators, [Delta(i, j)])
        ex = Expression([e1])
        out = str(ex)
        ref = "1\\sum_{0}\\delta_{0,1}X_{01}a_0(occ)"
        self.assertTrue(ref == out)

        out = ex._print_str()
        ref = " + 1\\sum_{i}\\delta_{ij}X_{ij}a_i"
        self.assertTrue(ref == out)
Example #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])
Example #17
0
C0 = E0("c")
C1 = E1("c", ["occ"], ["vir"])
C2 = E2("c", ["occ"], ["vir"])

ket = C0 + C1 + C2
HC = H * ket

bra = braE2("occ", "vir", "occ", "vir")
S = bra * HC
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
print("Sigma2")
print(final)

bra = braE1("occ", "vir")
S = bra * HC
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
print("Sigma1")
print(final)

bra = Expression([Term(1, [], [Tensor([], "")], [], [])])
S = bra * HC
out = apply_wick(S)
out.resolve()
final = AExpression(Ex=out)
print("Sigma0")
print(final)
Example #18
0
i = Idx(0, "occ")
a = Idx(0, "vir")
j = Idx(1, "occ")
b = Idx(1, "vir")

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

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, [])])