Exemplo n.º 1
0
def fock_builder_f(Dab, **kwargs):
    import sirfck

    filename = kwargs.get('filename', 'AOTWOINT')
    hfc = kwargs.get('hfc', 1)
    hfx = kwargs.get('hfx', 1)

    Dshape = Dab[0][0].shape
    fdim = (*Dshape, len(Dab))
    Js = Matrix(fdim)
    Kas = Matrix(fdim)
    Kbs = Matrix(fdim)
    Das = Matrix(fdim)
    Dbs = Matrix(fdim)
    for i, (Da, Db) in enumerate(Dab):
        Das[:, :, i] = Da
        Dbs[:, :, i] = Db
    for buf, ibuf in list_buffers(filename):
        Js, Kas, Kbs = sirfck.fckab(Js, Kas, Kbs, Das, Dbs, buf, ibuf.T)

    Fas = (hfc * Js[:, :, i] - hfx * Kas[:, :, i] for i in range(len(Dab)))
    Fbs = (hfc * Js[:, :, i] - hfx * Kbs[:, :, i] for i in range(len(Dab)))

    Fab = tuple((Fa, Fb) for Fa, Fb in zip(Fas, Fbs))
    return Fab
Exemplo n.º 2
0
 def test_outer(self):
     V1 = Matrix((2,))
     V1[0] = 1.0
     V2 = Matrix((2,))
     V2[1] = 1.0
     V12 = V1.x(V2)
     np.testing.assert_equal(V12, [[0, 1], [0, 0]])
Exemplo n.º 3
0
 def test_minor(self):
     M1 = Matrix((3, 3))
     M1[0, 0] = 1
     M1[0, 2] = 2
     M1[2, 0] = 3
     M1[2, 2] = 4
     np.testing.assert_equal(M1.minor(1, 1), [[1, 2], [3, 4]])
Exemplo n.º 4
0
 def get_molecule_info(self):
     noa = self.noa
     self.Rab = Matrix((noa, noa, 3))
     self.dRab = Matrix((noa, noa, 3))
     for a in range(noa):
         for b in range(noa):
             self.Rab[a, b, :] = (self.R[a, :] + self.R[b, :]) / 2
             self.dRab[a, b, :] = (self.R[a, :] - self.R[b, :]) / 2
Exemplo n.º 5
0
 def test_scatter_columns(self):
     M = Matrix((2, 2))
     M1 = Matrix((2, 3))
     M[0, 0] = 1
     M[0, 1] = 2
     M[1, 0] = 3
     M[1, 1] = 4
     M.scatter(M1, columns=[0, 2])
     np.testing.assert_equal(M1, [[1, 0, 2], [3, 0, 4]])
Exemplo n.º 6
0
 def test_pack_columns(self):
     M = Matrix((3, 2))
     M1 = Matrix((3, 3))
     M1[0, 0] = 1
     M1[0, 2] = 2
     M1[2, 0] = 3
     M1[2, 2] = 4
     M1.packto(M, columns=[0, 2])
     np.testing.assert_equal(M, [[1, 2], [0, 0], [3, 4]])
Exemplo n.º 7
0
 def test_scatter_rows(self):
     M = Matrix((2, 2))
     M1 = Matrix((3, 2))
     M[0, 0] = 1
     M[0, 1] = 2
     M[1, 0] = 3
     M[1, 1] = 4
     M.scatter(M1, rows=[0, 2])
     np.testing.assert_equal(M1, [[1, 2], [0, 0], [3, 4]])
Exemplo n.º 8
0
 def test_pack_rows(self):
     M = Matrix((2, 3))
     M1 = Matrix((3, 3))
     M1[0, 0] = 1
     M1[0, 2] = 2
     M1[2, 0] = 3
     M1[2, 2] = 4
     M1.packto(M, rows=[0, 2])
     np.testing.assert_equal(M, [[1, 0, 2], [3, 0, 4]])
Exemplo n.º 9
0
 def test_scatter_add(self):
     M = Matrix((2, 2))
     M1 = Matrix((3, 3))
     M1[1, 1] = 5
     M[0, 0] = 1
     M[0, 1] = 2
     M[1, 0] = 3
     M[1, 1] = 4
     M.scatteradd(M1, [0, 2], [0, 2])
     np.testing.assert_equal(M1, [[1, 0, 2], [0, 5, 0], [3, 0, 4]])
Exemplo n.º 10
0
 def test_fab_f(self):
     """Test alpha and beta Fock matrix, Fortran version"""
     d_a = Matrix((6, 6))
     d_b = Matrix((6, 6))
     d_a[0, 0] = 1
     d_a[1, 1] = 1
     d_b[0, 0] = 1
     (f_a, f_b), = fockab((d_a, d_b), filename=os.path.join(self.suppdir, "AOTWOINT"), f2py=True)
     np.testing.assert_allclose(f_a, self.faref)
     np.testing.assert_allclose(f_b, self.fbref)
Exemplo n.º 11
0
    def test_f_f(self):
        "Test total Fock, Fortran version"""
        d_a = Matrix((6, 6))
        d_b = Matrix((6, 6))
        d_a[0, 0] = 1
        d_a[1, 1] = 1
        d_b[0, 0] = 1
        dtot = d_a + d_b
        ftot = fock(dtot, filename=os.path.join(self.suppdir, "AOTWOINT"), f2py=True)

        fref = 0.5*(self.faref+self.fbref)
        np.testing.assert_allclose(ftot, fref)
Exemplo n.º 12
0
 def test_div_scalar(self):
     M = Matrix((2, 2))
     M[0, 0] = 1
     M[0, 1] = 2
     M[1, 0] = 3
     M[1, 1] = 4
     np.testing.assert_equal(M / 2, [[0.5, 1.0], [1.5, 2.0]])
Exemplo n.º 13
0
 def test_and(self):
     M = Matrix((2, 2))
     M[0, 0] = 1
     M[0, 1] = 2
     M[1, 0] = 3
     M[1, 1] = 4
     np.testing.assert_equal(M & M, 30)
Exemplo n.º 14
0
 def test_neg(self):
     M = Matrix((2, 2))
     M[0, 0] = 1
     M[0, 1] = 2
     M[1, 0] = 3
     M[1, 1] = 4
     np.testing.assert_equal(-M, [[-1.0, -2.0], [-3.0, -4.0]])
Exemplo n.º 15
0
 def test_div_self(self):
     M = Matrix((2, 2))
     M[0, 0] = 1
     M[0, 1] = 2
     M[1, 0] = 3
     M[1, 1] = 4
     np.testing.assert_almost_equal(M / M, [[1.0, 0.0], [0.0, 1.0]])
Exemplo n.º 16
0
def fock_builder_py(Dab, **kwargs):

    filename = kwargs.get('filename', 'AOTWOINT')
    hfc = kwargs.get('hfc', 1)
    hfx = kwargs.get('hfx', 1)

    Ds = [Da + Db for Da, Db in Dab]
    Js = [Matrix(D.shape) for D in Ds]
    Ks = [(Matrix(Da.shape), Matrix(Db.shape)) for Da, Db in Dab]
    for ig, g in list_integrals(filename):
        p, q, r, s = ig
        s, r, q, p = (p - 1, q - 1, r - 1, s - 1)
        if (p == q): g *= .5
        if (r == s): g *= .5
        if (p == r and q == s): g *= .5

        for D, (Da, Db), J, (Ka, Kb) in zip(Ds, Dab, Js, Ks):
            Jadd = g * (D[r, s] + D[s, r])
            J[p, q] += Jadd
            J[q, p] += Jadd
            Jadd = g * (D[p, q] + D[q, p])
            J[r, s] += Jadd
            J[s, r] += Jadd
            Ka[p, s] += g * Da[r, q]
            Ka[p, r] += g * Da[s, q]
            Ka[q, s] += g * Da[r, p]
            Ka[q, r] += g * Da[s, p]
            Ka[r, q] += g * Da[p, s]
            Ka[s, q] += g * Da[p, r]
            Ka[r, p] += g * Da[q, s]
            Ka[s, p] += g * Da[q, r]
            Kb[p, s] += g * Db[r, q]
            Kb[p, r] += g * Db[s, q]
            Kb[q, s] += g * Db[r, p]
            Kb[q, r] += g * Db[s, p]
            Kb[r, q] += g * Db[p, s]
            Kb[s, q] += g * Db[p, r]
            Kb[r, p] += g * Db[q, s]
            Kb[s, p] += g * Db[q, r]

    Fas = (hfc * J - hfx * Ka for J, (Ka, _) in zip(Js, Ks))
    Fbs = (hfc * J - hfx * Kb for J, (_, Kb) in zip(Js, Ks))

    Fab = tuple((Fa, Fb) for Fa, Fb in zip(Fas, Fbs))
    return Fab
Exemplo n.º 17
0
    def test_str2a(self):
        M = Matrix((2, 2))
        M[0, 0] = M[1, 1] = 1
        this = str(M)
        ref = """
 (2, 2)
              Column   1    Column   2
       1      1.00000000    0.00000000
       2      0.00000000    1.00000000
"""
        self.assertEqual(this, ref)
Exemplo n.º 18
0
    def test_str1(self):
        M = Matrix((2,))
        M[0] = M[1] = 1
        this = str(M)
        ref = """
 (2,)
              Column   1
       1      1.00000000
       2      1.00000000
"""
        self.assertEqual(this, ref)
Exemplo n.º 19
0
def fock(D, filename="AOTWOINT", hfc=1, hfx=1, f2py=True):
    """Routine for building alpha and beta fock matrix by reading AOTWOINT"""

    if f2py is True:
        try:
            import sirfck
        except (ImportError):  #pragma: no cover
            f2py = False
            print(
                "Warning: non-existent sirfck.so wanted - reverting to python")

    J = Matrix(D.shape)
    K = Matrix(D.shape)

    if f2py:
        for buf, ibuf in list_buffers(filename):
            J, K = sirfck.fck(J, K, D, D, buf, ibuf.T)
    else:
        for ig, g in list_integrals(filename):
            p, q, r, s = ig
            s, r, q, p = (p - 1, q - 1, r - 1, s - 1)
            if (p == q): g *= .5
            if (r == s): g *= .5
            if (p == r and q == s): g *= .5

            Jadd = g * (D[r, s] + D[s, r])
            J[p, q] += Jadd
            J[q, p] += Jadd
            Jadd = g * (D[p, q] + D[q, p])
            J[r, s] += Jadd
            J[s, r] += Jadd
            K[p, s] += g * D[r, q]
            K[p, r] += g * D[s, q]
            K[q, s] += g * D[r, p]
            K[q, r] += g * D[s, p]
            K[r, q] += g * D[p, s]
            K[s, q] += g * D[p, r]
            K[r, p] += g * D[q, s]
            K[s, p] += g * D[q, r]

    return hfc * J - 0.5 * hfx * K
Exemplo n.º 20
0
    def test_str2b(self):
        M = Matrix((6, 6))
        for i in range(6):
            M[i, i] = float(i)
        this = str(M)
        ref = """
 (6, 6)
              Column   1    Column   2    Column   3    Column   4    Column   5
       2      0.00000000    1.00000000    0.00000000    0.00000000    0.00000000
       3      0.00000000    0.00000000    2.00000000    0.00000000    0.00000000
       4      0.00000000    0.00000000    0.00000000    3.00000000    0.00000000
       5      0.00000000    0.00000000    0.00000000    0.00000000    4.00000000

              Column   6
       6      5.00000000
"""
        self.assertEqual(this, ref)
Exemplo n.º 21
0
 def test_mul_matrix_scalar(self):
     M = Matrix((2, 2))
     M[0, 0] = M[1, 1] = 2.0
     M[0, 1] = M[1, 0] = 1.0
     np.testing.assert_equal(M * 2, [[4, 2], [2, 4]])
Exemplo n.º 22
0
 def test_str0(self):
     M = Matrix(3)
     M[:] = range(3)
     self.assertEqual(str(M.max()), "    2.00000000")
Exemplo n.º 23
0
 def test_mul(self):
     M = Matrix((2, 2))
     M[0, 0] = M[1, 1] = 2.0
     M[0, 1] = M[1, 0] = 1.0
     np.testing.assert_equal(M * M, [[5, 4], [4, 5]])
Exemplo n.º 24
0
 def test_diag(self):
     ref = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
     this = Matrix.diag([1, 1, 1])
     np.testing.assert_equal(this, ref)