예제 #1
0
파일: incore.py 프로젝트: raybrad/pyscf
def aux_e2(mol, auxmol, intor="cint3c2e_sph", aosym="s1", comp=1, hermi=0, mol1=None):
    """3-center AO integrals (ij|L), where L is the auxiliary basis.
    """
    atm, bas, env = gto.mole.conc_env(mol._atm, mol._bas, mol._env, auxmol._atm, auxmol._bas, auxmol._env)
    if "cart" in intor:
        iloc = jloc = _ri.make_loc(0, mol.nbas, _ri._cgto_cart(bas))
    else:
        iloc = jloc = _ri.make_loc(0, mol.nbas, _ri._cgto_spheric(bas))
    if mol1 is None:
        basrange = (0, mol.nbas, 0, mol.nbas, mol.nbas, auxmol.nbas)
    else:
        # Append mol1 next to auxmol
        atm, bas, env = gto.mole.conc_env(atm, bas, env, mol1._atm, mol1._bas, mol1._env)
        basrange = (0, mol.nbas, mol.nbas + auxmol.nbas, mol1.nbas, mol.nbas, auxmol.nbas)
        jloc = None
    eri = _ri.nr_auxe2(intor, basrange, atm, bas, env, aosym, comp, iloc=iloc, jloc=jloc)
    return eri
예제 #2
0
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):
    '''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.array(atm, dtype=numpy.int32)
    c_bas = numpy.array(bas, dtype=numpy.int32)
    c_env = numpy.array(env)
    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, _ri._cgto_spheric(bas))
        kloc = _ri.make_loc(mol.nbas, auxmol.nbas, _ri._cgto_cart(bas))
    elif 'cart' in int3c:
        ao_loc = _ri.make_loc(0, mol.nbas, _ri._cgto_cart(bas))
        kloc = _ri.make_loc(mol.nbas, auxmol.nbas, _ri._cgto_cart(bas))
    else:
        ao_loc = _ri.make_loc(0, mol.nbas, _ri._cgto_spheric(bas))
        kloc = _ri.make_loc(mol.nbas, auxmol.nbas, _ri._cgto_spheric(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', list(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,
                     nao, nao, naoaux, ao_loc[bstart:bend], 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