Exemplo n.º 1
0
def run3c(fill, kpts, shls_slice=None):
    intor = 'int3c2e_sph'
    nao = cell.nao_nr()
    nkpts = len(kpts)
    if fill == 'PBCnr3c_fill_gs2':
        out = numpy.empty((nao * (nao + 1) // 2, nao))
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
    elif fill == 'PBCnr3c_fill_gs1':
        out = numpy.empty((nao, nao, nao))
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
    elif fill in ('PBCnr3c_fill_kks1', 'PBCnr3c_fill_kks2'):
        kptij_idx = numpy.asarray(
            [i * nkpts + j for i in range(nkpts) for j in range(i + 1)],
            dtype=numpy.int32)
        out = numpy.empty((len(kptij_idx), nao, nao, nao),
                          dtype=numpy.complex128)
    elif fill == 'PBCnr3c_fill_ks1':
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
        out = numpy.empty((nkpts, nao, nao, nao), dtype=numpy.complex128)
    elif fill == 'PBCnr3c_fill_ks2':
        out = numpy.empty((nkpts, nao * (nao + 1) // 2, nao),
                          dtype=numpy.complex128)
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
    else:
        raise RuntimeError
    nkpts_ij = len(kptij_idx)
    nimgs = len(Ls)
    expkL = numpy.exp(1j * numpy.dot(kpts, Ls.T))
    comp = 1
    if shls_slice is None:
        shls_slice = (0, cell.nbas, cell.nbas, cell.nbas * 2, cell.nbas * 2,
                      cell.nbas * 3)

    pcell = copy.copy(cell)
    pcell._atm, pcell._bas, pcell._env = \
    atm, bas, env = gto.conc_env(cell._atm, cell._bas, cell._env,
                                 cell._atm, cell._bas, cell._env)
    atm, bas, env = gto.conc_env(atm, bas, env, cell._atm, cell._bas,
                                 cell._env)
    ao_loc = gto.moleintor.make_loc(bas, 'int3c2e_sph')
    cintopt = lib.c_null_ptr()
    pbcopt = _pbcintor.PBCOpt(pcell).init_rcut_cond(pcell, 1e-9)

    libpbc.PBCnr3c_drv(getattr(libpbc, intor), getattr(libpbc, fill),
                       out.ctypes.data_as(ctypes.c_void_p),
                       ctypes.c_int(nkpts_ij), ctypes.c_int(nkpts),
                       ctypes.c_int(comp), ctypes.c_int(len(Ls)),
                       Ls.ctypes.data_as(ctypes.c_void_p),
                       expkL.ctypes.data_as(ctypes.c_void_p),
                       kptij_idx.ctypes.data_as(ctypes.c_void_p),
                       (ctypes.c_int * 6)(*shls_slice),
                       ao_loc.ctypes.data_as(ctypes.c_void_p), cintopt,
                       lib.c_null_ptr(), atm.ctypes.data_as(ctypes.c_void_p),
                       ctypes.c_int(cell.natm),
                       bas.ctypes.data_as(ctypes.c_void_p),
                       ctypes.c_int(cell.nbas),
                       env.ctypes.data_as(ctypes.c_void_p),
                       ctypes.c_int(env.size))
    return out
Exemplo n.º 2
0
def run3c(fill, kpts, shls_slice=None):
    intor = 'int3c2e_sph'
    nao = cell.nao_nr()
    nkpts = len(kpts)
    if fill == 'PBCnr3c_fill_gs2':
        out = numpy.empty((nao*(nao+1)//2,nao))
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
    elif fill == 'PBCnr3c_fill_gs1':
        out = numpy.empty((nao,nao,nao))
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
    elif fill in ('PBCnr3c_fill_kks1', 'PBCnr3c_fill_kks2'):
        kptij_idx = numpy.asarray([i*nkpts+j for i in range(nkpts) for j in range(i+1)], dtype=numpy.int32)
        out = numpy.empty((len(kptij_idx),nao,nao,nao), dtype=numpy.complex128)
    elif fill == 'PBCnr3c_fill_ks1':
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
        out = numpy.empty((nkpts,nao,nao,nao), dtype=numpy.complex128)
    elif fill == 'PBCnr3c_fill_ks2':
        out = numpy.empty((nkpts,nao*(nao+1)//2,nao), dtype=numpy.complex128)
        kptij_idx = numpy.arange(nkpts).astype(numpy.int32)
    else:
        raise RuntimeError
    nkpts_ij = len(kptij_idx)
    nimgs = len(Ls)
    expkL = numpy.exp(1j*numpy.dot(kpts, Ls.T))
    comp = 1
    if shls_slice is None:
        shls_slice = (0, cell.nbas, cell.nbas, cell.nbas*2,
                      cell.nbas*2, cell.nbas*3)

    pcell = copy.copy(cell)
    pcell._atm, pcell._bas, pcell._env = \
    atm, bas, env = gto.conc_env(cell._atm, cell._bas, cell._env,
                                 cell._atm, cell._bas, cell._env)
    atm, bas, env = gto.conc_env(atm, bas, env,
                                 cell._atm, cell._bas, cell._env)
    ao_loc = gto.moleintor.make_loc(bas, 'int3c2e_sph')
    cintopt = lib.c_null_ptr()
    pbcopt = _pbcintor.PBCOpt(pcell).init_rcut_cond(pcell, 1e-9)

    libpbc.PBCnr3c_drv(getattr(libpbc, intor), getattr(libpbc, fill),
                       out.ctypes.data_as(ctypes.c_void_p),
                       ctypes.c_int(nkpts_ij), ctypes.c_int(nkpts),
                       ctypes.c_int(comp), ctypes.c_int(len(Ls)),
                       Ls.ctypes.data_as(ctypes.c_void_p),
                       expkL.ctypes.data_as(ctypes.c_void_p),
                       kptij_idx.ctypes.data_as(ctypes.c_void_p),
                       (ctypes.c_int*6)(*shls_slice),
                       ao_loc.ctypes.data_as(ctypes.c_void_p), cintopt, pbcopt._this,
                       atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell.natm),
                       bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell.nbas),
                       env.ctypes.data_as(ctypes.c_void_p))
    return out
Exemplo n.º 3
0
def run2c(intor, fill, kpts, shls_slice=None):
    nkpts = len(kpts)

    atm, bas, env = gto.conc_env(cell._atm, cell._bas, cell._env, cell._atm,
                                 cell._bas, cell._env)
    if shls_slice is None:
        shls_slice = (0, cell.nbas, cell.nbas, cell.nbas * 2)
    ao_loc = gto.moleintor.make_loc(bas, intor)
    ni = ao_loc[shls_slice[1]] - ao_loc[shls_slice[0]]
    nj = ao_loc[shls_slice[3]] - ao_loc[shls_slice[2]]
    comp = 1
    out = numpy.empty((nkpts, comp, ni, nj), dtype=numpy.complex128)

    fintor = getattr(gto.moleintor.libcgto, intor)
    fill = getattr(libpbc, fill)
    intopt = lib.c_null_ptr()

    Ls = cell.get_lattice_Ls()
    expkL = numpy.asarray(numpy.exp(1j * numpy.dot(kpts, Ls.T)), order='C')
    drv = libpbc.PBCnr2c_drv
    drv(fintor, fill, out.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nkpts),
        ctypes.c_int(comp), ctypes.c_int(len(Ls)),
        Ls.ctypes.data_as(ctypes.c_void_p),
        expkL.ctypes.data_as(ctypes.c_void_p),
        (ctypes.c_int * 4)(*(shls_slice[:4])),
        ao_loc.ctypes.data_as(ctypes.c_void_p), intopt,
        atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell.natm),
        bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell.nbas),
        env.ctypes.data_as(ctypes.c_void_p))
    return out
Exemplo n.º 4
0
def run2c(intor, fill, kpts, shls_slice=None):
    nkpts = len(kpts)

    pcell = copy.copy(cell)
    pcell._atm, pcell._bas, pcell._env = \
    atm, bas, env = gto.conc_env(cell._atm, cell._bas, cell._env,
                                 cell._atm, cell._bas, cell._env)
    if shls_slice is None:
        shls_slice = (0, cell.nbas, cell.nbas, cell.nbas*2)
    ao_loc = gto.moleintor.make_loc(bas, intor)
    ni = ao_loc[shls_slice[1]] - ao_loc[shls_slice[0]]
    nj = ao_loc[shls_slice[3]] - ao_loc[shls_slice[2]]
    comp = 1
    out = numpy.empty((nkpts,comp,ni,nj), dtype=numpy.complex128)

    fintor = getattr(gto.moleintor.libcgto, intor)
    fill = getattr(libpbc, fill)
    intopt = lib.c_null_ptr()
    pbcopt = _pbcintor.PBCOpt(pcell).init_rcut_cond(pcell, 1e-9)

    expkL = numpy.asarray(numpy.exp(1j*numpy.dot(kpts, Ls.T)), order='C')
    drv = libpbc.PBCnr2c_drv
    drv(fintor, fill, out.ctypes.data_as(ctypes.c_void_p),
        ctypes.c_int(nkpts), ctypes.c_int(comp), ctypes.c_int(len(Ls)),
        Ls.ctypes.data_as(ctypes.c_void_p),
        expkL.ctypes.data_as(ctypes.c_void_p),
        (ctypes.c_int*4)(*(shls_slice[:4])),
        ao_loc.ctypes.data_as(ctypes.c_void_p), intopt, pbcopt._this,
        atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell.natm),
        bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell.nbas),
        env.ctypes.data_as(ctypes.c_void_p))
    return out
Exemplo n.º 5
0
def _int_nuc_vloc(mydf, nuccell, kpts, dm_kpts):
    '''Vnuc - Vloc'''
    cell = mydf.cell
    nkpts = len(kpts)

    # Use the 3c2e code with steep s gaussians to mimic nuclear density
    fakenuc = aft._fake_nuc(cell)
    fakenuc._atm, fakenuc._bas, fakenuc._env = \
            gto.conc_env(nuccell._atm, nuccell._bas, nuccell._env,
                         fakenuc._atm, fakenuc._bas, fakenuc._env)

    kptij_lst = numpy.hstack((kpts,kpts)).reshape(-1,2,3)
    v3c = df.incore.aux_e2(cell, fakenuc, 'int3c2e_ipip1', aosym='s1', comp=9,
                           kptij_lst=kptij_lst)
    v3c += df.incore.aux_e2(cell, fakenuc, 'int3c2e_ipvip1', aosym='s1', comp=9,
                            kptij_lst=kptij_lst)

    nao = cell.nao_nr()
    natm = cell.natm
    v3c = v3c.reshape(nkpts,3,3,nao,nao,natm*2)
    efg_loc = 1./nkpts * numpy.einsum('kxypqz,kqp->zxy', v3c, dm_kpts)
    efg_loc+= 1./nkpts * numpy.einsum('kyxqpz,kqp->zxy', v3c, dm_kpts)
    v3c = None

    # Fermi contact
    fc = df.incore.aux_e2(cell, fakenuc, 'int3c1e', aosym='s1', kptij_lst=kptij_lst)
    fc = fc.reshape(nkpts,nao,nao,natm*2)
    vfc = 1./nkpts * numpy.einsum('kpqz,kqp->z', fc, dm_kpts)
    for i in range(3):
        efg_loc[:,i,i] += 4./3*numpy.pi * vfc

    nuc_part = efg_loc[:natm]
    modchg_part = efg_loc[natm:]
    efg_loc = nuc_part - modchg_part

    if cell.dimension == 3:
        fac = numpy.pi/cell.vol
        nucbar = numpy.array([fac/nuccell.bas_exp(i)[0] for i in range(natm)])

        ipip = cell.pbc_intor('int1e_ipipovlp', 9, lib.HERMITIAN, kpts)
        ipvip = cell.pbc_intor('int1e_ipovlpip', 9, lib.HERMITIAN, kpts)
        d2rho_bar = 0
        for k in range(nkpts):
            v = (ipip[k] + ipvip[k]).reshape(3,3,nao,nao)
            d2rho_bar += numpy.einsum('xypq,qp->xy', v, dm_kpts[k])
            d2rho_bar += numpy.einsum('yxqp,qp->xy', v, dm_kpts[k])
        d2rho_bar *= 1./nkpts

        efg_loc -= numpy.einsum('z,xy->zxy', nucbar, d2rho_bar)
    return efg_loc.real
Exemplo n.º 6
0
def _int_nuc_vloc(mydf, nuccell, kpts, dm_kpts):
    '''Vnuc - Vloc'''
    cell = mydf.cell
    nkpts = len(kpts)

    # Use the 3c2e code with steep s gaussians to mimic nuclear density
    fakenuc = aft._fake_nuc(cell)
    fakenuc._atm, fakenuc._bas, fakenuc._env = \
            gto.conc_env(nuccell._atm, nuccell._bas, nuccell._env,
                         fakenuc._atm, fakenuc._bas, fakenuc._env)

    kptij_lst = numpy.hstack((kpts,kpts)).reshape(-1,2,3)
    v3c = df.incore.aux_e2(cell, fakenuc, 'int3c2e_ipip1', aosym='s1', comp=9,
                           kptij_lst=kptij_lst)
    v3c += df.incore.aux_e2(cell, fakenuc, 'int3c2e_ipvip1', aosym='s1', comp=9,
                            kptij_lst=kptij_lst)

    nao = cell.nao_nr()
    natm = cell.natm
    v3c = v3c.reshape(nkpts,3,3,nao,nao,natm*2)
    efg_loc = 1./nkpts * numpy.einsum('kxypqz,kqp->zxy', v3c, dm_kpts)
    efg_loc+= 1./nkpts * numpy.einsum('kyxqpz,kqp->zxy', v3c, dm_kpts)
    v3c = None

    # Fermi contact
    fc = df.incore.aux_e2(cell, fakenuc, 'int3c1e', aosym='s1', kptij_lst=kptij_lst)
    fc = fc.reshape(nkpts,nao,nao,natm*2)
    vfc = 1./nkpts * numpy.einsum('kpqz,kqp->z', fc, dm_kpts)
    for i in range(3):
        efg_loc[:,i,i] += 4./3*numpy.pi * vfc

    nuc_part = efg_loc[:natm]
    modchg_part = efg_loc[natm:]
    efg_loc = nuc_part - modchg_part

    if cell.dimension == 3:
        fac = numpy.pi/cell.vol
        nucbar = numpy.array([fac/nuccell.bas_exp(i)[0] for i in range(natm)])

        ipip = cell.pbc_intor('int1e_ipipovlp', 9, lib.HERMITIAN, kpts)
        ipvip = cell.pbc_intor('int1e_ipovlpip', 9, lib.HERMITIAN, kpts)
        d2rho_bar = 0
        for k in range(nkpts):
            v = (ipip[k] + ipvip[k]).reshape(3,3,nao,nao)
            d2rho_bar += numpy.einsum('xypq,qp->xy', v, dm_kpts[k])
            d2rho_bar += numpy.einsum('yxqp,qp->xy', v, dm_kpts[k])
        d2rho_bar *= 1./nkpts

        efg_loc -= numpy.einsum('z,xy->zxy', nucbar, d2rho_bar)
    return efg_loc.real