Exemplo n.º 1
0
def pyscf_from_file(chkfile):
    mol = chk.load_mol(chkfile)
    mf = RHF(mol)
    mf.__dict__.update(chk.load(chkfile, 'scf'))
    mc_dict = chk.load(chkfile, 'mcscf')
    if mc_dict:
        mc_dict['ci'] = chk.load(chkfile, 'ci')
        mc_dict['nelecas'] = tuple(map(int, chk.load(chkfile, 'nelecas')))
        mc = CASSCF(mf, 0, 0)
        mc.__dict__.update(mc_dict)
    else:
        mc = None
    return mf, mc
Exemplo n.º 2
0
def load_bands(chkfile):
    '''
        load bandstructure for plotting
    '''
    save_bands = load(chkfile, 'bands')
    band_structure = save_bands['bands']
    return band_structure
Exemplo n.º 3
0
def load_agf2(chkfile):
    ''' Load the AGF2 data from the chkfile.
    '''

    if mpi_helper.rank == 0:
        dic = chkutil.load(chkfile, 'agf2')
    else:
        dic = None

    mpi_helper.barrier()
    dic = mpi_helper.bcast_dict(dic)

    if 'gf' in dic:
        gf = dic['gf']
        dic['gf'] = GreensFunction(gf['energy'], gf['coupling'], chempot=gf['chempot'])
    elif 'gfa' in dic:
        gfa, gfb = dic['gfa'], dic['gfb']
        dic['gf'] = (GreensFunction(gfa['energy'], gfa['coupling'], chempot=gfa['chempot']),
                     GreensFunction(gfb['energy'], gfb['coupling'], chempot=gfb['chempot']))
        del(dic['gfa'], dic['gfb'])

    if 'se' in dic:
        se = dic['se']
        dic['se'] = SelfEnergy(se['energy'], se['coupling'], chempot=se['chempot'])
    elif 'sea' in dic:
        sea, seb = dic['sea'], dic['seb']
        dic['se'] = (SelfEnergy(sea['energy'], sea['coupling'], chempot=sea['chempot']),
                     SelfEnergy(seb['energy'], seb['coupling'], chempot=seb['chempot']))
        del(dic['sea'], dic['seb'])

    if 'ngf' in dic:
        dic['nmom'] = (dic.get('ngf', None), dic.get('nse', None))
        del(dic['ngf'], dic['nse'])

    return load_mol(chkfile), dic
Exemplo n.º 4
0
def load_kmf(chkfile):
    ''' Load a wavefunction'''
    from pyscf.lib.chkfile import load
    kmf = load(chkfile, 'scf')
    class fake_kmf:
        def __init__(self, kmf):
            self.kpts = kmf['kpts']
            self.mo_energy_kpts = kmf['mo_energy_kpts']
            self.mo_coeff_kpts = kmf['mo_coeff_kpts']
    kmf = fake_kmf(kmf)
    return kmf
Exemplo n.º 5
0
def load_kmf(chkfile):
    ''' Load a wavefunction'''
    from pyscf.lib.chkfile import load
    kmf = load(chkfile, 'scf')
    class fake_kmf:
        def __init__(self, kmf):
            self.kpts = kmf['kpts']
            self.mo_energy_kpts = kmf['mo_energy_kpts']
            self.mo_coeff_kpts = kmf['mo_coeff_kpts']
    kmf = fake_kmf(kmf)
    return kmf
Exemplo n.º 6
0
def load(chkfile, key):
    ''' Load array(s) from chkfile.

    See pyscf.lib.chkfile
    '''

    if mpi_helper.rank == 0:
        vals = chkutil.load(chkfile, key)
    else:
        vals = None

    mpi_helper.barrier()
    vals = mpi_helper.bcast_dict(vals)

    return vals
Exemplo n.º 7
0
Arquivo: rhf.py Projeto: pyscf/pyscf
def get_eph(ephobj, mo1, omega, vec, mo_rep):
    if isinstance(mo1, str):
        mo1 = chkfile.load(mo1, 'scf_mo1')
        mo1 = dict([(int(k), mo1[k]) for k in mo1])

    mol = ephobj.mol
    mf = ephobj.base
    vnuc_deriv = ephobj.vnuc_generator(mol)
    aoslices = mol.aoslice_by_atom()
    vind = rhf_deriv_generator(mf, mf.mo_coeff, mf.mo_occ)
    mocc = mf.mo_coeff[:, mf.mo_occ > 0]
    dm0 = np.dot(mocc, mocc.T) * 2

    natoms = mol.natm
    nao = mol.nao_nr()

    vcore = []
    for ia in range(natoms):
        h1 = vnuc_deriv(ia)
        v1 = vind(mo1[ia])
        shl0, shl1, p0, p1 = aoslices[ia]
        shls_slice = (shl0, shl1) + (0, mol.nbas) * 3
        vj1, vk1 = rhf._get_jk(
            mol,
            'int2e_ip1',
            3,
            's2kl',
            [
                'ji->s2kl',
                -dm0[:, p0:p1],  # vj1
                'li->s1kj',
                -dm0[:, p0:p1]
            ],  # vk1
            shls_slice=shls_slice)
        vhf = vj1 - vk1 * .5
        vtot = h1 + v1 + vhf + vhf.transpose(0, 2, 1)
        vcore.append(vtot)
    vcore = np.asarray(vcore).reshape(-1, nao, nao)
    mass = mol.atom_mass_list() * MP_ME
    vec = _freq_mass_weighted_vec(vec, omega, mass)
    mat = np.einsum('xJ,xuv->Juv', vec, vcore)
    if mo_rep:
        mat = np.einsum('Juv,up,vq->Jpq',
                        mat,
                        mf.mo_coeff.conj(),
                        mf.mo_coeff,
                        optimize=True)
    return mat
Exemplo n.º 8
0
    def run_pyscf(self) -> None:
        """Runs the PySCF calculation.

        This method is part of the public interface to allow the user to easily overwrite it in a
        subclass to further tailor the behavior to some specific use case.

        Raises:
            QiskitNatureError: If an invalid HF method type was supplied.
        """
        # pylint: disable=import-error
        from pyscf import dft, scf
        from pyscf.lib import chkfile as lib_chkfile

        method_name = None
        method_cls = None
        try:
            # attempt to gather the SCF-method class specified by the MethodType
            method_name = self.method.value.upper()
            method_cls = getattr(scf, method_name)
        except AttributeError as exc:
            raise QiskitNatureError(
                f"Failed to load {method_name} HF object.") from exc

        self._calc = method_cls(self._mol)

        if method_name in ("RKS", "ROKS", "UKS"):
            self._calc._numint.libxc = getattr(dft, self.xcf_library)
            self._calc.xc = self.xc_functional

        if self._chkfile is not None and os.path.exists(self._chkfile):
            self._calc.__dict__.update(lib_chkfile.load(self._chkfile, "scf"))

            logger.info("PySCF loaded from chkfile e(hf): %s",
                        self._calc.e_tot)
        else:
            self._calc.conv_tol = self._conv_tol
            self._calc.max_cycle = self._max_cycle
            self._calc.init_guess = self._init_guess
            self._calc.kernel()

            logger.info(
                "PySCF kernel() converged: %s, e(hf): %s",
                self._calc.converged,
                self._calc.e_tot,
            )
Exemplo n.º 9
0
def load_scf(chkfile):
    return load_cell(chkfile), load(chkfile, 'scf')
Exemplo n.º 10
0
# Check args
#
if len(sys.argv) != 2:
    raise AssertionError("Incorrect # of args\n"
                         "Use like: python pt2.py 1\n"
                         "Where 1 is the root you want to target.")
target_state = int(sys.argv[-1])

#
# Load MF orbitals
#
chkname = "_chk/pp_dz_b3lyp.chk"
mol = chkfile.load_mol(chkname)
mol.max_memory = int(1e5)  # memory in MB 1e6 -> 1 TB
mf = dft.RKS(mol)
mf.__dict__.update(chkfile.load(chkname, "scf"))

#
# Load SA-MCSCF
#
nelecas, ncas = (4, 4)
n_states = 3
weights = np.ones(n_states) / n_states

mc0 = mcscf.CASSCF(mf, ncas, nelecas).state_average_(weights)
mc0.fix_spin(ss=0)
mc0.chkfile = "_chk/pp_dz_cas_4e_4o.chk"
mc0.__dict__.update(chkfile.load(mc0.chkfile, "mcscf"))

#
# NEVPT2
Exemplo n.º 11
0
Author: James E. T. Smith <*****@*****.**>
Date: 1/29/2020
"""
import numpy as np
from pyscf import dft, mcscf
from pyscf.lib import chkfile
from pyscf.tools import molden

#
# Load MF orbitals
#
chkname = "_chk/pp_dianion_dz_b3lyp.chk"
mol = chkfile.load_mol(chkname)
mol.verbose = 5
mf = dft.RKS(mol)
mf.__dict__.update(chkfile.load(chkname, "scf"))

#
# SA-MCSCF
#
nelecas, ncas = (4, 4)
n_states = 3
weights = np.ones(n_states) / n_states

mc = mcscf.CASSCF(mf, ncas, nelecas).state_average_(weights)
mc.fix_spin(ss=0)
mc.natorb = True
mc.chkfile = "_chk/pp_dianion_dz_cas_4e_4o.chk"
cas_list = [142, 143, 150, 151]
mo = mcscf.sort_mo(mc, mf.mo_coeff, cas_list)
mc.mc1step(mo)
Exemplo n.º 12
0
def load_scf(chkfile):
    return load_cell(chkfile), load(chkfile, 'scf')
Exemplo n.º 13
0
def load_mcscf(chkfile):
    return load_mol(chkfile), load(chkfile, 'mcscf')
Exemplo n.º 14
0
This example shows how to access the data stored in checkpoint file,
Also how to quickly update an object using the data from the checkpoint file.
'''

import numpy
import h5py
from pyscf import gto, scf, ci
from pyscf.lib import chkfile

mol = gto.M(atom='N 0 0 0; N 0 0 1.2', basis='ccpvdz')
mf = scf.RHF(mol)
mf.chkfile = 'example.chk'
mf.run()
print('E(HF) = %s' % mf.e_tot)

scf_result_dic = chkfile.load('example.chk', 'scf')
mf_new = scf.RHF(mol)
mf_new.__dict__.update(scf_result_dic)
print('E(HF) from chkfile = %s' % mf.e_tot)

myci = ci.CISD(mf).run()
myci.dump_chk()
print('E(CISD) = %s' % myci.e_tot)

cisd_result_dic = chkfile.load('example.chk', 'cisd')
myci_new = ci.CISD(mf_new)
myci_new.__dict__.update(cisd_result_dic)
print('E(CISD) from chkfile = %s' % myci_new.e_tot)

mol_new = chkfile.load_mol('example.chk')
print(numpy.allclose(mol.atom_coords(), mol_new.atom_coords()))