def _test_cu_metallic_frozen_vir(self, kmf, cell, nk=[1, 1, 1]): assert cell.mesh == [7, 7, 7] ecc3_bench = -0.94610600274627665 max_cycle = 2 # The following calculation at full convergence gives -0.58688462599474 # for a cell.mesh = [25, 25, 25]. It is equivalent to a supercell [1, 1, 2] # calculation with frozen = [0, 3, 35]. mycc = pbcc.KGCCSD(kmf, frozen=[[2, 3, 34, 35], [0, 1]]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 eris = mycc.ao2mo() eris.mo_energy = [f.diagonal() for f in eris.fock] ecc3, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ecc3, ecc3_bench, 6) check_gamma = False # Turn me on to run the supercell calculation! if check_gamma: from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) kmf = pbcscf.RHF(supcell, exxdiv=None) ehf = kmf.scf() mycc = pbcc.RCCSD(kmf, frozen=[0, 3, 35]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 ecc, t1, t2 = mycc.kernel() print('Gamma energy =', ecc / np.prod(nk)) print('K-point energy =', ecc3)
def test_h4_fcc_k2_frozen_high_cost(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = build_h_cell() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() frozen = [[0, 3], []] mymp = pyscf.pbc.mp.kmp2.KMP2(kmf, frozen=frozen) ekmp2, _ = mymp.kernel() self.assertAlmostEqual(ekmp2, -0.022416773725207319, 6) self.assertAlmostEqual(mymp.e_tot, 2.155470531550681, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() mysmp = pyscf.pbc.mp.kmp2.KMP2(mf, frozen=[0, 7]) emp2, _ = mysmp.kernel() emp2 /= np.prod(nmp) self.assertAlmostEqual(emp2, -0.022416773725207319, 6)
def _test_cu_metallic_frozen_vir(self, kmf, cell, nk=[1,1,1]): assert cell.mesh == [7, 7, 7] ecc3_bench = -0.94610600274627665 max_cycle = 2 # The following calculation at full convergence gives -0.58688462599474 # for a cell.mesh = [25, 25, 25]. It is equivalent to a supercell [1, 1, 2] # calculation with frozen = [0, 3, 35]. mycc = pbcc.KGCCSD(kmf, frozen=[[2, 3, 34, 35], [0, 1]]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 eris = mycc.ao2mo() eris.mo_energy = [f.diagonal() for f in eris.fock] ecc3, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ecc3, ecc3_bench, 6) check_gamma = False # Turn me on to run the supercell calculation! if check_gamma: from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) kmf = pbcscf.RHF(supcell, exxdiv=None) ehf = kmf.scf() mycc = pbcc.RCCSD(kmf, frozen=[0, 3, 35]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 ecc, t1, t2 = mycc.kernel() print('Gamma energy =', ecc/np.prod(nk)) print('K-point energy =', ecc3)
def _test_cu_metallic_frozen_vir(self, kmf, cell, nk=[1,1,1]): assert cell.mesh == [7, 7, 7] ecc3_bench = -0.76794053711557086 max_cycle = 5 # The following calculation at full convergence gives -0.58688462599474 # for a cell.mesh = [25, 25, 25]. It is equivalent to a supercell [1, 1, 2] # calculation with frozen = [0, 3, 35]. mycc = pyscf.pbc.cc.kccsd_rhf.RCCSD(kmf, frozen=[[1, 17], [0]]) mycc.diis_start_cycle = 1 mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 ecc3, t1, t2 = mycc.kernel() self.assertAlmostEqual(ecc3, ecc3_bench, 6) check_gamma = False # Turn me on to run the supercell calculation! if check_gamma: from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) kmf = pbcscf.RHF(supcell, exxdiv=None) ehf = kmf.scf() mycc = pyscf.pbc.cc.RCCSD(kmf, frozen=[0, 3, 35]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 ecc, t1, t2 = mycc.kernel() print('Gamma energy =', ecc/np.prod(nk)) print('K-point energy =', ecc3)
def setUpClass(cls): cls.cell = cell = Cell() # Lift some degeneracies cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.67 1.68 1.69 ''' cell.basis = {'C': [[0, (0.8, 1.0)], [1, (1.0, 1.0)]]} # cell.basis = 'gth-dzvp' 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 = 5 cell.build() k = cell.make_kpts([cls.k, 1, 1]) # The Gamma-point reference cls.model_rks = model_rks = KRKS(super_cell(cell, [cls.k, 1, 1])) model_rks.conv_tol = 1e-14 model_rks.kernel() # K-points cls.model_krks = model_krks = KRKS(cell, k) model_krks.conv_tol = 1e-14 model_krks.kernel() adjust_mf_phase(model_rks, model_krks) ke = numpy.concatenate(model_krks.mo_energy) ke.sort() # Make sure mo energies are the same testing.assert_allclose(model_rks.mo_energy[0], ke) # TD cls.td_model_rks = td_model_rks = tdp.TDProxy(model_rks, "dft") td_model_rks.kernel() cls.td_model_krks = td_model_krks = ktdp.TDProxy(model_krks, "dft", [cls.k, 1, 1], KRKS) td_model_krks.kernel() # GW cls.gw = gw.GW(td_model_rks, td.TDRHF(model_rks).ao2mo()) cls.kgw = kgw.GW(td_model_krks, ktd.TDRHF(model_krks).ao2mo()) cls.order_k, cls.order_p, cls.order = ov_order_supercell(cls.kgw.imds) orbs = [] for k in range(cls.k): for o in numpy.arange(2, 6): orbs.append(numpy.where(numpy.logical_and(cls.order_k == k, cls.order_p == o))[0][0]) cls.gw.orbs = numpy.array(orbs) cls.kgw.orbs = numpy.arange(2, 6)
def test_dmd_high_cost(self): cell = gto.Cell() cell.atom=''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = { 'C': [[0, (0.8, 1.0)], [1, (1.0, 1.0)]]} 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 = 5 cell.build() nmp = [1,1,2] # treating 1*1*2 supercell at gamma point supcell = super_cell(cell,nmp) gmf = scf.GHF(supcell,exxdiv=None) ehf = gmf.kernel() gcc = cc.GCCSD(gmf) gcc.conv_tol=1e-12 gcc.conv_tol_normt=1e-10 gcc.max_cycle=250 ecc, t1, t2 = gcc.kernel() print('GHF energy (supercell) %.7f \n' % (float(ehf)/2.)) print('GCCSD correlation energy (supercell) %.7f \n' % (float(ecc)/2.)) eom = eom_gccsd.EOMIP(gcc) e1, v = eom.ipccsd(nroots=2) eom = eom_gccsd.EOMEA(gcc) e2, v = eom.eaccsd(nroots=2, koopmans=True) # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh kmf = scf.KGHF(cell, kpts=cell.make_kpts(nmp), exxdiv=None) ehf2 = kmf.kernel() mycc = cc.KGCCSD(kmf) mycc.conv_tol = 1e-12 mycc.conv_tol_normt = 1e-10 mycc.max_cycle=250 ecc2, t1, t2 = mycc.kernel() print('GHF energy %.7f \n' % (float(ehf2))) print('GCCSD correlation energy %.7f \n' % (float(ecc2))) kptlist = cell.make_kpts(nmp) eom = EOMIP(mycc) e1_obt, v = eom.ipccsd(nroots=2, kptlist=[0]) eom = EOMEA(mycc) e2_obt, v = eom.eaccsd(nroots=2, koopmans=True, kptlist=[0]) assert(ehf/2 - ehf2 < 1e-10) assert(ecc/2 - ecc2 < 1e-10) assert(e1[0]-(e1_obt[0][0]) < 1e-7) assert(e2[0]-(e2_obt[0][0]) < 1e-7)
def test_dmd_high_cost(self): cell = gto.Cell() cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = {'C': [[0, (0.8, 1.0)], [1, (1.0, 1.0)]]} 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 = 5 cell.build() nmp = [1, 1, 2] # treating 1*1*2 supercell at gamma point supcell = super_cell(cell, nmp) gmf = scf.GHF(supcell, exxdiv=None) ehf = gmf.kernel() gcc = cc.GCCSD(gmf) gcc.conv_tol = 1e-12 gcc.conv_tol_normt = 1e-10 gcc.max_cycle = 250 ecc, t1, t2 = gcc.kernel() print('GHF energy (supercell) %.7f \n' % (float(ehf) / 2.)) print('GCCSD correlation energy (supercell) %.7f \n' % (float(ecc) / 2.)) eom = eom_gccsd.EOMIP(gcc) e1, v = eom.ipccsd(nroots=2) eom = eom_gccsd.EOMEA(gcc) e2, v = eom.eaccsd(nroots=2, koopmans=True) # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh kmf = scf.KGHF(cell, kpts=cell.make_kpts(nmp), exxdiv=None) ehf2 = kmf.kernel() mycc = cc.KGCCSD(kmf) mycc.conv_tol = 1e-12 mycc.conv_tol_normt = 1e-10 mycc.max_cycle = 250 ecc2, t1, t2 = mycc.kernel() print('GHF energy %.7f \n' % (float(ehf2))) print('GCCSD correlation energy %.7f \n' % (float(ecc2))) kptlist = cell.make_kpts(nmp) eom = EOMIP(mycc) e1_obt, v = eom.ipccsd(nroots=2, kptlist=[0]) eom = EOMEA(mycc) e2_obt, v = eom.eaccsd(nroots=2, koopmans=True, kptlist=[0]) assert (ehf / 2 - ehf2 < 1e-10) assert (ecc / 2 - ecc2 < 1e-10) assert (e1[0] - (e1_obt[0][0]) < 1e-7) assert (e2[0] - (e2_obt[0][0]) < 1e-7)
def _test_cu_metallic_frozen_vir(self, kmf, cell): assert cell.mesh == [7, 7, 7] ecc3_bench = -0.76794053711557086 max_cycle = 5 # The following calculation at full convergence gives -0.58688462599474 # for a cell.mesh = [25, 25, 25]. It is equivalent to a supercell [1, 1, 2] # calculation with frozen = [0, 3, 35]. mycc = pbcc.kccsd_rhf.RCCSD(kmf, frozen=[[1, 17], [0]]) mycc.diis_start_cycle = 1 mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 eris = mycc.ao2mo() eris.mo_energy = [f.diagonal() for f in eris.fock] ecc3, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ecc3, ecc3_bench, 6) ew, ev = mycc.ipccsd(nroots=3, koopmans=True, kptlist=[1]) self.assertAlmostEqual(ew[0][0], -3.028339571372944, 3) self.assertAlmostEqual(ew[0][1], -2.850636489429295, 3) self.assertAlmostEqual(ew[0][2], -2.801491561537961, 3) ew, ev = mycc.eaccsd(nroots=3, koopmans=True, kptlist=[1]) self.assertAlmostEqual(ew[0][0], 3.266064683223669, 2) self.assertAlmostEqual(ew[0][1], 3.281390137070985, 2) self.assertAlmostEqual(ew[0][2], 3.426297911456726, 2) check_gamma = False # Turn me on to run the supercell calculation! nk = [1, 1, 2] if check_gamma: from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) kmf = pbcscf.RHF(supcell, exxdiv=None) ehf = kmf.scf() mycc = pbcc.RCCSD(kmf, frozen=[0, 3, 35]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.04 ecc, t1, t2 = mycc.kernel() print('Gamma energy =', ecc / np.prod(nk)) print('K-point energy =', ecc3_bench) ew, ev = mycc.ipccsd(nroots=5) # For cell mesh of [25, 25, 25], we get: # # EOM-CCSD root 0 E = -3.052456841625895 # EOM-CCSD root 1 E = -2.989798972232893 # EOM-CCSD root 2 E = -2.839646545189692 # EOM-CCSD root 3 E = -2.836645046801352 # EOM-CCSD root 4 E = -2.831020659800223 ew, ev = mycc.eaccsd(nroots=5)
def _test_cu_metallic_frozen_vir(self, kmf, cell): assert cell.mesh == [7, 7, 7] ecc3_bench = -0.76794053711557086 max_cycle = 5 # The following calculation at full convergence gives -0.58688462599474 # for a cell.mesh = [25, 25, 25]. It is equivalent to a supercell [1, 1, 2] # calculation with frozen = [0, 3, 35]. mycc = pbcc.kccsd_rhf.RCCSD(kmf, frozen=[[1, 17], [0]]) mycc.diis_start_cycle = 1 mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 eris = mycc.ao2mo() eris.mo_energy = [f.diagonal() for f in eris.fock] ecc3, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ecc3, ecc3_bench, 6) ew, ev = mycc.ipccsd(nroots=3, koopmans=True, kptlist=[1]) self.assertAlmostEqual(ew[0][0], -3.028339571372944, 3) self.assertAlmostEqual(ew[0][1], -2.850636489429295, 3) self.assertAlmostEqual(ew[0][2], -2.801491561537961, 3) ew, ev = mycc.eaccsd(nroots=3, koopmans=True, kptlist=[1]) self.assertAlmostEqual(ew[0][0], 3.266064683223669, 2) self.assertAlmostEqual(ew[0][1], 3.281390137070985, 2) self.assertAlmostEqual(ew[0][2], 3.426297911456726, 2) check_gamma = False # Turn me on to run the supercell calculation! if check_gamma: from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) kmf = pbcscf.RHF(supcell, exxdiv=None) ehf = kmf.scf() mycc = pbcc.RCCSD(kmf, frozen=[0, 3, 35]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.04 ecc, t1, t2 = mycc.kernel() print('Gamma energy =', ecc/np.prod(nk)) print('K-point energy =', ecc3_bench) ew, ev = mycc.ipccsd(nroots=5) # For cell mesh of [25, 25, 25], we get: # # EOM-CCSD root 0 E = -3.052456841625895 # EOM-CCSD root 1 E = -2.989798972232893 # EOM-CCSD root 2 E = -2.839646545189692 # EOM-CCSD root 3 E = -2.836645046801352 # EOM-CCSD root 4 E = -2.831020659800223 ew, ev = mycc.eaccsd(nroots=5)
def test_h4_fcc_k2_frozen(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1., 0., 0.], [0., 1., 0], [0, 0, 2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [ [0, [1.0, 1]], ] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple( np.dot(np.array(cell.atom[i][1]), np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() frozen = [[0, 3], []] mymp = pyscf.pbc.mp.kmp2.KMP2(kmf, frozen=frozen) ekmp2, _ = mymp.kernel() self.assertAlmostEqual(ekmp2, -0.022416773725207319, 6) self.assertAlmostEqual(mymp.e_tot, 2.155470531550681, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() mysmp = pyscf.pbc.mp.kmp2.KMP2(mf, frozen=[0, 7]) emp2, _ = mysmp.kernel() emp2 /= np.prod(nmp) self.assertAlmostEqual(emp2, -0.022416773725207319, 6)
def test_h4_fcc_k2_frozen(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1.,0.,0.],[0.,1.,0],[0,0,2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [[0, [1.0, 1]],] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple(np.dot(np.array(cell.atom[i][1]),np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0,0.0,0.0]) e = kmf.kernel() frozen = [[0, 3], []] mymp = pyscf.pbc.mp.kmp2.KMP2(kmf, frozen=frozen) ekmp2, _ = mymp.kernel() self.assertAlmostEqual(ekmp2, -0.022416773725207319, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() mysmp = pyscf.pbc.mp.kmp2.KMP2(mf, frozen=[0, 7]) emp2, _ = mysmp.kernel() emp2 /= np.prod(nmp) self.assertAlmostEqual(emp2, -0.022416773725207319, 6)
def setUpClass(cls): cls.cell = cell = Cell() # Lift some degeneracies cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.67 1.68 1.69 ''' cell.basis = {'C': [[0, (0.8, 1.0)], [1, (1.0, 1.0)]]} # cell.basis = 'gth-dzvp' 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 = 5 cell.build() k = cell.make_kpts([cls.k, 1, 1], scaled_center=cls.k_c) # The Gamma-point reference cls.model_rhf = model_rhf = RHF(super_cell(cell, [cls.k, 1, 1]), kpt=k[0]).density_fit() model_rhf.conv_tol = 1e-14 model_rhf.kernel() # K-points cls.model_krhf = model_krhf = KRHF(cell, k).density_fit() model_krhf.conv_tol = 1e-14 model_krhf.kernel() adjust_mf_phase(model_rhf, model_krhf) ke = numpy.concatenate(model_krhf.mo_energy) ke.sort() # Make sure mo energies are the same testing.assert_allclose(model_rhf.mo_energy, ke) # Make sure no degeneracies are present testing.assert_array_less(1e-4, ke[1:] - ke[:-1]) cls.ov_order = ov_order(model_krhf) # The Gamma-point TD cls.td_model_rhf = td_model_rhf = td.TDRHF(model_rhf) td_model_rhf.kernel() cls.ref_m = td_model_rhf.eri.tdhf_full_form()
def get_phase(self, cell=None, kpts=None, kmesh=None): ''' Get a super cell and the phase matrix that transform from real to k-space ''' if kmesh is None: kmesh = w90.mp_grid_loc if cell is None: cell = self.cell if kpts is None: kpts = self.kpts a = cell.lattice_vectors() Ts = lib.cartesian_prod( (np.arange(kmesh[0]), np.arange(kmesh[1]), np.arange(kmesh[2]))) Rs = np.dot(Ts, a) NRs = Rs.shape[0] phase = 1 / np.sqrt(NRs) * np.exp(1j * Rs.dot(kpts.T)) scell = pbctools.super_cell(cell, kmesh) return scell, phase
def test_kuccsd_openshell(): cell = gto.M( unit='B', a=[[0., 6.74027466, 6.74027466], [6.74027466, 0., 6.74027466], [6.74027466, 6.74027466, 0.]], mesh=[13] * 3, atom='''H 0 0 0 H 1.68506866 1.68506866 1.68506866 H 3.37013733 3.37013733 3.37013733''', basis=[[0, (1., 1.)], [0, (.5, 1.)]], verbose=1, charge=0, spin=1, ) nmp = [3, 1, 1] # cell spin multiplied by nkpts cell.spin = cell.spin * 3 # treating 3*1*1 supercell at gamma point supcell = super_cell(cell, nmp) umf = scf.UHF(supcell, exxdiv=None) umf.conv_tol = 1e-11 ehf = umf.kernel() ucc = cc.UCCSD(umf) ucc.conv_tol = 1e-12 ecc, t1, t2 = ucc.kernel() print('UHF energy (supercell) %.9f \n' % (float(ehf) / 3.)) print('UCCSD correlation energy (supercell) %.9f \n' % (float(ecc) / 3.)) assert abs(ehf / 3 - -1.003789445) < 1e-7 assert abs(ecc / 3 - -0.029056542) < 1e-6 # kpts calculations kpts = cell.make_kpts(nmp) kpts -= kpts[0] kmf = scf.KUHF(cell, kpts, exxdiv=None) kmf.conv_tol = 1e-11 ehf = kmf.kernel() kcc = cc.KUCCSD(kmf) kcc.conv_tol = 1e-12 ecc, t1, t2 = kcc.kernel() print('UHF energy (kpts) %.9f \n' % (float(ehf))) print('UCCSD correlation energy (kpts) %.9f \n' % (float(ecc))) assert abs(ehf - -1.003789445) < 1e-7 assert abs(ecc - -0.029056542) < 1e-6
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 test_ccsd_t_non_hf_frozen(self): '''Tests ccsd and ccsd_t for non-Hartree-Fock references with frozen orbitals.''' 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 test_kuccsd_supercell_vs_kpts_high_cost(): cell = gto.M( unit = 'B', a = [[ 0., 3.37013733, 3.37013733], [ 3.37013733, 0., 3.37013733], [ 3.37013733, 3.37013733, 0. ]], mesh = [13]*3, atom = '''He 0 0 0 He 1.68506866 1.68506866 1.68506866''', basis = [[0, (1., 1.)], [0, (.5, 1.)]], verbose = 0, ) nmp = [3,3,1] # treating supercell at gamma point supcell = super_cell(cell,nmp) gmf = scf.UHF(supcell,exxdiv=None) ehf = gmf.kernel() gcc = cc.UCCSD(gmf) ecc, t1, t2 = gcc.kernel() print('UHF energy (supercell) %f \n' % (float(ehf)/numpy.prod(nmp))) print('UCCSD correlation energy (supercell) %f \n' % (float(ecc)/numpy.prod(nmp))) assert abs(ehf / 9 - -4.343308413289) < 1e-7 assert abs(ecc / 9 - -0.009470753047083676) < 1e-6 # treating mesh of k points kpts = cell.make_kpts(nmp) kpts -= kpts[0] kmf = scf.KUHF(cell,kpts,exxdiv=None) ehf = kmf.kernel() kcc = cc.KUCCSD(kmf) ecc, t1, t2 = kcc.kernel() print('UHF energy (kpts) %f \n' % ehf) print('UCCSD correlation energy (kpts) %f \n' % ecc) assert abs(ehf - -4.343308413289) < 1e-7 assert abs(ecc - -0.009470753047083676) < 1e-6
def test_ccsd_t_non_hf(self): '''Tests ccsd and ccsd_t for non-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 = 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 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 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_ccsd_t_hf_frozen(self): '''Tests ccsd and ccsd_t for Hartree-Fock references with frozen orbitals.''' 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_ccsd_t_hf(self): '''Tests ccsd and ccsd_t for 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 = 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_h4_fcc_k2(self): '''Metallic hydrogen fcc lattice. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1., 0., 0.], [0., 1., 0], [0, 0, 2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [ [0, [1.0, 1]], ] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple( np.dot(np.array(cell.atom[i][1]), np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() #mymp = pbmp.KMP2(kmf) #ekmp2, _ = mymp.kernel() #print("KMP2 corr energy (per unit cell) = ", ekmp2) mycc = pbcc.KGCCSD(kmf) ekccsd, t1, t2 = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.06146759560406628, 6) # TODO: fill in as the eom-kgccsd completed... # ## Getting more roots than 1 is difficult #e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, 5.079427283440857, 6) #e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, 4.183328878177331, 6) #e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, -3.471710821544506, 6) #e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, -4.272015727359054, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() ##mysmp = pbmp.KMP2(mf) ##emp2, _ = mysmp.kernel() ##print("MP2 corr energy (per unit cell) = ", emp2 / np.prod(nmp)) myscc = pbcc.KGCCSD(mf) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.06146759560406628, 6)
def test_h4_fcc_k2_frozen(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1.,0.,0.],[0.,1.,0],[0,0,2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [[0, [1.0, 1]],] cell.pseudo = 'gth-pade' cell.output = '/dev/null' #cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple(np.dot(np.array(cell.atom[i][1]),np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0,0.0,0.0]) e = kmf.kernel() frozen = [[0, 3], []] mycc = pbcc.KCCSD(kmf, frozen=frozen) ekccsd, _, _ = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.04683399814247455, 6) # Getting more roots than 1 is difficult e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], 5.060562738181741, 6) e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] self.assertAlmostEqual(e[0][0], 4.188511644938458, 6) e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], -3.477663551987023, 6) e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] self.assertAlmostEqual(e[0][0], -4.23523412155825, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() myscc = pbcc.KCCSD(mf, frozen=[0, 7]) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.04683401678904569, 6) e = myscc.eaccsd(nroots=4, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], 4.188511680212755, 6) self.assertAlmostEqual(e[0][1], 4.205924087610756, 6) self.assertAlmostEqual(e[0][2], 5.060562771978923, 6) self.assertAlmostEqual(e[0][3], 5.077249823137741, 6) e = myscc.ipccsd(nroots=4, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], -4.261818242746091, 6) self.assertAlmostEqual(e[0][1], -4.235233956876479, 6) self.assertAlmostEqual(e[0][2], -3.477663568390151, 6) self.assertAlmostEqual(e[0][3], -3.459133332687474, 6)
def setUpClass(cls): cls.cell = cell = Cell() # Lift some degeneracies cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.67 1.68 1.69 ''' cell.basis = {'C': [[0, (0.8, 1.0)], [1, (1.0, 1.0)]]} # cell.basis = 'gth-dzvp' 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 = 5 cell.build() k = cell.make_kpts([cls.k, 1, 1], scaled_center=cls.k_c) # The Gamma-point reference cls.model_rhf = model_rhf = RHF(super_cell(cell, [cls.k, 1, 1]), kpt=k[0]).density_fit() model_rhf.conv_tol = 1e-14 model_rhf.kernel() # K-points cls.model_krhf = model_krhf = KRHF(cell, k).density_fit() model_krhf.conv_tol = 1e-14 model_krhf.kernel() adjust_mf_phase(model_rhf, model_krhf) ke = numpy.concatenate(model_krhf.mo_energy) ke.sort() # Make sure mo energies are the same testing.assert_allclose(model_rhf.mo_energy, ke) # Make sure no degeneracies are present testing.assert_array_less(1e-4, ke[1:] - ke[:-1]) # TD cls.td_model_rhf = td_model_rhf = td.TDRHF(model_rhf) td_model_rhf.kernel() cls.td_model_krhf = td_model_krhf = ktd.TDRHF(model_krhf) td_model_krhf.kernel() adjust_td_phase(td_model_rhf, td_model_krhf) # GW cls.gw = gw.GW(td_model_rhf) cls.kgw = kgw.GW(td_model_krhf) cls.order_k, cls.order_p, cls.order = ov_order_supercell(cls.kgw.imds) orbs = [] for k in range(cls.k): for o in numpy.arange(2, 6): orbs.append(numpy.where(numpy.logical_and(cls.order_k == k, cls.order_p == o))[0][0]) cls.gw.orbs = numpy.array(orbs) cls.kgw.orbs = numpy.arange(2, 6)
def test_h4_fcc_k2(self): '''Metallic hydrogen fcc lattice. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1.,0.,0.],[0.,1.,0],[0,0,2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [[0, [1.0, 1]],] cell.pseudo = 'gth-pade' cell.output = '/dev/null' #cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple(np.dot(np.array(cell.atom[i][1]),np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0,0.0,0.0]) e = kmf.kernel() mycc = pbcc.KCCSD(kmf) ekccsd, _, _ = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.06146759560406628, 6) # Getting more roots than 1 is difficult e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], 5.079427283440857, 6) e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] self.assertAlmostEqual(e[0][0], 4.183328878177331, 6) e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], -3.471710821544506, 6) e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] self.assertAlmostEqual(e[0][0], -4.272015727359054, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() myscc = pbcc.KCCSD(mf) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.06146759560406628, 6) e = myscc.eaccsd(nroots=4, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], 4.183328873793568, 6) self.assertAlmostEqual(e[0][1], 4.225034294249784, 6) self.assertAlmostEqual(e[0][2], 5.068962665511664, 6) self.assertAlmostEqual(e[0][3], 5.07942727935064 , 6) e = myscc.ipccsd(nroots=4, kptlist=(0,))[0] self.assertAlmostEqual(e[0][0], -4.272015724869052, 6) self.assertAlmostEqual(e[0][1], -4.254298274388934, 6) self.assertAlmostEqual(e[0][2], -3.471710821688812, 6) self.assertAlmostEqual(e[0][3], -3.462817764320668, 6)
def test_h4_fcc_k2_frozen(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1., 0., 0.], [0., 1., 0], [0, 0, 2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [ [0, [1.0, 1]], ] cell.pseudo = 'gth-pade' cell.output = '/dev/null' #cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple( np.dot(np.array(cell.atom[i][1]), np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() frozen = [[0, 3], []] mycc = pbcc.KCCSD(kmf, frozen=frozen) ekccsd, _, _ = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.04683399814247455, 6) # Getting more roots than 1 is difficult e = mycc.eaccsd(nroots=1, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], 5.060562738181741, 6) e = mycc.eaccsd(nroots=1, koopmans=False, kptlist=(1, ))[0] self.assertAlmostEqual(e[0][0], 4.188511644938458, 6) e = mycc.ipccsd(nroots=1, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], -3.477663551987023, 6) e = mycc.ipccsd(nroots=1, koopmans=False, kptlist=(1, ))[0] self.assertAlmostEqual(e[0][0], -4.23523412155825, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() myscc = pbcc.KCCSD(mf, frozen=[0, 7]) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.04683401678904569, 6) e = myscc.eaccsd(nroots=4, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], 4.188511680212755, 6) self.assertAlmostEqual(e[0][1], 4.205924087610756, 6) self.assertAlmostEqual(e[0][2], 5.060562771978923, 6) self.assertAlmostEqual(e[0][3], 5.077249823137741, 6) e = myscc.ipccsd(nroots=4, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], -4.261818242746091, 6) self.assertAlmostEqual(e[0][1], -4.235233956876479, 6) self.assertAlmostEqual(e[0][2], -3.477663568390151, 6) self.assertAlmostEqual(e[0][3], -3.459133332687474, 6)
def test_h4_fcc_k2_frozen(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1.,0.,0.],[0.,1.,0],[0,0,2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [[0, [1.0, 1]],] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple(np.dot(np.array(cell.atom[i][1]),np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0,0.0,0.0]) e = kmf.kernel() #mymp = pbmp.KMP2(kmf) #ekmp2, _ = mymp.kernel() #print("KMP2 corr energy (per unit cell) = ", ekmp2) # By not applying a level-shift, one gets a different initial CCSD answer. # One can check however that the t1/t2 from level-shifting are a solution # of the CCSD equations done without level-shifting. frozen = [[0, 1, 6, 7], []] mycc = pbcc.KGCCSD(kmf, frozen=frozen) ekccsd, t1, t2 = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.04683399814247455, 6) # TODO: fill in as the eom-kgccsd completed... # ## Getting more roots than 1 is difficult #e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, 5.060562738181741, 6) #e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, 4.188511644938458, 6) #e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, -3.477663551987023, 6) #e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, -4.23523412155825, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() #mysmp = pbmp.KMP2(mf) #emp2, _ = mysmp.kernel() #print("MP2 corr energy (per unit cell) = ", emp2 / np.prod(nmp)) myscc = pbcc.KGCCSD(mf, frozen=[0, 1, 14, 15]) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.04683401678904569, 6)
kmf_sc = k2gamma(kmf, abs_kpts, kmesh, realize=True, tol_deg=5e-5, real_split=False) c_g_ao = kmf_sc.mo_coeff[0] print "Supercell gamma MO in AO basis from conversion:" print c_g_ao dm_convert = 2.0 * c_g_ao[:, kmf_sc.mo_occ[0] > 0].dot( c_g_ao[:, kmf_sc.mo_occ[0] > 0].conj().T) # The following is to check whether the MO is correctly coverted: sc = tools_pbc.super_cell(cell, kmesh) #sc.verbose = 0 kmf_sc2 = pscf.KRHF(sc, [[0.0, 0.0, 0.0]]).density_fit() gdf = df.GDF(sc, [[0.0, 0.0, 0.0]]) kmf_sc2.with_df = gdf s = kmf_sc2.get_ovlp()[0] print "Run supercell gamma point calculation..." ekpt_sc = kmf_sc2.run([dm_convert]) #ekpt_sc = kmf_sc2.run() sc_mo = kmf_sc2.mo_coeff[0] print "Supercell gamma MO from direct calculation:" print sc_mo # lowdin of sc_mo and c_g_ao
for j in range(2): dmk[0][i][j,j] = 0.5 dmk[1][i][j+nao_half, j+nao_half] = 0.5 ehf = kmf.kernel(dmk) kcc = cc.KUCCSD(kmf) ecc,t1,t2 = kcc.kernel() print('========================================') print('UHF energy (kpts) %f \n' % (float(ehf))) print('UCCSD correlation energy (kpts) %f \n' % (float(ecc))) print('========================================') # Gamma point supercell calculation supcell = super_cell(cell,nmp) dms = np.zeros([2, supcell.nao_nr(), supcell.nao_nr()]) for i in range(nkpts): for j in range(2): dms[0][j+i*nao][j+i*nao] = 0.5 dms[1][j+i*nao+nao_half][j+i*nao+nao_half] = 0.5 gmf = scf.UHF(supcell,exxdiv=None).density_fit() gmf.chkfile = 'supcell.chk' ehf = gmf.kernel(dms) gcc = cc.UCCSD(gmf) ecc,t1,t2 = gcc.kernel() print('========================================') print('UHF energy (supercell) %f' % (float(ehf)/nk))
def plot_wf(self, outfile='MLWF', wf_list=None, supercell=[1, 1, 1], grid=[50, 50, 50]): ''' Export Wannier function at cell R xsf format: http://web.mit.edu/xcrysden_v1.5.60/www/XCRYSDEN/doc/XSF.html Attributes: wf_list : a list of MLWFs to plot supercell : a supercell used for plotting ''' if wf_list == None: wf_list = list(range(self.num_wann_loc)) from pyscf.pbc.tools import pbc super_cell = pbc.super_cell(self.cell, supercell) real_lattice_loc = super_cell.lattice_vectors() * param.BOHR atom_symbols_loc = [atom[0] for atom in super_cell._atom] atoms_cart_loc = np.asarray([ (np.asarray(atom[1]) * param.BOHR).tolist() for atom in super_cell._atom ]) num_atoms_loc = super_cell.natm nx, ny, nz = np.asarray(grid) nX, nY, nZ = tuple((np.asarray(grid) - 1) * np.asarray(supercell) + 1) superWF = np.empty([nX, nY, nZ]) superWF_temp = np.empty([nX, nY, nZ]) WFs = self.get_wannier(grid=grid) for wf_id in wf_list: assert wf_id in list(range(self.num_wann_loc)) WF = WFs[:, wf_id].reshape(nx, ny, nz).real for x in range(supercell[0]): for y in range(supercell[1]): for z in range(supercell[2]): superWF_temp[:nx, :ny, ((nz - 1) * z):((nz - 1) * z + nz)] = WF superWF_temp[:, ((ny - 1) * y):((ny - 1) * y + ny), :] = superWF_temp[:, :ny, :] superWF[((nx - 1) * x):((nx - 1) * x + nx), :, :] = superWF_temp[:nx, :, :] with open(outfile + '-' + str(wf_id) + '.xsf', 'w') as f: f.write('Generated by the pyWannier90\n\n') f.write('CRYSTAL\n') f.write('PRIMVEC\n') for row in range(3): f.write('%10.7f %10.7f %10.7f\n' % (real_lattice_loc[0, row], real_lattice_loc[1, row], \ real_lattice_loc[2, row])) f.write('PRIMVEC\n') for row in range(3): f.write('%10.7f %10.7f %10.7f\n' % (real_lattice_loc[0, row], real_lattice_loc[1, row], \ real_lattice_loc[2, row])) f.write('PRIMCOORD\n') f.write('%3d %3d\n' % (num_atoms_loc, 1)) for atom in range(len(atom_symbols_loc)): f.write('%s %7.7f %7.7f %7.7f\n' % (atom_symbols_loc[atom], atoms_cart_loc[atom][0], \ atoms_cart_loc[atom][1], atoms_cart_loc[atom][2])) f.write('\n\n') f.write( 'BEGIN_BLOCK_DATAGRID_3D\n3D_field\nBEGIN_DATAGRID_3D_UNKNOWN\n' ) f.write(' %5d %5d %5d\n' % (nX, nY, nZ)) f.write(' %10.7f %10.7f %10.7f\n' % tuple(np.zeros(3).tolist())) for row in range(3): f.write(' %10.7f %10.7f %10.7f\n' % (real_lattice_loc[0, row], real_lattice_loc[1, row], \ real_lattice_loc[2, row])) fmt = ' %13.5e' * nX + '\n' for iz in range(nZ): for iy in range(nY): f.write(fmt % tuple(superWF[:, iy, iz].tolist())) f.write('\n') f.write('END_DATAGRID_3D\nEND_BLOCK_DATAGRID_3D')
nmp = [2, 2, 2] ase_atom = lattice.get_ase_alkali_halide(A='Li', B='F') cell = pbcgto.Cell() cell.spin = 0 cell.symmetry = 0 cell.charge = 0 cell.unit = 'B' cell.verbose = 4 cell.atom = pyscf_ase.ase_atoms_to_pyscf(ase_atom) cell.a = ase_atom.cell cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.build() new = super_cell(cell, nmp) cell = pbcgto.Cell() #cell.unit = 'B' cell.spin = 0 cell.symmetry = 0 cell.charge = 0 cell.verbose = 4 cell.atom = new.atom cell.a = new.a cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.mesh = [10, 10, 10] cell.build() mf = pbchf.RHF(cell) mf.with_df = pbcdf.AFTDF(cell)
def setUpClass(cls): k_grid = [2, 1, 1] # Unit cell cls.cell = gto.Cell() cls.cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cls.cell.basis = 'gth-szv' cls.cell.pseudo = 'gth-pade' cls.cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000 ''' cls.cell.unit = 'B' cls.cell.verbose = 7 cls.cell.mesh = [24] * 3 cls.cell.build() # MF cls.mf = scf.KRHF(cls.cell, kpts=cls.cell.make_kpts(k_grid), exxdiv=None) cls.mf.chkfile = 'test_kgf_proper_rhf_chk.dat' if os.path.exists(cls.mf.chkfile): cls.mf.update() else: cls.mf.kernel() # Supercell cls.cell2 = super_cell(cls.cell, k_grid) cls.mf2 = scf.KRHF(cls.cell2, exxdiv=None) cls.order = numpy.argsort(numpy.hstack(cls.mf.mo_energy)) c1 = cls.mf.mo_coeff[0] c2 = cls.mf.mo_coeff[1] c1, c2 = numpy.concatenate((c1, c1), axis=0) / 2.**.5, numpy.concatenate((c2, -c2), axis=0) / 2.**.5 cls.mf2.mo_coeff = [numpy.concatenate((c1, c2), axis=1)[:, cls.order]] cls.mf2.mo_energy = [numpy.concatenate(cls.mf.mo_energy)[cls.order]] cls.mf2.mo_occ = [numpy.concatenate(cls.mf.mo_occ)[cls.order]] cls.mf2.make_rdm1() # CCSD cls.ccsd = cc.KRCCSD(cls.mf) cls.ccsd.conv_tol_normt = 1e-8 cls.ccsd.kernel() cls.ccsd2 = cc.KRCCSD(cls.mf2) cls.ccsd2.conv_tol_normt = 1e-8 cls.ccsd2.kernel() # TODO: lambda iterations cls.ccsd.l1 = cls.ccsd.t1 cls.ccsd.l2 = cls.ccsd.t2 # cls.ccsd.ipccsd(nroots=2) # cls.ccsd.eaccsd(nroots=2) # cls.ip_samples = [-0.71, -1] cls.ip_samples = [-0.71] cls.ea_samples = [1.13, 0.3] cls.eta = 0.01 # ===== cls.nocc, cls.nvirt = cls.ccsd.t1[0].shape cls.nmo = cls.nocc + cls.nvirt cls.o1 = cls.order[:2*cls.nocc] < cls.nmo cls.o2 = cls.order[:2*cls.nocc] >= cls.nmo cls.v1 = cls.order[2*cls.nocc:] < cls.nmo cls.v2 = cls.order[2*cls.nocc:] >= cls.nmo cls.a1 = cls.order < cls.nmo cls.a2 = cls.order >= cls.nmo # ===== cls.ccsd2.l1 = cls.ccsd2.t1 cls.ccsd2.l2 = cls.ccsd2.t2
def k2s(model, grid_spec, mf_constructor, threshold=None, degeneracy_threshold=None, imaginary_threshold=None): """ Converts k-point model into a supercell with real orbitals. Args: model: a mean-field pbc model; grid_spec (Iterable): integer dimensions of the k-grid in the mean-field model; mf_constructor (Callable): a function constructing the mean-field object; threshold (float): a threshold for determining the negative k-point index; degeneracy_threshold (float): a threshold for assuming degeneracy when composing real-valued orbitals; imaginary_threshold (float): a threshold for asserting real-valued supercell orbitals; Returns: The same class where the Cell object was replaced by the supercell and all fields were adjusted accordingly. """ # This hack works as follows. Provided TRS Hamiltonian # H(k) = H(-k)*, # with same real eigenvalues and eigenfunctions related as # psi(k) = c psi(-k)*, # c - arbitrary phase, it is easy to construct real (non-Bloch) eigenvectors of the whole Hamiltonian # real1(|k|) = c* psi(k) + psi(-k) = psi(-k)* + psi(-k) # and # real2(|k|) = 1.j * (c* psi(k) - psi(-k)) = 1.j* (psi(-k)* - psi(-k)). # The coefficient c is determined as # psi(k) * psi(-k) = c psi(-k)* * psi(-k) = c if imaginary_threshold is None: imaginary_threshold = 1e-7 mk = minus_k(model, threshold=threshold, degeneracy_threshold=degeneracy_threshold) # Fix phases ovlp = model.get_ovlp() phases = {} for k1, k2 in enumerate(mk): if k1 <= k2: c1 = model.mo_coeff[k1] c2 = model.mo_coeff[k2] o = ovlp[k1] r = reduce(numpy.dot, (c2.T, o, c1)) delta = abs(abs(r) - numpy.eye(r.shape[0])).max() if delta > imaginary_threshold: raise RuntimeError( "K-points connected by time reversal {:d} and {:d} are not complex conjugate: " "the difference {:.3e} is larger than the threshold {:.3e}" .format( k1, k2, delta, imaginary_threshold, )) p = numpy.angle(numpy.diag(r)) if k1 == k2: phases[k1] = numpy.exp(-.5j * p)[numpy.newaxis, :] else: phases[k1] = numpy.exp(-1.j * p)[numpy.newaxis, :] nk = len(model.kpts) t_vecs = cartesian_prod(tuple(numpy.arange(i) for i in grid_spec)) kpts_frac = model.cell.get_scaled_kpts(model.kpts) result = mf_constructor(super_cell(model.cell, grid_spec)) result_ovlp = result.get_ovlp()[0] moe = numpy.concatenate(model.mo_energy) moo = numpy.concatenate(model.mo_occ) # Complex-valued wf in a supercell moc = [] for mo_coeff, k in zip(model.mo_coeff, kpts_frac): psi = ( mo_coeff[numpy.newaxis, ...] * numpy.exp(2.j * numpy.pi * t_vecs.dot(k))[:, numpy.newaxis, numpy.newaxis]).reshape( -1, mo_coeff.shape[1]) norms = einsum("ai,ab,bi->i", psi.conj(), result_ovlp, psi)**.5 psi /= norms[numpy.newaxis, :] moc.append(psi) moc = numpy.concatenate(moc, axis=1) rotation_matrix = sparse.dok_matrix(moc.shape, dtype=moc.dtype) inv_rotation_matrix = sparse.dok_matrix(moc.shape, dtype=moc.dtype) nvecs = (0, ) + tuple(i.shape[1] for i in model.mo_coeff) nvecs = numpy.cumsum(nvecs) k_spaces = tuple(numpy.arange(i, j) for i, j in zip(nvecs[:-1], nvecs[1:])) for k in range(nk): i = k_spaces[k] j = k_spaces[mk[k]] if k == mk[k]: rotation_matrix[i, i] = phases[k] inv_rotation_matrix[i, i] = phases[k].conj() elif k < mk[k]: rotation_matrix[i, i] = .5**.5 * phases[k] rotation_matrix[j, i] = .5**.5 rotation_matrix[i, j] = -1.j * .5**.5 * phases[k] rotation_matrix[j, j] = 1.j * .5**.5 inv_rotation_matrix[i, i] = .5**.5 * phases[k].conj() inv_rotation_matrix[j, i] = 1.j * .5**.5 * phases[k].conj() inv_rotation_matrix[i, j] = .5**.5 inv_rotation_matrix[j, j] = -1.j * .5**.5 else: pass rotation_matrix = rotation_matrix.tocsc() inv_rotation_matrix = inv_rotation_matrix.tocsc() moc = sparse_transform(moc, 1, rotation_matrix) max_imag = abs(moc.imag).max() if max_imag > imaginary_threshold: raise RuntimeError( "Failed to compose real-valued orbitals: imaginary part is {:.3e}". format(max_imag)) moc = moc.real mok = numpy.concatenate( tuple([i] * len(j) for i, j in enumerate(model.mo_energy))) moi = numpy.concatenate( tuple(numpy.arange(len(j)) for j in model.mo_energy)) order = numpy.argsort(moe) moe = moe[order] moc = moc[:, order] moo = moo[order] mok = mok[order] moi = moi[order] rotation_matrix = rotation_matrix[:, order] inv_rotation_matrix = inv_rotation_matrix[order, :] result.mo_occ = moo, result.mo_energy = moe, result.mo_coeff = moc, result.supercell_rotation = rotation_matrix result.supercell_inv_rotation = inv_rotation_matrix result.supercell_orig_k = mok result.supercell_orig_i = moi assert_scf_converged(result, model.conv_tol**.5) p1 = abs( result.supercell_rotation.dot(result.supercell_inv_rotation) - numpy.eye(rotation_matrix.shape[0])).max() p2 = abs( result.supercell_inv_rotation.dot(result.supercell_rotation) - numpy.eye(rotation_matrix.shape[0])).max() if p1 > 1e-14 or p2 > 1e-14: raise RuntimeError("Rotation matrix error: {:.3e}, {:.3e}".format( p1, p2)) return result
def test_h4_fcc_k2_frozen(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1., 0., 0.], [0., 1., 0], [0, 0, 2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [ [0, [1.0, 1]], ] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple( np.dot(np.array(cell.atom[i][1]), np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() #mymp = pbmp.KMP2(kmf) #ekmp2, _ = mymp.kernel() #print("KMP2 corr energy (per unit cell) = ", ekmp2) # By not applying a level-shift, one gets a different initial CCSD answer. # One can check however that the t1/t2 from level-shifting are a solution # of the CCSD equations done without level-shifting. frozen = [[0, 1, 6, 7], []] mycc = pbcc.KGCCSD(kmf, frozen=frozen) ekccsd, t1, t2 = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.04683399814247455, 6) # TODO: fill in as the eom-kgccsd completed... # ## Getting more roots than 1 is difficult #e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, 5.060562738181741, 6) #e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, 4.188511644938458, 6) #e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, -3.477663551987023, 6) #e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, -4.23523412155825, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() #mysmp = pbmp.KMP2(mf) #emp2, _ = mysmp.kernel() #print("MP2 corr energy (per unit cell) = ", emp2 / np.prod(nmp)) myscc = pbcc.KGCCSD(mf, frozen=[0, 1, 14, 15]) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.04683401678904569, 6)
3.370137329, 0.000000000, 3.370137329 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]
def test_h4_fcc_k2(self): '''Metallic hydrogen fcc lattice. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1., 0., 0.], [0., 1., 0], [0, 0, 2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [ [0, [1.0, 1]], ] cell.pseudo = 'gth-pade' cell.output = '/dev/null' #cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple( np.dot(np.array(cell.atom[i][1]), np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() mycc = pbcc.KCCSD(kmf) ekccsd, _, _ = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.06146759560406628, 6) # Getting more roots than 1 is difficult e = mycc.eaccsd(nroots=1, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], 5.079427283440857, 6) e = mycc.eaccsd(nroots=1, koopmans=False, kptlist=(1, ))[0] self.assertAlmostEqual(e[0][0], 4.183328878177331, 6) e = mycc.ipccsd(nroots=1, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], -3.471710821544506, 6) e = mycc.ipccsd(nroots=1, koopmans=False, kptlist=(1, ))[0] self.assertAlmostEqual(e[0][0], -4.272015727359054, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() myscc = pbcc.KCCSD(mf) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.06146759560406628, 6) e = myscc.eaccsd(nroots=4, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], 4.183328873793568, 6) self.assertAlmostEqual(e[0][1], 4.225034294249784, 6) self.assertAlmostEqual(e[0][2], 5.068962665511664, 6) self.assertAlmostEqual(e[0][3], 5.07942727935064, 6) e = myscc.ipccsd(nroots=4, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], -4.272015724869052, 6) self.assertAlmostEqual(e[0][1], -4.254298274388934, 6) self.assertAlmostEqual(e[0][2], -3.471710821688812, 6) self.assertAlmostEqual(e[0][3], -3.462817764320668, 6)
def k2gamma(kmf, abs_kpts, kmesh, realize=True, real_split=False, tol_deg=5e-5): ''' convert the k-sampled mo coefficient to corresponding supercell gamma-point mo coefficient. set realize = True to make sure the final wavefunction to be real. return the supercell gamma point object math: C_{\nu ' n'} = C_{\vecR\mu, \veck m} = \qty[ \frac{1}{\sqrt{N_{\UC}}} \e^{\ii \veck\cdot\vecR} C^{\veck}_{\mu m}] ''' #np.set_printoptions(4,linewidth=1000) R_abs_mesh = get_R_vec(kmf.cell, abs_kpts, kmesh) phase = np.exp(1j * np.einsum('Ru, ku -> Rk', R_abs_mesh, abs_kpts)) E_k = np.asarray(kmf.mo_energy) occ_k = np.asarray(kmf.mo_occ) C_k = np.asarray(kmf.mo_coeff) Nk, Nao, Nmo = C_k.shape NR = R_abs_mesh.shape[0] C_gamma = np.einsum('Rk, kum -> Rukm', phase, C_k) / np.sqrt(NR) C_gamma = C_gamma.reshape((NR, Nao, Nk * Nmo)) # sort energy of km E_k_flat = E_k.flatten() E_k_sort_idx = np.argsort(E_k_flat) E_k_sort = E_k_flat[E_k_sort_idx] occ_sort = occ_k.flatten()[E_k_sort_idx] C_gamma = C_gamma[:, :, E_k_sort_idx] C_gamma = C_gamma.reshape((NR * Nao, Nk * Nmo)) # supercell object sc = tools_pbc.super_cell(cell, kmesh) sc.verbose = 0 kmf_sc = pscf.KRHF( sc, [[0.0, 0.0, 0.0]]).density_fit() # TODO spin polarize ? DF or not? S_sc = kmf_sc.get_ovlp()[0].real # make MO to be real if realize: real_tol = tol_deg # tolerance of residue of real or imag part null_tol = min(tol_deg * 10.0, 1.0e-3) # tolerance of 0 for nat_orb selection print "Realize the gamma point MO ..." C_gamma_real = np.zeros_like(C_gamma, dtype=np.double) res, res_idx = find_degenerate(E_k_sort, C_gamma, real_split=real_split, tol=tol_deg) print "Energy spectrum group:", res print "Energy idx:", res_idx col_idx = 0 for i, gi_idx in enumerate(res_idx): gi = C_gamma[:, gi_idx] # using dm to solve natural orbitals, to make the orbitals real dm = gi.dot(gi.conj().T) if la.norm(dm.imag) > real_tol: print "density matrix of converted Gamma MO has large imaginary part." sys.exit(1) eigval, eigvec = la.eigh(dm.real, S_sc, type=2) nat_orb = eigvec[:, eigval > null_tol] if nat_orb.shape[1] != len(gi_idx): print "Realization error, not find correct number of linear combination coefficient" sys.exit(1) for j in xrange(nat_orb.shape[1]): C_gamma_real[:, col_idx] = nat_orb[:, j] col_idx += 1 C_gamma = C_gamma_real # save to kmf_sc obj kmf_sc.mo_coeff = [C_gamma] kmf_sc.mo_energy = [np.asarray(E_k_sort)] kmf_sc.mo_occ = [np.asarray(occ_sort)] return kmf_sc
def test_h4_fcc_k2(self): '''Metallic hydrogen fcc lattice. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1.,0.,0.],[0.,1.,0],[0,0,2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [[0, [1.0, 1]],] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple(np.dot(np.array(cell.atom[i][1]),np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0,0.0,0.0]) e = kmf.kernel() #mymp = pbmp.KMP2(kmf) #ekmp2, _ = mymp.kernel() #print("KMP2 corr energy (per unit cell) = ", ekmp2) mycc = pbcc.KGCCSD(kmf) ekccsd, t1, t2 = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.06146759560406628, 6) # TODO: fill in as the eom-kgccsd completed... # ## Getting more roots than 1 is difficult #e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, 5.079427283440857, 6) #e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, 4.183328878177331, 6) #e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, -3.471710821544506, 6) #e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, -4.272015727359054, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() ##mysmp = pbmp.KMP2(mf) ##emp2, _ = mysmp.kernel() ##print("MP2 corr energy (per unit cell) = ", emp2 / np.prod(nmp)) myscc = pbcc.KGCCSD(mf) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.06146759560406628, 6)