Ejemplo n.º 1
0
    def test_shls_slice1(self):
        mol = gto.M(atom='H 0 -.5 0; H 0 .5 0', basis='cc-pvdz')
        nao = mol.nao_nr()
        dm = numpy.random.random((nao,nao))
        mol1 = gto.M(atom='He 2 0 0', basis='6-31g')
        nao1 = mol1.nao_nr()
        dm1 = numpy.random.random((nao1,nao1))
        eri0 = gto.conc_mol(mol, mol1).intor('int2e_sph').reshape([nao+nao1]*4)

        j1part = jk.get_jk((mol1,mol1,mol,mol), dm1[:1,:1], scripts='ijkl,ji->kl', intor='int2e',
                           shls_slice=(0,1,0,1,0,mol.nbas,0,mol.nbas))
        j1ref = numpy.einsum('ijkl,ji->kl', eri0[nao:nao+1,nao:nao+1,:nao,:nao], dm1[:1,:1])
        self.assertAlmostEqual(abs(j1part - j1ref).max(), 0, 12)

        k1part = jk.get_jk((mol1,mol,mol,mol1), dm1[:,:1], scripts='ijkl,li->kj', intor='int2e',
                           shls_slice=(0,1,0,1,0,mol.nbas,0,mol1.nbas))
        k1ref = numpy.einsum('ijkl,li->kj', eri0[nao:nao+1,:1,:nao,nao:], dm1[:,:1])
        self.assertAlmostEqual(abs(k1part - k1ref).max(), 0, 12)

        j1part = jk.get_jk(mol, dm[:1,1:2], scripts='ijkl,ji->kl', intor='int2e',
                           shls_slice=(1,2,0,1,0,mol.nbas,0,mol.nbas))
        j1ref = numpy.einsum('ijkl,ji->kl', eri0[1:2,:1,:nao,:nao], dm[:1,1:2])
        self.assertAlmostEqual(abs(j1part - j1ref).max(), 0, 12)

        k1part = jk.get_jk(mol, dm[:,1:2], scripts='ijkl,li->kj', intor='int2e',
                           shls_slice=(1,2,0,1,0,mol.nbas,0,mol.nbas))
        k1ref = numpy.einsum('ijkl,li->kj', eri0[:1,1:2,:nao,:nao], dm[:,1:2])
        self.assertAlmostEqual(abs(k1part - k1ref).max(), 0, 12)
Ejemplo n.º 2
0
    def test_shls_slice1(self):
        mol = gto.M(atom='H 0 -.5 0; H 0 .5 0', basis='cc-pvdz')
        nao = mol.nao_nr()
        dm = numpy.random.random((nao,nao))
        mol1 = gto.M(atom='He 2 0 0', basis='6-31g')
        nao1 = mol1.nao_nr()
        dm1 = numpy.random.random((nao1,nao1))
        eri0 = gto.conc_mol(mol, mol1).intor('int2e_sph').reshape([nao+nao1]*4)

        j1part = jk.get_jk((mol1,mol1,mol,mol), dm1[:1,:1], scripts='ijkl,ji->kl', intor='int2e',
                           shls_slice=(0,1,0,1,0,mol.nbas,0,mol.nbas))
        j1ref = numpy.einsum('ijkl,ji->kl', eri0[nao:nao+1,nao:nao+1,:nao,:nao], dm1[:1,:1])
        self.assertAlmostEqual(abs(j1part - j1ref).max(), 0, 12)

        k1part = jk.get_jk((mol1,mol,mol,mol1), dm1[:,:1], scripts='ijkl,li->kj', intor='int2e',
                           shls_slice=(0,1,0,1,0,mol.nbas,0,mol1.nbas))
        k1ref = numpy.einsum('ijkl,li->kj', eri0[nao:nao+1,:1,:nao,nao:], dm1[:,:1])
        self.assertAlmostEqual(abs(k1part - k1ref).max(), 0, 12)

        j1part = jk.get_jk(mol, dm[:1,1:2], scripts='ijkl,ji->kl', intor='int2e',
                           shls_slice=(1,2,0,1,0,mol.nbas,0,mol.nbas))
        j1ref = numpy.einsum('ijkl,ji->kl', eri0[1:2,:1,:nao,:nao], dm[:1,1:2])
        self.assertAlmostEqual(abs(j1part - j1ref).max(), 0, 12)

        k1part = jk.get_jk(mol, dm[:,1:2], scripts='ijkl,li->kj', intor='int2e',
                           shls_slice=(1,2,0,1,0,mol.nbas,0,mol.nbas))
        k1ref = numpy.einsum('ijkl,li->kj', eri0[:1,1:2,:nao,:nao], dm[:,1:2])
        self.assertAlmostEqual(abs(k1part - k1ref).max(), 0, 12)
Ejemplo n.º 3
0
def find_cabs(mol, auxmol, lindep=1e-8):
    cabs_mol = gto.conc_mol(mol, auxmol)
    nao = mol.nao_nr()
    s = cabs_mol.intor_symmetric('int1e_ovlp')

    ls12 = scipy.linalg.solve(s[:nao,:nao], s[:nao,nao:], sym_pos=True)
    s[nao:,nao:] -= s[nao:,:nao].dot(ls12)
    w, v = scipy.linalg.eigh(s[nao:,nao:])
    c2 = v[:,w>lindep]/numpy.sqrt(w[w>lindep])
    c1 = ls12.dot(c2)
    return cabs_mol, numpy.vstack((-c1,c2))
Ejemplo n.º 4
0
def add_ghost_link(subsys_mols, sub_settings):
    """Adds linking ghost atoms to the subsystem mol objects.

    Parameters
    ----------
    subsys_mols : list
        A list of mol objects for the different subsystems.
    sub_settings : list
        A list of subsystem settings
    """

    max_dist = 3.8
    ghost_basis = '3-21g'

    #First get array of interatom distances
    coord_array = np.asarray(np.vstack([x.atom_coords() for x in subsys_mols]))
    inter_dist = gto.inter_distance(None, coords=coord_array)
    close_indices = np.argwhere(inter_dist <= max_dist)
    #Iterate through all close indices and add link atoms to the sub on one conditional line.
    lowest_index = 0
    for i, subsystem in enumerate(sub_settings):
        num_atoms = len(subsys_mols[i].atom)
        high_index = lowest_index + num_atoms
        if subsystem.addlinkbasis:
            ghost_mol = gto.M()
            ghost_mol.atom = []
            ghost_mol.basis = {}
            for index in close_indices:
                if ((index[0] >= lowest_index and index[0] < high_index) and
                    (index[1] < lowest_index or index[1] >= high_index)):
                    atm1_coord = coord_array[index[0]]
                    atm2_coord = coord_array[index[1]]
                    if subsystem.basis:
                        new_atom, new_basis = helpers.gen_link_basis(
                            atm1_coord, atm2_coord, subsystem.basis)
                    else:
                        new_atom, new_basis = helpers.gen_link_basis(
                            atm1_coord, atm2_coord, ghost_basis)

                    ghost_mol.atom.append(new_atom)
                    ghost_mol.basis.update(new_basis)

            ghost_mol.build(unit='bohr')
            subsys_mols[i] = gto.conc_mol(subsys_mols[i], ghost_mol)
        lowest_index = high_index
Ejemplo n.º 5
0
    eri0 = mol.intor('int2e_sph').reshape((nao,)*4)
    vj = get_jk(mol, dm, 'ijkl,ji->kl')
    print(numpy.allclose(vj, numpy.einsum('ijkl,ji->kl', eri0, dm)))
    vj = get_jk(mol, dm, 'ijkl,ji->kl', aosym='s8')
    print(numpy.allclose(vj, numpy.einsum('ijkl,ji->kl', eri0, dm)))
    vk = get_jk(mol, dm, 'ijkl,jk->il', aosym='s8')
    print(numpy.allclose(vk, numpy.einsum('ijkl,jk->il', eri0, dm)))
    vj, vk = get_jk(mol, (dm,dm), ('ijkl,ji->kl','ijkl,li->kj'))
    eri1 = mol.intor('int2e_ip1_sph', comp=3).reshape([3]+[nao]*4)
    j1 = get_jk(mol, dm, 'ijkl,lk->ij', intor='int2e_ip1_sph', aosym='s2kl', comp=3)
    print(numpy.allclose(j1, numpy.einsum('xijkl,lk->xij', eri1, dm)))

    mol1 = gto.M(atom='He 2 0 0', basis='6-31g')
    nao1 = mol1.nao_nr()
    dm1 = numpy.random.random((nao1,nao1))
    eri0 = gto.conc_mol(mol, mol1).intor('int2e_sph').reshape([nao+nao1]*4)
    jcross = get_jk((mol1,mol1,mol,mol), dm, scripts='ijkl,lk->ij', aosym='s4')
    ecoul = numpy.einsum('ij,ij', jcross, dm1)
    print(numpy.allclose(jcross, numpy.einsum('ijkl,lk->ij', eri0[nao:,nao:,:nao,:nao], dm)))
    print(ecoul-numpy.einsum('ijkl,lk,ij', eri0[nao:,nao:,:nao,:nao], dm, dm1))
    kcross = get_jk((mol1,mol,mol,mol1), dm, scripts='ijkl,jk->il')
    ex = numpy.einsum('ij,ji', kcross, dm1)
    print(numpy.allclose(kcross, numpy.einsum('ijkl,jk->il', eri0[nao:,:nao,:nao,nao:], dm)))
    print(ex-numpy.einsum('ijkl,jk,li', eri0[nao:,:nao,:nao,nao:], dm, dm1))

    eri1 = gto.conc_mol(mol, mol1).intor('int2e_ip1_sph',comp=3).reshape([3]+[nao+nao1]*4)
    j1cross = get_jk((mol1,mol1,mol,mol), dm, scripts='ijkl,lk->ij', intor='int2e_ip1_sph', comp=3)
    print(numpy.allclose(j1cross, numpy.einsum('xijkl,lk->xij', eri1[:,nao:,nao:,:nao,:nao], dm)))
    j1part = get_jk((mol1,mol1,mol,mol), dm, scripts='ijkl,lk->ij', intor='int2e_ip1_sph', comp=3,
                    shls_slice=(0,1,0,1,0,mol.nbas,0,mol.nbas))
    print(numpy.allclose(j1part, numpy.einsum('xijkl,lk->xij', eri1[:,nao:nao+1,nao:nao+1,:nao,:nao], dm)))
Ejemplo n.º 6
0
Archivo: jk.py Proyecto: eronca/pyscf
    eri0 = mol.intor('cint2e_sph').reshape((nao,)*4)
    vj = get_jk(mol, dm, 'ijkl,ji->kl')
    print(numpy.allclose(vj, numpy.einsum('ijkl,ji->kl', eri0, dm)))
    vj = get_jk(mol, dm, 'ijkl,ji->kl', aosym='s8')
    print(numpy.allclose(vj, numpy.einsum('ijkl,ji->kl', eri0, dm)))
    vk = get_jk(mol, dm, 'ijkl,jk->il', aosym='s8')
    print(numpy.allclose(vk, numpy.einsum('ijkl,jk->il', eri0, dm)))
    vj, vk = get_jk(mol, (dm,dm), ('ijkl,ji->kl','ijkl,li->kj'))
    eri1 = mol.intor('cint2e_ip1_sph', comp=3).reshape([3]+[nao]*4)
    j1 = get_jk(mol, dm, 'ijkl,lk->ij', intor='cint2e_ip1_sph', aosym='s2kl', comp=3)
    print(numpy.allclose(j1, numpy.einsum('xijkl,lk->xij', eri1, dm)))

    mol1 = gto.M(atom='He 2 0 0', basis='6-31g')
    nao1 = mol1.nao_nr()
    dm1 = numpy.random.random((nao1,nao1))
    eri0 = gto.conc_mol(mol, mol1).intor('cint2e_sph').reshape([nao+nao1]*4)
    jcross = get_jk((mol1,mol1,mol,mol), dm, scripts='ijkl,lk->ij', aosym='s4')
    ecoul = numpy.einsum('ij,ij', jcross, dm1)
    print(numpy.allclose(jcross, numpy.einsum('ijkl,lk->ij', eri0[nao:,nao:,:nao,:nao], dm)))
    print(ecoul-numpy.einsum('ijkl,lk,ij', eri0[nao:,nao:,:nao,:nao], dm, dm1))
    kcross = get_jk((mol1,mol,mol,mol1), dm, scripts='ijkl,jk->il')
    ex = numpy.einsum('ij,ji', kcross, dm1)
    print(numpy.allclose(kcross, numpy.einsum('ijkl,jk->il', eri0[nao:,:nao,:nao,nao:], dm)))
    print(ex-numpy.einsum('ijkl,jk,li', eri0[nao:,:nao,:nao,nao:], dm, dm1))

    eri1 = gto.conc_mol(mol, mol1).intor('cint2e_ip1_sph',comp=3).reshape([3]+[nao+nao1]*4)
    j1cross = get_jk((mol1,mol1,mol,mol), dm, scripts='ijkl,lk->ij', intor='cint2e_ip1_sph', comp=3)
    print(numpy.allclose(j1cross, numpy.einsum('xijkl,lk->xij', eri1[:,nao:,nao:,:nao,:nao], dm)))
    j1part = get_jk((mol1,mol1,mol,mol), dm, scripts='ijkl,lk->ij', intor='cint2e_ip1_sph', comp=3,
                    shls_slice=(0,1,0,1,0,mol.nbas,0,mol.nbas))
    print(numpy.allclose(j1part, numpy.einsum('xijkl,lk->xij', eri1[:,nao:nao+1,nao:nao+1,:nao,:nao], dm)))