def get_pnucp(mydf, kpts=None): cell = mydf.cell if kpts is None: kpts_lst = numpy.zeros((1, 3)) else: kpts_lst = numpy.reshape(kpts, (-1, 3)) log = logger.Logger(mydf.stdout, mydf.verbose) t1 = (logger.process_clock(), logger.perf_counter()) nkpts = len(kpts_lst) nao = cell.nao_nr() nao_pair = nao * (nao + 1) // 2 Gv, Gvbase, kws = cell.get_Gv_weights(mydf.mesh) charge = -cell.atom_charges() kpt_allow = numpy.zeros(3) coulG = tools.get_coulG(cell, kpt_allow, mesh=mydf.mesh, Gv=Gv) coulG *= kws if mydf.eta == 0: wj = numpy.zeros((nkpts, nao_pair), dtype=numpy.complex128) SI = cell.get_SI(Gv) vG = numpy.einsum('i,ix->x', charge, SI) * coulG wj = numpy.zeros((nkpts, nao_pair), dtype=numpy.complex128) else: nuccell = copy.copy(cell) half_sph_norm = .5 / numpy.sqrt(numpy.pi) norm = half_sph_norm / mole.gaussian_int(2, mydf.eta) chg_env = [mydf.eta, norm] ptr_eta = cell._env.size ptr_norm = ptr_eta + 1 chg_bas = [[ia, 0, 1, 1, 0, ptr_eta, ptr_norm, 0] for ia in range(cell.natm)] nuccell._atm = cell._atm nuccell._bas = numpy.asarray(chg_bas, dtype=numpy.int32) nuccell._env = numpy.hstack((cell._env, chg_env)) wj = lib.asarray(mydf._int_nuc_vloc(nuccell, kpts_lst, 'int3c2e_pvp1')) t1 = log.timer_debug1('pnucp pass1: analytic int', *t1) aoaux = ft_ao.ft_ao(nuccell, Gv) vG = numpy.einsum('i,xi->x', charge, aoaux) * coulG if cell.dimension == 3: nucbar = sum( [z / nuccell.bas_exp(i)[0] for i, z in enumerate(charge)]) nucbar *= numpy.pi / cell.vol ovlp = cell.pbc_intor('int1e_kin', 1, lib.HERMITIAN, kpts_lst) for k in range(nkpts): s = lib.pack_tril(ovlp[k]) # *2 due to the factor 1/2 in T wj[k] -= nucbar * 2 * s max_memory = max(2000, mydf.max_memory - lib.current_memory()[0]) for aoaoks, p0, p1 in mydf.ft_loop(mydf.mesh, kpt_allow, kpts_lst, max_memory=max_memory, aosym='s2', intor='GTO_ft_pdotp'): for k, aoao in enumerate(aoaoks): if aft_jk.gamma_point(kpts_lst[k]): wj[k] += numpy.einsum('k,kx->x', vG[p0:p1].real, aoao.real) wj[k] += numpy.einsum('k,kx->x', vG[p0:p1].imag, aoao.imag) else: wj[k] += numpy.einsum('k,kx->x', vG[p0:p1].conj(), aoao) t1 = log.timer_debug1('contracting pnucp', *t1) wj_kpts = [] for k, kpt in enumerate(kpts_lst): if aft_jk.gamma_point(kpt): wj_kpts.append(lib.unpack_tril(wj[k].real.copy())) else: wj_kpts.append(lib.unpack_tril(wj[k])) if kpts is None or numpy.shape(kpts) == (3, ): wj_kpts = wj_kpts[0] return numpy.asarray(wj_kpts)
def get_pbc_pvxp(cell, kpts=None): import numpy import copy import time from pyscf import lib from pyscf.lib import logger from pyscf.pbc import tools from pyscf.gto import mole from pyscf.pbc.df import ft_ao from pyscf.pbc.df import aft_jk from pyscf.pbc.df import aft if kpts is None: kpts_lst = numpy.zeros((1,3)) else: kpts_lst = numpy.reshape(kpts, (-1,3)) log = logger.Logger(cell.stdout, cell.verbose) t1 = t0 = (time.clock(), time.time()) mydf = aft.AFTDF(cell, kpts) mydf.eta = 0.2 ke_guess = aft.estimate_ke_cutoff_for_eta(cell, mydf.eta, cell.precision) mydf.mesh = tools.cutoff_to_mesh(cell.lattice_vectors(), ke_guess) log.debug('mydf.mesh %s', mydf.mesh) nkpts = len(kpts_lst) nao = cell.nao_nr() nao_pair = nao * (nao+1) // 2 Gv, Gvbase, kws = cell.get_Gv_weights(mydf.mesh) charge = -cell.atom_charges() # Apply Koseki effective charge? kpt_allow = numpy.zeros(3) coulG = tools.get_coulG(cell, kpt_allow, mesh=mydf.mesh, Gv=Gv) coulG *= kws if mydf.eta == 0: soc_mat = numpy.zeros((nkpts,3,nao*nao), dtype=numpy.complex128) SI = cell.get_SI(Gv) vG = numpy.einsum('i,ix->x', charge, SI) * coulG else: nuccell = copy.copy(cell) half_sph_norm = .5/numpy.sqrt(numpy.pi) norm = half_sph_norm/mole.gaussian_int(2, mydf.eta) chg_env = [mydf.eta, norm] ptr_eta = cell._env.size ptr_norm = ptr_eta + 1 chg_bas = [[ia, 0, 1, 1, 0, ptr_eta, ptr_norm, 0] for ia in range(cell.natm)] nuccell._atm = cell._atm nuccell._bas = numpy.asarray(chg_bas, dtype=numpy.int32) nuccell._env = numpy.hstack((cell._env, chg_env)) soc_mat = mydf._int_nuc_vloc(nuccell, kpts_lst, 'int3c2e_pvxp1_sph', aosym='s1', comp=3) soc_mat = numpy.asarray(soc_mat).reshape(nkpts,3,nao**2) t1 = log.timer_debug1('pnucp pass1: analytic int', *t1) aoaux = ft_ao.ft_ao(nuccell, Gv) vG = numpy.einsum('i,xi->x', charge, aoaux) * coulG max_memory = max(2000, mydf.max_memory-lib.current_memory()[0]) for aoaoks, p0, p1 in mydf.ft_loop(mydf.mesh, kpt_allow, kpts_lst, max_memory=max_memory, aosym='s1', intor='GTO_ft_pxp_sph', comp=3): for k, aoao in enumerate(aoaoks): aoao = aoao.reshape(3,-1,nao**2) if aft_jk.gamma_point(kpts_lst[k]): soc_mat[k] += numpy.einsum('k,ckx->cx', vG[p0:p1].real, aoao.real) soc_mat[k] += numpy.einsum('k,ckx->cx', vG[p0:p1].imag, aoao.imag) else: soc_mat[k] += numpy.einsum('k,ckx->cx', vG[p0:p1].conj(), aoao) t1 = log.timer_debug1('contracting pnucp', *t1) soc_mat_kpts = [] for k, kpt in enumerate(kpts_lst): if aft_jk.gamma_point(kpt): soc_mat_kpts.append(soc_mat[k].real.reshape(3,nao,nao)) else: soc_mat_kpts.append(soc_mat[k].reshape(3,nao,nao)) if kpts is None or numpy.shape(kpts) == (3,): soc_mat_kpts = soc_mat_kpts[0] return numpy.asarray(soc_mat_kpts)
def get_pnucp(mydf, kpts=None): cell = mydf.cell if kpts is None: kpts_lst = numpy.zeros((1, 3)) else: kpts_lst = numpy.reshape(kpts, (-1, 3)) log = logger.Logger(mydf.stdout, mydf.verbose) t1 = t0 = (time.clock(), time.time()) nkpts = len(kpts_lst) nao = cell.nao_nr() nao_pair = nao * (nao + 1) // 2 Gv, Gvbase, kws = cell.get_Gv_weights(mydf.gs) kpt_allow = numpy.zeros(3) if mydf.eta == 0: charge = -cell.atom_charges() #coulG=4*numpy.pi/G^2 is cancelled with (sigma dot p i, sigma dot p j) SI = cell.get_SI(Gv) vGR = numpy.einsum('i,ix->x', 4 * numpy.pi * charge, SI.real) * kws vGI = numpy.einsum('i,ix->x', 4 * numpy.pi * charge, SI.imag) * kws wjR = numpy.zeros((nkpts, nao_pair)) wjI = numpy.zeros((nkpts, nao_pair)) else: nuccell = copy.copy(cell) half_sph_norm = .5 / numpy.sqrt(numpy.pi) norm = half_sph_norm / mole._gaussian_int(2, mydf.eta) chg_env = [mydf.eta, norm] ptr_eta = cell._env.size ptr_norm = ptr_eta + 1 chg_bas = [[ia, 0, 1, 1, 0, ptr_eta, ptr_norm, 0] for ia in range(cell.natm)] nuccell._atm = cell._atm nuccell._bas = numpy.asarray(chg_bas, dtype=numpy.int32) nuccell._env = numpy.hstack((cell._env, chg_env)) wj = lib.asarray( mydf._int_nuc_vloc(nuccell, kpts_lst, 'int3c2e_pvp1_sph')) wjR = wj.real wjI = wj.imag t1 = log.timer_debug1('pnucp pass1: analytic int', *t1) charge = -cell.atom_charges() #coulG=4*numpy.pi/G^2 is cancelled with (sigma dot p i, sigma dot p j) aoaux = ft_ao.ft_ao(nuccell, Gv) vGR = numpy.einsum('i,xi->x', 4 * numpy.pi * charge, aoaux.real) * kws vGI = numpy.einsum('i,xi->x', 4 * numpy.pi * charge, aoaux.imag) * kws max_memory = max(2000, mydf.max_memory - lib.current_memory()[0]) for k, pqkR, pqkI, p0, p1 \ in mydf.ft_loop(mydf.gs, kpt_allow, kpts_lst, max_memory=max_memory, aosym='s2'): # rho_ij(G) nuc(-G) / G^2 # = [Re(rho_ij(G)) + Im(rho_ij(G))*1j] [Re(nuc(G)) - Im(nuc(G))*1j] / G^2 if not aft_jk.gamma_point(kpts_lst[k]): wjI[k] += numpy.einsum('k,xk->x', vGR[p0:p1], pqkI) wjI[k] -= numpy.einsum('k,xk->x', vGI[p0:p1], pqkR) wjR[k] += numpy.einsum('k,xk->x', vGR[p0:p1], pqkR) wjR[k] += numpy.einsum('k,xk->x', vGI[p0:p1], pqkI) t1 = log.timer_debug1('contracting Vnuc', *t1) if mydf.eta != 0 and cell.dimension == 3: nucbar = sum([z / nuccell.bas_exp(i)[0] for i, z in enumerate(charge)]) nucbar *= numpy.pi / cell.vol * 2 ovlp = cell.pbc_intor('int1e_kin_sph', 1, lib.HERMITIAN, kpts_lst) for k in range(nkpts): s = lib.pack_tril(ovlp[k]) wjR[k] -= nucbar * s.real wjI[k] -= nucbar * s.imag wj = [] for k, kpt in enumerate(kpts_lst): if aft_jk.gamma_point(kpt): wj.append(lib.unpack_tril(wjR[k])) else: wj.append(lib.unpack_tril(wjR[k] + wjI[k] * 1j)) if kpts is None or numpy.shape(kpts) == (3, ): wj = wj[0] return wj
def get_pnucp(mydf, kpts=None): cell = mydf.cell if kpts is None: kpts_lst = numpy.zeros((1,3)) else: kpts_lst = numpy.reshape(kpts, (-1,3)) log = logger.Logger(mydf.stdout, mydf.verbose) t1 = t0 = (time.clock(), time.time()) nkpts = len(kpts_lst) nao = cell.nao_nr() nao_pair = nao * (nao+1) // 2 Gv, Gvbase, kws = cell.get_Gv_weights(mydf.mesh) charge = -cell.atom_charges() kpt_allow = numpy.zeros(3) coulG = tools.get_coulG(cell, kpt_allow, mesh=mydf.mesh, Gv=Gv) coulG *= kws if mydf.eta == 0: wj = numpy.zeros((nkpts,nao_pair), dtype=numpy.complex128) SI = cell.get_SI(Gv) vG = numpy.einsum('i,ix->x', charge, SI) * coulG wj = numpy.zeros((nkpts,nao_pair), dtype=numpy.complex128) else: nuccell = copy.copy(cell) half_sph_norm = .5/numpy.sqrt(numpy.pi) norm = half_sph_norm/mole.gaussian_int(2, mydf.eta) chg_env = [mydf.eta, norm] ptr_eta = cell._env.size ptr_norm = ptr_eta + 1 chg_bas = [[ia, 0, 1, 1, 0, ptr_eta, ptr_norm, 0] for ia in range(cell.natm)] nuccell._atm = cell._atm nuccell._bas = numpy.asarray(chg_bas, dtype=numpy.int32) nuccell._env = numpy.hstack((cell._env, chg_env)) wj = lib.asarray(mydf._int_nuc_vloc(nuccell, kpts_lst, 'int3c2e_pvp1')) t1 = log.timer_debug1('pnucp pass1: analytic int', *t1) aoaux = ft_ao.ft_ao(nuccell, Gv) vG = numpy.einsum('i,xi->x', charge, aoaux) * coulG if cell.dimension == 3: nucbar = sum([z/nuccell.bas_exp(i)[0] for i,z in enumerate(charge)]) nucbar *= numpy.pi/cell.vol ovlp = cell.pbc_intor('int1e_kin', 1, lib.HERMITIAN, kpts_lst) for k in range(nkpts): s = lib.pack_tril(ovlp[k]) # *2 due to the factor 1/2 in T wj[k] -= nucbar*2 * s max_memory = max(2000, mydf.max_memory-lib.current_memory()[0]) for aoaoks, p0, p1 in mydf.ft_loop(mydf.mesh, kpt_allow, kpts_lst, max_memory=max_memory, aosym='s2', intor='GTO_ft_pdotp'): for k, aoao in enumerate(aoaoks): if aft_jk.gamma_point(kpts_lst[k]): wj[k] += numpy.einsum('k,kx->x', vG[p0:p1].real, aoao.real) wj[k] += numpy.einsum('k,kx->x', vG[p0:p1].imag, aoao.imag) else: wj[k] += numpy.einsum('k,kx->x', vG[p0:p1].conj(), aoao) t1 = log.timer_debug1('contracting pnucp', *t1) wj_kpts = [] for k, kpt in enumerate(kpts_lst): if aft_jk.gamma_point(kpt): wj_kpts.append(lib.unpack_tril(wj[k].real.copy())) else: wj_kpts.append(lib.unpack_tril(wj[k])) if kpts is None or numpy.shape(kpts) == (3,): wj_kpts = wj_kpts[0] return numpy.asarray(wj_kpts)