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
def test_pbcintor(): cell = gto.Cell() cell.build(a=numpy.eye(3) * 2.5, atom='C', basis='ccpvdz') pbcopt = _pbcintor.PBCOpt(cell) pbcopt.init_rcut_cond(cell) pbcopt.del_rcut_cond()
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
#!/usr/bin/env python # Copyright 2014-2018 The PySCF Developers. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import unittest import numpy from pyscf.pbc import gto from pyscf.pbc.gto import _pbcintor cell = gto.Cell() cell.build(a=numpy.eye(3) * 2.5, atom='C', basis='ccpvdz') pbcopt = _pbcintor.PBCOpt(cell) pbcopt.init_rcut_cond(cell) pbcopt.del_rcut_cond()
def wrap_int3c(cell, auxcell, intor='int3c2e', aosym='s1', comp=1, kptij_lst=numpy.zeros((1, 2, 3)), cintopt=None, pbcopt=None): intor = cell._add_suffix(intor) 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) ao_loc = gto.moleintor.make_loc(bas, intor) aux_loc = auxcell.ao_loc_nr(auxcell.cart or 'ssc' in intor) ao_loc = numpy.asarray(numpy.hstack([ao_loc, ao_loc[-1] + aux_loc[1:]]), dtype=numpy.int32) atm, bas, env = gto.conc_env(atm, bas, env, auxcell._atm, auxcell._bas, auxcell._env) Ls = cell.get_lattice_Ls() nimgs = len(Ls) kpti = kptij_lst[:, 0] kptj = kptij_lst[:, 1] if gamma_point(kptij_lst): kk_type = 'g' dtype = numpy.double nkpts = nkptij = 1 kptij_idx = numpy.array([0], dtype=numpy.int32) expkL = numpy.ones(1) elif is_zero(kpti - kptj): # j_only kk_type = 'k' dtype = numpy.complex128 kpts = kptij_idx = numpy.asarray(kpti, order='C') expkL = numpy.exp(1j * numpy.dot(kpts, Ls.T)) nkpts = nkptij = len(kpts) else: kk_type = 'kk' dtype = numpy.complex128 kpts = unique(numpy.vstack([kpti, kptj]))[0] expkL = numpy.exp(1j * numpy.dot(kpts, Ls.T)) wherei = numpy.where( abs(kpti.reshape(-1, 1, 3) - kpts).sum(axis=2) < KPT_DIFF_TOL)[1] wherej = numpy.where( abs(kptj.reshape(-1, 1, 3) - kpts).sum(axis=2) < KPT_DIFF_TOL)[1] nkpts = len(kpts) kptij_idx = numpy.asarray(wherei * nkpts + wherej, dtype=numpy.int32) nkptij = len(kptij_lst) fill = 'PBCnr3c_fill_%s%s' % (kk_type, aosym[:2]) drv = libpbc.PBCnr3c_drv if cintopt is None: cintopt = _vhf.make_cintopt(atm, bas, env, intor) # Remove the precomputed pair data because the pair data corresponds to the # integral of cell #0 while the lattice sum moves shls to all repeated images. if intor[:3] != 'ECP': libpbc.CINTdel_pairdata_optimizer(cintopt) if pbcopt is None: pbcopt = _pbcintor.PBCOpt(pcell).init_rcut_cond(pcell) if isinstance(pbcopt, _pbcintor.PBCOpt): cpbcopt = pbcopt._this else: cpbcopt = lib.c_null_ptr() nbas = cell.nbas def int3c(shls_slice, out): shls_slice = (shls_slice[0], shls_slice[1], nbas + shls_slice[2], nbas + shls_slice[3], nbas * 2 + shls_slice[4], nbas * 2 + shls_slice[5]) drv( getattr(libpbc, intor), getattr(libpbc, fill), out.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nkptij), ctypes.c_int(nkpts), ctypes.c_int(comp), ctypes.c_int(nimgs), 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, cpbcopt, atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell.natm), bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nbas), # need to pass cell.nbas to libpbc.PBCnr3c_drv env.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(env.size)) return out return int3c