Beispiel #1
0
    def make_nevpt_object(self, dirname=None):
        # dirname None implies exact solve, i.e. no NECI invokation to supply RDMs
        mol = self.get_mol_obj()
        m = scf.RHF(mol)
        m.conv_tol = 1e-10
        if dirname is not None:
            try:
                casci = mcscf.CASCI(m, self.ncas, self.nelecas)
                pyscf_serializer.selective_deserialize(
                    casci, pfile='{}/casci.pkl'.format(dirname))
                casci.fcisolver = fciqmcscf.FCIQMCCI(mol)
                casci.fcisolver.dirname = dirname
            except IOError:
                m.kernel()
                m.analyze(with_meta_lowdin=0)

                casci = mcscf.CASCI(m, self.ncas, self.nelecas)
                casci.fcisolver = fciqmcscf.FCIQMCCI(mol)
                casci.fcisolver.only_ints = True
                try:
                    casci.kernel()
                except TypeError:
                    pass

                pyscf_serializer.selective_serialize(
                    casci, ['mo_coeff', '_scf.mo_occ', '_scf.mo_coeff'],
                    pfile='{}/casci.pkl'.format(dirname))
                if not os.path.abspath(dirname) == os.path.abspath('.'):
                    shutil.move('FCIDUMP', dirname)
                return
        else:
            m.kernel()
            casci = mcscf.CASCI(m, self.ncas, self.nelecas)
            casci.kernel()
        return mrpt.NEVPT(casci)
Beispiel #2
0
 def test_mc2step_6o6e_fciqmc(self):
     mc = mcscf.CASSCF(m, 6, 6)
     mc.max_cycle_macro = 10
     mc.fcisolver = fciqmcscf.FCIQMCCI(mol)
     mc.fcisolver.RDMSamples = 5000
     emc = mc.mc2step()[0]
     self.assertAlmostEqual(emc, -108.98028859357791, 7)
    def __init__(self,
                 fciqmc_dir=None,
                 mol_kwargs=None,
                 fname='nevpt2_store.pkl',
                 casorbs=None,
                 norb=None,
                 nelecas=None,
                 save_dms=False,
                 threshs=(1e-14, ),
                 analyze=False):
        self.save_dms = save_dms
        self.casorbs = casorbs
        if isinstance(mol_kwargs, dict):
            self.mol_kwargs = mol_kwargs
            mol = self.mol()
            hf = scf.RHF(mol)
            hf.conv_tol = 1e-10
            hf.kernel()
            if analyze: hf.analyze()
            self.hf_canon_mo = hf.mo_coeff
            self.hf_mo_energy = hf.mo_energy
            self.norb, self.nelecas = norb, nelecas
            if casorbs is not None: self.norb = len(casorbs)
            casci = mcscf.CASCI(hf, self.norb, self.nelecas)
            if casorbs is not None: casci.mo_coeff = casci.sort_mo(casorbs)
            self.hf_canon_mo = casci.mo_coeff
            if fciqmc_dir is not None:
                print '### Initial invokation for subsequent FCIQMC RDM sampling'
                output_fcidump(casci, mol, fciqmc_dir)
                self.save(fname)
            else:
                print '### Exact CASCI+NEVPT2 invokation'
                output_fcidump(casci, mol)
                casci.kernel()
                self.casci_canon_mo = casci.mo_coeff
                self.casci_mo_energy = casci.mo_energy
                nevpt2 = mrpt.NEVPT(casci)
                nevpt2.threshs = threshs
                nevpt2.kernel(self.save_dms)
                self.save(fname)
        elif isinstance(fname, str) and os.path.exists(fname):
            self.load(fname)
            mol = self.mol()
            hf = scf.RHF(mol)
            casci = mcscf.CASCI(hf, self.norb, self.nelecas)
            casci.mo_coeff = self.casci_canon_mo if self.casci_canon_mo is not None else self.hf_canon_mo
            casci.mo_energy = self.casci_mo_energy if self.casci_canon_mo is not None else self.hf_mo_energy

            if fciqmc_dir is not None:
                print '### Stochastic NEVPT2 invokation with FCIQMC RDMs'
                casci.fcisolver = fciqmcscf.FCIQMCCI(mol)
                casci.fcisolver.dirname = fciqmc_dir
            else:
                print '### Exact NEVPT2 invokation from previous CASCI'
            nevpt2 = mrpt.NEVPT(casci)
            nevpt2.threshs = threshs
            nevpt2.canonicalized = self.casci_canon_mo is not None
            nevpt2.kernel(self.save_dms)
        else:
            raise Exception('Neither a mol dict nor a valid path was provided')
def output_fcidump(casci, mol, dirname=None):
    tmp = casci.fcisolver
    casci.fcisolver = fciqmcscf.FCIQMCCI(mol)
    casci.fcisolver.only_ints = 1
    try:
        casci.kernel()
    except TypeError:
        pass
    if dirname not in (None, '.'):
        shutil.move('FCIDUMP', '{}/FCIDUMP'.format(dirname))
    casci.fcisolver = tmp
Beispiel #5
0
    def serialize_cas(self, dirname='.'):
        mol, casci = self.get_mc_obj()
        casci.fcisolver = fciqmcscf.FCIQMCCI(mol)
        casci.fcisolver.only_ints = True
        try:
            casci.kernel()
        except TypeError:
            pass

        pyscf_serializer.selective_serialize(
            casci, ['mo_coeff', '_scf.mo_occ', '_scf.mo_coeff'],
            pfile='{}/casci.pkl'.format(dirname))
        if not dirname == '.':
            shutil.move('FCIDUMP', dirname)
    def test_mc2step_4o4e_fciqmc_wdipmom(self):
        #nelec is the number of electrons in the active space
        nelec = 4
        norb = 4
        mc = mcscf.CASSCF(m, norb, nelec)
        mc.max_cycle_macro = 10
        mc.fcisolver = fciqmcscf.FCIQMCCI(mol, calc_exact_states=True, hbrdm_rank=4)
        mc.fcisolver.RDMSamples = 5000

        emc, e_ci, fcivec, casscf_mo, casscf_mo_e = mc.mc2step()
        self.assertAlmostEqual(emc,-108.91378666934476, 7)

        # Calculate dipole moment in casscf_mo basis
        # First find the 1RDM in the full space
        one_pdm = fciqmc.find_full_casscf_12rdm(mc.fcisolver, casscf_mo,
                'spinfree_TwoRDM.1', norb, nelec)[0]
        dipmom = fciqmc.calc_dipole(mol,casscf_mo,one_pdm)
        print('Dipole moments: ',dipmom)
verbose = 0,
output = None,
atom = [
    ['N',(  0.000000,  0.000000, -b/2)],
    ['N',(  0.000000,  0.000000,  b/2)], ],
basis = {'N': 'ccpvdz', },
symmetry = True,
symmetry_subgroup = 'D2h'
)
m = scf.RHF(mol)
m.conv_tol = 1e-9
m.scf()

mc = mcscf.CASSCF(m, 6, 6)
mc.max_cycle_macro = 10
mc.fcisolver = fciqmcscf.FCIQMCCI(mol, calc_exact_states=True, hbrdm_rank=2)
mc.fcisolver.RDMSamples = 5000
emc = mc.mc2step()[0]

print emc

'''
mc2 = mcscf.CASSCF(m, 6, 6)
emc2 = mc2.mc2step()[0]
print abs(emc-emc2)<1e-11
'''

assert(0)


class KnowValues(unittest.TestCase):