Esempio n. 1
0
def print_properties(name, natm, nmo):                
    aom = numpy.zeros((natm,nmo,nmo))
    totaom = numpy.zeros((nmo,nmo))
    props = numpy.zeros((natm,NPROPS))
    totprops = numpy.zeros((NPROPS))
    with h5py.File(name) as f:
        for i in range(natm):
            idx = 'atom_props'+str(i)
            props[i] = f[idx+'/totprops'].value
            idx = 'ovlp'+str(i)
            aom[i] = f[idx+'/aom'].value
    for i in range(natm):
        log.info('Follow AOM for atom %d', i)
        dump_tri(sys.stdout, aom[i], ncol=NCOL, digits=DIGITS, start=0)
        totaom += aom[i]
        for j in range(NPROPS):
            log.info('Nuclei %d prop %s value : %8.5f', i, PROPS[j], props[i,j])
            totprops[j] += props[i,j]
    for j in range(NPROPS):
        log.info('Tot prop %s value : %8.5f', PROPS[j], totprops[j])
    log.info('Follow total AOM')
    dump_tri(sys.stdout, totaom, ncol=NCOL, digits=DIGITS, start=0)
    i = numpy.identity(nmo)
    diff = numpy.linalg.norm(totaom-i)
    log.info('Diff in S matrix : %8.5f', diff)
Esempio n. 2
0
    def analyze(self, mo_coeff=None, ci=None, verbose=logger.DEBUG):
        from pyscf.tools import dump_mat
        if mo_coeff is None: mo_coeff = self.mo_coeff
        if ci is None: ci = self.ci
        nelecas = self.nelecas
        ncas = self.ncas
        ncore = self.ncore

        casdm1a, casdm1b = self.fcisolver.make_rdm1s(ci, ncas, nelecas)
        mocore = mo_coeff[0][:, :ncore[0]]
        mocas = mo_coeff[0][:, ncore[0]:ncore[0] + ncas]
        dm1a = numpy.dot(mocore, mocore.T)
        dm1a += reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        mocore = mo_coeff[1][:, :ncore[1]]
        mocas = mo_coeff[1][:, ncore[1]:ncore[1] + ncas]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))

        if verbose >= logger.INFO:
            log = logger.Logger(self.stdout, verbose)
            label = self.mol.spheric_labels(True)
            if log.verbose >= logger.DEBUG:
                log.info('alpha density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1a, label)
                log.info('beta density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1b, label)

            s = reduce(
                numpy.dot,
                (mo_coeff[0].T, self._scf.get_ovlp(), self._scf.mo_coeff[0]))
            idx = numpy.argwhere(abs(s) > .4)
            for i, j in idx:
                log.info('alpha <mo-mcscf|mo-hf> %d  %d  %12.8f' %
                         (i + 1, j + 1, s[i, j]))
            s = reduce(
                numpy.dot,
                (mo_coeff[1].T, self._scf.get_ovlp(), self._scf.mo_coeff[1]))
            idx = numpy.argwhere(abs(s) > .4)
            for i, j in idx:
                log.info('beta <mo-mcscf|mo-hf> %d  %d  %12.8f' %
                         (i + 1, j + 1, s[i, j]))

            log.info('\n** Largest CI components **')
            if ci is not None and numpy.ndim(ci) >= 2:
                if ci[0].ndim == 2:
                    for i, state in enumerate(ci):
                        log.info(
                            ' string alpha, string beta, state %d CI coefficients',
                            i)
                        for c, ia, ib in fci.addons.large_ci(
                                state, self.ncas, self.nelecas):
                            log.info('  %9s    %9s    %.12f', ia, ib, c)
                else:
                    log.info(' string alpha, string beta, CI coefficients')
                    for c, ia, ib in fci.addons.large_ci(
                            ci, self.ncas, self.nelecas):
                        log.info('  %9s    %9s    %.12f', ia, ib, c)
        return dm1a, dm1b
Esempio n. 3
0
def analyze(casscf, mo_coeff=None, ci=None, verbose=logger.INFO):
    from pyscf.tools import dump_mat
    from pyscf.mcscf import addons
    if mo_coeff is None: mo_coeff = casscf.mo_coeff
    if ci is None: ci = casscf.ci
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(casscf.stdout, verbose)
    nelecas = casscf.nelecas
    ncas = casscf.ncas
    ncore = casscf.ncore
    nocc = ncore + ncas

    casdm1a, casdm1b = casscf.fcisolver.make_rdm1s(ci, ncas, nelecas)
    mocore = mo_coeff[:,:ncore]
    mocas = mo_coeff[:,ncore:nocc]
    dm1b = numpy.dot(mocore, mocore.T)
    dm1a = dm1b + reduce(numpy.dot, (mocas, casdm1a, mocas.T))
    dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))

    if log.verbose >= logger.INFO:
        label = ['%d%3s %s%-4s' % x for x in casscf.mol.spheric_labels()]
        if log.verbose >= logger.DEBUG:
            log.info('alpha density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1a, label)
            log.info('beta density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1b, label)

        # note the last two args of ._eig for mc1step_symm
        occ, ucas = casscf._eig(-(casdm1a+casdm1b), ncore, nocc)
        log.info('Natural occ %s', str(-occ))
        for i, k in enumerate(numpy.argmax(abs(ucas), axis=0)):
            if ucas[k,i] < 0:
                ucas[:,i] *= -1
        mo_cas = numpy.dot(mo_coeff[:,ncore:nocc], ucas)
        log.info('Natural orbital in CAS space')
        dump_mat.dump_rec(log.stdout, mo_cas, label, start=1)

        s = reduce(numpy.dot, (casscf.mo_coeff.T, casscf._scf.get_ovlp(),
                               casscf._scf.mo_coeff))
        idx = numpy.argwhere(abs(s)>.4)
        for i,j in idx:
            log.info('<mo-mcscf|mo-hf> %d, %d, %12.8f', i+1, j+1, s[i,j])

        log.info('** Largest CI components **')
        log.info(' string alpha, string beta, CI coefficients')
        for c,ia,ib in fci.addons.large_ci(ci, casscf.ncas, casscf.nelecas):
            log.info('  %9s    %9s    %.12f', ia, ib, c)

        dm1 = dm1a + dm1b
        s = casscf._scf.get_ovlp()
        casscf._scf.mulliken_pop(casscf.mol, dm1, s, verbose=log)
        casscf._scf.mulliken_pop_meta_lowdin_ao(casscf.mol, dm1, verbose=log)
    return dm1a, dm1b
Esempio n. 4
0
    def analyze(self, mo_coeff=None, ci=None, verbose=logger.DEBUG):
        from pyscf.tools import dump_mat
        if mo_coeff is None: mo_coeff = self.mo_coeff
        if ci is None: ci = self.ci
        nelecas = self.nelecas
        ncas = self.ncas
        ncore = self.ncore

        casdm1a, casdm1b = self.fcisolver.make_rdm1s(ci, ncas, nelecas)
        mocore = mo_coeff[0][:,:ncore[0]]
        mocas = mo_coeff[0][:,ncore[0]:ncore[0]+ncas]
        dm1a = numpy.dot(mocore, mocore.T)
        dm1a += reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        mocore = mo_coeff[1][:,:ncore[1]]
        mocas = mo_coeff[1][:,ncore[1]:ncore[1]+ncas]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))

        if verbose >= logger.INFO:
            log = logger.Logger(self.stdout, verbose)
            label = self.mol.spheric_labels(True)
            if log.verbose >= logger.DEBUG:
                log.info('alpha density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1a, label)
                log.info('beta density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1b, label)

            s = reduce(numpy.dot, (mo_coeff[0].T, self._scf.get_ovlp(),
                                   self._scf.mo_coeff[0]))
            idx = numpy.argwhere(abs(s)>.4)
            for i,j in idx:
                log.info('alpha <mo-mcscf|mo-hf> %d  %d  %12.8f' % (i+1,j+1,s[i,j]))
            s = reduce(numpy.dot, (mo_coeff[1].T, self._scf.get_ovlp(),
                                   self._scf.mo_coeff[1]))
            idx = numpy.argwhere(abs(s)>.4)
            for i,j in idx:
                log.info('beta <mo-mcscf|mo-hf> %d  %d  %12.8f' % (i+1,j+1,s[i,j]))

            log.info('\n** Largest CI components **')
            if ci is not None and numpy.ndim(ci) >= 2:
                if ci[0].ndim == 2:
                    for i, state in enumerate(ci):
                        log.info(' string alpha, string beta, state %d CI coefficients', i)
                        for c,ia,ib in fci.addons.large_ci(state, self.ncas, self.nelecas):
                            log.info('  %9s    %9s    %.12f', ia, ib, c)
                else:
                    log.info(' string alpha, string beta, CI coefficients')
                    for c,ia,ib in fci.addons.large_ci(ci, self.ncas, self.nelecas):
                        log.info('  %9s    %9s    %.12f', ia, ib, c)
        return dm1a, dm1b
Esempio n. 5
0
    def analyze(self, mo_coeff=None, ci=None, verbose=logger.DEBUG):
        from pyscf.tools import dump_mat
        if mo_coeff is None: mo_coeff = self.mo_coeff
        if ci is None: ci = self.ci
        nelecas = casscf.nelecas
        ncas = casscf.ncas
        ncore = casscf.ncore

        casdm1a, casdm1b = self.fcisolver.make_rdm1s(ci, ncas, nelecas)
        mocore = mo_coeff[0][:,:ncore[0]]
        mocas = mo_coeff[0][:,ncore[0]:ncore[0]+ncas]
        dm1a = numpy.dot(mocore, mocore.T)
        dm1a += reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        mocore = mo_coeff[1][:,:ncore[1]]
        mocas = mo_coeff[1][:,ncore[1]:ncore[1]+ncas]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))

        if verbose >= logger.INFO:
            log = logger.Logger(self.stdout, verbose)
            label = ['%d%3s %s%-4s' % x for x in self.mol.spheric_labels()]
            if log.verbose >= logger.DEBUG:
                log.info('alpha density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1a, label)
                log.info('beta density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1b, label)

            s = reduce(numpy.dot, (mo_coeff[0].T, self._scf.get_ovlp(),
                                   self._scf.mo_coeff[0]))
            idx = numpy.argwhere(abs(s)>.4)
            for i,j in idx:
                log.info('alpha <mo-mcscf|mo-hf> %d, %d, %12.8f' % (i+1,j+1,s[i,j]))
            s = reduce(numpy.dot, (mo_coeff[1].T, self._scf.get_ovlp(),
                                   self._scf.mo_coeff[1]))
            idx = numpy.argwhere(abs(s)>.4)
            for i,j in idx:
                log.info('beta <mo-mcscf|mo-hf> %d, %d, %12.8f' % (i+1,j+1,s[i,j]))

            ss = self.spin_square(ci, mo_coeff, self._scf.get_ovlp())
            log.info('\nS^2 = %.7f, 2S+1 = %.7f', ss[0], ss[1])

            log.info('\n** Largest CI components **')
            log.info(' string alpha, string beta, CI coefficients')
            for c,ia,ib in fci.addons.large_ci(ci, self.ncas, self.nelecas):
                log.info('  %9s    %9s    %.12f', ia, ib, c)
        return dm1a, dm1b
Esempio n. 6
0
    def build(self):

        t0 = (time.clock(), time.time())
        lib.logger.TIMER_LEVEL = 3

        self.mol = lib.chkfile.load_mol(self.chkfile)
        self.nelectron = self.mol.nelectron
        self.charge = self.mol.charge
        self.spin = self.mol.spin
        self.natm = self.mol.natm
        self.coords = numpy.asarray([(numpy.asarray(atom[1])).tolist()
                                     for atom in self.mol._atom])
        self.charges = self.mol.atom_charges()
        if (self.cas):
            self.mo_coeff = lib.chkfile.load(self.chkfile, 'mcscf/mo_coeff')
        else:
            self.mo_coeff = lib.chkfile.load(self.chkfile, 'scf/mo_coeff')
        self.mo_occ = lib.chkfile.load(self.chkfile, 'scf/mo_occ')
        nprims, nmo = self.mo_coeff.shape
        self.nprims = nprims
        self.nmo = nmo
        if self.charges[self.inuc] == 1:
            self.rad = grid.BRAGG[self.charges[self.inuc]]
        else:
            self.rad = grid.BRAGG[self.charges[self.inuc]] * 0.5

        if (self.corr):
            self.rdm1 = lib.chkfile.load(self.chkfile, 'rdm/rdm1')
            natocc, natorb = numpy.linalg.eigh(self.rdm1)
            natorb = numpy.dot(self.mo_coeff, natorb)
            self.mo_coeff = natorb
            self.mo_occ = natocc
        nocc = self.mo_occ[abs(self.mo_occ) > self.occdrop]
        nocc = len(nocc)
        self.nocc = nocc

        idx = 'atom' + str(self.inuc)
        with h5py.File(self.surfile) as f:
            self.xnuc = f[idx + '/xnuc'].value
            self.xyzrho = f[idx + '/xyzrho'].value
            self.npang = f[idx + '/npang'].value
            self.ntrial = f[idx + '/ntrial'].value
            self.rmin = f[idx + '/rmin'].value
            self.rmax = f[idx + '/rmax'].value
            self.rsurf = f[idx + '/rsurf'].value
            self.nlimsurf = f[idx + '/nlimsurf'].value
            self.agrids = f[idx + '/coords'].value

        self.brad = self.rmin * self.betafac

        if self.verbose >= logger.WARN:
            self.check_sanity()
        if self.verbose > logger.NOTE:
            self.dump_input()

        if (self.iqudr == 'legendre'):
            self.iqudr = 1
        if (self.biqudr == 'legendre'):
            self.biqudr = 1

        if (self.mapr == 'becke'):
            self.mapr = 1
        elif (self.mapr == 'exp'):
            self.mapr = 2
        elif (self.mapr == 'none'):
            self.mapr = 0
        if (self.bmapr == 'becke'):
            self.bmapr = 1
        elif (self.bmapr == 'exp'):
            self.bmapr = 2
        elif (self.bmapr == 'none'):
            self.bmapr = 0

        if (self.full):
            self.nocc = self.nmo
            nocc = self.nmo
        else:
            nocc = self.mo_occ[self.mo_occ > self.occdrop]
            nocc = len(nocc)
            self.nocc = nocc

        self.aom = numpy.zeros((nocc, nocc))

        with lib.with_omp_threads(self.nthreads):
            aomb = int_beta(self)
            aoma = out_beta(self)

        idx = 0
        for i in range(nocc):
            for j in range(i + 1):
                self.aom[i, j] = aoma[idx] + aomb[idx]
                self.aom[j, i] = self.aom[i, j]
                idx += 1
        if (self.nmo <= 30):
            dump_tri(self.stdout, self.aom, ncol=NCOL, digits=DIGITS, start=0)

        logger.info(self, 'Write info to HDF5 file')
        atom_dic = {'aom': self.aom}
        lib.chkfile.save(self.surfile, 'ovlp' + str(self.inuc), atom_dic)
        logger.info(self, '')

        logger.info(self, 'AOM of atom %d done', self.inuc)
        logger.timer(self, 'AOM build', *t0)

        return self
Esempio n. 7
0
def analyze(casscf, mo_coeff=None, ci=None, verbose=logger.INFO,
            large_ci_tol=.1, **kwargs):
    from pyscf.lo import orth
    from pyscf.tools import dump_mat
    if mo_coeff is None: mo_coeff = casscf.mo_coeff
    if ci is None: ci = casscf.ci
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(casscf.stdout, verbose)
    nelecas = casscf.nelecas
    ncas = casscf.ncas
    ncore = casscf.ncore
    nocc = ncore + ncas
    label = casscf.mol.spheric_labels(True)

    if isinstance(ci, (tuple, list)):
        ci0 = ci[0]
        log.info('** Natural natural orbitals are based on the first root **')
    else:
        ci0 = ci
    if ci0 is None and hasattr(casscf, 'casdm1'):
        casdm1 = casscf.casdm1
        mocore = mo_coeff[:,:ncore]
        mocas = mo_coeff[:,ncore:nocc]
        dm1a =(numpy.dot(mocore, mocore.T) * 2
             + reduce(numpy.dot, (mocas, casdm1, mocas.T)))
        dm1b = None
        dm1 = dm1a
    elif hasattr(casscf.fcisolver, 'make_rdm1s'):
        casdm1a, casdm1b = casscf.fcisolver.make_rdm1s(ci0, ncas, nelecas)
        casdm1 = casdm1a + casdm1b
        mocore = mo_coeff[:,:ncore]
        mocas = mo_coeff[:,ncore:nocc]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1a = dm1b + reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))
        dm1 = dm1a + dm1b
        if log.verbose >= logger.DEBUG1:
            log.info('alpha density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1a, label, **kwargs)
            log.info('beta density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1b, label, **kwargs)
    else:
        casdm1 = casscf.fcisolver.make_rdm1(ci0, ncas, nelecas)
        mocore = mo_coeff[:,:ncore]
        mocas = mo_coeff[:,ncore:nocc]
        dm1a =(numpy.dot(mocore, mocore.T) * 2
             + reduce(numpy.dot, (mocas, casdm1, mocas.T)))
        dm1b = None
        dm1 = dm1a

    if log.verbose >= logger.INFO:
        ovlp_ao = casscf._scf.get_ovlp()
        # note the last two args of ._eig for mc1step_symm
        occ, ucas = casscf._eig(-casdm1, ncore, nocc)
        log.info('Natural occ %s', str(-occ))
        for i, k in enumerate(numpy.argmax(abs(ucas), axis=0)):
            if ucas[k,i] < 0:
                ucas[:,i] *= -1
        orth_coeff = orth.orth_ao(casscf.mol, 'meta_lowdin', s=ovlp_ao)
        mo_cas = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mo_coeff[:,ncore:nocc], ucas))
        log.info('Natural orbital (expansion on meta-Lowdin AOs) in CAS space')
        dump_mat.dump_rec(log.stdout, mo_cas, label, start=1, **kwargs)

        if casscf._scf.mo_coeff is not None:
            s = reduce(numpy.dot, (casscf.mo_coeff.T, ovlp_ao, casscf._scf.mo_coeff))
            idx = numpy.argwhere(abs(s)>.4)
            for i,j in idx:
                log.info('<mo-mcscf|mo-hf> %d  %d  %12.8f', i+1, j+1, s[i,j])

        if hasattr(casscf.fcisolver, 'large_ci') and ci is not None:
            log.info('** Largest CI components **')
            if isinstance(ci, (tuple, list)):
                for i, civec in enumerate(ci):
                    res = casscf.fcisolver.large_ci(civec, casscf.ncas, casscf.nelecas)
                    log.info(' string alpha, string beta, state %d CI coefficient', i)
                    for c,ia,ib in res:
                        log.info('  %9s    %9s    %.12f', ia, ib, c)
            else:
                log.info(' string alpha, string beta, CI coefficient')
                res = casscf.fcisolver.large_ci(ci, casscf.ncas, casscf.nelecas)
                for c,ia,ib in res:
                    log.info('  %9s    %9s    %.12f', ia, ib, c)

        casscf._scf.mulliken_meta(casscf.mol, dm1, s=ovlp_ao, verbose=log)
    return dm1a, dm1b
Esempio n. 8
0
    def analyze(self,
                mo_coeff=None,
                ci=None,
                verbose=None,
                large_ci_tol=LARGE_CI_TOL,
                with_meta_lowdin=WITH_META_LOWDIN,
                **kwargs):
        from pyscf.lo import orth
        from pyscf.tools import dump_mat
        if mo_coeff is None: mo_coeff = self.mo_coeff
        if ci is None: ci = self.ci
        log = logger.new_logger(self, verbose)
        nelecas = self.nelecas
        ncas = self.ncas
        ncore = self.ncore
        mocore_a = mo_coeff[0][:, :ncore[0]]
        mocas_a = mo_coeff[0][:, ncore[0]:ncore[0] + ncas]
        mocore_b = mo_coeff[1][:, :ncore[1]]
        mocas_b = mo_coeff[1][:, ncore[1]:ncore[1] + ncas]

        label = self.mol.ao_labels()
        if (isinstance(ci, (list, tuple)) and
                not isinstance(self.fcisolver, addons.StateAverageFCISolver)):
            log.warn(
                'Mulitple states found in UCASCI solver. Density '
                'matrix of first state is generated in .analyze() function.')
            civec = ci[0]
        else:
            civec = ci
        casdm1a, casdm1b = self.fcisolver.make_rdm1s(civec, ncas, nelecas)
        dm1a = numpy.dot(mocore_a, mocore_a.T)
        dm1a += reduce(numpy.dot, (mocas_a, casdm1a, mocas_a.T))
        dm1b = numpy.dot(mocore_b, mocore_b.T)
        dm1b += reduce(numpy.dot, (mocas_b, casdm1b, mocas_b.T))
        if log.verbose >= logger.DEBUG2:
            log.debug2('alpha density matrix (on AO)')
            dump_mat.dump_tri(self.stdout, dm1a, label)
            log.debug2('beta density matrix (on AO)')
            dump_mat.dump_tri(self.stdout, dm1b, label)

        if log.verbose >= logger.INFO:
            ovlp_ao = self._scf.get_ovlp()
            occa, ucasa = self._eig(-casdm1a, ncore[0], ncore[0] + ncas)
            occb, ucasb = self._eig(-casdm1b, ncore[1], ncore[1] + ncas)
            log.info('Natural alpha-occupancy %s', str(-occa))
            log.info('Natural beta-occupancy %s', str(-occb))
            mocas_a = numpy.dot(mocas_a, ucasa)
            mocas_b = numpy.dot(mocas_b, ucasb)
            if with_meta_lowdin:
                orth_coeff = orth.orth_ao(self.mol, 'meta_lowdin', s=ovlp_ao)
                mocas_a = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mocas_a))
                mocas_b = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mocas_b))
                log.info(
                    'Natural alpha-orbital (expansion on meta-Lowdin AOs) in CAS space'
                )
                dump_mat.dump_rec(log.stdout,
                                  mocas_a,
                                  label,
                                  start=1,
                                  **kwargs)
                log.info(
                    'Natural beta-orbital (expansion on meta-Lowdin AOs) in CAS space'
                )
                dump_mat.dump_rec(log.stdout,
                                  mocas_b,
                                  label,
                                  start=1,
                                  **kwargs)
            else:
                log.info(
                    'Natural alpha-orbital (expansion on AOs) in CAS space')
                dump_mat.dump_rec(log.stdout,
                                  mocas_a,
                                  label,
                                  start=1,
                                  **kwargs)
                log.info(
                    'Natural beta-orbital (expansion on AOs) in CAS space')
                dump_mat.dump_rec(log.stdout,
                                  mocas_b,
                                  label,
                                  start=1,
                                  **kwargs)

            tol = getattr(__config__, 'mcscf_addons_map2hf_tol', 0.4)
            s = reduce(numpy.dot,
                       (mo_coeff[0].T, ovlp_ao, self._scf.mo_coeff[0]))
            idx = numpy.argwhere(abs(s) > tol)
            for i, j in idx:
                log.info('alpha <mo-mcscf|mo-hf> %d  %d  %12.8f' %
                         (i + 1, j + 1, s[i, j]))
            s = reduce(numpy.dot,
                       (mo_coeff[1].T, ovlp_ao, self._scf.mo_coeff[1]))
            idx = numpy.argwhere(abs(s) > tol)
            for i, j in idx:
                log.info('beta <mo-mcscf|mo-hf> %d  %d  %12.8f' %
                         (i + 1, j + 1, s[i, j]))

            if hasattr(self.fcisolver, 'large_ci') and ci is not None:
                log.info('\n** Largest CI components **')
                if isinstance(ci, (tuple, list)):
                    for i, state in enumerate(ci):
                        log.info(
                            '  [alpha occ-orbitals] [beta occ-orbitals]  state %-3d CI coefficient',
                            i)
                        res = self.fcisolver.large_ci(state,
                                                      self.ncas,
                                                      self.nelecas,
                                                      large_ci_tol,
                                                      return_strs=False)
                        for c, ia, ib in res:
                            log.info('  %-20s %-30s %.12f', ia, ib, c)
                else:
                    log.info(
                        '  [alpha occ-orbitals] [beta occ-orbitals]            CI coefficient'
                    )
                    res = self.fcisolver.large_ci(ci,
                                                  self.ncas,
                                                  self.nelecas,
                                                  large_ci_tol,
                                                  return_strs=False)
                    for c, ia, ib in res:
                        log.info('  %-20s %-30s %.12f', ia, ib, c)
        return dm1a, dm1b
Esempio n. 9
0
def analyze(casscf, mo_coeff=None, ci=None, verbose=logger.INFO):
    from pyscf.tools import dump_mat
    from pyscf.mcscf import addons

    if mo_coeff is None:
        mo_coeff = casscf.mo_coeff
    if ci is None:
        ci = casscf.ci
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(casscf.stdout, verbose)
    nelecas = casscf.nelecas
    ncas = casscf.ncas
    ncore = casscf.ncore
    nocc = ncore + ncas
    label = casscf.mol.spheric_labels(True)

    if hasattr(casscf.fcisolver, "make_rdm1s"):
        casdm1a, casdm1b = casscf.fcisolver.make_rdm1s(ci, ncas, nelecas)
        casdm1 = casdm1a + casdm1b
        mocore = mo_coeff[:, :ncore]
        mocas = mo_coeff[:, ncore:nocc]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1a = dm1b + reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))
        dm1 = dm1a + dm1b
        if log.verbose >= logger.DEBUG1:
            log.info("alpha density matrix (on AO)")
            dump_mat.dump_tri(log.stdout, dm1a, label)
            log.info("beta density matrix (on AO)")
            dump_mat.dump_tri(log.stdout, dm1b, label)
    else:
        casdm1 = casscf.fcisolver.make_rdm1(ci, ncas, nelecas)
        mocore = mo_coeff[:, :ncore]
        mocas = mo_coeff[:, ncore:nocc]
        dm1a = numpy.dot(mocore, mocore.T) * 2 + reduce(numpy.dot, (mocas, casdm1, mocas.T))
        dm1b = None
        dm1 = dm1a

    if log.verbose >= logger.INFO:
        # note the last two args of ._eig for mc1step_symm
        occ, ucas = casscf._eig(-casdm1, ncore, nocc)
        log.info("Natural occ %s", str(-occ))
        for i, k in enumerate(numpy.argmax(abs(ucas), axis=0)):
            if ucas[k, i] < 0:
                ucas[:, i] *= -1
        mo_cas = numpy.dot(mo_coeff[:, ncore:nocc], ucas)
        log.info("Natural orbital in CAS space")
        dump_mat.dump_rec(log.stdout, mo_cas, label, start=1)

        if casscf._scf.mo_coeff is not None:
            s = reduce(numpy.dot, (casscf.mo_coeff.T, casscf._scf.get_ovlp(), casscf._scf.mo_coeff))
            idx = numpy.argwhere(abs(s) > 0.4)
            for i, j in idx:
                log.info("<mo-mcscf|mo-hf> %d  %d  %12.8f", i + 1, j + 1, s[i, j])

        if ci is not None:
            log.info("** Largest CI components **")
            log.info(" string alpha, string beta, CI coefficients")
            for c, ia, ib in fci.addons.large_ci(ci, casscf.ncas, casscf.nelecas):
                log.info("  %9s    %9s    %.12f", ia, ib, c)

        s = casscf._scf.get_ovlp()
        # casscf._scf.mulliken_pop(casscf.mol, dm1, s, verbose=log)
        casscf._scf.mulliken_pop_meta_lowdin_ao(casscf.mol, dm1, verbose=log)
    return dm1a, dm1b
Esempio n. 10
0
    def analyze(self, mo_coeff=None, ci=None, verbose=None,
                large_ci_tol=LARGE_CI_TOL, with_meta_lowdin=WITH_META_LOWDIN,
                **kwargs):
        from pyscf.lo import orth
        from pyscf.tools import dump_mat
        if mo_coeff is None: mo_coeff = self.mo_coeff
        if ci is None: ci = self.ci
        log = logger.new_logger(self, verbose)
        nelecas = self.nelecas
        ncas = self.ncas
        ncore = self.ncore
        mocore_a = mo_coeff[0][:,:ncore[0]]
        mocas_a = mo_coeff[0][:,ncore[0]:ncore[0]+ncas]
        mocore_b = mo_coeff[1][:,:ncore[1]]
        mocas_b = mo_coeff[1][:,ncore[1]:ncore[1]+ncas]

        label = self.mol.ao_labels()
        if (isinstance(ci, (list, tuple)) and
            not isinstance(self.fcisolver, addons.StateAverageFCISolver)):
            log.warn('Mulitple states found in UCASCI solver. Density '
                     'matrix of first state is generated in .analyze() function.')
            civec = ci[0]
        else:
            civec = ci
        casdm1a, casdm1b = self.fcisolver.make_rdm1s(civec, ncas, nelecas)
        dm1a = numpy.dot(mocore_a, mocore_a.T)
        dm1a += reduce(numpy.dot, (mocas_a, casdm1a, mocas_a.T))
        dm1b = numpy.dot(mocore_b, mocore_b.T)
        dm1b += reduce(numpy.dot, (mocas_b, casdm1b, mocas_b.T))
        if log.verbose >= logger.DEBUG2:
            log.debug2('alpha density matrix (on AO)')
            dump_mat.dump_tri(self.stdout, dm1a, label)
            log.debug2('beta density matrix (on AO)')
            dump_mat.dump_tri(self.stdout, dm1b, label)

        if log.verbose >= logger.INFO:
            ovlp_ao = self._scf.get_ovlp()
            occa, ucasa = self._eig(-casdm1a, ncore[0], ncore[0]+ncas)
            occb, ucasb = self._eig(-casdm1b, ncore[1], ncore[1]+ncas)
            log.info('Natural alpha-occupancy %s', str(-occa))
            log.info('Natural beta-occupancy %s', str(-occb))
            mocas_a = numpy.dot(mocas_a, ucasa)
            mocas_b = numpy.dot(mocas_b, ucasb)
            if with_meta_lowdin:
                orth_coeff = orth.orth_ao(self.mol, 'meta_lowdin', s=ovlp_ao)
                mocas_a = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mocas_a))
                mocas_b = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mocas_b))
                log.info('Natural alpha-orbital (expansion on meta-Lowdin AOs) in CAS space')
                dump_mat.dump_rec(log.stdout, mocas_a, label, start=1, **kwargs)
                log.info('Natural beta-orbital (expansion on meta-Lowdin AOs) in CAS space')
                dump_mat.dump_rec(log.stdout, mocas_b, label, start=1, **kwargs)
            else:
                log.info('Natural alpha-orbital (expansion on AOs) in CAS space')
                dump_mat.dump_rec(log.stdout, mocas_a, label, start=1, **kwargs)
                log.info('Natural beta-orbital (expansion on AOs) in CAS space')
                dump_mat.dump_rec(log.stdout, mocas_b, label, start=1, **kwargs)

            tol = getattr(__config__, 'mcscf_addons_map2hf_tol', 0.4)
            s = reduce(numpy.dot, (mo_coeff[0].T, ovlp_ao, self._scf.mo_coeff[0]))
            idx = numpy.argwhere(abs(s)>tol)
            for i,j in idx:
                log.info('alpha <mo-mcscf|mo-hf> %d  %d  %12.8f' % (i+1,j+1,s[i,j]))
            s = reduce(numpy.dot, (mo_coeff[1].T, ovlp_ao, self._scf.mo_coeff[1]))
            idx = numpy.argwhere(abs(s)>tol)
            for i,j in idx:
                log.info('beta <mo-mcscf|mo-hf> %d  %d  %12.8f' % (i+1,j+1,s[i,j]))

            if getattr(self.fcisolver, 'large_ci', None) and ci is not None:
                log.info('\n** Largest CI components **')
                if isinstance(ci, (tuple, list)):
                    for i, state in enumerate(ci):
                        log.info('  [alpha occ-orbitals] [beta occ-orbitals]  state %-3d CI coefficient', i)
                        res = self.fcisolver.large_ci(state, self.ncas, self.nelecas,
                                                      large_ci_tol, return_strs=False)
                        for c,ia,ib in res:
                            log.info('  %-20s %-30s %.12f', ia, ib, c)
                else:
                    log.info('  [alpha occ-orbitals] [beta occ-orbitals]            CI coefficient')
                    res = self.fcisolver.large_ci(ci, self.ncas, self.nelecas,
                                                  large_ci_tol, return_strs=False)
                    for c,ia,ib in res:
                        log.info('  %-20s %-30s %.12f', ia, ib, c)
        return dm1a, dm1b
Esempio n. 11
0
    rdm1[i, i] = 2.0

# from AO basis to MO basis
s = coeff.T.dot(s).dot(coeff)
pop = numpy.einsum('ij,ji->', s, rdm1)
lib.logger.info(mol, '* Info on MO basis')
lib.logger.info(mol, 'Population : %12.6f' % pop)

# From MO basis to AO basis
coeff = numpy.linalg.inv(coeff)
s = coeff.T.dot(s).dot(coeff)
pop = numpy.einsum('ij,ji->', s, dm)
lib.logger.info(mol, '* Backtransform from MO to AO basis')
lib.logger.info(mol, 'Population : %12.6f' % pop)
lib.logger.info(mol, '* Overlap on AO basis')
dump_tri(mol.stdout, s, ncol=15, digits=5, start=0)

# Reference AO basis
with h5py.File(name + '_integrals.h5') as f:
    sref = f['molecule/overlap'].value
lib.logger.info(mol, '* REF Overlap on AO basis')
dump_tri(mol.stdout, sref, ncol=15, digits=5, start=0)

# Read info from aom program
aom = numpy.zeros((mol.natm, nmo, nmo))
totaom = numpy.zeros((nmo, nmo))
with h5py.File(name + '.chk.h5') as f:
    for i in range(mol.natm):
        idx = 'ovlp' + str(i)
        aom[i] = f[idx + '/aom'].value
for i in range(mol.natm):
Esempio n. 12
0
def analyze(casscf, mo_coeff=None, ci=None, verbose=logger.INFO):
    from pyscf.lo import orth
    from pyscf.tools import dump_mat
    if mo_coeff is None: mo_coeff = casscf.mo_coeff
    if ci is None: ci = casscf.ci
    if isinstance(verbose, logger.Logger):
        log = verbose
    else:
        log = logger.Logger(casscf.stdout, verbose)
    nelecas = casscf.nelecas
    ncas = casscf.ncas
    ncore = casscf.ncore
    nocc = ncore + ncas
    label = casscf.mol.spheric_labels(True)

    if hasattr(casscf.fcisolver, 'make_rdm1s'):
        casdm1a, casdm1b = casscf.fcisolver.make_rdm1s(ci, ncas, nelecas)
        casdm1 = casdm1a + casdm1b
        mocore = mo_coeff[:,:ncore]
        mocas = mo_coeff[:,ncore:nocc]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1a = dm1b + reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))
        dm1 = dm1a + dm1b
        if log.verbose >= logger.DEBUG1:
            log.info('alpha density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1a, label)
            log.info('beta density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1b, label)
    else:
        casdm1 = casscf.fcisolver.make_rdm1(ci, ncas, nelecas)
        mocore = mo_coeff[:,:ncore]
        mocas = mo_coeff[:,ncore:nocc]
        dm1a =(numpy.dot(mocore, mocore.T) * 2
             + reduce(numpy.dot, (mocas, casdm1, mocas.T)))
        dm1b = None
        dm1 = dm1a

    if log.verbose >= logger.INFO:
        ovlp_ao = casscf._scf.get_ovlp()
        # note the last two args of ._eig for mc1step_symm
        occ, ucas = casscf._eig(-casdm1, ncore, nocc)
        log.info('Natural occ %s', str(-occ))
        for i, k in enumerate(numpy.argmax(abs(ucas), axis=0)):
            if ucas[k,i] < 0:
                ucas[:,i] *= -1
        orth_coeff = orth.orth_ao(casscf.mol, 'meta_lowdin', s=ovlp_ao)
        mo_cas = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mo_coeff[:,ncore:nocc], ucas))
        log.info('Natural orbital (expansion on meta-Lowdin AOs) in CAS space')
        dump_mat.dump_rec(log.stdout, mo_cas, label, start=1)

        if casscf._scf.mo_coeff is not None:
            s = reduce(numpy.dot, (casscf.mo_coeff.T, ovlp_ao, casscf._scf.mo_coeff))
            idx = numpy.argwhere(abs(s)>.4)
            for i,j in idx:
                log.info('<mo-mcscf|mo-hf> %d  %d  %12.8f', i+1, j+1, s[i,j])

        if ci is not None and numpy.ndim(ci) >= 2:
            log.info('** Largest CI components **')
            if ci[0].ndim == 2:
                for i, state in enumerate(ci):
                    log.info(' string alpha, string beta, state %d CI coefficients', i)
                    for c,ia,ib in fci.addons.large_ci(state, casscf.ncas, casscf.nelecas):
                        log.info('  %9s    %9s    %.12f', ia, ib, c)
            else:
                log.info(' string alpha, string beta, CI coefficients')
                for c,ia,ib in fci.addons.large_ci(ci, casscf.ncas, casscf.nelecas):
                    log.info('  %9s    %9s    %.12f', ia, ib, c)

        casscf._scf.mulliken_meta(casscf.mol, dm1, s=ovlp_ao, verbose=log)
    return dm1a, dm1b
Esempio n. 13
0
    def build(self):

        t0 = (time.clock(), time.time())
        lib.logger.TIMER_LEVEL = 3

        self.cell = libpbc.chkfile.load_cell(self.chkfile)
        self.a = self.cell.lattice_vectors()
        self.b = self.cell.reciprocal_vectors()
        self.vol = self.cell.vol
        self.nelectron = self.cell.nelectron
        self.charge = self.cell.charge
        self.spin = self.cell.spin
        self.natm = self.cell.natm
        self.ls = self.cell.get_lattice_Ls(dimension=self.cell.dimension)
        self.ls = self.ls[numpy.argsort(lib.norm(self.ls, axis=1))]
        self.kpts = lib.chkfile.load(self.chkfile, 'kcell/kpts')
        self.nkpts = len(self.kpts)
        self.coords = numpy.asarray([(numpy.asarray(atom[1])).tolist()
                                     for atom in self.cell._atom])
        self.charges = self.cell.atom_charges()
        if self.charges[self.inuc] == 1:
            self.rad = grid.BRAGG[self.charges[self.inuc]]
        else:
            self.rad = grid.BRAGG[self.charges[self.inuc]] * 0.5

        idx = 'atom' + str(self.inuc)
        with h5py.File(self.surfile) as f:
            self.xnuc = f[idx + '/xnuc'].value
            self.xyzrho = f[idx + '/xyzrho'].value
            self.npang = f[idx + '/npang'].value
            self.ntrial = f[idx + '/ntrial'].value
            self.rmin = f[idx + '/rmin'].value
            self.rmax = f[idx + '/rmax'].value
            self.rsurf = f[idx + '/rsurf'].value
            self.nlimsurf = f[idx + '/nlimsurf'].value
            self.agrids = f[idx + '/coords'].value

        self.brad = self.rmin * self.betafac

        # TODO: general orbitals
        mo_coeff = lib.chkfile.load(self.chkfile, 'scf/mo_coeff')
        nprims, nmo = mo_coeff[0].shape
        if (self.orbs == -1):
            self.orbs = nmo
        self.nprims = nprims
        self.nmo = self.orbs * self.nkpts
        self.mo_coeff = numpy.zeros((self.nprims, self.nmo),
                                    dtype=numpy.complex128)
        self.tags = numpy.zeros(self.nmo, dtype=numpy.int32)
        ii = 0
        for k in range(self.nkpts):
            for i in range(self.orbs):
                self.mo_coeff[:, ii] = mo_coeff[k][:, i]
                self.tags[ii] = k
                ii += 1

        if self.verbose >= logger.WARN:
            self.check_sanity()
        if self.verbose > logger.NOTE:
            self.dump_input()

        if (self.iqudr == 'legendre'):
            self.iqudr = 1
        if (self.biqudr == 'legendre'):
            self.biqudr = 1

        if (self.mapr == 'becke'):
            self.mapr = 1
        elif (self.mapr == 'exp'):
            self.mapr = 2
        elif (self.mapr == 'none'):
            self.mapr = 0
        if (self.bmapr == 'becke'):
            self.bmapr = 1
        elif (self.bmapr == 'exp'):
            self.bmapr = 2
        elif (self.bmapr == 'none'):
            self.bmapr = 0

        self.aom = numpy.zeros((self.nmo, self.nmo), dtype=numpy.complex128)
        with lib.with_omp_threads(self.nthreads):
            aomb = int_beta(self)
            aoma = out_beta(self)

        idx = 0
        for i in range(self.nmo):
            for j in range(i + 1):
                self.aom[i, j] = aoma[idx] + aomb[idx]
                self.aom[j, i] = self.aom[i, j].conj()
                idx += 1
        norm = float(1.0 / self.nkpts)
        self.aom = self.aom * norm
        if (self.nmo <= 30):
            dump_tri(self.stdout, self.aom, ncol=NCOL, digits=DIGITS, start=0)

        logger.info(self, 'Write info to HDF5 file')
        atom_dic = {'aom': self.aom}
        lib.chkfile.save(self.surfile, 'ovlp' + str(self.inuc), atom_dic)
        logger.info(self, '')

        logger.info(self, 'AOM of atom %d done', self.inuc)
        logger.timer(self, 'AOM build', *t0)

        return self
Esempio n. 14
0
    def analyze(self,
                mo_coeff=None,
                ci=None,
                verbose=logger.DEBUG,
                large_ci_tol=0.1,
                **kwargs):
        from pyscf.tools import dump_mat
        if mo_coeff is None: mo_coeff = self.mo_coeff
        if ci is None: ci = self.ci
        nelecas = self.nelecas
        ncas = self.ncas
        ncore = self.ncore

        casdm1a, casdm1b = self.fcisolver.make_rdm1s(ci, ncas, nelecas)
        mocore = mo_coeff[0][:, :ncore[0]]
        mocas = mo_coeff[0][:, ncore[0]:ncore[0] + ncas]
        dm1a = numpy.dot(mocore, mocore.T)
        dm1a += reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        mocore = mo_coeff[1][:, :ncore[1]]
        mocas = mo_coeff[1][:, ncore[1]:ncore[1] + ncas]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))

        if verbose >= logger.INFO:
            log = logger.Logger(self.stdout, verbose)
            label = self.mol.ao_labels()
            if log.verbose >= logger.DEBUG:
                log.info('alpha density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1a, label)
                log.info('beta density matrix (on AO)')
                dump_mat.dump_tri(self.stdout, dm1b, label)

            s = reduce(
                numpy.dot,
                (mo_coeff[0].T, self._scf.get_ovlp(), self._scf.mo_coeff[0]))
            idx = numpy.argwhere(abs(s) > .4)
            for i, j in idx:
                log.info('alpha <mo-mcscf|mo-hf> %d  %d  %12.8f' %
                         (i + 1, j + 1, s[i, j]))
            s = reduce(
                numpy.dot,
                (mo_coeff[1].T, self._scf.get_ovlp(), self._scf.mo_coeff[1]))
            idx = numpy.argwhere(abs(s) > .4)
            for i, j in idx:
                log.info('beta <mo-mcscf|mo-hf> %d  %d  %12.8f' %
                         (i + 1, j + 1, s[i, j]))

            log.info('\n** Largest CI components **')
            if (hasattr(self.fcisolver, 'large_ci') and ci is not None
                    and numpy.ndim(ci) >= 2):
                if ci[0].ndim == 2:
                    for i, state in enumerate(ci):
                        log.info(
                            '  [alpha occ-orbitals] [beta occ-orbitals]  state %-3d CI coefficient',
                            i)
                        res = self.fcisolver.large_ci(state,
                                                      self.ncas,
                                                      self.nelecas,
                                                      large_ci_tol,
                                                      return_strs=False)
                        for c, ia, ib in res:
                            log.info('  %-20s %-30s %.12f', ia, ib, c)
                else:
                    log.info(
                        '  [alpha occ-orbitals] [beta occ-orbitals]            CI coefficient'
                    )
                    res = self.fcisolver.large_ci(ci,
                                                  self.ncas,
                                                  self.nelecas,
                                                  large_ci_tol,
                                                  return_strs=False)
                    for c, ia, ib in res:
                        log.info('  %-20s %-30s %.12f', ia, ib, c)
        return dm1a, dm1b
Esempio n. 15
0
def analyze(casscf,
            mo_coeff=None,
            ci=None,
            verbose=logger.INFO,
            large_ci_tol=.1,
            **kwargs):
    from pyscf.lo import orth
    from pyscf.tools import dump_mat
    log = logger.new_logger(casscf, verbose)

    if mo_coeff is None: mo_coeff = casscf.mo_coeff
    if ci is None: ci = casscf.ci
    nelecas = casscf.nelecas
    ncas = casscf.ncas
    ncore = casscf.ncore
    nocc = ncore + ncas
    label = casscf.mol.ao_labels()

    if isinstance(ci, (tuple, list)):
        ci0 = ci[0]
        log.info('** Natural natural orbitals are based on the first root **')
    else:
        ci0 = ci
    if ci0 is None and hasattr(casscf, 'casdm1'):
        casdm1 = casscf.casdm1
        mocore = mo_coeff[:, :ncore]
        mocas = mo_coeff[:, ncore:nocc]
        dm1a = (numpy.dot(mocore, mocore.T) * 2 +
                reduce(numpy.dot, (mocas, casdm1, mocas.T)))
        dm1b = None
        dm1 = dm1a
    elif hasattr(casscf.fcisolver, 'make_rdm1s'):
        casdm1a, casdm1b = casscf.fcisolver.make_rdm1s(ci0, ncas, nelecas)
        casdm1 = casdm1a + casdm1b
        mocore = mo_coeff[:, :ncore]
        mocas = mo_coeff[:, ncore:nocc]
        dm1b = numpy.dot(mocore, mocore.T)
        dm1a = dm1b + reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))
        dm1 = dm1a + dm1b
        if log.verbose >= logger.DEBUG2:
            log.info('alpha density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1a, label, **kwargs)
            log.info('beta density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1b, label, **kwargs)
    else:
        casdm1 = casscf.fcisolver.make_rdm1(ci0, ncas, nelecas)
        mocore = mo_coeff[:, :ncore]
        mocas = mo_coeff[:, ncore:nocc]
        dm1a = (numpy.dot(mocore, mocore.T) * 2 +
                reduce(numpy.dot, (mocas, casdm1, mocas.T)))
        dm1b = None
        dm1 = dm1a

    if log.verbose >= logger.INFO:
        ovlp_ao = casscf._scf.get_ovlp()
        # note the last two args of ._eig for mc1step_symm
        occ, ucas = casscf._eig(-casdm1, ncore, nocc)
        log.info('Natural occ %s', str(-occ))
        for i, k in enumerate(numpy.argmax(abs(ucas), axis=0)):
            if ucas[k, i] < 0:
                ucas[:, i] *= -1
        orth_coeff = orth.orth_ao(casscf.mol, 'meta_lowdin', s=ovlp_ao)
        mo_cas = reduce(numpy.dot,
                        (orth_coeff.T, ovlp_ao, mo_coeff[:, ncore:nocc], ucas))
        log.info('Natural orbital (expansion on meta-Lowdin AOs) in CAS space')
        dump_mat.dump_rec(log.stdout, mo_cas, label, start=1, **kwargs)
        if log.verbose >= logger.DEBUG2:
            if not casscf.natorb:
                log.debug2(
                    'NOTE: mc.mo_coeff in active space is different to '
                    'the natural orbital coefficients printed in above.')
            log.debug2(
                ' ** CASCI/CASSCF orbital coefficients (expansion on meta-Lowdin AOs) **'
            )
            c = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mo_coeff))
            dump_mat.dump_rec(log.stdout, c, label, start=1, **kwargs)

        if casscf._scf.mo_coeff is not None:
            s = reduce(numpy.dot,
                       (casscf.mo_coeff.T, ovlp_ao, casscf._scf.mo_coeff))
            idx = numpy.argwhere(abs(s) > .4)
            for i, j in idx:
                log.info('<mo-mcscf|mo-hf> %d  %d  %12.8f', i + 1, j + 1, s[i,
                                                                            j])

        if hasattr(casscf.fcisolver, 'large_ci') and ci is not None:
            log.info('** Largest CI components **')
            if isinstance(ci, (tuple, list)):
                for i, civec in enumerate(ci):
                    res = casscf.fcisolver.large_ci(civec,
                                                    casscf.ncas,
                                                    casscf.nelecas,
                                                    large_ci_tol,
                                                    return_strs=False)
                    log.info(
                        '  [alpha occ-orbitals] [beta occ-orbitals]  state %-3d CI coefficient',
                        i)
                    for c, ia, ib in res:
                        log.info('  %-20s %-30s %.12f', ia, ib, c)
            else:
                log.info(
                    '  [alpha occ-orbitals] [beta occ-orbitals]            CI coefficient'
                )
                res = casscf.fcisolver.large_ci(ci,
                                                casscf.ncas,
                                                casscf.nelecas,
                                                large_ci_tol,
                                                return_strs=False)
                for c, ia, ib in res:
                    log.info('  %-20s %-30s %.12f', ia, ib, c)

        casscf._scf.mulliken_meta(casscf.mol, dm1, s=ovlp_ao, verbose=log)
    return dm1a, dm1b
Esempio n. 16
0
def analyze(casscf,
            mo_coeff=None,
            ci=None,
            verbose=None,
            large_ci_tol=LARGE_CI_TOL,
            with_meta_lowdin=WITH_META_LOWDIN,
            **kwargs):
    from pyscf.lo import orth
    from pyscf.tools import dump_mat
    from pyscf.mcscf import addons
    log = logger.new_logger(casscf, verbose)

    if mo_coeff is None: mo_coeff = casscf.mo_coeff
    if ci is None: ci = casscf.ci
    nelecas = casscf.nelecas
    ncas = casscf.ncas
    ncore = casscf.ncore
    nocc = ncore + ncas
    mocore = mo_coeff[:, :ncore]
    mocas = mo_coeff[:, ncore:nocc]

    label = casscf.mol.ao_labels()
    if (isinstance(ci, (list, tuple)) and
            not isinstance(casscf.fcisolver, addons.StateAverageFCISolver)):
        log.warn(
            'Mulitple states found in CASCI/CASSCF solver. Density '
            'matrix of the first state is generated in .analyze() function.')
        civec = ci[0]
    else:
        civec = ci
    if getattr(casscf.fcisolver, 'make_rdm1s', None):
        casdm1a, casdm1b = casscf.fcisolver.make_rdm1s(civec, ncas, nelecas)
        casdm1 = casdm1a + casdm1b
        dm1b = numpy.dot(mocore, mocore.T)
        dm1a = dm1b + reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))
        dm1 = dm1a + dm1b
        if log.verbose >= logger.DEBUG2:
            log.info('alpha density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1a, label, **kwargs)
            log.info('beta density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1b, label, **kwargs)
    else:
        casdm1 = casscf.fcisolver.make_rdm1(civec, ncas, nelecas)
        dm1a = (numpy.dot(mocore, mocore.T) * 2 +
                reduce(numpy.dot, (mocas, casdm1, mocas.T)))
        dm1b = None
        dm1 = dm1a

    if log.verbose >= logger.INFO:
        ovlp_ao = casscf._scf.get_ovlp()
        # note the last two args of ._eig for mc1step_symm
        occ, ucas = casscf._eig(-casdm1, ncore, nocc)
        log.info('Natural occ %s', str(-occ))
        mocas = numpy.dot(mocas, ucas)
        if with_meta_lowdin:
            log.info(
                'Natural orbital (expansion on meta-Lowdin AOs) in CAS space')
            orth_coeff = orth.orth_ao(casscf.mol, 'meta_lowdin', s=ovlp_ao)
            mocas = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mocas))
        else:
            log.info('Natural orbital (expansion on AOs) in CAS space')
        dump_mat.dump_rec(log.stdout, mocas, label, start=1, **kwargs)
        if log.verbose >= logger.DEBUG2:
            if not casscf.natorb:
                log.debug2(
                    'NOTE: mc.mo_coeff in active space is different to '
                    'the natural orbital coefficients printed in above.')
            if with_meta_lowdin:
                c = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mo_coeff))
                log.debug2('MCSCF orbital (expansion on meta-Lowdin AOs)')
            else:
                c = mo_coeff
                log.debug2('MCSCF orbital (expansion on AOs)')
            dump_mat.dump_rec(log.stdout, c, label, start=1, **kwargs)

        if casscf._scf.mo_coeff is not None:
            addons.map2hf(casscf, casscf._scf.mo_coeff)

        if getattr(casscf.fcisolver, 'large_ci', None) and ci is not None:
            log.info('** Largest CI components **')
            if isinstance(ci, (tuple, list)):
                for i, civec in enumerate(ci):
                    res = casscf.fcisolver.large_ci(civec,
                                                    casscf.ncas,
                                                    casscf.nelecas,
                                                    large_ci_tol,
                                                    return_strs=False)
                    log.info(
                        '  [alpha occ-orbitals] [beta occ-orbitals]  state %-3d CI coefficient',
                        i)
                    for c, ia, ib in res:
                        log.info('  %-20s %-30s %.12f', ia, ib, c)
            else:
                log.info(
                    '  [alpha occ-orbitals] [beta occ-orbitals]            CI coefficient'
                )
                res = casscf.fcisolver.large_ci(ci,
                                                casscf.ncas,
                                                casscf.nelecas,
                                                large_ci_tol,
                                                return_strs=False)
                for c, ia, ib in res:
                    log.info('  %-20s %-30s %.12f', ia, ib, c)

        if with_meta_lowdin:
            casscf._scf.mulliken_meta(casscf.mol, dm1, s=ovlp_ao, verbose=log)
        else:
            casscf._scf.mulliken_pop(casscf.mol, dm1, s=ovlp_ao, verbose=log)
    return dm1a, dm1b
Esempio n. 17
0
def analyze(casscf, mo_coeff=None, ci=None, verbose=None,
            large_ci_tol=LARGE_CI_TOL, with_meta_lowdin=WITH_META_LOWDIN,
            **kwargs):
    from pyscf.lo import orth
    from pyscf.tools import dump_mat
    from pyscf.mcscf import addons
    log = logger.new_logger(casscf, verbose)

    if mo_coeff is None: mo_coeff = casscf.mo_coeff
    if ci is None: ci = casscf.ci
    nelecas = casscf.nelecas
    ncas = casscf.ncas
    ncore = casscf.ncore
    nocc = ncore + ncas
    mocore = mo_coeff[:,:ncore]
    mocas = mo_coeff[:,ncore:nocc]

    label = casscf.mol.ao_labels()
    if (isinstance(ci, (list, tuple)) and
        not isinstance(casscf.fcisolver, addons.StateAverageFCISolver)):
        log.warn('Mulitple states found in CASCI/CASSCF solver. Density '
                 'matrix of first state is generated in .analyze() function.')
        civec = ci[0]
    else:
        civec = ci
    if getattr(casscf.fcisolver, 'make_rdm1s', None):
        casdm1a, casdm1b = casscf.fcisolver.make_rdm1s(civec, ncas, nelecas)
        casdm1 = casdm1a + casdm1b
        dm1b = numpy.dot(mocore, mocore.T)
        dm1a = dm1b + reduce(numpy.dot, (mocas, casdm1a, mocas.T))
        dm1b += reduce(numpy.dot, (mocas, casdm1b, mocas.T))
        dm1 = dm1a + dm1b
        if log.verbose >= logger.DEBUG2:
            log.info('alpha density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1a, label, **kwargs)
            log.info('beta density matrix (on AO)')
            dump_mat.dump_tri(log.stdout, dm1b, label, **kwargs)
    else:
        casdm1 = casscf.fcisolver.make_rdm1(civec, ncas, nelecas)
        dm1a =(numpy.dot(mocore, mocore.T) * 2
             + reduce(numpy.dot, (mocas, casdm1, mocas.T)))
        dm1b = None
        dm1 = dm1a

    if log.verbose >= logger.INFO:
        ovlp_ao = casscf._scf.get_ovlp()
        # note the last two args of ._eig for mc1step_symm
        occ, ucas = casscf._eig(-casdm1, ncore, nocc)
        log.info('Natural occ %s', str(-occ))
        mocas = numpy.dot(mocas, ucas)
        if with_meta_lowdin:
            log.info('Natural orbital (expansion on meta-Lowdin AOs) in CAS space')
            orth_coeff = orth.orth_ao(casscf.mol, 'meta_lowdin', s=ovlp_ao)
            mocas = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mocas))
        else:
            log.info('Natural orbital (expansion on AOs) in CAS space')
        dump_mat.dump_rec(log.stdout, mocas, label, start=1, **kwargs)
        if log.verbose >= logger.DEBUG2:
            if not casscf.natorb:
                log.debug2('NOTE: mc.mo_coeff in active space is different to '
                           'the natural orbital coefficients printed in above.')
            if with_meta_lowdin:
                c = reduce(numpy.dot, (orth_coeff.T, ovlp_ao, mo_coeff))
                log.debug2('MCSCF orbital (expansion on meta-Lowdin AOs)')
            else:
                c = mo_coeff
                log.debug2('MCSCF orbital (expansion on AOs)')
            dump_mat.dump_rec(log.stdout, c, label, start=1, **kwargs)

        if casscf._scf.mo_coeff is not None:
            addons.map2hf(casscf, casscf._scf.mo_coeff)

        if getattr(casscf.fcisolver, 'large_ci', None) and ci is not None:
            log.info('** Largest CI components **')
            if isinstance(ci, (tuple, list)):
                for i, civec in enumerate(ci):
                    res = casscf.fcisolver.large_ci(civec, casscf.ncas, casscf.nelecas,
                                                    large_ci_tol, return_strs=False)
                    log.info('  [alpha occ-orbitals] [beta occ-orbitals]  state %-3d CI coefficient', i)
                    for c,ia,ib in res:
                        log.info('  %-20s %-30s %.12f', ia, ib, c)
            else:
                log.info('  [alpha occ-orbitals] [beta occ-orbitals]            CI coefficient')
                res = casscf.fcisolver.large_ci(ci, casscf.ncas, casscf.nelecas,
                                                large_ci_tol, return_strs=False)
                for c,ia,ib in res:
                    log.info('  %-20s %-30s %.12f', ia, ib, c)

        if with_meta_lowdin:
            casscf._scf.mulliken_meta(casscf.mol, dm1, s=ovlp_ao, verbose=log)
        else:
            casscf._scf.mulliken_pop(casscf.mol, dm1, s=ovlp_ao, verbose=log)
    return dm1a, dm1b