예제 #1
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])
예제 #2
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])
예제 #3
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])
예제 #4
0
 def test_delta(self):
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     a = Idx(0, "vir")
     b = Idx(1, "vir")
     D1 = Delta(i, j)
     D2 = Delta(i, j)
     D3 = Delta(j, i)
     D4 = Delta(a, b)
     self.assertTrue(D1 == D2)
     self.assertTrue(D1 == D3)
     self.assertTrue(D1 != D4)
예제 #5
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))
예제 #6
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))
예제 #7
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)
예제 #8
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)
예제 #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]))
예제 #10
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)
예제 #11
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)
예제 #12
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)
예제 #13
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])
예제 #14
0
    def test_string(self):
        P1 = Projector()
        self.assertTrue(str(P1) == "P")

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        O1 = FOperator(i, False)
        O2 = FOperator(i, True)
        O3 = FOperator(a, False)
        O4 = FOperator(a, True)
        so1 = "a_0(occ)"
        so2 = "a^{\\dagger}_0(occ)"
        so3 = "a_0(vir)"
        so4 = "a^{\\dagger}_0(vir)"
        self.assertTrue(str(O1) == so1)
        self.assertTrue(str(O2) == so2)
        self.assertTrue(str(O3) == so3)
        self.assertTrue(str(O4) == so4)

        x = Idx(0, "nm", fermion=False)
        Ob1 = BOperator(x, False)
        Ob2 = BOperator(x, True)
        sob1 = "b_0(nm)"
        sob2 = "b^{\\dagger}_0(nm)"
        self.assertTrue(str(Ob1) == sob1)
        self.assertTrue(str(Ob2) == sob2)

        T1 = Tensor([i, a], "g")
        st1 = "g_{00}"
        self.assertTrue(str(T1) == st1)

        S1 = Sigma(i)
        ss1 = "\\sum_{0}"
        self.assertTrue(str(S1) == ss1)

        j = Idx(1, "occ")
        D1 = Delta(i, j)
        sd1 = "\\delta_{0,1}"
        self.assertTrue(str(D1) == sd1)
예제 #15
0
    def test_inc(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        a = Idx(0, "vir")
        I = Idx(0, "nm", fermion=False)
        J = Idx(1, "nm", fermion=False)

        iii = 3

        # Fermion operator
        O1 = FOperator(i, False)._inc(iii)
        self.assertTrue(O1.idx.index == iii)

        # Boson operator
        O2 = BOperator(I, False)._inc(iii)
        O3 = BOperator(J, True)._inc(iii)
        self.assertTrue(O2.idx.index == iii)
        self.assertTrue(O3.idx.index == iii + 1)

        # Projector
        P1 = Projector()
        P2 = P1._inc(iii)
        self.assertTrue(P1 == P2)

        # tensor
        T1 = Tensor([i, a], "g")._inc(iii)
        self.assertTrue(T1.indices[0].index == iii)
        self.assertTrue(T1.indices[1].index == iii)

        # sigma
        S3 = Sigma(j)._inc(iii)
        self.assertTrue(S3.idx.index == iii + 1)

        # delta
        D1 = Delta(i, j)._inc(iii)
        self.assertTrue(D1.i1.index == iii)
        self.assertTrue(D1.i2.index == iii + 1)