Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def _make_Lpq(mydf, mol, auxmol):
    atm, bas, env, ao_loc = incore._env_and_aoloc('cint3c1e_sph', mol, auxmol)
    nao = ao_loc[mol.nbas]
    naux = ao_loc[-1] - nao
    nao_pair = nao * (nao+1) // 2

    if mydf.metric.upper() == 'S':
        intor = 'cint3c1e_sph'
        s_aux = auxmol.intor_symmetric('cint1e_ovlp_sph')
    elif mydf.metric.upper() == 'T':
        intor = 'cint3c1e_p2_sph'
        s_aux = auxmol.intor_symmetric('cint1e_kin_sph') * 2
    else:  # metric.upper() == 'J'
        intor = 'cint3c2e_sph'
        s_aux = incore.fill_2c2e(mol, auxmol)
    cintopt = gto.moleintor.make_cintopt(atm, bas, env, intor)

    if mydf.charge_constraint:
        ovlp = lib.pack_tril(mol.intor_symmetric('cint1e_ovlp_sph'))

        aux_loc = auxmol.ao_loc_nr()
        s_index = numpy.hstack([range(aux_loc[i],aux_loc[i+1])
                                for i,l in enumerate(auxmol._bas[:,ANG_OF]) if l == 0])
        a = numpy.zeros((naux+1,naux+1))
        a[:naux,:naux] = s_aux
        a[naux,s_index] = a[s_index,naux] = 1
        try:
            cd = scipy.linalg.cho_factor(a)
            def solve(Lpq):
                return scipy.linalg.cho_solve(cd, Lpq)
        except scipy.linalg.LinAlgError:
            def solve(Lpq):
                return scipy.linalg.solve(a, Lpq)
    else:
        cd = scipy.linalg.cho_factor(s_aux)
        def solve(Lpq):
            return scipy.linalg.cho_solve(cd, Lpq, overwrite_b=True)

    def get_Lpq(shls_slice, col0, col1, buf):
        # Be cautious here, _ri.nr_auxe2 assumes buf in F-order
        Lpq = _ri.nr_auxe2(intor, atm, bas, env, shls_slice, ao_loc,
                           's2ij', 1, cintopt, buf).T
        if mydf.charge_constraint:
            Lpq = numpy.ndarray(shape=(naux+1,col1-col0), buffer=buf)
            Lpq[naux,:] = ovlp[col0:col1]
            Lpq1 = solve(Lpq)
            assert(Lpq1.flags.f_contiguous)
            lib.transpose(Lpq1.T, out=Lpq)
            return Lpq[:naux]
        else:
            return solve(Lpq)
    return get_Lpq
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
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):
    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
Exemplo n.º 7
0
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