Ejemplo n.º 1
0
def _mo_without_core(gw, mo):
    return mo[:, get_frozen_mask(gw)]
Ejemplo n.º 2
0
def _mo_energy_without_core(gw, mo_energy):
    return mo_energy[get_frozen_mask(gw)]
Ejemplo n.º 3
0
Archivo: rpa.py Proyecto: pyscf/pyscf
def _mo_without_core(rpa, mo):
    return mo[:, get_frozen_mask(rpa)]
Ejemplo n.º 4
0
    def __init__(self, cc, mo_coeff=None, method='incore', ao2mofn=ao2mo.full):
        cput0 = (time.clock(), time.time())
        moidx = get_frozen_mask(cc)
        if mo_coeff is None:
            self.mo_coeff = mo_coeff = cc.mo_coeff[:, moidx]
        else:  # If mo_coeff is not canonical orbital
            self.mo_coeff = mo_coeff = mo_coeff[:, moidx]
        dm = cc._scf.make_rdm1(cc.mo_coeff, cc.mo_occ)
        fockao = cc._scf.get_hcore() + cc._scf.get_veff(cc.mol, dm)
        self.fock = reduce(numpy.dot, (mo_coeff.T, fockao, mo_coeff))

        nocc = cc.nocc
        nmo = cc.nmo
        nvir = nmo - nocc
        mem_incore, mem_outcore, mem_basic = _mem_usage(nocc, nvir)
        mem_now = lib.current_memory()[0]

        log = logger.Logger(cc.stdout, cc.verbose)
        if (method == 'incore' and (mem_incore + mem_now < cc.max_memory)
                or cc.mol.incore_anyway):
            if ao2mofn == ao2mo.full:
                if cc._scf._eri is not None:
                    eri = ao2mo.restore(1, ao2mofn(cc._scf._eri, mo_coeff),
                                        nmo)
                else:
                    eri = ao2mo.restore(
                        1, ao2mofn(cc._scf.mol, mo_coeff, compact=0), nmo)
            else:
                eri = ao2mofn(cc._scf.mol,
                              (mo_coeff, mo_coeff, mo_coeff, mo_coeff),
                              compact=0)
                if mo_coeff.dtype == np.float: eri = eri.real
                eri = eri.reshape((nmo, ) * 4)

            self.dtype = eri.dtype
            self.oooo = eri[:nocc, :nocc, :nocc, :nocc].copy()
            self.ooov = eri[:nocc, :nocc, :nocc, nocc:].copy()
            self.ovoo = eri[:nocc, nocc:, :nocc, :nocc].copy()
            self.oovo = eri[:nocc, :nocc, nocc:, :nocc].copy()
            self.ovov = eri[:nocc, nocc:, :nocc, nocc:].copy()
            self.oovv = eri[:nocc, :nocc, nocc:, nocc:].copy()
            self.ovvo = eri[:nocc, nocc:, nocc:, :nocc].copy()
            self.ovvv = eri[:nocc, nocc:, nocc:, nocc:].copy()

        elif hasattr(cc._scf, 'with_df') and cc._scf.with_df:
            raise NotImplementedError

        else:
            orbo = mo_coeff[:, :nocc]
            self.dtype = mo_coeff.dtype
            ds_type = mo_coeff.dtype.char
            self.feri = lib.H5TmpFile()
            self.oooo = self.feri.create_dataset('oooo',
                                                 (nocc, nocc, nocc, nocc),
                                                 ds_type)
            self.ooov = self.feri.create_dataset('ooov',
                                                 (nocc, nocc, nocc, nvir),
                                                 ds_type)
            self.ovoo = self.feri.create_dataset('ovoo',
                                                 (nocc, nvir, nocc, nocc),
                                                 ds_type)
            self.oovo = self.feri.create_dataset('oovo',
                                                 (nocc, nocc, nvir, nocc),
                                                 ds_type)
            self.ovov = self.feri.create_dataset('ovov',
                                                 (nocc, nvir, nocc, nvir),
                                                 ds_type)
            self.oovv = self.feri.create_dataset('oovv',
                                                 (nocc, nocc, nvir, nvir),
                                                 ds_type)
            self.ovvo = self.feri.create_dataset('ovvo',
                                                 (nocc, nvir, nvir, nocc),
                                                 ds_type)
            self.ovvv = self.feri.create_dataset('ovvv',
                                                 (nocc, nvir, nvir, nvir),
                                                 ds_type)

            cput1 = time.clock(), time.time()
            # <ij||pq> = <ij|pq> - <ij|qp> = (ip|jq) - (iq|jp)
            tmpfile2 = tempfile.NamedTemporaryFile(dir=lib.param.TMPDIR)
            ao2mo.general(cc.mol, (orbo, mo_coeff, mo_coeff, mo_coeff),
                          tmpfile2.name, 'aa')
            with h5py.File(tmpfile2.name) as f:
                buf = numpy.empty((nmo, nmo, nmo))
                for i in range(nocc):
                    lib.unpack_tril(f['aa'][i * nmo:(i + 1) * nmo], out=buf)
                    self.oooo[i] = buf[:nocc, :nocc, :nocc]
                    self.ooov[i] = buf[:nocc, :nocc, nocc:]
                    self.ovoo[i] = buf[nocc:, :nocc, :nocc]
                    self.ovov[i] = buf[nocc:, :nocc, nocc:]
                    self.oovo[i] = buf[:nocc, nocc:, :nocc]
                    self.oovv[i] = buf[:nocc, nocc:, nocc:]
                    self.ovvo[i] = buf[nocc:, nocc:, :nocc]
                    self.ovvv[i] = buf[nocc:, nocc:, nocc:]
                del (f['aa'])
                buf = None

            cput1 = log.timer_debug1('transforming oopq, ovpq', *cput1)

        log.timer('GW integral transformation', *cput0)
Ejemplo n.º 5
0
Archivo: rpa.py Proyecto: pyscf/pyscf
def _mo_energy_without_core(rpa, mo_energy):
    return mo_energy[get_frozen_mask(rpa)]