コード例 #1
0
 def kernel(self, h1, h2, norb, nelec, ci0=None, ecore=0, **kwargs):
     fakemol = gto.M(verbose=0)
     nelec = numpy.sum(nelec)
     fakemol.nelectron = nelec
     fake_hf = scf.RHF(fakemol)
     fake_hf._eri = ao2mo.restore(8, h2, norb)
     fake_hf.get_hcore = lambda *args: h1
     fake_hf.get_ovlp = lambda *args: numpy.eye(norb)
     fake_hf.kernel()
     self.mycc = cc.CCSD(fake_hf)
     self.eris = self.mycc.ao2mo()
     e_corr, t1, t2 = self.mycc.kernel(eris=self.eris)
     l1, l2 = self.mycc.solve_lambda(t1, t2, eris=self.eris)
     e = fake_hf.e_tot + e_corr
     return e + ecore, [t1, t2, l1, l2]
コード例 #2
0
    def test_dump_chk(self):
        cc1 = copy.copy(mycc)
        cc1.nmo = mf.mo_energy.size
        cc1.nocc = mol.nelectron // 2
        cc1.dump_chk()
        cc1 = cc.CCSD(mf)
        cc1.__dict__.update(lib.chkfile.load(cc1._scf.chkfile, 'ccsd'))
        e = cc1.energy(cc1.t1, cc1.t2, eris)
        self.assertAlmostEqual(e, -0.13539788638119823, 8)

        cc1.e_corr = -1
        cc1.chkfile = None
        cc1.dump_chk(frozen=2)
        self.assertEqual(lib.chkfile.load(cc1._scf.chkfile, 'ccsd/e_corr'),
                         mycc.e_corr)
コード例 #3
0
    def setUp(self):
        geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
        basis = '6-31g'
        multiplicity = 1
        charge = 0
        self.molecule = PyscfMolecularData(geometry, basis, multiplicity,
                                           charge)

        mol = prepare_pyscf_molecule(self.molecule)
        mol.verbose = 0
        self.molecule._pyscf_data['mol'] = mol
        self.molecule._pyscf_data['scf'] = mf = scf.RHF(mol).run()
        self.molecule._pyscf_data['mp2'] = mp.MP2(mf).run()
        self.molecule._pyscf_data['cisd'] = ci.CISD(mf).run()
        self.molecule._pyscf_data['ccsd'] = cc.CCSD(mf).run()
        self.molecule._pyscf_data['fci'] = fci.FCI(mf).run()
コード例 #4
0
    def test_ccsd(self):
        mycc = cc.CCSD(mf)
        ecc = mycc.kernel()[0]
        norb = mf.mo_coeff.shape[1]
        nelec = mol.nelec
        h2e = ao2mo.restore(1, ao2mo.kernel(mf._eri, mf.mo_coeff), norb)
        h1e = reduce(numpy.dot, (mf.mo_coeff.T, mf.get_hcore(), mf.mo_coeff))
        eci, civec = fci.direct_spin0.kernel(h1e, h2e, norb, nelec)
        dm1ref = fci.direct_spin0.make_rdm1(civec, norb, nelec)
        eci = eci + mol.energy_nuc() - mf.e_tot
        self.assertAlmostEqual(eci, ecc, 7)

        l1, l2 = mycc.solve_lambda()
        self.assertAlmostEqual(finger(l1), 0.0106196828089, 5)
        dm1 = mycc.make_rdm1()
        self.assertAlmostEqual(abs(dm1ref - dm1).max(), 0, 5)
コード例 #5
0
def run_ccsd(mol, chkfile):
    """
    run CCSD

    mol     : input/output, a pyscf.gto.Mole object
    """
    t = Timer('CCSD').start()
    mf = scf.RHF(mol).set(chkfile=chkfile).run()
    mycc = cc.CCSD(mf).run()
    print(t)
    if chkfile:
        t = Timer('savechk').start()
        lib.chkfile.save(chkfile, 'cc/t1', mycc.t1)
        lib.chkfile.save(chkfile, 'cc/t2', mycc.t2)
        print(t)
    return mycc
コード例 #6
0
def pyscf_ccsd_amplitude_calculator(domain):
    """
    Calculates CCSD amplitudes in the domain.
    Args:
        domain (Domain): a domain to calculate at;

    Returns:
        CCSD amplitudes.
    """
    mf = scf.RHF(domain.mol)
    mf.build(domain.mol)
    mf.mo_coeff = domain.psi
    mf.mo_energy = domain.e
    mf.mo_occ = numpy.round(domain.occupations).astype(int)
    domain_ccsd = cc.CCSD(mf)
    domain_ccsd.kernel()
    return domain_ccsd.t1, domain_ccsd.t2.swapaxes(1, 2)
コード例 #7
0
ファイル: test_ccsd_t.py プロジェクト: pyscf/pyscf
def setUpModule():
    global mol, rhf, mcc
    mol = gto.Mole()
    mol.atom = [[8, (0., 0., 0.)], [1, (0., -.757, .587)],
                [1, (0., .757, .587)]]
    mol.symmetry = True
    mol.verbose = 7
    mol.output = '/dev/null'
    mol.basis = 'ccpvdz'
    mol.build()
    rhf = scf.RHF(mol)
    rhf.conv_tol = 1e-14
    rhf.scf()

    mcc = cc.CCSD(rhf)
    mcc.conv_tol = 1e-14
    mcc.ccsd()
コード例 #8
0
ファイル: test_ccsd_t.py プロジェクト: v3op01/pyscf
 def test_ccsd_t(self):
     mol = gto.M()
     numpy.random.seed(12)
     nocc, nvir = 5, 12
     eris = lambda :None
     eris.ovvv = numpy.random.random((nocc*nvir,nvir*(nvir+1)//2)) * .1
     eris.ovoo = numpy.random.random((nocc,nvir,nocc,nocc)) * .1
     eris.ovov = numpy.random.random((nocc*nvir,nocc*nvir)) * .1
     t1 = numpy.random.random((nocc,nvir)) * .1
     t2 = numpy.random.random((nocc,nocc,nvir,nvir)) * .1
     t2 = t2 + t2.transpose(1,0,3,2)
     mf = scf.RHF(mol)
     mycc = cc.CCSD(mf)
     mycc.mo_energy = mycc._scf.mo_energy = numpy.arange(0., nocc+nvir)
     eris.fock = numpy.diag(mycc.mo_energy)
     e = ccsd_t.kernel(mycc, eris, t1, t2)
     self.assertAlmostEqual(e, -8.4953387936460398, 9)
コード例 #9
0
def get_ES(n, na, nb, Enuc, h1, h2):

    mol_FC = gto.M(verbose=0)
    mol_FC.charge = 0
    mol_FC.nelectron = na + nb
    mol_FC.spin = na - nb
    mol_FC.incore_anyway = True
    mol_FC.nao_nr = lambda *args: n
    mol_FC.energy_nuc = lambda *args: Enuc
    mf_FC = scf.RHF(mol_FC)
    mf_FC.get_hcore = lambda *args: h1
    mf_FC.get_ovlp = lambda *args: np.eye(n)
    mf_FC._eri = ao2mo.restore(8, h2, n)
    rho = np.zeros((n, n))
    for i in range(na):
        rho[i, i] = 2.0
    Ehf = mf_FC.kernel(rho) + Enuc
    Ecc = (cc.CCSD(mf_FC)).kernel()[0]

    return Ehf, Ecc, mol_FC, mf_FC
コード例 #10
0
    def test_make_natural_orbitals_from_unrestricted(self):
        from pyscf import mp, ci, cc
        npt = numpy.testing

        mol = gto.M(atom='O 0 0 0; O 0 0 1.2', basis='3-21g', spin=2)
        myhf = scf.UHF(mol).run()
        ncas, nelecas = (8, 12)
        mymc = mcscf.CASCI(myhf, ncas, nelecas)

        # Test UHF
        # The tests below are only to ensure that `make_natural_orbitals` can
        # run at all since we've confirmed above that the NOONs are correct for MP2
        mcscf.addons.make_natural_orbitals(myhf)

        # Test MP2
        # Trusted results from ORCA v4.2.1
        rmp2_noons = [
            1.99992786, 1.99992701, 1.99414062, 1.98906552, 1.96095173,
            1.96095165, 1.95280755, 1.02078458, 1.02078457, 0.04719006,
            0.01274288, 0.01274278, 0.00728679, 0.00582683, 0.00543964,
            0.00543962, 0.00290772, 0.00108258
        ]
        mymp = mp.UMP2(myhf).run()
        noons, natorbs = mcscf.addons.make_natural_orbitals(mymp)
        npt.assert_array_almost_equal(rmp2_noons, noons)
        mymc.kernel(natorbs)

        # The tests below are only to ensure that `make_natural_orbitals` can
        # run at all since we've confirmed above that the NOONs are correct.
        # Test CISD
        mycisd = ci.CISD(myhf).run()
        noons, natorbs = mcscf.addons.make_natural_orbitals(mycisd)
        mymc.kernel(natorbs)

        # Test CCSD
        myccsd = cc.CCSD(myhf).run()
        noons, natorbs = mcscf.addons.make_natural_orbitals(myccsd)
        mymc.kernel(natorbs)
コード例 #11
0
ファイル: ddcosmo.py プロジェクト: tmash/pyscf
    mol = gto.Mole()
    mol.atom = ''' O                  0.00000000    0.00000000   -0.11081188
                   H                 -0.00000000   -0.84695236    0.59109389
                   H                 -0.00000000    0.89830571    0.52404783 '''
    mol.basis = '3-21g' #cc-pvdz'
    mol.build()
    cm = DDCOSMO(mol)
    cm.verbose = 4
    mf = ddcosmo_for_scf(scf.RHF(mol), cm)#.newton()
    mf.verbose = 4
    print(mf.kernel() - -75.570364368059)
    cm.verbose = 3
    e = ddcosmo_for_casci(mcscf.CASCI(mf, 4, 4)).kernel()[0]
    print(e - -75.5743583693215)
    cc_cosmo = ddcosmo_for_post_scf(cc.CCSD(mf)).run()
    print(cc_cosmo.e_tot - -75.70961637250134)

    mol = gto.Mole()
    mol.atom = ''' Fe                 0.00000000    0.00000000   -0.11081188
                   H                 -0.00000000   -0.84695236    0.59109389
                   H                 -0.00000000    0.89830571    0.52404783 '''
    mol.basis = '3-21g' #cc-pvdz'
    mol.build()
    cm = DDCOSMO(mol)
    cm.eps = -1
    cm.verbose = 4
    mf = ddcosmo_for_scf(scf.ROHF(mol), cm).newton()
    mf.verbose=4
    mf.kernel()
コード例 #12
0
basis_set = results.basis_set
aux_basis_set = (results.aux_basis_set
                 if results.aux_basis_set != 'undefined' else None)
pseudo_potential = (results.pseudo_potential
                    if results.pseudo_potential != 'undefined' else None)
functional = results.functional
charge = int(results.charge) if results.charge is not None else 0
multiplicity = int(
    results.multiplicity) if results.multiplicity is not None else 1
spin = (multiplicity - 1) / 2
num_frozen_cores = int(
    results.frozen_cores) if results.frozen_cores is not None else 0

sys.argv = [sys.argv[0]]

# -----------------------
#     PYSCF
# -----------------------

mol = gto.M(
    atom=atomic_coords, basis=basis_set, spin=spin, charge=charge, verbose=5)

mf = scf.RHF(mol)
if density_fit:
    mf = mf.density_fit()
    mf.with_df.auxbasis = aux_basis_set
mf.run()

my_cc = cc.CCSD(mf)
my_cc.kernel()
コード例 #13
0
ファイル: 01_simple.py プロジェクト: jamesETsmith/fri-cc
H          4.70175       -2.08942        2.84660
H          6.20095       -2.12814        1.90186
H          4.81547       -3.11370        1.40130"""
# Pentane with ccpvdz fails with m_keep = 1e5
# Pentane with ccpvdz fails with m_keep = 1e6

mol = gto.M(atom=pentane, basis="631g", verbose=4)

nocc = mol.nelec[0]
nvirt = mol.nao_nr() - nocc
print(f" nocc = {nocc}\nnvirt = {nvirt}")
print(f"|t2| = {nocc**2 * nvirt**2}")

mf = scf.RHF(mol).run()

mycc2 = cc.CCSD(mf)
t_ccsd = time.time()
mycc2.kernel()
t_ccsd = time.time() - t_ccsd

fri_settings = {
    "m_keep": 1e3,
    "compression": "fri",
    "sampling_method": "systematic",
    "compressed_contractions": ["O^2V^4"],
    # "compressed_contractions": [],
}
mycc = fricc.FRICCSD(mf, fri_settings=fri_settings)
mycc.max_cycle = 50

t_fricc = time.time()
コード例 #14
0
rdm2_mp2 = numpy.zeros((nocc, nvir, nocc, nvir))
rdm2_mp2 = 2.0 * einsum('iajb,iajb->iajb', eri_mo, e_denom)
rdm2_mp2 -= einsum('ibja,iajb->iajb', eri_mo, e_denom)
e_mp2 = numpy.einsum('iajb,iajb->', eri_mo, rdm2_mp2, optimize=True)
lib.logger.info(mf, "!*** E(MP2): %12.8f" % e_mp2)
lib.logger.info(mf, "!**** E(HF+MP2): %12.8f" % (e_mp2 + ehf))
#
mo_vir = cv
coeff = numpy.hstack([mo_core, mo_occ, mo_vir])
nao, nmo = coeff.shape
nocc = mol.nelectron // 2
occ = numpy.zeros(nmo)
for i in range(nocc):
    occ[i] = 2.0
#
mycc = cc.CCSD(mf, mo_coeff=coeff, mo_occ=occ)
mycc.diis_space = 10
mycc.frozen = ncore
mycc.conv_tol = 1e-6
mycc.conv_tol_normt = 1e-6
mycc.max_cycle = 150
ecc, t1, t2 = mycc.kernel()
nao, nmo = coeff.shape
eris = mycc.ao2mo()
e3 = ccsd_t.kernel(mycc, eris, t1, t2)
lib.logger.info(mycc, "* CCSD(T) energy : %12.6f" % (ehf + ecc + e3))
l1, l2 = ccsd_t_lambda.kernel(mycc, eris, t1, t2)[1:]
rdm1 = ccsd_t_rdm.make_rdm1(mycc, t1, t2, l1, l2, eris=eris)
rdm2 = ccsd_t_rdm.make_rdm2(mycc, t1, t2, l1, l2, eris=eris)
#
eri_mo = ao2mo.kernel(mf._eri, coeff[:, :nmo], compact=False)
コード例 #15
0
fock = h1
for p in range(Norbs):
    for q in range(Norbs):
        fock[p,q] += sum([2 * h2Tensor.array[p,i,q,i] - h2Tensor.array[p,i,i,q] for i in range(Nocc)])
fockTensor.array = fock

fockTensor.assignDiagramArrays(vacuum)
h2Tensor.assignDiagramArrays(vacuum)
t1Tensor.getShape(vacuum)
t2Tensor.getShape(vacuum)

CC.convergeCCSDAmplitudes(t1Tensor, t2Tensor, energyEquation, singlesAmplitudeEquation, doublesAmplitudeEquation, fockTensor)
t4 = time()
print("Time for CCSD calculation:", t4 - t3)

print("\n")
print("Comparison with true answers")
print("MP2")
trueMP2 = mp.MP2(mf)
print(trueMP2.kernel())
t5 = time()
print("MP2 time:", t5-t4)

print("\n")
print("CCSD")
trueCCSD = cc.CCSD(mf)
print(trueCCSD.kernel())
t6 = time()
print("CCSD time:", t6-t5)

texify.texify([energyEquation, singlesAmplitudeEquation, doublesAmplitudeEquation], "CCSDEquations")
コード例 #16
0
ファイル: 03-ccsd.py プロジェクト: zzy2014/pyscf
A simple example to run CCSD with background charges.
'''

import numpy
from pyscf import gto, scf, cc, qmmm

mol = gto.M(atom='''
C       1.1879  -0.3829 0.0000
C       0.0000  0.5526  0.0000
O       -1.1867 -0.2472 0.0000
H       -1.9237 0.3850  0.0000
H       2.0985  0.2306  0.0000
H       1.1184  -1.0093 0.8869
H       1.1184  -1.0093 -0.8869
H       -0.0227 1.1812  0.8852
H       -0.0227 1.1812  -0.8852
            ''',
            basis='3-21g',
            verbose=4)

numpy.random.seed(1)
coords = numpy.random.random((5, 3)) * 10
charges = (numpy.arange(5) + 1.) * -.1

#
# Background charges have to be patched to the underlying SCF calculaitons.
#
mf = qmmm.mm_charge(scf.RHF(mol), coords, charges).run()

cc.CCSD(mf).run()
コード例 #17
0
from pyscf import solvent

mol = gto.M(atom='''
C        0.000000    0.000000             -0.542500
O        0.000000    0.000000              0.677500
H        0.000000    0.9353074360871938   -1.082500
H        0.000000   -0.9353074360871938   -1.082500
            ''',
            basis='ccpvdz',
            verbose=3)
mf = scf.RHF(mol).run()

#
# 1. Allow solvent response to CASSCF optimization
#
mycc = solvent.ddCOSMO(cc.CCSD(mf))
# Adjust solvent model by modifying the attribute .with_solvent
mycc.with_solvent.eps = 32.613  # methanol dielectric constant
mycc.run()

#
# Freeze solvent effects in the CASSCF optimization
#
# Solvent is fully relaxed in the HF calculation.
#
mf = solvent.ddCOSMO(scf.RHF(mol)).run()
# By passing density to solvent model, the solvent potential is frozen at the
# HF level.
mycc = solvent.ddCOSMO(cc.CCSD(mf), dm=mf.make_rdm1())
mycc.run()
コード例 #18
0
ファイル: test_ccsd_lambda.py プロジェクト: pyscf/pyscf
    def test_ccsd(self):
        mol = gto.M()
        mf = scf.RHF(mol)
        mcc = cc.CCSD(mf)
        numpy.random.seed(12)
        mcc.nocc = nocc = 5
        mcc.nmo = nmo = 12
        nvir = nmo - nocc
        eri0 = numpy.random.random((nmo, nmo, nmo, nmo))
        eri0 = ao2mo.restore(1, ao2mo.restore(8, eri0, nmo), nmo)
        fock0 = numpy.random.random((nmo, nmo))
        fock0 = fock0 + fock0.T + numpy.diag(range(nmo)) * 2
        t1 = numpy.random.random((nocc, nvir))
        t2 = numpy.random.random((nocc, nocc, nvir, nvir))
        t2 = t2 + t2.transpose(1, 0, 3, 2)
        l1 = numpy.random.random((nocc, nvir))
        l2 = numpy.random.random((nocc, nocc, nvir, nvir))
        l2 = l2 + l2.transpose(1, 0, 3, 2)

        eris = cc.ccsd._ChemistsERIs()
        eris.oooo = eri0[:nocc, :nocc, :nocc, :nocc].copy()
        eris.ovoo = eri0[:nocc, nocc:, :nocc, :nocc].copy()
        eris.oovv = eri0[:nocc, :nocc, nocc:, nocc:].copy()
        eris.ovvo = eri0[:nocc, nocc:, nocc:, :nocc].copy()
        idx = numpy.tril_indices(nvir)
        eris.ovvv = eri0[:nocc, nocc:, nocc:, nocc:][:, :, idx[0],
                                                     idx[1]].copy()
        eris.vvvv = ao2mo.restore(4, eri0[nocc:, nocc:, nocc:, nocc:], nvir)
        eris.fock = fock0
        eris.mo_energy = fock0.diagonal()

        saved = ccsd_lambda.make_intermediates(mcc, t1, t2, eris)
        l1new, l2new = ccsd_lambda.update_lambda(mcc, t1, t2, l1, l2, eris,
                                                 saved)
        self.assertAlmostEqual(abs(l1new).sum(), 38172.7896467303, 8)
        self.assertAlmostEqual(numpy.dot(l1new.flatten(), numpy.arange(35)),
                               739312.005491083, 8)
        self.assertAlmostEqual(
            numpy.dot(l1new.flatten(), numpy.sin(numpy.arange(35))),
            7019.50937051188, 8)
        self.assertAlmostEqual(
            numpy.dot(numpy.sin(l1new.flatten()), numpy.arange(35)),
            69.6652346635955, 8)

        self.assertAlmostEqual(abs(l2new).sum(), 72035.4931071527, 8)
        self.assertAlmostEqual(
            abs(l2new - l2new.transpose(1, 0, 3, 2)).sum(), 0, 9)
        self.assertAlmostEqual(numpy.dot(l2new.flatten(), numpy.arange(35**2)),
                               48427109.5409886, 7)
        self.assertAlmostEqual(
            numpy.dot(l2new.flatten(), numpy.sin(numpy.arange(35**2))),
            137.758016736487, 8)
        self.assertAlmostEqual(
            numpy.dot(numpy.sin(l2new.flatten()), numpy.arange(35**2)),
            507.656936701192, 8)

        mcc.max_memory = 0
        saved = ccsd_lambda.make_intermediates(mcc, t1, t2, eris)
        l1new, l2new = ccsd_lambda.update_lambda(mcc, t1, t2, l1, l2, eris,
                                                 saved)
        self.assertAlmostEqual(abs(l1new).sum(), 38172.7896467303, 8)
        self.assertAlmostEqual(numpy.dot(l1new.flatten(), numpy.arange(35)),
                               739312.005491083, 8)
        self.assertAlmostEqual(
            numpy.dot(l1new.flatten(), numpy.sin(numpy.arange(35))),
            7019.50937051188, 8)
        self.assertAlmostEqual(
            numpy.dot(numpy.sin(l1new.flatten()), numpy.arange(35)),
            69.6652346635955, 8)

        self.assertAlmostEqual(abs(l2new).sum(), 72035.4931071527, 8)
        self.assertAlmostEqual(
            abs(l2new - l2new.transpose(1, 0, 3, 2)).sum(), 0, 9)
        self.assertAlmostEqual(numpy.dot(l2new.flatten(), numpy.arange(35**2)),
                               48427109.5409886, 7)
        self.assertAlmostEqual(
            numpy.dot(l2new.flatten(), numpy.sin(numpy.arange(35**2))),
            137.758016736487, 8)
        self.assertAlmostEqual(
            numpy.dot(numpy.sin(l2new.flatten()), numpy.arange(35**2)),
            507.656936701192, 8)
コード例 #19
0
ファイル: uccsd_t_rdm.py プロジェクト: zwang123/pyscf
    from pyscf import ao2mo
    from pyscf import cc
    from pyscf.cc import uccsd_t_slow
    from pyscf.cc import uccsd_t_lambda

    mol = gto.Mole()
    mol.atom = [[8, (0., 0., 0.)], [1, (0., -.957, .587)],
                [1, (0.2, .757, .487)]]
    mol.basis = '631g'
    mol.build()
    mf0 = mf = scf.RHF(mol).run(conv_tol=1.)
    mf = scf.addons.convert_to_uhf(mf)

    from pyscf.cc import ccsd_t_lambda_slow as ccsd_t_lambda
    from pyscf.cc import ccsd_t_rdm_slow as ccsd_t_rdm
    mycc0 = cc.CCSD(mf0)
    eris0 = mycc0.ao2mo()
    mycc0.kernel(eris=eris0)
    t1 = mycc0.t1
    t2 = mycc0.t2
    imds = ccsd_t_lambda.make_intermediates(mycc0, t1, t2, eris0)
    l1, l2 = ccsd_t_lambda.update_lambda(mycc0, t1, t2, t1, t2, eris0, imds)
    dm1ref = ccsd_t_rdm.make_rdm1(mycc0, t1, t2, l1, l2, eris0)
    dm2ref = ccsd_t_rdm.make_rdm2(mycc0, t1, t2, l1, l2, eris0)

    t1 = (t1, t1)
    t2aa = t2 - t2.transpose(1, 0, 2, 3)
    t2 = (t2aa, t2, t2aa)
    l1 = (l1, l1)
    l2aa = l2 - l2.transpose(1, 0, 2, 3)
    l2 = (l2aa, l2, l2aa)
コード例 #20
0
#!/usr/bin/env python

from pyscf import gto, scf, cc
from pyscf.cc import ccsd_t

mol = gto.Mole()
mol.basis = 'aug-cc-pvdz'
mol.atom = (('Ne', 0, 0, 0), )
mol.verbose = 4
mol.build()

mf = scf.RHF(mol)
mf.chkfile = 'scf.chk'
ehf = mf.kernel()

ccsd = cc.CCSD(mf)
eccsd = ccsd.kernel()[0]
ecorr_ccsdt = ccsd_t.kernel(ccsd, ccsd.ao2mo())
print("E(CCSD(T)) = {}".format(ehf + eccsd + ecorr_ccsdt))
コード例 #21
0
H  3.355625 0.000000 -0.542380
H  1.208097 0.000000 -1.782255
'''
mol = gto.M(atom=atomstring,
            unit='angstrom',
            basis='ccpvdz',
            verbose=4,
            symmetry=0,
            spin=0)

# Create HF molecule
mf = scf.RHF(mol)
mf.conv_tol = 1e-9
mf.scf()

mycc = cc.CCSD(mf)
mycc.set(frozen=list(range(0, 6)) +
         list(range(36, mf.mo_coeff.shape[0]))).run()

#####HCI###
'''
ncore, nact = 2, 8
mch = shci.SHCISCF(mf, nact, 10)
mch.fcisolver.nPTiter = 0  # Turn off perturbative calc.
mch.fcisolver.sweep_iter = [0, 3]
mch.fcisolver.DoRDM = True
# Setting large epsilon1 thresholds highlights improvement from perturbation.
mch.fcisolver.sweep_epsilon = [1e-2, 1e-2]
mch.max_cycle_macro = 1
e_noPT = mch.mc1step()[0]
exit(0)
コード例 #22
0
 def test_no_diis(self):
     cc1 = cc.CCSD(mf)
     cc1.diis = False
     cc1.max_cycle = 4
     cc1.kernel()
     self.assertAlmostEqual(cc1.e_corr, -0.13516622806104395, 8)
コード例 #23
0
 def test_incore_complete(self):
     cc1 = cc.CCSD(mf)
     cc1.incore_complete = True
     cc1.conv_tol = 1e-10
     cc1.kernel()
     self.assertAlmostEqual(cc1.e_corr, -0.13539788638119823, 8)
コード例 #24
0
 def test_ao_direct(self):
     cc1 = cc.CCSD(mf)
     cc1.direct = True
     cc1.conv_tol = 1e-10
     cc1.kernel(t1=numpy.zeros_like(mycc.t1))
     self.assertAlmostEqual(cc1.e_corr, -0.13539788638119823, 8)
コード例 #25
0
 def test_iterative_dampling(self):
     cc1 = cc.CCSD(mf)
     cc1.max_cycle = 3
     cc1.iterative_damping = 0.7
     cc1.kernel()
     self.assertAlmostEqual(cc1.e_corr, -0.13508743605375528, 8)
コード例 #26
0
from pyscf.cc import ccsd_t
from pyscf import symm
from pyscf.tools import fcidump

#mol = gto.M(atom='Li 0. 0. 0.', basis='cc-pcvtz')
mol = gto.Mole()
mol.atom = 'Li 0. 0. 0.'
mol.basis = 'cc-pcvtz'
mol.charge = 0
mol.spin = 1  
mol.build()
FCIDUMP='B.ezfio.FCIDUMP'


#
# Hamiltonians of FCIDUMP file can be load
#
ctx = fcidump.read(FCIDUMP)

#
# Construct an SCF object using the quantities defined in FCIDUMP
# (pyscf-1.7.4 or newer)
#
mf = fcidump.to_scf(FCIDUMP, molpro_orbsym=True)
mf.mol.verbose = 4
mf.run()
#mf.MP2().run()

mycc = cc.CCSD(mf).run()
et=mycc.ccsd_t()
コード例 #27
0
H       -0.0227 1.1812  0.8852
H       -0.0227 1.1812  -0.8852
                ''',
                basis='3-21g')

    mf = scf.RHF(mol)
    conv_params = {
        'convergence_energy': 1e-4,  # Eh
        'convergence_grms': 3e-3,    # Eh/Bohr
        'convergence_gmax': 4.5e-3,  # Eh/Bohr
        'convergence_drms': 1.2e-2,  # Angstrom
        'convergence_dmax': 1.8e-2,  # Angstrom
    }
    opt = GeometryOptimizer(mf).set(params=conv_params)#.run()
    opt.max_cycle=1
    opt.run()
    mol1 = opt.mol
    print(mf.kernel() - -153.219208484874)
    print(scf.RHF(mol1).kernel() - -153.222680852335)

    mf = dft.RKS(mol)
    mf.xc = 'pbe,'
    mf.conv_tol = 1e-7
    mol1 = optimize(mf)

    mymp2 = mp.MP2(scf.RHF(mol))
    mol1 = optimize(mymp2)

    mycc = cc.CCSD(scf.RHF(mol))
    mol1 = optimize(mycc)
コード例 #28
0
ファイル: Pyscf.py プロジェクト: nbraunsc/MIM
    def energy_gradient(self, input_xyz):
        mol = gto.Mole()
        mol.atom = input_xyz
        mol.basis = self.basis
        mol.charge = self.charge
        if self.spin != 0:
            mol.spin = self.spin-1
        else:
            mol.spin = self.spin
        print("spin:", mol.spin)
        print("charge:", mol.charge)
        #mol.unit = 'Bohr'
        mol.unit = 'Angstrom'
        #mol.symmetry = True
        mol.build()
        #mf.conv_tol = 1e-14
        
        if self.theory == 'DFT':
            if self.spin != 0:
                mf = dft.UKS(mol)
                mf.xc = self.xc
                e = mf.kernel()
                g = mf.nuc_grad_method().kernel()
                h = 0
                #hess = mf.Hessian().kernel()
                #h = hess.transpose(0,2,1,3).reshape(len(input_xyz)*3, len(input_xyz)*3, order='C')

            else:
                mf = dft.RKS(mol)
                mf.xc = self.xc
                e = mf.kernel()
                g = mf.nuc_grad_method().kernel()
                hess = mf.Hessian().kernel()
                h = hess.transpose(0,2,1,3).reshape(len(input_xyz)*3, len(input_xyz)*3, order='C')
                return e, g, h


        if self.theory == 'RHF': #Restricted HF calc
            mf = scf.RHF(mol).run()
            e = mf.kernel()
            mf.dump_scf_summary()
            g = mf.nuc_grad_method().kernel()
            hess = mf.Hessian().kernel()
            h = hess.transpose(0,2,1,3).reshape(len(input_xyz)*3, len(input_xyz)*3, order='C')
            return e, g, h
        
        if self.theory == 'UHF': #Unrestricted HF calc
            mf = scf.UHF(mol).run()
            e = mf.kernel()
            mf.dump_scf_summary()
            g = mf.nuc_grad_method().kernel()
            hess = mf.Hessian().kernel()
            h = hess.transpose(0,2,1,3).reshape(len(input_xyz)*3, len(input_xyz)*3, order='C')
            return e, g, h
        
        if self.theory == 'ROHF': #Restricted Open shell HF calc
            mf = scf.ROHF(mol).run()
            e = mf.kernel()
            mf.dump_scf_summary()
            g = mf.nuc_grad_method().kernel()
            h = 0
            #hess = mf.Hessian().kernel()
            #h = hess.transpose(0,2,1,3).reshape(len(input_xyz)*3, len(input_xyz)*3, order='C')
            return e, g, h
    
        if self.theory == 'MP2': #Perturbation second order calc
            mf = scf.RHF(mol).run()
            postmf = mp.MP2(mf).run()
            e = mf.kernel() + postmf.kernel()[0]
            g2 = postmf.nuc_grad_method()
            g = g2.kernel()
            h = 0
            return e, g, h
    
        if self.theory == 'CISD':    #CI for singles and double excitations
            mf = scf.RHF(mol).run()
            postmf = ci.CISD(mf).run()
            e = postmf.kernel()
            g2 = postmf.nuc_grad_method()
            g = g2.kernel()
            h = 0
            return e, g, h
    
        if self.theory == 'CCSD':    #Couple Cluster for singles and doubles
            mf = scf.RHF(mol).run()
            postmf = cc.CCSD(mf).run()
            e = mf.kernel() + postmf.kernel()[0]
            g2 = postmf.nuc_grad_method()
            g = g2.kernel()
            h = 0
            return e, g, h
        
        if self.theory == 'CCSD(T)':    #Couple Cluster for singles and doubles, pertub triples
            mf = scf.RHF(mol).run()
            mycc = cc.CCSD(mf).run()
            et = mycc.ccsd_t()
            #postmf = cc.ccsd_t(mf).run()
            #e = mf.kernel() + postmf.kernel()[0]
            e = mycc.e_tot + et
            g=0
            #g2 = postmf.nuc_grad_method()
            #g = g2.kernel()
            h = 0
            return e, g, h

        if self.theory == 'CASSCF':
            mf = scf.RHF(mol).run()
            postmf = mcscf.CASSCF(mf, self.active_space, self.nelec).run()
            e = postmf.kernel()
            g2 = postmf.nuc_grad_method()
            g = g2.kernel()
            h = 0
            return e, g, h

        if self.theory == 'CASCI':
            mf = scf.RHF(mol).run()
            h = 0
            return e, g, h
コード例 #29
0
ファイル: uccsd_t_slow.py プロジェクト: zhjiang-1/pyscf
    from pyscf import gto
    from pyscf import scf
    from pyscf import cc

    mol = gto.Mole()
    mol.atom = [
        [8 , (0. , 0.     , 0.)],
        [1 , (0. , -.757 , .587)],
        [1 , (0. ,  .757 , .587)]]

    mol.basis = '631g'
    mol.build()
    rhf = scf.RHF(mol)
    rhf.conv_tol = 1e-14
    rhf.scf()
    mcc = cc.CCSD(rhf)
    mcc.conv_tol = 1e-14
    mcc.ccsd()
    t1a = t1b = mcc.t1
    t2ab = mcc.t2
    t2aa = t2bb = t2ab - t2ab.transpose(1,0,2,3)
    mcc = uccsd.UCCSD(scf.addons.convert_to_uhf(rhf))
    e3a = kernel(mcc, mcc.ao2mo(), (t1a,t1b), (t2aa,t2ab,t2bb))
    print(e3a - -0.00099642337843278096)

    mol = gto.Mole()
    mol.atom = [
        [8 , (0. , 0.     , 0.)],
        [1 , (0. , -.757 , .587)],
        [1 , (0. ,  .757 , .587)]]
    mol.spin = 2
コード例 #30
0
from openfermionpyscf import PyscfMolecularData
from pyscf import scf, mp, ci, cc, fci

geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
basis = '6-31g'
multiplicity = 1
charge = 0
molecule = PyscfMolecularData(geometry, basis, multiplicity, charge)

mol = prepare_pyscf_molecule(molecule)
mol.verbose = 0
molecule._pyscf_data['mol'] = mol
molecule._pyscf_data['scf'] = mf = scf.RHF(mol).run()
molecule._pyscf_data['mp2'] = mp.MP2(mf).run()
molecule._pyscf_data['cisd'] = ci.CISD(mf).run()
molecule._pyscf_data['ccsd'] = cc.CCSD(mf).run()
molecule._pyscf_data['fci'] = fci.FCI(mf).run()


def test_accessing_rdm():
    mo = molecule.canonical_orbitals
    overlap = molecule.overlap_integrals
    h1 = molecule.one_body_integrals
    h2 = molecule.two_body_integrals
    mf = molecule._pyscf_data['scf']
    e_core = mf.energy_nuc()

    rdm1 = molecule.cisd_one_rdm
    rdm2 = molecule.cisd_two_rdm
    e_ref = molecule._pyscf_data['cisd'].e_tot
    e_tot = (numpy.einsum('pq,pq', h1, rdm1) +