def test_rhf_smearing(self): mf = pscf.RHF(cell) pscf.addons.smearing_(mf, 0.1, 'fermi') mo_energy = numpy.arange(nao)*.2+numpy.cos(.5)*.1 mf.get_occ(mo_energy) self.assertAlmostEqual(mf.entropy, 3.0922723199786408, 9) mf.smearing_method = 'gauss' occ = mf.get_occ(mo_energy) self.assertAlmostEqual(mf.entropy, 0.4152467504725415, 9) mf.kernel() self.assertAlmostEqual(mf.entropy, 0, 15)
def test_ccsd_t_hf(self): '''Tests ccsd and ccsd_t for Hartree-Fock references using supercell vs k-point calculation.''' n = 14 cell = make_test_cell.test_cell_n3([n] * 3) nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcscf.KRHF(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcscf.RHF(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.15530756381467772, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.0011112735513837887, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def test_ccsd_t_hf_frozen(self): '''Tests ccsd and ccsd_t for Hartree-Fock references with frozen orbitals using supercell vs k-point calculation.''' n = 14 cell = make_test_cell.test_cell_n3([n] * 3) nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcscf.KRHF(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf, frozen=1) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcscf.RHF(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf, frozen=2) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.1137362020855094, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.0006758642528821, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def test_hf(self): with lib.light_speed(2) as c: mf = scf.RHF(cell).sfx2c1e() mf.with_df = df.AFTDF(cell) dm = mf.get_init_guess() h1 = mf.get_hcore() self.assertAlmostEqual( numpy.einsum('ij,ji', dm, h1), 2 / 3.7865300454631 * -0.47578184212352159 + 0j, 8) kpts = cell.make_kpts([3, 1, 1]) h1 = mf.get_hcore(kpt=kpts[1]) self.assertAlmostEqual( numpy.einsum('ij,ji', dm, h1), 2 / 3.7865300454631 * -0.09637799091491725 + 0j, 8)
def test_get_jk_with_casscf(self): from pyscf import mcscf pcell = cell2.copy() pcell.verbose = 0 pcell.mesh = [8]*3 mf = pbcscf.RHF(pcell) mf.exxdiv = None ehf = mf.kernel() mc = mcscf.CASSCF(mf, 1, 2).run() self.assertAlmostEqual(mc.e_tot, ehf, 9) mc = mcscf.CASSCF(mf, 2, 0).run() self.assertAlmostEqual(mc.e_tot, ehf, 9)
def test_krhf_vs_rhf(self): np.random.seed(1) k = np.random.random(3) mf = pscf.RHF(cell, k, exxdiv='vcut_sph') mf.max_cycle = 1 mf.diis = None e1 = mf.kernel() kmf = pscf.KRHF(cell, [k], exxdiv='vcut_sph') kmf.max_cycle = 1 kmf.diis = None e2 = kmf.kernel() self.assertAlmostEqual(e1, e2, 9) self.assertAlmostEqual(e1, -11.451118801956275, 9)
def get_scf(cell): scf = pbchf.RHF(cell, exxdiv=None) scf.conv_tol = 1e-10 scf.conv_tol_grad = 1e-8 scf.diis = True scf.diis_space = 20 scf.direct_scf_tol = 1e-14 scf.init_guess = 'minao' scf.max_cycle = 200 scf.max_memory = 8000 scf.verbose = 10 scf.scf() return scf
def k2gamma(kmf, kmesh=None): r''' convert the k-sampled mean-field object to the corresponding supercell gamma-point mean-field object. math: C_{\nu ' n'} = C_{\vecR\mu, \veck m} = \frac{1}{\sqrt{N_{\UC}}} \e^{\ii \veck\cdot\vecR} C^{\veck}_{\mu m} ''' def transform(mo_energy, mo_coeff, mo_occ): scell, E_g, C_gamma = mo_k2gamma(kmf.cell, mo_energy, mo_coeff, kmf.kpts, kmesh)[:3] E_sort_idx = np.argsort(np.hstack(mo_energy)) mo_occ = np.hstack(mo_occ)[E_sort_idx] return scell, E_g, C_gamma, mo_occ if isinstance(kmf, scf.khf.KRHF): scell, E_g, C_gamma, mo_occ = transform(kmf.mo_energy, kmf.mo_coeff, kmf.mo_occ) mf = scf.RHF(scell) elif isinstance(kmf, scf.kuhf.KUHF): scell, Ea, Ca, occ_a = transform(kmf.mo_energy[0], kmf.mo_coeff[0], kmf.mo_occ[0]) scell, Eb, Cb, occ_b = transform(kmf.mo_energy[1], kmf.mo_coeff[1], kmf.mo_occ[1]) mf = scf.UHF(scell) E_g = [Ea, Eb] C_gamma = [Ca, Cb] mo_occ = [occ_a, occ_b] else: raise NotImplementedError('SCF object %s not supported' % kmf) mf.mo_coeff = C_gamma mf.mo_energy = E_g mf.mo_occ = mo_occ mf.converged = kmf.converged # Scale energy by number of primitive cells within supercell mf.e_tot = len(kmf.kpts) * kmf.e_tot # Use unfolded overlap matrix for better error cancellation #s_k = kmf.cell.pbc_intor('int1e_ovlp', hermi=1, kpts=kmf.kpts, pbcopt=lib.c_null_ptr()) s_k = kmf.get_ovlp() ovlp = to_supercell_ao_integrals(kmf.cell, kmf.kpts, s_k) assert np.allclose(ovlp, ovlp.T) ovlp = (ovlp + ovlp.T) / 2 mf.get_ovlp = lambda *args: ovlp return mf
def setUpModule(): global cell, cell1, mf0, kmdf, kmdf1, kpts L = 5. n = 11 cell = pgto.Cell() cell.a = numpy.diag([L,L,L]) cell.mesh = numpy.array([n,n,n]) cell.atom = '''C 3. 2. 3. C 1. 1. 1.''' cell.basis = 'ccpvdz' cell.verbose = 0 cell.rcut = 17 cell.build(0,0) mf0 = pscf.RHF(cell) mf0.exxdiv = 'vcut_sph' numpy.random.seed(1) kpts = numpy.random.random((5,3)) kpts[0] = 0 kpts[3] = kpts[0]-kpts[1]+kpts[2] kpts[4] *= 1e-5 kmdf = mdf.MDF(cell) kmdf.linear_dep_threshold = 1e-7 kmdf.auxbasis = 'weigend' kmdf.kpts = kpts kmdf.mesh = (11,)*3 kmdf.eta = 0.154728892598 cell1 = pgto.Cell() cell1.a = numpy.eye(3) * 3. cell1.mesh = [10]*3 cell1.atom = '''C 3. 2. 3. C 1. 1. 1.''' cell1.basis = [[0, (3.5, 1)], [0, (1.0, 1)], [1, (0.6, 1)]] cell1.rcut = 9.5 cell1.build(0,0) kmdf1 = mdf.MDF(cell1) kmdf1.linear_dep_threshold = 1e-7 kmdf1.auxbasis = df.aug_etb(cell1, 1.8) kmdf1.kpts = kpts kmdf1.mesh = [6]*3 kmdf1.eta = 0.1
def test_cell(cell, ngs, nk): ############################################# # Do a supercell Gamma-pt calculation # ############################################# supcell = pyscf.pbc.tools.super_cell(cell, nk) supcell.gs = np.array([ nk[0] * ngs + 1 * (nk[0] - 1) // 2, nk[1] * ngs + 1 * (nk[1] - 1) // 2, nk[2] * ngs + 1 * (nk[2] - 1) // 2 ]) print "supcell gs =", supcell.gs supcell.build() scaled_gamma = ase.dft.kpoints.monkhorst_pack((1, 1, 1)) gamma = supcell.get_abs_kpts(scaled_gamma) ############################################# # Running HF # ############################################# print "" print "*********************************" print "STARTING HF " print "*********************************" print "" mf = pbchf.RHF(supcell, exxdiv=None) mf.conv_tol = 1e-15 #mf.verbose = 7 escf = mf.scf() escf_per_cell = escf / np.prod(nk) print "scf energy (per unit cell) = %.17g" % escf_per_cell ############################################# # Running CCSD # ############################################# print "" print "*********************************" print "STARTING CCSD " print "*********************************" print "" cc = pyscf.pbc.cc.CCSD(mf) cc.conv_tol = 1e-15 #cc.verbose = 7 ecc, t1, it2 = cc.kernel() ecc_per_cell = ecc / np.prod(nk) print "cc energy (per unit cell) = %.17g" % ecc_per_cell return escf_per_cell, ecc_per_cell
def test_get_veff(self): mf = pscf.RHF(cell) numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j dm = dm + dm.conj().T v11 = mf.get_veff(cell, dm, kpt=cell.get_abs_kpts([.25, .25, .25])) v12 = mf.get_veff(cell, dm, kpts_band=cell.get_abs_kpts([.25, .25, .25])) v13 = mf.get_veff(cell, dm, kpt=cell.get_abs_kpts([-1. / 3, 1. / 3, .25]), kpts_band=cell.get_abs_kpts([.25, .25, .25])) v14 = mf.get_veff(cell, dm, kpt=cell.get_abs_kpts([-1. / 3, 1. / 3, .25]), kpts_band=cell.make_kpts([2, 1, 1])) self.assertTrue(v11.dtype == numpy.complex128) self.assertTrue(v12.dtype == numpy.complex128) mf = pscf.UHF(cell) v21 = mf.get_veff(cell, dm, kpt=cell.get_abs_kpts([.25, .25, .25])) dm = [dm * .5, dm * .5] v22 = mf.get_veff(cell, dm, kpts_band=cell.get_abs_kpts([.25, .25, .25])) v23 = mf.get_veff(cell, dm, kpt=cell.get_abs_kpts([-1. / 3, 1. / 3, .25]), kpts_band=cell.get_abs_kpts([.25, .25, .25])) v24 = mf.get_veff(cell, dm, kpt=cell.get_abs_kpts([-1. / 3, 1. / 3, .25]), kpts_band=cell.make_kpts([2, 1, 1])) self.assertAlmostEqual(abs(v11 - v21).max(), 0, 9) self.assertAlmostEqual(abs(v12 - v22).max(), 0, 9) self.assertAlmostEqual(abs(v13 - v23).max(), 0, 9) self.assertAlmostEqual(abs(v14 - v24).max(), 0, 9) self.assertAlmostEqual(lib.finger(v11), -0.30110964334164825 + 0.81409418199767414j, 9) self.assertAlmostEqual(lib.finger(v12), -2.1601376488983997 - 9.4070613374115908j, 9)
def test_ccsd_t_non_hf_frozen(self): '''Tests ccsd and ccsd_t for non-Hartree-Fock references with frozen orbitals using supercell vs k-point calculation.''' n = 14 cell = make_test_cell.test_cell_n3([n] * 3) #import sys #cell.stdout = sys.stdout #cell.verbose = 7 nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcdft.KRKS(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf, frozen=1) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcdft.RKS(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf, frozen=2) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.11467718013872311, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.00066503872045200996, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def run_cell(cell, n, nk): ############################################# # Do a supercell Gamma-pt calculation # ############################################# supcell = pyscf.pbc.tools.super_cell(cell, nk) supcell.build() gamma = [0, 0, 0] mf = pbchf.RHF(supcell, exxdiv=None) mf.conv_tol = 1e-14 #mf.verbose = 7 escf = mf.scf() escf_per_cell = escf / np.prod(nk) cc = pyscf.pbc.cc.CCSD(mf) cc.conv_tol = 1e-8 ecc, t1, it2 = cc.kernel() ecc_per_cell = ecc / np.prod(nk) return escf_per_cell, ecc_per_cell
def test_jk_single_kpt_high_cost(self): mf0 = pscf.RHF(cell) mf0.exxdiv = None mf = df_jk.density_fit(mf0, auxbasis='weigend', mesh=(11,)*3) mf.with_df.mesh = cell.mesh mf.with_df.eta = 0.3 mf.with_df.exp_to_discard = 0.3 dm = mf.get_init_guess() vj, vk = mf.get_jk(cell, dm) ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) j_ref = 48.283789539266174 # rsjk result k_ref = 32.30441176447805 # rsjk result self.assertAlmostEqual(ej1, j_ref, 4) self.assertAlmostEqual(ek1, k_ref, 2) self.assertAlmostEqual(ej1, 48.283745538383684, 8) self.assertAlmostEqual(ek1, 32.30260871417842 , 8) numpy.random.seed(12) nao = cell.nao_nr() dm = numpy.random.random((nao,nao)) dm = dm + dm.T vj1, vk1 = mf.get_jk(cell, dm, hermi=0) ej1 = numpy.einsum('ij,ji->', vj1, dm) ek1 = numpy.einsum('ij,ji->', vk1, dm) self.assertAlmostEqual(ej1, 242.04678235140264, 8) self.assertAlmostEqual(ek1, 280.15934926575903, 8) numpy.random.seed(1) kpt = numpy.random.random(3) mydf = df.DF(cell, [kpt]).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.mesh = cell.mesh mydf.eta = 0.3 mydf.exp_to_discard = mydf.eta vj, vk = mydf.get_jk(dm, 1, kpt, exxdiv=None) ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ej1, 241.15121903857556+0j, 8) self.assertAlmostEqual(ek1, 279.64649194057051+0j, 8) vj, vk = mydf.get_jk(dm, 1, kpt, with_j=False, exxdiv='ewald') ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ek1, 691.64624456329909+0j, 6)
def test_pp_int(self): from pyscf import gto, scf from pyscf.pbc import gto as pbcgto from pyscf.pbc import scf as pbcscf from pyscf.pbc import df cell = pbcgto.Cell() cell.atom = 'He 1. .5 .5; C .1 1.3 2.1' cell.basis = { 'He': [(0, (2.5, 1)), (0, (1., 1))], 'C': 'gth-szv', } cell.pseudo = { 'C': 'gth-pade', 'He': pbcgto.pseudo.parse('''He 2 0.40000000 3 -1.98934751 -0.75604821 0.95604821 2 0.29482550 3 1.23870466 .855 .3 .71 -1.1 .9 0.32235865 2 2.25670239 -0.39677748 0.93894690 ''') } cell.a = numpy.eye(3) cell.dimension = 0 cell.build() mol = cell.to_mol() hcore = scf.RHF(mol).get_hcore() mydf = df.AFTDF(cell) ref = mydf.get_pp() + mol.intor('int1e_kin') self.assertAlmostEqual(abs(hcore - ref).max(), 0, 2) mf = pbcscf.RHF(cell) mf.with_df = mydf mf.run() e_ref = mf.e_tot e_tot = scf.RHF(mol).run().e_tot self.assertAlmostEqual(abs(e_ref - e_tot).max(), 0, 6)
def test_jk_single_kpt_high_cost(self): mf0 = pscf.RHF(cell) mf0.exxdiv = None mf = rsdf_jk.density_fit(mf0, auxbasis='weigend', mesh=(11,)*3) mf.with_df.mesh = cell.mesh mf.with_df.omega = 0.3 mf.with_df.exp_to_discard = 0.3 dm = mf.get_init_guess() vj, vk = mf.get_jk(cell, dm) ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) j_ref = 48.283789539266174 # rsjk result k_ref = 32.30441176447805 # rsjk result self.assertAlmostEqual(ej1, j_ref, 4) self.assertAlmostEqual(ek1, k_ref, 2) self.assertAlmostEqual(ej1, 48.2837455394308037, 7) self.assertAlmostEqual(ek1, 32.3026087105977950, 7) numpy.random.seed(12) nao = cell.nao_nr() dm = numpy.random.random((nao,nao)) dm = dm + dm.T vj1, vk1 = mf.get_jk(cell, dm, hermi=0) ej1 = numpy.einsum('ij,ji->', vj1, dm) ek1 = numpy.einsum('ij,ji->', vk1, dm) self.assertAlmostEqual(ej1, 242.0467816643269714, 7) self.assertAlmostEqual(ek1, 280.1593488661793572, 7) numpy.random.seed(1) kpt = numpy.random.random(3) mydf = rsdf.RSDF(cell, [kpt]).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.omega = 0.3 mydf.exp_to_discard = 0.3 vj, vk = mydf.get_jk(dm, 1, kpt, exxdiv=None) ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ej1, 241.1512182675005249+0j, 7) self.assertAlmostEqual(ek1, 279.6464915858919085+0j, 7) vj, vk = mydf.get_jk(dm, 1, kpt, with_j=False, exxdiv='ewald') ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ek1, 691.6462442086188958+0j, 6)
def _get_pbc(self): import pyscf.pbc.gto as pbc_gto import pyscf.pbc.scf as pbc_scf cell = pbc_gto.Cell() cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000''' cell.unit = 'B' cell.verbose = 0 cell.build() pbc_mf = pbc_scf.RHF(cell, exxdiv=None) pbc_mf.kernel() return pbc_mf
def _get_pbc2(self): import pyscf.pbc.gto as pbc_gto import pyscf.pbc.scf as pbc_scf cell = pbc_gto.Cell() cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000''' cell.unit = 'B' cell.verbose = 0 cell.build() kpt = cell.make_kpts((1, 1, 1), scaled_center=(0, 0, 1./3.)) pbc_mf2 = pbc_scf.RHF(cell, kpt=kpt, exxdiv=None) pbc_mf2.kernel() return pbc_mf2
def k2gamma(kmf, kmesh=None): r''' convert the k-sampled mean-field object to the corresponding supercell gamma-point mean-field object. math: C_{\nu ' n'} = C_{\vecR\mu, \veck m} = \frac{1}{\sqrt{N_{\UC}}} \e^{\ii \veck\cdot\vecR} C^{\veck}_{\mu m} ''' scell, E_g, C_gamma = mo_k2gamma(kmf.cell, kmf.mo_energy, kmf.mo_coeff, kmf.kpts, kmesh)[:3] E_sort_idx = np.argsort(np.hstack(kmf.mo_energy)) mo_occ = np.hstack(kmf.mo_occ)[E_sort_idx] mf = scf.RHF(scell) mf.mo_coeff = C_gamma mf.mo_energy = E_g mf.mo_occ = mo_occ return mf
def run_cell(cell, n, nk): ############################################# # Do a supercell Gamma-pt calculation # ############################################# supcell = pyscf.pbc.tools.super_cell(cell, nk) supcell.build() gamma = [0, 0, 0] ############################################# # Running HF # ############################################# # print "" # print "*********************************" # print "STARTING HF " # print "*********************************" # print "" mf = pbchf.RHF(supcell, exxdiv=None) mf.conv_tol = 1e-14 #mf.verbose = 7 escf = mf.scf() escf_per_cell = escf / np.prod(nk) # print "scf energy (per unit cell) = %.17g" % escf_per_cell ############################################# # Running CCSD # ############################################# # print "" # print "*********************************" # print "STARTING CCSD " # print "*********************************" # print "" cc = pyscf.pbc.cc.CCSD(mf) cc.conv_tol = 1e-8 #cc.verbose = 7 ecc, t1, it2 = cc.kernel() ecc_per_cell = ecc / np.prod(nk) # print "cc energy (per unit cell) = %.17g" % ecc_per_cell return escf_per_cell, ecc_per_cell
def test_single_kpt(self): cell = pbcgto.Cell() cell.atom = ''' H 0 0 0 H 1 0 0 H 0 1 0 H 0 1 1 ''' cell.a = np.eye(3) * 2 cell.basis = [[0, [1.2, 1]], [1, [1.0, 1]]] cell.verbose = 0 cell.build() kpts = cell.get_abs_kpts([.5, .5, .5]).reshape(1, 3) mf = pbcscf.KRHF(cell, kpts=kpts).run(conv_tol=1e-9) kcc = pyscf.pbc.cc.kccsd_rhf.RCCSD(mf) e0 = kcc.kernel()[0] mf = pbcscf.RHF(cell, kpt=kpts[0]).run() mycc = pyscf.pbc.cc.RCCSD(mf) e1 = mycc.kernel()[0] self.assertAlmostEqual(e0, e1, 7)
def k2gamma(kmf, kmesh=None): r''' convert the k-sampled mean-field object to the corresponding supercell gamma-point mean-field object. math: C_{\nu ' n'} = C_{\vecR\mu, \veck m} = \frac{1}{\sqrt{N_{\UC}}} \e^{\ii \veck\cdot\vecR} C^{\veck}_{\mu m} ''' from pyscf.pbc import scf def transform(mo_energy, mo_coeff, mo_occ): scell, E_g, C_gamma = mo_k2gamma(kmf.cell, mo_energy, mo_coeff, kmf.kpts, kmesh)[:3] E_sort_idx = np.argsort(np.hstack(mo_energy)) mo_occ = np.hstack(mo_occ)[E_sort_idx] return scell, E_g, C_gamma, mo_occ if isinstance(kmf, scf.khf.KRHF): scell, E_g, C_gamma, mo_occ = transform(kmf.mo_energy, kmf.mo_coeff, kmf.mo_occ) mf = scf.RHF(scell) elif isinstance(kmf, scf.kuhf.KUHF): scell, Ea, Ca, occ_a = transform(kmf.mo_energy[0], kmf.mo_coeff[0], kmf.mo_occ[0]) scell, Eb, Cb, occ_b = transform(kmf.mo_energy[1], kmf.mo_coeff[1], kmf.mo_occ[1]) mf = scf.UHF(scell) E_g = [Ea, Eb] C_gamma = [Ca, Cb] mo_occ = [occ_a, occ_b] else: raise NotImplementedError('SCF object %s not supported' % kmf) mf.mo_coeff = C_gamma mf.mo_energy = E_g mf.mo_occ = mo_occ return mf
def test_ccsd_t_non_hf(self): '''Tests ccsd and ccsd_t for non-Hartree-Fock references.''' n = 14 cell = make_test_cell.test_cell_n3([n] * 3) nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcdft.KRKS(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcdft.RKS(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.15632445245405927, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.00114619248449, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def setUpModule(): global cell, cell1, cell2, kpts, kpt0, kpts1, mf0 cell = pgto.Cell() cell.atom = 'He 1. .5 .5; C .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))], 'C' :'gth-szv',} cell.pseudo = {'C':'gth-pade'} cell.a = np.eye(3) * 2.5 cell.mesh = [21] * 3 cell.build() np.random.seed(1) kpts = np.random.random((4,3)) kpts[3] = kpts[0]-kpts[1]+kpts[2] kpt0 = np.zeros(3) cell1 = pgto.Cell() cell1.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell1.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell1.a = np.eye(3) * 2.5 cell1.mesh = [21] * 3 cell1.build() cell2 = pgto.Cell() cell2.atom = ''' He 1.3 .2 .3 He .1 .1 1.1 ''' cell2.basis = {'He': [[0, [0.8, 1]], [1, [0.6, 1]]]} cell2.mesh = [17]*3 cell2.a = numpy.array(([2.0, .9, 0. ], [0.1, 1.9, 0.4], [0.8, 0 , 2.1])) cell2.build() kpts1 = np.random.random((4,3)) kpts1[3] = kpts1[0]-kpts1[1]+kpts1[2] + cell2.reciprocal_vectors().T.dot(np.ones(3)) mf0 = pbcscf.RHF(cell) mf0.exxdiv = None
def test_kpt_vs_supercell_high_cost(self): # For large n, agreement is always achieved # n = 17 # For small n, agreement only achieved if "wrapping" k-k'+G in get_coulG n = 9 nk = (3, 1, 1) cell = make_primitive_cell([n] * 3) abs_kpts = cell.make_kpts(nk, wrap_around=True) kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph') ekpt = kmf.scf() self.assertAlmostEqual(ekpt, -11.221426249047617, 8) # nk = (5, 1, 1) # abs_kpts = cell.make_kpts(nk, wrap_around=True) # kmf = khf.KRHF(cell, abs_kpts, exxdiv='vcut_sph') # ekpt = kmf.scf() # self.assertAlmostEqual(ekpt, -12.337299166550796, 8) supcell = pyscf.pbc.tools.super_cell(cell, nk) mf = pscf.RHF(supcell, exxdiv='vcut_sph') esup = mf.scf() / np.prod(nk) self.assertAlmostEqual(ekpt, esup, 8)
L = 5. n = 11 cell = pgto.Cell() cell.a = numpy.diag([L,L,L]) cell.mesh = numpy.array([n,n,n]) cell.atom = '''C 3. 2. 3. C 1. 1. 1.''' cell.basis = 'ccpvdz' cell.verbose = 0 cell.max_memory = 0 cell.rcut = 28.3 cell.build() mf0 = pscf.RHF(cell) mf0.exxdiv = None def finger(a): w = numpy.cos(numpy.arange(a.size)) return numpy.dot(a.ravel(), w) class KnowValues(unittest.TestCase): def test_jk_single_kpt(self): mf = mdf_jk.density_fit(mf0, auxbasis='weigend', mesh=(11,)*3) mf.with_df.mesh = [11]*3 mf.with_df.eta = 0.3 mf.with_df.linear_dep_threshold = 1e-7 dm = mf.get_init_guess() vj, vk = mf.get_jk(cell, dm)
cell.unit = 'A' cell.a = [[4, 0, 0], [0, 1, 0], [0, 0, 1]] cell.atom = ''' H 0.0000000 0.0000000 0.0000000 H 1.0000000 0.0000000 0.0000000 H 2.0000000 0.0000000 0.0000000 H 3.0000000 0.0000000 0.0000000 ''' cell.basis = 'sto-6g' cell.dimension = 1 cell.verbose = 4 cell.build() gdf = df.GDF(cell) mf = scf.RHF(cell) mf.with_df = gdf mf.with_df.auxbasis = 'cc-pvdz-jkfit' mf.max_cycle = 150 mf.chkfile = name + '.chk' #mf.with_df._cderi_to_save = name+'_eri.h5' #mf.with_df._cderi = name+'_eri.h5' #mf = mole_scf.addons.remove_linear_dep_(mf) #mf.__dict__.update(scf.chkfile.load(name+'.chk', 'scf')) #dm = mf.make_rdm1() ehf = mf.kernel() ncore = 0 nao, nmo = mf.mo_coeff.shape nocc = cell.nelectron // 2 - ncore nvir = nmo - nocc - ncore
n = 5 cell = pgto.Cell() cell.a = numpy.diag([L, L, L]) cell.gs = numpy.array([n, n, n]) cell.atom = '''C 3. 2. 3. C 1. 1. 1.''' #cell.basis = {'He': [[0, (1.0, 1.0)]]} #cell.basis = '631g' #cell.basis = {'He': [[0, (2.4, 1)], [1, (1.1, 1)]]} cell.basis = 'ccpvdz' cell.verbose = 0 cell.build(0, 0) cell.verbose = 5 mf = pscf.RHF(cell) dm = mf.get_init_guess() auxbasis = 'weigend' #from pyscf import df #auxbasis = df.addons.aug_etb_for_dfbasis(cell, beta=1.5, start_at=0) #from pyscf.pbc.df import mdf #mf.with_df = mdf.MDF(cell) #mf.auxbasis = auxbasis mf = density_fit(mf, auxbasis) mf.with_df.gs = (5, ) * 3 vj = mf.with_df.get_jk(dm, exxdiv=mf.exxdiv, with_k=False)[0] print(numpy.einsum('ij,ji->', vj, dm), 'ref=46.698942480902062') vj, vk = mf.with_df.get_jk(dm, exxdiv=mf.exxdiv) print(numpy.einsum('ij,ji->', vj, dm), 'ref=46.698942480902062') print(numpy.einsum('ij,ji->', vk, dm), 'ref=37.348163681114187') print(numpy.einsum('ij,ji->', mf.get_hcore(cell), dm),
3.370137329, 3.370137329, 0.000000000''' cell.unit = 'B' cell.verbose = 5 cell.precision = 1e-12 cell.build() cell.rcut *= 2.0 cell.build() omegas = [-10.99479191] # #Run old code # supcell = super_cell(cell, nmp) mf = scf.RHF(supcell, exxdiv=None) mf.diis = None mf.conv_tol_grad = 1e-8 mf.conv_tol = 1e-8 ehf = mf.kernel() mf.analyze() mycc = cc.RCCSD(mf) mycc.frozen = [0, 1, 3, 4, 5, 6, 9, 10, 11, 12, 14, 15] mycc.ip_partition = None mycc.ea_partition = None mycc.conv_tol_normt = 1e-10 mycc.conv_tol = 1e-10 mycc.kernel() #p=[8,9,10,11,12,13,14,15] #q=[8,9,10,11,12,13,14,15] p = [2, 3]
f.write(''.join(['%5.3s' % atomN[0] for atomN in vaspAtomicInfo]) + '\n') f.write(''.join(['%5d' % atomN[1] for atomN in vaspAtomicInfo]) + '\n') f.write('Cartesian \n') for ia in range(cell.natm): f.write(' %14.8f %14.8f %14.8f\n' % tuple(swappedCoords[ia])) f.write('\n') f.write('%6.5s %6.5s %6.5s \n' % (self.nx, self.ny, self.nz)) fmt = ' %14.8e ' for iz in range(self.nz): for iy in range(self.ny): f.write('\n') for ix in range(self.nx): f.write(fmt % field[ix, iy, iz]) def read(self, chgcar_file): raise NotImplementedError if __name__ == '__main__': from pyscf.pbc import scf from pyscf.tools import chgcar cell = gto.M(atom='H 0 0 0; H 0 0 1', a=numpy.eye(3) * 3) mf = scf.RHF(cell).run() chgcar.density(cell, 'h2.CHGCAR', mf.make_rdm1()) #makes total density chgcar.orbital(cell, 'h2_mo1.CHGCAR', mf.mo_coeff[:, 0]) # makes mo#1 (sigma) chgcar.orbital(cell, 'h2_mo2.CHGCAR', mf.mo_coeff[:, 1]) # makes mo#2 (sigma*)