예제 #1
0
파일: df.py 프로젝트: v3op01/pyscf
    def build(self):
        t0 = (time.clock(), time.time())
        log = logger.Logger(self.stdout, self.verbose)
        mol = self.mol
        auxmol = self.auxmol = incore.format_aux_basis(self.mol, self.auxbasis)
        nao = mol.nao_nr()
        naux = auxmol.nao_nr()
        nao_pair = nao * (nao + 1) // 2

        max_memory = (self.max_memory - lib.current_memory()[0]) * .8
        if nao_pair * naux * 3 * 8 / 1e6 < max_memory:
            self._cderi = incore.cholesky_eri(mol, auxmol=auxmol, verbose=log)
        else:
            if not isinstance(self._cderi, str):
                if isinstance(self._cderi_file, str):
                    self._cderi = self._cderi_file
                else:
                    self._cderi = self._cderi_file.name
            outcore.cholesky_eri(mol,
                                 self._cderi,
                                 dataname='j3c',
                                 auxmol=auxmol,
                                 verbose=log)
            if nao_pair * nao * 8 / 1e6 < max_memory:
                with addons.load(self._cderi, 'j3c') as feri:
                    cderi = numpy.asarray(feri)
                self._cderi = cderi
            log.timer_debug1('Generate density fitting integrals', *t0)

        return self
예제 #2
0
파일: r_incore.py 프로젝트: v1j4y/pyscf
def cholesky_eri(mol, auxbasis='weigend+etb', aosym='s1', verbose=0):
    t0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    auxmol = incore.format_aux_basis(mol, auxbasis)

    j2c = incore.fill_2c2e(mol, auxmol)
    log.debug('size of aux basis %d', j2c.shape[0])
    t1 = log.timer('2c2e', *t0)
    low = scipy.linalg.cholesky(j2c, lower=True)
    j2c = None
    t1 = log.timer('Cholesky 2c2e', *t1)

    j3c_ll = aux_e2(mol, auxmol, intor='cint3c2e_spinor', aosym=aosym)
    j3c_ss = aux_e2(mol, auxmol, intor='cint3c2e_spsp1_spinor', aosym=aosym)
    t1 = log.timer('3c2e', *t1)
    cderi_ll = scipy.linalg.solve_triangular(low, j3c_ll.T, lower=True,
                                             overwrite_b=True)
    cderi_ss = scipy.linalg.solve_triangular(low, j3c_ss.T, lower=True,
                                             overwrite_b=True)
    # solve_triangular return cderi in Fortran order
    cderi = (pyscf.lib.transpose(cderi_ll.T),
             pyscf.lib.transpose(cderi_ss.T))
    log.timer('cholesky_eri', *t0)
    return cderi
예제 #3
0
파일: df.py 프로젝트: eronca/pyscf
    def build(self):
        t0 = (time.clock(), time.time())
        log = logger.Logger(self.stdout, self.verbose)
        mol = self.mol
        auxmol = self.auxmol = incore.format_aux_basis(self.mol, self.auxbasis)
        nao = mol.nao_nr()
        naux = auxmol.nao_nr()
        nao_pair = nao*(nao+1)//2

        max_memory = (self.max_memory - lib.current_memory()[0]) * .8
        if nao_pair*naux*3*8/1e6 < max_memory:
            self._cderi = incore.cholesky_eri(mol, auxmol=auxmol, verbose=log)
        else:
            if not isinstance(self._cderi, str):
                if isinstance(self._cderi_file, str):
                    self._cderi = self._cderi_file
                else:
                    self._cderi = self._cderi_file.name
            outcore.cholesky_eri(mol, self._cderi, auxmol=auxmol, verbose=log)
            if nao_pair*nao*8/1e6 < max_memory:
                with addons.load(self._cderi) as feri:
                    cderi = numpy.asarray(feri)
                self._cderi = cderi
            log.timer_debug1('Generate density fitting integrals', *t0)

        return self
예제 #4
0
파일: r_incore.py 프로젝트: pengdl/pyscf
def cholesky_eri(mol, auxbasis='weigend+etb', aosym='s1', verbose=0):
    t0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    auxmol = incore.format_aux_basis(mol, auxbasis)

    j2c = incore.fill_2c2e(mol, auxmol)
    log.debug('size of aux basis %d', j2c.shape[0])
    t1 = log.timer('2c2e', *t0)
    low = scipy.linalg.cholesky(j2c, lower=True)
    j2c = None
    t1 = log.timer('Cholesky 2c2e', *t1)

    j3c_ll = aux_e2(mol, auxmol, intor='cint3c2e_spinor', aosym=aosym)
    j3c_ss = aux_e2(mol, auxmol, intor='cint3c2e_spsp1_spinor', aosym=aosym)
    t1 = log.timer('3c2e', *t1)
    cderi_ll = scipy.linalg.solve_triangular(low,
                                             j3c_ll.T,
                                             lower=True,
                                             overwrite_b=True)
    cderi_ss = scipy.linalg.solve_triangular(low,
                                             j3c_ss.T,
                                             lower=True,
                                             overwrite_b=True)
    # solve_triangular return cderi in Fortran order
    cderi = (pyscf.lib.transpose(cderi_ll.T), pyscf.lib.transpose(cderi_ss.T))
    log.timer('cholesky_eri', *t0)
    return cderi
예제 #5
0
파일: df.py 프로젝트: eronca/pyscf
    def build(self):
        t0 = (time.clock(), time.time())
        log = logger.Logger(self.stdout, self.verbose)
        mol = self.mol
        auxmol = self.auxmol = incore.format_aux_basis(self.mol, self.auxbasis)
        n2c = mol.nao_2c()
        naux = auxmol.nao_nr()
        nao_pair = n2c*(n2c+1)//2

        max_memory = (self.max_memory - lib.current_memory()[0]) * .8
        if nao_pair*naux*3*16/1e6*2 < max_memory:
            self._cderi = r_incore.cholesky_eri(mol, auxbasis=self.auxbasis,
                                                aosym='s2', verbose=log)
        else:
            raise NotImplementedError
            self._cderifile = self._cderi
            self._cderi = r_outcore.cholesky_eri(mol, self._cderi.name,
                                                 auxbasis=self.auxbasis,
                                                 verbose=log)
        return self
예제 #6
0
파일: df.py 프로젝트: v3op01/pyscf
    def build(self):
        t0 = (time.clock(), time.time())
        log = logger.Logger(self.stdout, self.verbose)
        mol = self.mol
        auxmol = self.auxmol = incore.format_aux_basis(self.mol, self.auxbasis)
        n2c = mol.nao_2c()
        naux = auxmol.nao_nr()
        nao_pair = n2c * (n2c + 1) // 2

        max_memory = (self.max_memory - lib.current_memory()[0]) * .8
        if nao_pair * naux * 3 * 16 / 1e6 * 2 < max_memory:
            self._cderi = r_incore.cholesky_eri(mol,
                                                auxbasis=self.auxbasis,
                                                aosym='s2',
                                                verbose=log)
        else:
            raise NotImplementedError
            self._cderifile = self._cderi
            self._cderi = r_outcore.cholesky_eri(mol,
                                                 self._cderi.name,
                                                 auxbasis=self.auxbasis,
                                                 verbose=log)
        return self
예제 #7
0
파일: outcore.py 프로젝트: v1j4y/pyscf
def general(mol, mo_coeffs, erifile, auxbasis='weigend+etb', dataname='eri_mo', tmpdir=None,
            int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph', comp=1,
            max_memory=2000, ioblk_size=256, verbose=0, compact=True):
    ''' Transform ij of (ij|L) to MOs.
    '''
    assert(aosym in ('s1', 's2ij'))
    assert(comp == 1)
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)

    swapfile = tempfile.NamedTemporaryFile(dir=tmpdir)
    cholesky_eri_b(mol, swapfile.name, auxbasis, dataname,
                   int3c, aosym, int2c, comp, ioblk_size, verbose=log)
    fswap = h5py.File(swapfile.name, 'r')
    time1 = log.timer('AO->MO eri transformation 1 pass', *time0)

    ijsame = compact and iden_coeffs(mo_coeffs[0], mo_coeffs[1])
    nmoi = mo_coeffs[0].shape[1]
    nmoj = mo_coeffs[1].shape[1]
    nao = mo_coeffs[0].shape[0]
    auxmol = incore.format_aux_basis(mol, auxbasis)
    naoaux = auxmol.nao_nr()
    aosym = _stand_sym_code(aosym)
    if aosym == 's1':
        nao_pair = nao * nao
        aosym_as_nr_e2 = 's1'
    else:
        nao_pair = nao * (nao+1) // 2
        aosym_as_nr_e2 = 's2kl'

    if compact and ijsame and aosym != 's1':
        log.debug('i-mo == j-mo')
        ijmosym = 's2'
        nij_pair = nmoi*(nmoi+1) // 2
        moij = numpy.asarray(mo_coeffs[0], order='F')
        ijshape = (0, nmoi, 0, nmoi)
    else:
        ijmosym = 's1'
        nij_pair = nmoi*nmoj
        moij = numpy.asarray(numpy.hstack((mo_coeffs[0],mo_coeffs[1])), order='F')
        ijshape = (0, nmoi, nmoi, nmoj)

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    if comp == 1:
        chunks = (min(int(16e3/nmoj),naoaux), nmoj) # 128K
        h5d_eri = feri.create_dataset(dataname, (naoaux,nij_pair), 'f8',
                                      chunks=chunks)
        aopairblks = len(fswap[dataname])
    else:
        chunks = (1, min(int(16e3/nmoj),naoaux), nmoj) # 128K
        h5d_eri = feri.create_dataset(dataname, (comp,naoaux,nij_pair), 'f8',
                                      chunks=chunks)
        aopairblks = len(fswap[dataname+'/0'])
    if comp > 1:
        for icomp in range(comp):
            feri.create_group(str(icomp)) # for h5py old version

    iolen = min(int(ioblk_size*1e6/8/(nao_pair+nij_pair)), naoaux)
    totstep = (naoaux+iolen-1)//iolen * comp
    buf = numpy.empty((iolen, nao_pair))
    istep = 0
    ti0 = time1
    for icomp in range(comp):
        for row0, row1 in prange(0, naoaux, iolen):
            nrow = row1 - row0
            istep += 1

            log.debug('step 2 [%d/%d], [%d,%d:%d], row = %d',
                      istep, totstep, icomp, row0, row1, nrow)
            col0 = 0
            for ic in range(aopairblks):
                if comp == 1:
                    dat = fswap['%s/%d'%(dataname,ic)]
                else:
                    dat = fswap['%s/%d/%d'%(dataname,icomp,ic)]
                col1 = col0 + dat.shape[1]
                buf[:nrow,col0:col1] = dat[row0:row1]
                col0 = col1

            buf1 = _ao2mo.nr_e2_(buf[:nrow], moij, ijshape, aosym_as_nr_e2, ijmosym)
            if comp == 1:
                h5d_eri[row0:row1] = buf1
            else:
                h5d_eri[icomp,row0:row1] = buf1

            ti0 = log.timer('step 2 [%d/%d], [%d,%d:%d], row = %d'%
                            (istep, totstep, icomp, row0, row1, nrow), *ti0)

    fswap.close()
    feri.close()
    log.timer('AO->MO CD eri transformation 2 pass', *time1)
    log.timer('AO->MO CD eri transformation', *time0)
    return erifile
예제 #8
0
파일: outcore.py 프로젝트: v1j4y/pyscf
def cholesky_eri_b(mol, erifile, auxbasis='weigend+etb', dataname='eri_mo',
                   int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph',
                   comp=1, ioblk_size=256, verbose=logger.NOTE):
    '''3-center 2-electron AO integrals
    '''
    assert(aosym in ('s1', 's2ij'))
    assert(comp == 1)
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    auxmol = incore.format_aux_basis(mol, auxbasis)
    j2c = incore.fill_2c2e(mol, auxmol, intor=int2c)
    log.debug('size of aux basis %d', j2c.shape[0])
    time1 = log.timer('2c2e', *time0)
    low = scipy.linalg.cholesky(j2c, lower=True)
    j2c = None
    time1 = log.timer('Cholesky 2c2e', *time1)

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    if comp > 1:
        for icomp in range(comp):
            feri.create_group(str(icomp)) # for h5py old version

    atm, bas, env = \
            pyscf.gto.mole.conc_env(mol._atm, mol._bas, mol._env,
                                    auxmol._atm, auxmol._bas, auxmol._env)
    c_atm = numpy.asarray(atm, dtype=numpy.int32, order='C')
    c_bas = numpy.asarray(bas, dtype=numpy.int32, order='C')
    c_env = numpy.asarray(env, dtype=numpy.double, order='C')
    natm = ctypes.c_int(mol.natm+auxmol.natm)
    nbas = ctypes.c_int(mol.nbas)
    if 'ssc' in int3c:
        ao_loc = _ri.make_loc(0, mol.nbas, bas)
        kloc = _ri.make_loc(mol.nbas, auxmol.nbas, bas, True)
    elif 'cart' in int3c:
        ao_loc = _ri.make_loc(0, mol.nbas, bas, True)
        kloc = _ri.make_loc(mol.nbas, auxmol.nbas, bas, True)
    else:
        ao_loc = _ri.make_loc(0, mol.nbas, bas)
        kloc = _ri.make_loc(mol.nbas, auxmol.nbas, bas)
    nao = ao_loc[-1] - ao_loc[0]
    naoaux = kloc[-1] - kloc[0]

    if aosym == 's1':
        nao_pair = nao * nao
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's1')
    else:
        nao_pair = nao * (nao+1) // 2
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's2ij')
    log.debug('erifile %.8g MB, IO buf size %.8g MB',
              naoaux*nao_pair*8/1e6, comp*buflen*naoaux*8/1e6)
    if log.verbose >= logger.DEBUG1:
        log.debug1('shranges = %s', shranges)
    cintopt = _vhf.make_cintopt(c_atm, c_bas, c_env, int3c)
    bufs1 = numpy.empty((comp*max([x[2] for x in shranges]),naoaux))
    for istep, sh_range in enumerate(shranges):
        log.debug('int3c2e [%d/%d], AO [%d:%d], nrow = %d', \
                  istep+1, len(shranges), *sh_range)
        bstart, bend, nrow = sh_range
        basrange = (bstart, bend-bstart, 0, mol.nbas, mol.nbas, auxmol.nbas)
        buf = bufs1[:comp*nrow].reshape(comp,nrow,naoaux)
        if 's1' in aosym:
            ijkoff = ao_loc[bstart] * nao * naoaux
        else:
            ijkoff = ao_loc[bstart] * (ao_loc[bstart]+1) // 2 * naoaux
        _ri.nr_auxe2(int3c, basrange,
                     atm, bas, env, aosym, comp, cintopt, buf, ijkoff,
                     ao_loc[bend]-ao_loc[bstart],
                     nao, naoaux, ao_loc[bstart:bend+1], ao_loc, kloc)
        for icomp in range(comp):
            if comp == 1:
                label = '%s/%d'%(dataname,istep)
            else:
                label = '%s/%d/%d'%(dataname,icomp,istep)
            cderi = scipy.linalg.solve_triangular(low, buf[icomp].T,
                                                  lower=True, overwrite_b=True)
            feri[label] = cderi
        time1 = log.timer('gen CD eri [%d/%d]' % (istep+1,len(shranges)), *time1)
    buf = bufs1 = None

    feri.close()
    _ri.libri.CINTdel_optimizer(ctypes.byref(cintopt))
    return erifile
예제 #9
0
파일: outcore.py 프로젝트: pengdl/pyscf
def cholesky_eri(mol, erifile, auxbasis='weigend+etb', dataname='eri_mo', tmpdir=None,
                 int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph', comp=1,
                 ioblk_size=256, auxmol=None, verbose=0):
    '''3-center 2-electron AO integrals
    '''
    assert(aosym in ('s1', 's2ij'))
    assert(comp == 1)
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    if auxmol is None:
        auxmol = incore.format_aux_basis(mol, auxbasis)

    swapfile = tempfile.NamedTemporaryFile(dir=tmpdir)
    cholesky_eri_b(mol, swapfile.name, auxbasis, dataname,
                   int3c, aosym, int2c, comp, ioblk_size, verbose=log)
    fswap = h5py.File(swapfile.name, 'r')
    time1 = log.timer('generate (ij|L) 1 pass', *time0)

    nao = mol.nao_nr()
    naoaux = auxmol.nao_nr()
    aosym = _stand_sym_code(aosym)
    if aosym == 's1':
        nao_pair = nao * nao
    else:
        nao_pair = nao * (nao+1) // 2

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    if comp == 1:
        chunks = (min(int(16e3/nao),naoaux), nao) # 128K
        h5d_eri = feri.create_dataset(dataname, (naoaux,nao_pair), 'f8',
                                      chunks=chunks)
    else:
        chunks = (1, min(int(16e3/nao),naoaux), nao) # 128K
        h5d_eri = feri.create_dataset(dataname, (comp,naoaux,nao_pair), 'f8',
                                      chunks=chunks)
    aopairblks = len(fswap[dataname+'/0'])

    iolen = min(int(ioblk_size*1e6/8/nao_pair), naoaux)
    totstep = (naoaux+iolen-1)//iolen * comp
    buf = numpy.empty((iolen, nao_pair))
    ti0 = time1
    for icomp in range(comp):
        istep = 0
        for row0, row1 in prange(0, naoaux, iolen):
            nrow = row1 - row0
            istep += 1

            col0 = 0
            for ic in range(aopairblks):
                dat = fswap['%s/%d/%d'%(dataname,icomp,ic)]
                col1 = col0 + dat.shape[1]
                buf[:nrow,col0:col1] = dat[row0:row1]
                col0 = col1
            if comp == 1:
                h5d_eri[row0:row1] = buf[:nrow]
            else:
                h5d_eri[icomp,row0:row1] = buf[:nrow]
            ti0 = log.timer('step 2 [%d/%d], [%d,%d:%d], row = %d'%
                            (istep, totstep, icomp, row0, row1, nrow), *ti0)

    fswap.close()
    feri.close()
    log.timer('cholesky_eri', *time0)
    return erifile
예제 #10
0
파일: outcore.py 프로젝트: pengdl/pyscf
def cholesky_eri_b(mol, erifile, auxbasis='weigend+etb', dataname='eri_mo',
                   int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph',
                   comp=1, ioblk_size=256, verbose=logger.NOTE):
    '''3-center 2-electron AO integrals
    '''
    assert(aosym in ('s1', 's2ij'))
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    auxmol = incore.format_aux_basis(mol, auxbasis)
    j2c = incore.fill_2c2e(mol, auxmol, intor=int2c)
    log.debug('size of aux basis %d', j2c.shape[0])
    time1 = log.timer('2c2e', *time0)
    low = scipy.linalg.cholesky(j2c, lower=True)
    j2c = None
    time1 = log.timer('Cholesky 2c2e', *time1)

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    for icomp in range(comp):
        feri.create_group('%s/%d'%(dataname,icomp)) # for h5py old version

    def store(b, label):
        cderi = scipy.linalg.solve_triangular(low, b, lower=True, overwrite_b=True)
        if cderi.flags.f_contiguous:
            cderi = lib.transpose(cderi.T)
        feri[label] = cderi

    atm, bas, env, ao_loc = incore._env_and_aoloc(int3c, mol, auxmol)
    nao = ao_loc[mol.nbas]
    naoaux = ao_loc[-1] - nao
    if aosym == 's1':
        nao_pair = nao * nao
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's1')
    else:
        nao_pair = nao * (nao+1) // 2
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's2ij')
    log.debug('erifile %.8g MB, IO buf size %.8g MB',
              naoaux*nao_pair*8/1e6, comp*buflen*naoaux*8/1e6)
    if log.verbose >= logger.DEBUG1:
        log.debug1('shranges = %s', shranges)
    cintopt = gto.moleintor.make_cintopt(atm, bas, env, int3c)
    bufs1 = numpy.empty((comp*max([x[2] for x in shranges]),naoaux))

    for istep, sh_range in enumerate(shranges):
        log.debug('int3c2e [%d/%d], AO [%d:%d], nrow = %d', \
                  istep+1, len(shranges), *sh_range)
        bstart, bend, nrow = sh_range
        shls_slice = (bstart, bend, 0, mol.nbas, mol.nbas, mol.nbas+auxmol.nbas)
        buf = _ri.nr_auxe2(int3c, atm, bas, env, shls_slice, ao_loc,
                           aosym, comp, cintopt, bufs1)
        if comp == 1:
            store(buf.T, '%s/0/%d'%(dataname,istep))
        else:
            for icomp in range(comp):
                store(buf[icomp].T, '%s/%d/%d'%(dataname,icomp,istep))
        time1 = log.timer('gen CD eri [%d/%d]' % (istep+1,len(shranges)), *time1)
    buf = bufs1 = None

    feri.close()
    return erifile
예제 #11
0
파일: outcore.py 프로젝트: diradical/pyscf
def cholesky_eri_b(mol, erifile, auxbasis='weigend', dataname='eri_mo',
                   int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph',
                   comp=1, ioblk_size=256, verbose=logger.NOTE):
    assert(aosym in ('s1', 's2ij'))
    assert(comp == 1)
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    auxmol = incore.format_aux_basis(mol, auxbasis)
    j2c = incore.fill_2c2e(mol, auxmol, intor=int2c)
    log.debug('size of aux basis %d', j2c.shape[0])
    time1 = log.timer('2c2e', *time0)
    low = scipy.linalg.cholesky(j2c, lower=True)
    j2c = None
    time1 = log.timer('Cholesky 2c2e', *time1)

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    if comp > 1:
        for icomp in range(comp):
            feri.create_group(str(icomp)) # for h5py old version

    nao = mol.nao_nr()
    naoaux = auxmol.nao_nr()
    if aosym == 's1':
        fill = _fpointer('RIfill_s1_auxe2')
        nao_pair = nao * nao
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's1')
    else:
        fill = _fpointer('RIfill_s2ij_auxe2')
        nao_pair = nao * (nao+1) // 2
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's2ij')
    log.debug('erifile %.8g MB, IO buf size %.8g MB',
              naoaux*nao_pair*8/1e6, comp*buflen*naoaux*8/1e6)
    log.debug1('shranges = %s', shranges)

    atm, bas, env = \
            pyscf.gto.mole.conc_env(mol._atm, mol._bas, mol._env,
                                    auxmol._atm, auxmol._bas, auxmol._env)
    c_atm = numpy.array(atm, dtype=numpy.int32)
    c_bas = numpy.array(bas, dtype=numpy.int32)
    c_env = numpy.array(env)
    natm = ctypes.c_int(mol.natm)
    nbas = ctypes.c_int(mol.nbas)
    fintor = _fpointer(int3c)
    cintopt = _vhf.make_cintopt(c_atm, c_bas, c_env, int3c)
    for istep, sh_range in enumerate(shranges):
        log.debug('int3c2e [%d/%d], AO [%d:%d], nrow = %d', \
                  istep+1, len(shranges), *sh_range)
        bstart, bend, nrow = sh_range
        buf = numpy.empty((comp,nrow,naoaux))
        libri.RInr_3c2e_auxe2_drv(fintor, fill,
                                  buf.ctypes.data_as(ctypes.c_void_p),
                                  ctypes.c_int(bstart), ctypes.c_int(bend-bstart),
                                  ctypes.c_int(mol.nbas), ctypes.c_int(auxmol.nbas),
                                  ctypes.c_int(comp), cintopt,
                                  c_atm.ctypes.data_as(ctypes.c_void_p), natm,
                                  c_bas.ctypes.data_as(ctypes.c_void_p), nbas,
                                  c_env.ctypes.data_as(ctypes.c_void_p))
        for icomp in range(comp):
            if comp == 1:
                label = '%s/%d'%(dataname,istep)
            else:
                label = '%s/%d/%d'%(dataname,icomp,istep)
            cderi = scipy.linalg.solve_triangular(low, buf[icomp].T,
                                                  lower=True, overwrite_b=True)
            feri[label] = cderi
        time1 = log.timer('gen CD eri [%d/%d]' % (istep+1,len(shranges)), *time1)

    feri.close()
    libri.CINTdel_optimizer(ctypes.byref(cintopt))
    return erifile
예제 #12
0
파일: outcore.py 프로젝트: berquist/pyscf
def cholesky_eri_b(mol, erifile, auxbasis='weigend+etb', dataname='eri_mo',
                   int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph',
                   comp=1, ioblk_size=256, verbose=logger.NOTE):
    '''3-center 2-electron AO integrals
    '''
    assert(aosym in ('s1', 's2ij'))
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    auxmol = incore.format_aux_basis(mol, auxbasis)
    j2c = incore.fill_2c2e(mol, auxmol, intor=int2c)
    log.debug('size of aux basis %d', j2c.shape[0])
    time1 = log.timer('2c2e', *time0)
    low = scipy.linalg.cholesky(j2c, lower=True)
    j2c = None
    time1 = log.timer('Cholesky 2c2e', *time1)

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    for icomp in range(comp):
        feri.create_group('%s/%d'%(dataname,icomp)) # for h5py old version

    def store(b, label):
        cderi = scipy.linalg.solve_triangular(low, b, lower=True, overwrite_b=True)
        if cderi.flags.f_contiguous:
            cderi = lib.transpose(cderi.T)
        feri[label] = cderi

    atm, bas, env, ao_loc = incore._env_and_aoloc(int3c, mol, auxmol)
    nao = ao_loc[mol.nbas]
    naoaux = ao_loc[-1] - nao
    if aosym == 's1':
        nao_pair = nao * nao
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's1')
    else:
        nao_pair = nao * (nao+1) // 2
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's2ij')
    log.debug('erifile %.8g MB, IO buf size %.8g MB',
              naoaux*nao_pair*8/1e6, comp*buflen*naoaux*8/1e6)
    if log.verbose >= logger.DEBUG1:
        log.debug1('shranges = %s', shranges)
    cintopt = gto.moleintor.make_cintopt(atm, bas, env, int3c)
    bufs1 = numpy.empty((comp*max([x[2] for x in shranges]),naoaux))

    for istep, sh_range in enumerate(shranges):
        log.debug('int3c2e [%d/%d], AO [%d:%d], nrow = %d', \
                  istep+1, len(shranges), *sh_range)
        bstart, bend, nrow = sh_range
        shls_slice = (bstart, bend, 0, mol.nbas, mol.nbas, mol.nbas+auxmol.nbas)
        buf = _ri.nr_auxe2(int3c, atm, bas, env, shls_slice, ao_loc,
                           aosym, comp, cintopt, bufs1)
        if comp == 1:
            store(buf.T, '%s/0/%d'%(dataname,istep))
        else:
            for icomp in range(comp):
                store(buf[icomp].T, '%s/%d/%d'%(dataname,icomp,istep))
        time1 = log.timer('gen CD eri [%d/%d]' % (istep+1,len(shranges)), *time1)
    buf = bufs1 = None

    feri.close()
    return erifile
예제 #13
0
파일: outcore.py 프로젝트: ushnishray/pyscf
def cholesky_eri(
    mol,
    erifile,
    auxbasis="weigend+etb",
    dataname="eri_mo",
    tmpdir=None,
    int3c="cint3c2e_sph",
    aosym="s2ij",
    int2c="cint2c2e_sph",
    comp=1,
    ioblk_size=256,
    auxmol=None,
    verbose=0,
):
    """3-center 2-electron AO integrals
    """
    assert aosym in ("s1", "s2ij")
    assert comp == 1
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    if auxmol is None:
        auxmol = incore.format_aux_basis(mol, auxbasis)

    swapfile = tempfile.NamedTemporaryFile(dir=tmpdir)
    cholesky_eri_b(mol, swapfile.name, auxbasis, dataname, int3c, aosym, int2c, comp, ioblk_size, verbose=log)
    fswap = h5py.File(swapfile.name, "r")
    time1 = log.timer("generate (ij|L) 1 pass", *time0)

    nao = mol.nao_nr()
    naoaux = auxmol.nao_nr()
    aosym = _stand_sym_code(aosym)
    if aosym == "s1":
        nao_pair = nao * nao
    else:
        nao_pair = nao * (nao + 1) // 2

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del (feri[dataname])
    else:
        feri = h5py.File(erifile, "w")
    if comp == 1:
        chunks = (min(int(16e3 / nao), naoaux), nao)  # 128K
        h5d_eri = feri.create_dataset(dataname, (naoaux, nao_pair), "f8", chunks=chunks)
    else:
        chunks = (1, min(int(16e3 / nao), naoaux), nao)  # 128K
        h5d_eri = feri.create_dataset(dataname, (comp, naoaux, nao_pair), "f8", chunks=chunks)
    aopairblks = len(fswap[dataname + "/0"])

    iolen = min(int(ioblk_size * 1e6 / 8 / nao_pair), naoaux)
    totstep = (naoaux + iolen - 1) // iolen * comp
    buf = numpy.empty((iolen, nao_pair))
    ti0 = time1
    for icomp in range(comp):
        istep = 0
        for row0, row1 in prange(0, naoaux, iolen):
            nrow = row1 - row0
            istep += 1

            col0 = 0
            for ic in range(aopairblks):
                dat = fswap["%s/%d/%d" % (dataname, icomp, ic)]
                col1 = col0 + dat.shape[1]
                buf[:nrow, col0:col1] = dat[row0:row1]
                col0 = col1
            if comp == 1:
                h5d_eri[row0:row1] = buf[:nrow]
            else:
                h5d_eri[icomp, row0:row1] = buf[:nrow]
            ti0 = log.timer("step 2 [%d/%d], [%d,%d:%d], row = %d" % (istep, totstep, icomp, row0, row1, nrow), *ti0)

    fswap.close()
    feri.close()
    log.timer("cholesky_eri", *time0)
    return erifile
예제 #14
0
파일: outcore.py 프로젝트: ushnishray/pyscf
def general(
    mol,
    mo_coeffs,
    erifile,
    auxbasis="weigend+etb",
    dataname="eri_mo",
    tmpdir=None,
    int3c="cint3c2e_sph",
    aosym="s2ij",
    int2c="cint2c2e_sph",
    comp=1,
    max_memory=2000,
    ioblk_size=256,
    verbose=0,
    compact=True,
):
    """ Transform ij of (ij|L) to MOs.
    """
    assert aosym in ("s1", "s2ij")
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)

    swapfile = tempfile.NamedTemporaryFile(dir=tmpdir)
    cholesky_eri_b(mol, swapfile.name, auxbasis, dataname, int3c, aosym, int2c, comp, ioblk_size, verbose=log)
    fswap = h5py.File(swapfile.name, "r")
    time1 = log.timer("AO->MO eri transformation 1 pass", *time0)

    nmoi = mo_coeffs[0].shape[1]
    nmoj = mo_coeffs[1].shape[1]
    nao = mo_coeffs[0].shape[0]
    auxmol = incore.format_aux_basis(mol, auxbasis)
    naoaux = auxmol.nao_nr()
    aosym = _stand_sym_code(aosym)
    if aosym == "s1":
        nao_pair = nao * nao
        aosym_as_nr_e2 = "s1"
    else:
        nao_pair = nao * (nao + 1) // 2
        aosym_as_nr_e2 = "s2kl"

    ijmosym, nij_pair, moij, ijshape = ao2mo.incore._conc_mos(mo_coeffs[0], mo_coeffs[1], compact and aosym != "s1")

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del (feri[dataname])
    else:
        feri = h5py.File(erifile, "w")
    if comp == 1:
        chunks = (min(int(64e3 / nmoj), naoaux), nmoj)  # 512K
        h5d_eri = feri.create_dataset(dataname, (naoaux, nij_pair), "f8", chunks=chunks)
    else:
        chunks = (1, min(int(64e3 / nmoj), naoaux), nmoj)  # 512K
        h5d_eri = feri.create_dataset(dataname, (comp, naoaux, nij_pair), "f8", chunks=chunks)
    aopairblks = len(fswap[dataname + "/0"])

    iolen = min(int(ioblk_size * 1e6 / 8 / (nao_pair + nij_pair)), naoaux)
    totstep = (naoaux + iolen - 1) // iolen * comp
    buf = numpy.empty((iolen, nao_pair))
    ti0 = time1
    for icomp in range(comp):
        istep = 0
        for row0, row1 in prange(0, naoaux, iolen):
            nrow = row1 - row0
            istep += 1

            log.debug("step 2 [%d/%d], [%d,%d:%d], row = %d", istep, totstep, icomp, row0, row1, nrow)
            col0 = 0
            for ic in range(aopairblks):
                dat = fswap["%s/%d/%d" % (dataname, icomp, ic)]
                col1 = col0 + dat.shape[1]
                buf[:nrow, col0:col1] = dat[row0:row1]
                col0 = col1

            buf1 = _ao2mo.nr_e2(buf[:nrow], moij, ijshape, aosym_as_nr_e2, ijmosym)
            if comp == 1:
                h5d_eri[row0:row1] = buf1
            else:
                h5d_eri[icomp, row0:row1] = buf1

            ti0 = log.timer("step 2 [%d/%d], [%d,%d:%d], row = %d" % (istep, totstep, icomp, row0, row1, nrow), *ti0)

    fswap.close()
    feri.close()
    log.timer("AO->MO CD eri transformation 2 pass", *time1)
    log.timer("AO->MO CD eri transformation", *time0)
    return erifile
예제 #15
0
파일: outcore.py 프로젝트: v1j4y/pyscf
def cholesky_eri(mol, erifile, auxbasis='weigend+etb', dataname='eri_mo', tmpdir=None,
                 int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph', comp=1,
                 ioblk_size=256, verbose=0):
    '''3-center 2-electron AO integrals
    '''
    assert(aosym in ('s1', 's2ij'))
    assert(comp == 1)
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)

    swapfile = tempfile.NamedTemporaryFile(dir=tmpdir)
    cholesky_eri_b(mol, swapfile.name, auxbasis, dataname,
                   int3c, aosym, int2c, comp, ioblk_size, verbose=log)
    fswap = h5py.File(swapfile.name, 'r')
    time1 = log.timer('generate (ij|L) 1 pass', *time0)

    nao = mol.nao_nr()
    auxmol = incore.format_aux_basis(mol, auxbasis)
    naoaux = auxmol.nao_nr()
    aosym = _stand_sym_code(aosym)
    if aosym == 's1':
        nao_pair = nao * nao
    else:
        nao_pair = nao * (nao+1) // 2

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    if comp == 1:
        chunks = (min(int(16e3/nao),naoaux), nao) # 128K
        h5d_eri = feri.create_dataset(dataname, (naoaux,nao_pair), 'f8',
                                      chunks=chunks)
        aopairblks = len(fswap[dataname])
    else:
        chunks = (1, min(int(16e3/nao),naoaux), nao) # 128K
        h5d_eri = feri.create_dataset(dataname, (comp,naoaux,nao_pair), 'f8',
                                      chunks=chunks)
        aopairblks = len(fswap[dataname+'/0'])
    if comp > 1:
        for icomp in range(comp):
            feri.create_group(str(icomp)) # for h5py old version

    iolen = min(int(ioblk_size*1e6/8/nao_pair), naoaux)
    totstep = (naoaux+iolen-1)//iolen * comp
    buf = numpy.empty((iolen, nao_pair))
    istep = 0
    ti0 = time1
    for icomp in range(comp):
        for row0, row1 in prange(0, naoaux, iolen):
            nrow = row1 - row0
            istep += 1

            col0 = 0
            for ic in range(aopairblks):
                if comp == 1:
                    dat = fswap['%s/%d'%(dataname,ic)]
                else:
                    dat = fswap['%s/%d/%d'%(dataname,icomp,ic)]
                col1 = col0 + dat.shape[1]
                buf[:nrow,col0:col1] = dat[row0:row1]
                col0 = col1
            if comp == 1:
                h5d_eri[row0:row1] = buf[:nrow]
            else:
                h5d_eri[icomp,row0:row1] = buf[:nrow]
            ti0 = log.timer('step 2 [%d/%d], [%d,%d:%d], row = %d'%
                            (istep, totstep, icomp, row0, row1, nrow), *ti0)

    fswap.close()
    feri.close()
    log.timer('cholesky_eri', *time0)
    return erifile
예제 #16
0
파일: outcore.py 프로젝트: pengdl/pyscf
def general(mol, mo_coeffs, erifile, auxbasis='weigend+etb', dataname='eri_mo', tmpdir=None,
            int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph', comp=1,
            max_memory=2000, ioblk_size=256, verbose=0, compact=True):
    ''' Transform ij of (ij|L) to MOs.
    '''
    assert(aosym in ('s1', 's2ij'))
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)

    swapfile = tempfile.NamedTemporaryFile(dir=tmpdir)
    cholesky_eri_b(mol, swapfile.name, auxbasis, dataname,
                   int3c, aosym, int2c, comp, ioblk_size, verbose=log)
    fswap = h5py.File(swapfile.name, 'r')
    time1 = log.timer('AO->MO eri transformation 1 pass', *time0)

    nmoi = mo_coeffs[0].shape[1]
    nmoj = mo_coeffs[1].shape[1]
    nao = mo_coeffs[0].shape[0]
    auxmol = incore.format_aux_basis(mol, auxbasis)
    naoaux = auxmol.nao_nr()
    aosym = _stand_sym_code(aosym)
    if aosym == 's1':
        nao_pair = nao * nao
        aosym_as_nr_e2 = 's1'
    else:
        nao_pair = nao * (nao+1) // 2
        aosym_as_nr_e2 = 's2kl'

    ijmosym, nij_pair, moij, ijshape = \
            ao2mo.incore._conc_mos(mo_coeffs[0], mo_coeffs[1],
                                   compact and aosym != 's1')

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    if comp == 1:
        chunks = (min(int(16e3/nmoj),naoaux), nmoj) # 128K
        h5d_eri = feri.create_dataset(dataname, (naoaux,nij_pair), 'f8',
                                      chunks=chunks)
    else:
        chunks = (1, min(int(16e3/nmoj),naoaux), nmoj) # 128K
        h5d_eri = feri.create_dataset(dataname, (comp,naoaux,nij_pair), 'f8',
                                      chunks=chunks)
    aopairblks = len(fswap[dataname+'/0'])

    iolen = min(int(ioblk_size*1e6/8/(nao_pair+nij_pair)), naoaux)
    totstep = (naoaux+iolen-1)//iolen * comp
    buf = numpy.empty((iolen, nao_pair))
    ti0 = time1
    for icomp in range(comp):
        istep = 0
        for row0, row1 in prange(0, naoaux, iolen):
            nrow = row1 - row0
            istep += 1

            log.debug('step 2 [%d/%d], [%d,%d:%d], row = %d',
                      istep, totstep, icomp, row0, row1, nrow)
            col0 = 0
            for ic in range(aopairblks):
                dat = fswap['%s/%d/%d'%(dataname,icomp,ic)]
                col1 = col0 + dat.shape[1]
                buf[:nrow,col0:col1] = dat[row0:row1]
                col0 = col1

            buf1 = _ao2mo.nr_e2(buf[:nrow], moij, ijshape, aosym_as_nr_e2, ijmosym)
            if comp == 1:
                h5d_eri[row0:row1] = buf1
            else:
                h5d_eri[icomp,row0:row1] = buf1

            ti0 = log.timer('step 2 [%d/%d], [%d,%d:%d], row = %d'%
                            (istep, totstep, icomp, row0, row1, nrow), *ti0)

    fswap.close()
    feri.close()
    log.timer('AO->MO CD eri transformation 2 pass', *time1)
    log.timer('AO->MO CD eri transformation', *time0)
    return erifile
예제 #17
0
파일: outcore.py 프로젝트: pulkin/pyscf
def cholesky_eri_b(mol, erifile, auxbasis='weigend+etb', dataname='eri_mo',
                   int3c='int3c2e_sph', aosym='s2ij', int2c='int2c2e_sph',
                   comp=1, ioblk_size=256, auxmol=None, verbose=logger.NOTE):
    '''3-center 2-electron AO integrals
    '''
    assert(aosym in ('s1', 's2ij'))
    time0 = (time.clock(), time.time())
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(mol.stdout, verbose)
    if auxmol is None:
        auxmol = format_aux_basis(mol, auxbasis)
    j2c = auxmol.intor(int2c, hermi=1)
    log.debug('size of aux basis %d', j2c.shape[0])
    time1 = log.timer('2c2e', *time0)
    try:
        low = scipy.linalg.cholesky(j2c, lower=True)
    except scipy.linalg.LinAlgError:
        j2c[numpy.diag_indices(j2c.shape[1])] += 1e-14
        low = scipy.linalg.cholesky(j2c, lower=True)
    j2c = None
    naux = low.shape[0]
    time1 = log.timer('Cholesky 2c2e', *time1)

    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile)
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    for icomp in range(comp):
        feri.create_group('%s/%d'%(dataname,icomp)) # for h5py old version

    def store(b, label):
        if b.ndim == 3 and b.flags.f_contiguous:
            b = lib.transpose(b.T, axes=(0,2,1)).reshape(naux,-1)
        else:
            b = b.reshape((-1,naux)).T
        cderi = scipy.linalg.solve_triangular(low, b, lower=True, overwrite_b=True)
        feri[label] = cderi

    int3c = gto.moleintor.ascint3(int3c)
    atm, bas, env = gto.mole.conc_env(mol._atm, mol._bas, mol._env,
                                      auxmol._atm, auxmol._bas, auxmol._env)
    ao_loc = gto.moleintor.make_loc(bas, int3c)
    nao = ao_loc[mol.nbas]
    naoaux = ao_loc[-1] - nao
    if aosym == 's1':
        nao_pair = nao * nao
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's1')
    else:
        nao_pair = nao * (nao+1) // 2
        buflen = min(max(int(ioblk_size*1e6/8/naoaux/comp), 1), nao_pair)
        shranges = _guess_shell_ranges(mol, buflen, 's2ij')
    log.debug('erifile %.8g MB, IO buf size %.8g MB',
              naoaux*nao_pair*8/1e6, comp*buflen*naoaux*8/1e6)
    if log.verbose >= logger.DEBUG1:
        log.debug1('shranges = %s', shranges)
    cintopt = gto.moleintor.make_cintopt(atm, bas, env, int3c)
    bufs1 = numpy.empty((comp*max([x[2] for x in shranges]),naoaux))

    for istep, sh_range in enumerate(shranges):
        log.debug('int3c2e [%d/%d], AO [%d:%d], nrow = %d', \
                  istep+1, len(shranges), *sh_range)
        bstart, bend, nrow = sh_range
        shls_slice = (bstart, bend, 0, mol.nbas, mol.nbas, mol.nbas+auxmol.nbas)
        buf = gto.moleintor.getints3c(int3c, atm, bas, env, shls_slice, comp,
                                      aosym, ao_loc, cintopt, out=bufs1)
        if comp == 1:
            store(buf, '%s/0/%d'%(dataname,istep))
        else:
            for icomp in range(comp):
                store(buf[icomp], '%s/%d/%d'%(dataname,icomp,istep))
        time1 = log.timer('gen CD eri [%d/%d]' % (istep+1,len(shranges)), *time1)
    buf = bufs1 = None

    feri.close()
    return erifile