Esempio n. 1
0
def test_cc_step_diis():  # pragma: nocover
    from pyscf import gto
    from pyscf import scf
    mol = gto.Mole()
    mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                [1, (0., 0.757, 0.587)]]

    mol.basis = {
        'H': 'sto-3g',
        'O': 'sto-3g',
    }
    mol.build()
    rhf = scf.RHF(mol)
    rhf.scf()  # -76.0267656731

    from tcc.cc_solvers import residual_diis_solver
    from tcc.cc_solvers import update_diis_solver
    from tcc.rccsd import RCCSD
    cc = RCCSD(rhf)

    converged1, energy1, _ = residual_diis_solver(cc,
                                                  conv_tol_energy=1e-10,
                                                  conv_tol_res=1e-10,
                                                  max_cycle=100,
                                                  lam=1)
    cc._converged = False

    converged2, energy2, _ = update_diis_solver(cc,
                                                conv_tol_energy=1e-10,
                                                conv_tol_res=1e-10,
                                                beta=0,
                                                max_cycle=100)
Esempio n. 2
0
def compare_to_aq():  # pragma: nocover
    from pyscf import gto
    from pyscf import scf
    mol = gto.Mole()
    mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                [1, (0., 0.757, 0.587)]]
    mol.basis = {
        'H': '3-21g',
        'O': '3-21g',
    }
    mol.build()
    rhf = scf.RHF(mol)
    rhf.scf()  # -76.0267656731

    # load reference arrays
    import h5py
    import numpy as np
    f1 = h5py.File('data/test_references/aq_ccsd_amps.h5', 'r')
    # use amplitudes from the last iteration
    num_steps = int(len(f1.keys()) / 2)
    t1 = f1['t1_' + str(num_steps)][()].T
    t2 = f1['t2_' + str(num_steps)][()].T
    f1.close()

    f1 = h5py.File('data/test_references/aq_ccsd_mos.h5', 'r')
    CA = np.hstack((f1['cI'][()].T, f1['cA'][()].T))
    CB = np.hstack((f1['ci'][()].T, f1['ca'][()].T))
    f1.close()

    # permute AO indices to match pyscf order
    perm = [0, 1, 2, 4, 5, 3, 7, 8, 6, 9, 10, 11, 12]
    from tcc.utils import perm_matrix
    m = perm_matrix(perm)
    CA_perm = m.dot(CA)

    from tcc.cc_solvers import residual_diis_solver
    from tcc.cc_solvers import step_solver, classic_solver
    from tcc.rccsd import RCCSD
    cc = RCCSD(rhf, mo_coeff=CA_perm)

    converged, energy, amps = classic_solver(cc,
                                             conv_tol_energy=1e-14,
                                             conv_tol_res=1e-10,
                                             max_cycle=200)

    print('dt1: {}'.format(np.max(t1 - amps.t1)))
    print('dt2: {}'.format(np.max(t2 - amps.t2)))

    from tcc.tensors import Tensors
    test_amps = Tensors(t1=t1, t2=t2)
    h = cc.create_ham()
    r = cc.calc_residuals(h, test_amps)

    print('max r1: {}'.format(np.max(r.t1)))
    print('max r2: {}'.format(np.max(r.t2)))
Esempio n. 3
0
    def test_root_solver(self):
        from pyscf import gto
        from pyscf import scf

        mol = gto.Mole()
        mol.verbose = 5
        mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                    [1, (0., 0.757, 0.587)]]

        mol.basis = {
            'H': 'sto-3g',
            'O': 'sto-3g',
        }
        mol.build(parse_arg=False)
        rhf = scf.RHF(mol)
        rhf.scf()  # -74.963063129719586

        from tcc.cc_solvers import root_solver
        from tcc.rccsd import RCCSD
        cc = RCCSD(rhf)

        converged, energy, amps = root_solver(cc)
        self.assertEqual(converged, True)
        self.assertEqual(np.allclose(energy, -0.049467465836162607, 1e-5),
                         True)
Esempio n. 4
0
def test_cc_unitary():  # pragma: nocover
    from pyscf import gto
    from pyscf import scf
    mol = gto.Mole()
    mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                [1, (0., 0.757, 0.587)]]

    mol.basis = {
        'H': 'sto-3g',
        'O': 'sto-3g',
    }
    mol.build()
    rhf = scf.RHF(mol)
    rhf.scf()  # -76.0267656731

    from tcc.cc_solvers import residual_diis_solver
    from tcc.cc_solvers import classic_solver
    from tcc.rccsd import RCCSD_UNIT, RCCSD
    cc1 = RCCSD_UNIT(rhf)
    cc2 = RCCSD(rhf)

    converged1, energy2, _ = residual_diis_solver(cc1,
                                                  ndiis=5,
                                                  conv_tol_energy=-1,
                                                  conv_tol_res=1e-10)

    converged2, energy2, _ = residual_diis_solver(cc2,
                                                  ndiis=5,
                                                  conv_tol_energy=-1,
                                                  conv_tol_res=1e-10)
Esempio n. 5
0
def test_cc():  # pragma: nocover
    from pyscf import gto
    from pyscf import scf
    mol = gto.Mole()
    mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                [1, (0., 0.757, 0.587)]]

    mol.basis = {
        'H': 'sto-3g',
        'O': 'sto-3g',
    }
    mol.build()
    uhf = scf.UHF(mol)
    uhf.scf()  # -76.0267656731
    rhf = scf.RHF(mol)
    rhf.scf()  # -76.0267656731

    from tcc.uccsd_dir import UCCSD
    from tcc.rccsd import RCCSD
    cc1 = UCCSD(uhf)
    cc2 = RCCSD(rhf)

    from tcc.cc_solvers import classic_solver

    converged1, energy1, amps1 = classic_solver(cc1,
                                                conv_tol_energy=1e-8,
                                                max_cycle=100)

    converged2, energy2, amps2 = classic_solver(cc2,
                                                conv_tol_energy=1e-8,
                                                max_cycle=100)
Esempio n. 6
0
def test_mp2_energy():  # pragma: nocover
    from pyscf import gto
    from pyscf import scf
    mol = gto.Mole()
    mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                [1, (0., 0.757, 0.587)]]

    mol.basis = {
        'H': 'cc-pvdz',
        'O': 'cc-pvdz',
    }
    mol.build()
    rhf = scf.RHF(mol)
    rhf.scf()  # -76.0267656731
    CCobj = RCCSD(rhf)
    h = CCobj.create_ham()
    a = CCobj.init_amplitudes(h)
    energy = CCobj.calculate_energy(h, a)
    print('E_mp2 - E_cc,init = {:18.12g}'.format(energy - -0.204019967288338))
Esempio n. 7
0
def test_compare_to_hirata():  # pragma: nocover
    from pyscf import gto
    from pyscf import scf
    mol = gto.Mole()
    mol.atom = """
    # H2O
    H    0.000000000000000   1.079252144093028   1.474611055780858
    O    0.000000000000000   0.000000000000000   0.000000000000000
    H    0.000000000000000   1.079252144093028  -1.474611055780858
    """
    mol.unit = 'Bohr'
    mol.basis = {
        'H':
        gto.basis.parse("""
            H         S   
                      3.42525091         0.15432897
                      0.62391373         0.53532814
                      0.16885540         0.44463454
            """),
        'O':
        gto.basis.parse("""
            O         S   
                    130.70932000         0.15432897
                     23.80886100         0.53532814
                      6.44360830         0.44463454
            O         S   
                      5.03315130        -0.09996723
                      1.16959610         0.39951283
                      0.38038900         0.70011547
            O         P   
                      5.03315130         0.15591627
                      1.16959610         0.60768372
                      0.38038900         0.39195739
            """),
    }
    mol.build()
    rhf = scf.RHF(mol)
    rhf.scf()

    from tcc.cc_solvers import classic_solver, update_diis_solver
    from tcc.rccsd import RCCSD
    cc1 = RCCSD(rhf)

    converged, energy, amps = classic_solver(cc1,
                                             conv_tol_energy=1e-10,
                                             lam=3,
                                             conv_tol_res=1e-10,
                                             max_cycle=200)

    print('E_cc: {}'.format(energy))
    print('E_tot: {}'.format(rhf.e_tot + energy))
    print('delta E: {}'.format(energy - -0.0501273286))
Esempio n. 8
0
    def test_classic_solver(self):
        from tcc.cc_solvers import classic_solver
        from tcc.rccsd import RCCSD

        cc = RCCSD(self.rhf)
        converged, energy, amps = classic_solver(cc)
        self.assertEqual(converged, True)
        self.assertEqual(np.allclose(energy, -0.2133432609672395, 1e-5), True)

        converged, energy, _ = classic_solver(cc,
                                              amps,
                                              lam=3,
                                              conv_tol_energy=1e-10)
        self.assertEqual(converged, True)
        self.assertEqual(np.allclose(energy, -0.2133432609672395, 1e-5), True)
Esempio n. 9
0
    def test_rccsd_unit(self):
        from tcc.cc_solvers import classic_solver, residual_diis_solver
        from tcc.rccsd import RCCSD, RCCSD_UNIT

        cc1 = RCCSD(self.rhf)
        cc2 = RCCSD_UNIT(self.rhf)
        converged1, energy1, amps = classic_solver(cc1)
        converged2, energy2, _ = classic_solver(cc2)

        self.assertEqual(converged1, converged2)

        self.assertEqual(np.allclose(energy1, -0.2133432609672395, 1e-5), True)
        self.assertEqual(np.allclose(energy1, energy2, 1e-5), True)
        
        converged1, energy1, _ = residual_diis_solver(cc1, amps=amps,
                                                         conv_tol_energy=1e-10)
        converged2, energy2, _ = residual_diis_solver(cc2, amps=amps,
                                                conv_tol_energy=1e-10)
        
        self.assertEqual(np.allclose(energy1, -0.2133432609672395, 1e-5), True)
        self.assertEqual(np.allclose(energy1, energy2, 1e-5), True)
Esempio n. 10
0
def test_cc_ri():  # pragma: nocover
    from pyscf import gto
    from pyscf import scf
    mol = gto.Mole()
    mol.atom = [['O', (0., 0., 0.)], ['H', (0., -0.757, 0.587)],
                ['H', (0., 0.757, 0.587)]]

    mol.basis = 'sto-3g'
    mol.build()
    rhf = scf.RHF(mol)
    rhf.scf()  # -76.0267656731

    rhf_ri = scf.density_fit(scf.RHF(mol))
    rhf_ri.scf()

    from tcc.cc_solvers import residual_diis_solver
    from tcc.cc_solvers import classic_solver
    from tcc.rccsd import RCCSD_DIR_RI, RCCSD
    cc1 = RCCSD_DIR_RI(rhf_ri)
    cc2 = RCCSD(rhf)

    converged1, energy2, _ = classic_solver(cc1, conv_tol_energy=-1)

    converged2, energy2, _ = classic_solver(cc2, conv_tol_energy=-1)