def test_ft_aopair2(self): numpy.random.seed(12) invh = numpy.random.random(3) + numpy.eye(3) * 2.5 b = 2*numpy.pi * invh Gv = numpy.dot(lib.cartesian_prod(Gvbase), b) dat = ft_ao.ft_aopair(mol, Gv) self.assertAlmostEqual(finger(dat), (-3.1468496579780125-0.019209667673850885j), 9) dat1 = ft_ao.ft_aopair(mol, Gv, b=b, gxyz=gxyz, Gvbase=Gvbase) self.assertAlmostEqual(finger(dat1), (-3.1468496579780125-0.019209667673850885j), 9)
def test_ft_aopair(self): numpy.random.seed(12) invh = numpy.diag(numpy.random.random(3)) Gv = 2*numpy.pi* numpy.dot(gxyz, invh) dat = ft_ao.ft_aopair(mol, Gv) self.assertAlmostEqual(finger(dat), (-5.9794759129252348+8.07254562525371j), 9) dat_s2 = ft_ao.ft_aopair(mol, Gv, aosym='s2') nao = dat.shape[-1] for i in range(nao): for j in range(i+1): dat[:,i,j] = dat[:,j,i] = dat_s2[:,i*(i+1)//2+j] self.assertAlmostEqual(finger(dat), (-5.9794759129252348+8.07254562525371j), 9)
def test_ft_aopair1(self): dat = ft_ao.ft_aopair(mol, Gv) self.assertAlmostEqual(finger(dat), (-5.9794759129252348+8.07254562525371j), 9) dat_s2 = ft_ao.ft_aopair(mol, Gv, aosym='s2') nao = dat.shape[-1] for i in range(nao): for j in range(i+1): dat[:,i,j] = dat[:,j,i] = dat_s2[:,i*(i+1)//2+j] self.assertAlmostEqual(finger(dat), (-5.9794759129252348+8.07254562525371j), 9) dat1 = ft_ao.ft_aopair(mol, Gv, b=b, gxyz=gxyz, Gvbase=Gvbase) self.assertAlmostEqual(finger(dat1), (-5.9794759129252348+8.07254562525371j), 9)
def test_ft_aopair2(self): numpy.random.seed(12) invh = numpy.random.random(3) + numpy.eye(3) * 2.5 b = 2 * numpy.pi * invh Gv = numpy.dot(lib.cartesian_prod(Gvbase), b) dat = ft_ao.ft_aopair(mol, Gv) self.assertAlmostEqual(finger(dat), (-3.1468496579780125 - 0.019209667673850885j), 9) dat1 = ft_ao.ft_aopair(mol, Gv, b=b, gxyz=gxyz, Gvbase=Gvbase) self.assertAlmostEqual(finger(dat1), (-3.1468496579780125 - 0.019209667673850885j), 9)
def test_ft_aopair(self): numpy.random.seed(12) invh = numpy.diag(numpy.random.random(3)) Gv = 2 * numpy.pi * numpy.dot(gxyz, invh) dat = ft_ao.ft_aopair(mol, Gv) self.assertAlmostEqual(finger(dat), (-5.9794759129252348 + 8.07254562525371j), 9) dat_s2 = ft_ao.ft_aopair(mol, Gv, aosym='s2') nao = dat.shape[-1] for i in range(nao): for j in range(i + 1): dat[:, i, j] = dat[:, j, i] = dat_s2[:, i * (i + 1) // 2 + j] self.assertAlmostEqual(finger(dat), (-5.9794759129252348 + 8.07254562525371j), 9)
def test_ft_aopair1(self): dat = ft_ao.ft_aopair(mol, Gv) self.assertAlmostEqual(finger(dat), (-5.9794759129252348 + 8.07254562525371j), 9) dat_s2 = ft_ao.ft_aopair(mol, Gv, aosym='s2') nao = dat.shape[-1] for i in range(nao): for j in range(i + 1): dat[:, i, j] = dat[:, j, i] = dat_s2[:, i * (i + 1) // 2 + j] self.assertAlmostEqual(finger(dat), (-5.9794759129252348 + 8.07254562525371j), 9) dat1 = ft_ao.ft_aopair(mol, Gv, b=b, gxyz=gxyz, Gvbase=Gvbase) self.assertAlmostEqual(finger(dat1), (-5.9794759129252348 + 8.07254562525371j), 9)
def test_ft_aopair_pxp(self): numpy.random.seed(12) invh = numpy.diag(numpy.random.random(3)) Gv = 2 * numpy.pi * numpy.dot(gxyz, invh) dat = ft_ao.ft_aopair(mol, Gv, intor='GTO_ft_pxp_sph', comp=3) self.assertAlmostEqual(finger(dat), (3.7490985032017079 + 43.665863070814687j), 8)
def test_ft_aopair_pdotp(self): numpy.random.seed(12) invh = numpy.diag(numpy.random.random(3)) Gv = 2 * numpy.pi * numpy.dot(gxyz, invh) dat = ft_ao.ft_aopair(mol, Gv, intor='GTO_ft_pdotp_sph') self.assertAlmostEqual(finger(dat), (-80.69687735727976 + 69.239798150854909j), 9)
def test_ft_aopair_overlap0(self): G = numpy.asarray([[-1.679872, 1.679872, 2.937055], [-1.425679, 1.425679 , 2.492629], [-1.187609 , 1.187609 , 2.076392]]) mol = gto.M(atom='Ne 7 0.0 0.0; Ne 7 0.0 0.0', basis='3-21g') dat = ft_ao.ft_aopair(mol, G) self.assertAlmostEqual(lib.finger(dat), (-1.4150713647161861-0.8020058716859948j), 12)
def test_ft_aopair_overlap0(self): G = numpy.asarray([[-1.679872, 1.679872, 2.937055], [-1.425679, 1.425679, 2.492629], [-1.187609, 1.187609, 2.076392]]) mol = gto.M(atom='Ne 7 0.0 0.0; Ne 7 0.0 0.0', basis='3-21g') dat = ft_ao.ft_aopair(mol, G) self.assertAlmostEqual(lib.fp(dat), (-1.4150713647161861 - 0.8020058716859948j), 12)
def pw_loop(self, mol, auxmol, gs, shls_slice=None, max_memory=2000): '''Plane wave part''' if isinstance(gs, int): gs = [gs]*3 naux = auxmol.nao_nr() Gv, Gvbase, kws = non_uniform_kgrids(gs) nxyz = [i*2 for i in gs] gxyz = lib.cartesian_prod([range(i) for i in nxyz]) kk = numpy.einsum('ki,ki->k', Gv, Gv) idx = numpy.argsort(kk)[::-1] # idx = idx[(kk[idx] < 300.) & (kk[idx] > 1e-4)] # ~ Cut high energy plain waves # log.debug('Cut grids %d to %d', Gv.shape[0], len(idx)) kk = kk[idx] Gv = Gv[idx] kws = kws[idx] gxyz = gxyz[idx] coulG = .5/numpy.pi**2 * kws / kk if shls_slice is None: ni = nj = mol.nao_nr() else: ao_loc = mol.ao_loc_nr() ni = ao_loc[shls_slice[1]] - ao_loc[shls_slice[0]] nj = ao_loc[shls_slice[3]] - ao_loc[shls_slice[2]] nij = ni * nj blksize = min(max(16, int(max_memory*1e6*.7/16/nij)), 16384) sublk = max(16,int(blksize//4)) pqkRbuf = numpy.empty(nij*sublk) pqkIbuf = numpy.empty(nij*sublk) LkRbuf = numpy.empty(naux*sublk) LkIbuf = numpy.empty(naux*sublk) for p0, p1 in lib.prange(0, coulG.size, blksize): aoao = ft_ao.ft_aopair(mol, Gv[p0:p1], shls_slice, 's1', Gvbase, gxyz[p0:p1], nxyz) aoaux = ft_ao.ft_ao(auxmol, Gv[p0:p1], None, Gvbase, gxyz[p0:p1], nxyz) for i0, i1 in lib.prange(0, p1-p0, sublk): nG = i1 - i0 pqkR = numpy.ndarray((ni,nj,nG), buffer=pqkRbuf) pqkI = numpy.ndarray((ni,nj,nG), buffer=pqkIbuf) LkR = numpy.ndarray((naux,nG), buffer=LkRbuf) LkI = numpy.ndarray((naux,nG), buffer=LkIbuf) pqkR[:] = aoao[i0:i1].real.transpose(1,2,0) pqkI[:] = aoao[i0:i1].imag.transpose(1,2,0) LkR [:] = aoaux[i0:i1].real.T LkI [:] = aoaux[i0:i1].imag.T yield (pqkR.reshape(-1,nG), LkR, pqkI.reshape(-1,nG), LkI, coulG[p0+i0:p0+i1]) aoao = aoaux = None
def test_ft_aopair_pxp(self): dat = ft_ao.ft_aopair(mol, Gv, intor='GTO_ft_pxp_sph', comp=3) self.assertAlmostEqual(finger(dat), (3.7490985032017079 + 43.665863070814687j), 8)
def test_ft_aopair_pdotp(self): dat = ft_ao.ft_aopair(mol, Gv, intor='GTO_ft_pdotp_sph') self.assertAlmostEqual(finger(dat), (-80.69687735727976 + 69.239798150854909j), 9)
def _make_j3c(mydf, mol, auxmol): log = logger.Logger(mydf.stdout, mydf.verbose) atm, bas, env, ao_loc = incore._env_and_aoloc('cint3c2e_sph', mol, auxmol) nao = ao_loc[mol.nbas] naux = ao_loc[-1] - nao nao_pair = nao * (nao+1) // 2 cintopt = gto.moleintor.make_cintopt(atm, bas, env, 'cint3c2e_sph') if mydf.approx_sr_level == 0: get_Lpq = _make_Lpq(mydf, mol, auxmol) else: get_Lpq = _make_Lpq_atomic_approx(mydf, mol, auxmol) feri = h5py.File(mydf._cderi) chunks = (min(256,naux), min(256,nao_pair)) # 512K feri.create_dataset('j3c', (naux,nao_pair), 'f8', chunks=chunks) feri.create_dataset('Lpq', (naux,nao_pair), 'f8', chunks=chunks) def save(label, dat, col0, col1): feri[label][:,col0:col1] = dat Gv, Gvbase, kws = non_uniform_kgrids(mydf.gs) nxyz = [i*2 for i in mydf.gs] gxyz = lib.cartesian_prod([range(i) for i in nxyz]) kk = numpy.einsum('ki,ki->k', Gv, Gv) idx = numpy.argsort(kk)[::-1] kk = kk[idx] Gv = Gv[idx] kws = kws[idx] gxyz = gxyz[idx] coulG = .5/numpy.pi**2 * kws / kk aoaux = ft_ao.ft_ao(auxmol, Gv, None, Gvbase, gxyz, nxyz) kLR = numpy.asarray(aoaux.real, order='C') kLI = numpy.asarray(aoaux.imag, order='C') j2c = auxmol.intor('cint2c2e_sph', hermi=1).T # .T to C-ordr lib.dot(kLR.T*coulG, kLR, -1, j2c, 1) lib.dot(kLI.T*coulG, kLI, -1, j2c, 1) kLR *= coulG.reshape(-1,1) kLI *= coulG.reshape(-1,1) aoaux = coulG = kk = kws = idx = None max_memory = max(2000, mydf.max_memory-lib.current_memory()[0]) buflen = min(max(int(max_memory*.3*1e6/8/naux), 1), nao_pair) shranges = outcore._guess_shell_ranges(mol, buflen, 's2ij') buflen = max([x[2] for x in shranges]) blksize = max(16, int(max_memory*.15*1e6/16/buflen)) pqkbuf = numpy.empty(buflen*blksize) bufs1 = numpy.empty((buflen*naux)) # bufs2 holds either Lpq and ft_aopair bufs2 = numpy.empty(max(buflen*(naux+1),buflen*blksize*2)) # *2 for cmplx col1 = 0 for istep, sh_range in enumerate(shranges): log.debug('int3c2e [%d/%d], AO [%d:%d], ncol = %d', \ istep+1, len(shranges), *sh_range) bstart, bend, ncol = sh_range col0, col1 = col1, col1+ncol shls_slice = (bstart, bend, 0, bend, mol.nbas, mol.nbas+auxmol.nbas) Lpq = get_Lpq(shls_slice, col0, col1, bufs2) save('Lpq', Lpq, col0, col1) j3c = _ri.nr_auxe2('cint3c2e_sph', atm, bas, env, shls_slice, ao_loc, 's2ij', 1, cintopt, bufs1) j3c = j3c.T # -> (L|pq) in C-order lib.dot(j2c, Lpq, -.5, j3c, 1) Lpq = None for p0, p1 in lib.prange(0, Gv.shape[0], blksize): aoao = ft_ao.ft_aopair(mol, Gv[p0:p1], shls_slice[:4], 's2', Gvbase, gxyz[p0:p1], nxyz, buf=bufs2) nG = p1 - p0 pqkR = numpy.ndarray((ncol,nG), buffer=pqkbuf) pqkR[:] = aoao.real.T lib.dot(kLR[p0:p1].T, pqkR.T, -1, j3c, 1) pqkI = numpy.ndarray((ncol,nG), buffer=pqkbuf) pqkI[:] = aoao.imag.T lib.dot(kLI[p0:p1].T, pqkI.T, -1, j3c, 1) aoao = aoaux = None save('j3c', j3c, col0, col1) feri.close()
def test_ft_aopair_pxp(self): dat = ft_ao.ft_aopair(mol, Gv, intor='GTO_ft_pxp_sph', comp=3) self.assertAlmostEqual(finger(dat), (3.7490985032017079+43.665863070814687j), 8)
def test_ft_aopair_pdotp(self): dat = ft_ao.ft_aopair(mol, Gv, intor='GTO_ft_pdotp_sph') self.assertAlmostEqual(finger(dat), (-80.69687735727976+69.239798150854909j), 9)