def _init_df_eris(cc, eris): from pyscf.pbc.df import df from pyscf.ao2mo import _ao2mo if cc._scf.with_df._cderi is None: cc._scf.with_df.build() cell = cc._scf.cell if cell.dimension == 2: # 2D ERIs are not positive definite. The 3-index tensors are stored in # two part. One corresponds to the positive part and one corresponds # to the negative part. The negative part is not considered in the # DF-driven CCSD implementation. raise NotImplementedError nocc = cc.nocc nmo = cc.nmo nvir = nmo - nocc nao = cell.nao_nr() kpts = cc.kpts nkpts = len(kpts) naux = cc._scf.with_df.get_naoaux() if gamma_point(kpts): dtype = np.double else: dtype = np.complex128 dtype = np.result_type(dtype, *eris.mo_coeff) eris.Lpv = Lpv = np.empty((nkpts, nkpts), dtype=object) with h5py.File(cc._scf.with_df._cderi, 'r') as f: kptij_lst = f['j3c-kptij'].value tao = [] ao_loc = None for ki, kpti in enumerate(kpts): for kj, kptj in enumerate(kpts): kpti_kptj = np.array((kpti, kptj)) Lpq = np.asarray(df._getitem(f, 'j3c', kpti_kptj, kptij_lst)) mo = np.hstack((eris.mo_coeff[ki], eris.mo_coeff[kj][:, nocc:])) mo = np.asarray(mo, dtype=dtype, order='F') if dtype == np.double: out = _ao2mo.nr_e2(Lpq, mo, (0, nmo, nmo, nmo + nvir), aosym='s2') else: #Note: Lpq.shape[0] != naux if linear dependency is found in auxbasis if Lpq[0].size != nao**2: # aosym = 's2' Lpq = lib.unpack_tril(Lpq).astype(np.complex128) out = _ao2mo.r_e2(Lpq, mo, (0, nmo, nmo, nmo + nvir), tao, ao_loc) Lpv[ki, kj] = out.reshape(-1, nmo, nvir) return eris
def _init_cis_df_eris(cis, eris): """Add 3-center electron repulsion integrals, i.e. (L|pq), in `eris`, where `L` denotes DF auxiliary basis functions and `p` and `q` canonical crystalline orbitals. Note that `p` and `q` contain kpt indices `kp` and `kq`, and the third kpt index `kL` is determined by the conservation of momentum. Arguments: cis {KCIS} -- A KCIS instance eris {_CIS_ERIS} -- A _CIS_ERIS instance to which we want to add 3c ints Returns: _CIS_ERIS -- A _CIS_ERIS instance with 3c ints """ from pyscf.pbc.df import df from pyscf.ao2mo import _ao2mo from pyscf.pbc.lib.kpts_helper import gamma_point log = logger.Logger(cis.stdout, cis.verbose) if cis._scf.with_df._cderi is None: cis._scf.with_df.build() cell = cis._scf.cell if cell.dimension == 2: # 2D ERIs are not positive definite. The 3-index tensors are stored in # two part. One corresponds to the positive part and one corresponds # to the negative part. The negative part is not considered in the # DF-driven CCSD implementation. raise NotImplementedError nocc = cis.nocc nmo = cis.nmo nao = cell.nao_nr() kpts = cis.kpts nkpts = len(kpts) if gamma_point(kpts): dtype = np.double else: dtype = np.complex128 eris.dtype = dtype = np.result_type(dtype, *eris.mo_coeff) eris.Lpq_mo = Lpq_mo = np.empty((nkpts, nkpts), dtype=object) cput0 = (time.clock(), time.time()) with h5py.File(cis._scf.with_df._cderi, 'r') as f: kptij_lst = f['j3c-kptij'].value tao = [] ao_loc = None for ki, kpti in enumerate(kpts): for kj, kptj in enumerate(kpts): kpti_kptj = np.array((kpti, kptj)) Lpq_ao = np.asarray(df._getitem(f, 'j3c', kpti_kptj, kptij_lst)) mo = np.hstack((eris.mo_coeff[ki], eris.mo_coeff[kj])) mo = np.asarray(mo, dtype=dtype, order='F') if dtype == np.double: out = _ao2mo.nr_e2(Lpq_ao, mo, (0, nmo, nmo, nmo + nmo), aosym='s2') else: #Note: Lpq.shape[0] != naux if linear dependency is found in auxbasis if Lpq_ao[0].size != nao**2: # aosym = 's2' Lpq_ao = lib.unpack_tril(Lpq_ao).astype(np.complex128) out = _ao2mo.r_e2(Lpq_ao, mo, (0, nmo, nmo, nmo + nmo), tao, ao_loc) Lpq_mo[ki, kj] = out.reshape(-1, nmo, nmo) log.timer_debug1("transforming DF-CIS integrals", *cput0) return eris
def _init_mp_df_eris(mp): """Compute 3-center electron repulsion integrals, i.e. (L|ov), where `L` denotes DF auxiliary basis functions and `o` and `v` occupied and virtual canonical crystalline orbitals. Note that `o` and `v` contain kpt indices `ko` and `kv`, and the third kpt index `kL` is determined by the conservation of momentum. Arguments: mp (KMP2) -- A KMP2 instance Returns: Lov (numpy.ndarray) -- 3-center DF ints, with shape (nkpts, nkpts, naux, nocc, nvir) """ from pyscf.pbc.df import df from pyscf.ao2mo import _ao2mo from pyscf.pbc.lib.kpts_helper import gamma_point log = logger.Logger(mp.stdout, mp.verbose) if mp._scf.with_df._cderi is None: mp._scf.with_df.build() cell = mp._scf.cell if cell.dimension == 2: # 2D ERIs are not positive definite. The 3-index tensors are stored in # two part. One corresponds to the positive part and one corresponds # to the negative part. The negative part is not considered in the # DF-driven CCSD implementation. raise NotImplementedError nocc = mp.nocc nmo = mp.nmo nvir = nmo - nocc nao = cell.nao_nr() mo_coeff = _add_padding(mp, mp.mo_coeff, mp.mo_energy)[0] kpts = mp.kpts nkpts = len(kpts) if gamma_point(kpts): dtype = np.double else: dtype = np.complex128 dtype = np.result_type(dtype, *mo_coeff) Lov = np.empty((nkpts, nkpts), dtype=object) cput0 = (logger.process_clock(), logger.perf_counter()) bra_start = 0 bra_end = nocc ket_start = nmo + nocc ket_end = ket_start + nvir with h5py.File(mp._scf.with_df._cderi, 'r') as f: kptij_lst = f['j3c-kptij'][:] tao = [] ao_loc = None for ki, kpti in enumerate(kpts): for kj, kptj in enumerate(kpts): kpti_kptj = np.array((kpti, kptj)) Lpq_ao = np.asarray(df._getitem(f, 'j3c', kpti_kptj, kptij_lst)) mo = np.hstack((mo_coeff[ki], mo_coeff[kj])) mo = np.asarray(mo, dtype=dtype, order='F') if dtype == np.double: out = _ao2mo.nr_e2( Lpq_ao, mo, (bra_start, bra_end, ket_start, ket_end), aosym='s2') else: #Note: Lpq.shape[0] != naux if linear dependency is found in auxbasis if Lpq_ao[0].size != nao**2: # aosym = 's2' Lpq_ao = lib.unpack_tril(Lpq_ao).astype(np.complex128) out = _ao2mo.r_e2(Lpq_ao, mo, (bra_start, bra_end, ket_start, ket_end), tao, ao_loc) Lov[ki, kj] = out.reshape(-1, nocc, nvir) log.timer_debug1("transforming DF-MP2 integrals", *cput0) return Lov