Пример #1
0
    def get_vind(self, mf):
        '''Compute Ax'''
        singlet = self.singlet
        cell = mf.cell
        kpts = mf.kpts

        mo_coeff = mf.mo_coeff
        mo_energy = mf.mo_energy
        mo_occ = mf.mo_occ
        nkpts = len(mo_occ)
        nao, nmo = mo_coeff[0][0].shape
        occidxa = [numpy.where(mo_occ[0][k]> 0)[0] for k in range(nkpts)]
        occidxb = [numpy.where(mo_occ[1][k]> 0)[0] for k in range(nkpts)]
        viridxa = [numpy.where(mo_occ[0][k]==0)[0] for k in range(nkpts)]
        viridxb = [numpy.where(mo_occ[1][k]==0)[0] for k in range(nkpts)]
        orboa = [mo_coeff[0][k][:,occidxa[k]] for k in range(nkpts)]
        orbob = [mo_coeff[1][k][:,occidxb[k]] for k in range(nkpts)]
        orbva = [mo_coeff[0][k][:,viridxa[k]] for k in range(nkpts)]
        orbvb = [mo_coeff[1][k][:,viridxb[k]] for k in range(nkpts)]

        e_ai_a = _get_eai(mo_energy[0], mo_occ[0])
        e_ai_b = _get_eai(mo_energy[1], mo_occ[1])
        hdiag = numpy.hstack([x.ravel() for x in (e_ai_a + e_ai_b)])
        tot_x_a = sum(x.size for x in e_ai_a)
        tot_x_b = sum(x.size for x in e_ai_b)

        mem_now = lib.current_memory()[0]
        max_memory = max(2000, self.max_memory*.8-mem_now)
        vresp = _gen_uhf_response(mf, hermi=0, max_memory=max_memory)

        def vind(zs):
            nz = len(zs)
            zs = [_unpack(z, mo_occ) for z in zs]
            dmvo = numpy.empty((2,nz,nkpts,nao,nao), dtype=numpy.complex128)
            for i in range(nz):
                dm1a, dm1b = zs[i]
                for k in range(nkpts):
                    dmvo[0,i,k] = reduce(numpy.dot, (orbva[k], dm1a[k], orboa[k].T.conj()))
                    dmvo[1,i,k] = reduce(numpy.dot, (orbvb[k], dm1b[k], orbob[k].T.conj()))

            v1ao = vresp(dmvo)
            v1s = []
            for i in range(nz):
                dm1a, dm1b = zs[i]
                v1as = []
                v1bs = []
                for k in range(nkpts):
                    v1a = reduce(numpy.dot, (orbva[k].T.conj(), v1ao[0,i,k], orboa[k]))
                    v1b = reduce(numpy.dot, (orbvb[k].T.conj(), v1ao[1,i,k], orbob[k]))
                    v1a += e_ai_a[k] * dm1a[k]
                    v1b += e_ai_b[k] * dm1b[k]
                    v1as.append(v1a.ravel())
                    v1bs.append(v1b.ravel())
                v1s += v1as + v1bs
            return numpy.hstack(v1s).reshape(nz,-1)

        return vind, hdiag
Пример #2
0
    def init_guess(self, mf, nstates=None):
        if nstates is None: nstates = self.nstates

        mo_energy = mf.mo_energy
        mo_occ = mf.mo_occ
        e_ai_a = _get_eai(mo_energy[0], mo_occ[0])
        e_ai_b = _get_eai(mo_energy[1], mo_occ[1])
        eai = numpy.hstack([x.ravel() for x in (e_ai_a + e_ai_b)])
        nov = eai.size
        nroot = min(nstates, nov)
        x0 = numpy.zeros((nroot, nov))
        idx = numpy.argsort(eai)
        for i in range(nroot):
            x0[i, idx[i]] = 1  # lowest excitations
        return x0
Пример #3
0
    def get_vind(self, mf):
        singlet = self.singlet
        cell = mf.cell
        kpts = mf.kpts

        mo_coeff = mf.mo_coeff
        mo_energy = mf.mo_energy
        mo_occ = mf.mo_occ
        nkpts = len(mo_occ)
        nao, nmo = mo_coeff[0][0].shape
        occidxa = [numpy.where(mo_occ[0][k] > 0)[0] for k in range(nkpts)]
        occidxb = [numpy.where(mo_occ[1][k] > 0)[0] for k in range(nkpts)]
        viridxa = [numpy.where(mo_occ[0][k] == 0)[0] for k in range(nkpts)]
        viridxb = [numpy.where(mo_occ[1][k] == 0)[0] for k in range(nkpts)]
        orboa = [mo_coeff[0][k][:, occidxa[k]] for k in range(nkpts)]
        orbob = [mo_coeff[1][k][:, occidxb[k]] for k in range(nkpts)]
        orbva = [mo_coeff[0][k][:, viridxa[k]] for k in range(nkpts)]
        orbvb = [mo_coeff[1][k][:, viridxb[k]] for k in range(nkpts)]

        e_ai_a = _get_eai(mo_energy[0], mo_occ[0])
        e_ai_b = _get_eai(mo_energy[1], mo_occ[1])
        hdiag = numpy.hstack([x.ravel() for x in (e_ai_a + e_ai_b)])
        hdiag = numpy.hstack((hdiag, hdiag))
        tot_x_a = sum(x.size for x in e_ai_a)
        tot_x_b = sum(x.size for x in e_ai_b)
        tot_x = tot_x_a + tot_x_b

        mem_now = lib.current_memory()[0]
        max_memory = max(2000, self.max_memory * .8 - mem_now)
        vresp = _gen_uhf_response(mf, hermi=0, max_memory=max_memory)

        def vind(xys):
            nz = len(xys)
            x1s = [_unpack(x[:tot_x], mo_occ) for x in xys]
            y1s = [_unpack(x[tot_x:], mo_occ) for x in xys]
            dmvo = numpy.empty((2, nz, nkpts, nao, nao),
                               dtype=numpy.complex128)
            for i in range(nz):
                xa, xb = x1s[i]
                ya, yb = y1s[i]
                for k in range(nkpts):
                    dmx = reduce(numpy.dot,
                                 (orbva[k], xa[k], orboa[k].T.conj()))
                    dmy = reduce(numpy.dot,
                                 (orboa[k], ya[k].T, orbva[k].T.conj()))
                    dmvo[0, i, k] = dmx + dmy  # AX + BY
                    dmx = reduce(numpy.dot,
                                 (orbvb[k], xb[k], orbob[k].T.conj()))
                    dmy = reduce(numpy.dot,
                                 (orbob[k], yb[k].T, orbvb[k].T.conj()))
                    dmvo[1, i, k] = dmx + dmy  # AX + BY

            v1ao = vresp(dmvo)
            v1s = []
            for i in range(nz):
                xa, xb = x1s[i]
                ya, yb = y1s[i]
                v1xsa = []
                v1xsb = []
                v1ysa = []
                v1ysb = []
                for k in range(nkpts):
                    v1xa = reduce(numpy.dot,
                                  (orbva[k].T.conj(), v1ao[0, i, k], orboa[k]))
                    v1xb = reduce(numpy.dot,
                                  (orbvb[k].T.conj(), v1ao[1, i, k], orbob[k]))
                    v1ya = reduce(
                        numpy.dot,
                        (orboa[k].T.conj(), v1ao[0, i, k], orbva[k])).T
                    v1yb = reduce(
                        numpy.dot,
                        (orbob[k].T.conj(), v1ao[1, i, k], orbvb[k])).T
                    v1xa += e_ai_a[k] * xa[k]
                    v1xb += e_ai_b[k] * xb[k]
                    v1ya += e_ai_a[k] * ya[k]
                    v1yb += e_ai_b[k] * yb[k]
                    v1xsa.append(v1xa.ravel())
                    v1xsb.append(v1xb.ravel())
                    v1ysa.append(-v1ya.ravel())
                    v1ysb.append(-v1yb.ravel())
                v1s += v1xsa + v1xsb + v1ysa + v1ysb
            return numpy.hstack(v1s).reshape(nz, -1)

        return vind, hdiag