def test_convert_to_kscf(self): from pyscf.pbc import df from pyscf.soscf import newton_ah cell1 = cell.copy() cell1.verbose = 0 pscf.addons.convert_to_rhf(pscf.KRHF(cell1)) pscf.addons.convert_to_uhf(pscf.KRHF(cell1)) pscf.addons.convert_to_ghf(pscf.KRHF(cell1)) pscf.addons.convert_to_rhf(pscf.KROHF(cell1)) pscf.addons.convert_to_uhf(pscf.KROHF(cell1)) pscf.addons.convert_to_ghf(pscf.KROHF(cell1)) pscf.addons.convert_to_rhf(pscf.KUHF(cell1)) pscf.addons.convert_to_uhf(pscf.KUHF(cell1)) pscf.addons.convert_to_ghf(pscf.KUHF(cell1)) #pscf.addons.convert_to_rhf(pscf.KGHF(cell1)) #pscf.addons.convert_to_uhf(pscf.KGHF(cell1)) pscf.addons.convert_to_ghf(pscf.KGHF(cell1)) self.assertTrue (isinstance(pscf.addons.convert_to_rhf(pscf.KRHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) self.assertFalse(isinstance(pscf.addons.convert_to_uhf(pscf.KRHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) self.assertFalse(isinstance(pscf.addons.convert_to_ghf(pscf.KRHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) self.assertFalse(isinstance(pscf.addons.convert_to_rhf(pscf.KUHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) self.assertTrue (isinstance(pscf.addons.convert_to_uhf(pscf.KUHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) self.assertFalse(isinstance(pscf.addons.convert_to_ghf(pscf.KUHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) #self.assertFalse(isinstance(pscf.addons.convert_to_rhf(pscf.KGHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) #self.assertFalse(isinstance(pscf.addons.convert_to_uhf(pscf.KGHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) #self.assertTrue (isinstance(pscf.addons.convert_to_ghf(pscf.KGHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF)) mf1 = pscf.khf.KRHF(cell1) cell2 = cell1.copy() cell2.spin = 2 mf2 = mf1.convert_from_(kmf_u) self.assertEqual(kmf_u.kpts.shape, (2, 3)) self.assertEqual(mf2.kpts.shape, (2, 3)) self.assertTrue (isinstance(mf2, pscf.khf.KRHF)) self.assertTrue (isinstance(mf1.convert_from_(pscf.KUHF(cell2)), pscf.khf.KRHF)) self.assertFalse(isinstance(mf1.convert_from_(pscf.KUHF(cell2)), pscf.krohf.KROHF)) self.assertFalse(isinstance(mf1.convert_from_(kmf_u.newton()), newton_ah._CIAH_SOSCF)) self.assertTrue (isinstance(mf1.convert_from_(pscf.KUHF(cell2).density_fit()).with_df, df.df.GDF)) self.assertTrue (isinstance(mf1.convert_from_(pscf.KUHF(cell2).mix_density_fit()).with_df, df.mdf.MDF)) self.assertFalse(isinstance(mf1.convert_from_(pscf.KROHF(cell2)), pscf.krohf.KROHF)) self.assertRaises(AssertionError, mf1.convert_from_, pscf.UHF(cell1)) mf1 = pscf.krohf.KROHF(cell1) self.assertTrue (isinstance(mf1.convert_from_(kmf_u), pscf.krohf.KROHF)) self.assertTrue (isinstance(mf1.convert_from_(pscf.KUHF(cell2)), pscf.krohf.KROHF)) self.assertFalse(isinstance(mf1.convert_from_(kmf_u.newton()), newton_ah._CIAH_SOSCF)) self.assertTrue (isinstance(mf1.convert_from_(pscf.KUHF(cell2).density_fit()).with_df, df.df.GDF)) self.assertTrue (isinstance(mf1.convert_from_(pscf.KUHF(cell2).mix_density_fit()).with_df, df.mdf.MDF)) self.assertTrue (isinstance(mf1.convert_from_(kmf_r), pscf.krohf.KROHF)) self.assertRaises(AssertionError, mf1.convert_from_, pscf.UHF(cell1)) self.assertTrue(isinstance(pscf.addons.convert_to_rhf(pscf.KROHF(cell2)), pscf.krohf.KROHF)) #self.assertTrue(isinstance(pscf.addons.convert_to_rhf(pscf.KROHF(cell2).newton()), pscf.krohf.KROHF)) mf1 = pscf.kuhf.KUHF(cell1) self.assertTrue (isinstance(mf1.convert_from_(kmf_r), pscf.kuhf.KUHF)) self.assertFalse(isinstance(mf1.convert_from_(kmf_r.newton()), newton_ah._CIAH_SOSCF)) self.assertTrue (isinstance(mf1.convert_from_(kmf_r.density_fit()).with_df, df.df.GDF)) self.assertTrue (isinstance(mf1.convert_from_(kmf_ro.mix_density_fit()).with_df, df.mdf.MDF)) self.assertRaises(AssertionError, mf1.convert_from_, pscf.UHF(cell1))
def test_init(self): from pyscf.pbc import dft cell_u = cell.copy() cell_u.spin = 2 self.assertTrue(isinstance(pscf.RKS (cell ), dft.rks.RKS )) self.assertTrue(isinstance(pscf.RKS (cell_u), dft.roks.ROKS )) self.assertTrue(isinstance(pscf.UKS (cell ), dft.uks.UKS )) self.assertTrue(isinstance(pscf.ROKS (cell ), dft.roks.ROKS )) self.assertTrue(isinstance(pscf.KS (cell ), dft.rks.RKS )) self.assertTrue(isinstance(pscf.KS (cell_u), dft.uks.UKS )) self.assertTrue(isinstance(pscf.KRKS (cell ), dft.krks.KRKS )) self.assertTrue(isinstance(pscf.KRKS (cell_u), dft.krks.KRKS )) self.assertTrue(isinstance(pscf.KUKS (cell ), dft.kuks.KUKS )) self.assertTrue(isinstance(pscf.KROKS(cell ), dft.kroks.KROKS)) self.assertTrue(isinstance(pscf.KKS (cell ), dft.krks.KRKS )) self.assertTrue(isinstance(pscf.KKS (cell_u), dft.kuks.KUKS )) self.assertTrue(isinstance(pscf.RHF (cell ), pscf.hf.RHF )) self.assertTrue(isinstance(pscf.RHF (cell_u), pscf.rohf.ROHF )) self.assertTrue(isinstance(pscf.KRHF (cell ), pscf.khf.KRHF )) self.assertTrue(isinstance(pscf.KRHF (cell_u), pscf.khf.KRHF )) self.assertTrue(isinstance(pscf.UHF (cell ), pscf.uhf.UHF )) self.assertTrue(isinstance(pscf.KUHF (cell_u), pscf.kuhf.KUHF )) self.assertTrue(isinstance(pscf.GHF (cell ), pscf.ghf.GHF )) self.assertTrue(isinstance(pscf.KGHF (cell_u), pscf.kghf.KGHF )) self.assertTrue(isinstance(pscf.ROHF (cell ), pscf.rohf.ROHF )) self.assertTrue(isinstance(pscf.ROHF (cell_u), pscf.rohf.ROHF )) self.assertTrue(isinstance(pscf.KROHF(cell ), pscf.krohf.KROHF)) self.assertTrue(isinstance(pscf.KROHF(cell_u), pscf.krohf.KROHF)) self.assertTrue(isinstance(pscf.HF (cell ), pscf.hf.RHF )) self.assertTrue(isinstance(pscf.HF (cell_u), pscf.uhf.UHF )) self.assertTrue(isinstance(pscf.KHF (cell ), pscf.khf.KRHF )) self.assertTrue(isinstance(pscf.KHF (cell_u), pscf.kuhf.KUHF ))
def test_small_system(self): # issue #686 mol = pgto.Cell(atom='H 0 0 0;', a=[[3, 0, 0], [0, 3, 0], [0, 0, 3]], basis=[[0, [1, 1]]], spin=1, verbose=7, output='/dev/null') mf = pscf.KROHF(mol, kpts=[[0., 0., 0.]]).run() self.assertAlmostEqual(mf.e_tot, -0.10439957735616917, 8) mol = pgto.Cell(atom='He 0 0 0;', a=[[3, 0, 0], [0, 3, 0], [0, 0, 3]], basis=[[0, [1, 1]]], verbose=7, output='/dev/null') mf = pscf.KROHF(mol, kpts=[[0., 0., 0.]]).run() self.assertAlmostEqual(mf.e_tot, -2.2719576422665635, 8)
def test_get_init_guess(self): cell1 = cell.copy() cell1.dimension = 1 cell1.build(0, 0) mf = pscf.ROHF(cell1) dm = mf.get_init_guess(key='minao') self.assertAlmostEqual(lib.finger(dm), -0.06586028869608128, 8) mf = pscf.KROHF(cell1) dm = mf.get_init_guess(key='minao') self.assertAlmostEqual(lib.finger(dm), -0.06586028869608128, 8)
def test_krhf_vs_rhf(self): np.random.seed(1) k = np.random.random(3) mf = pscf.ROHF(cell, k, exxdiv='vcut_sph') mf.max_cycle = 1 mf.diis = None e1 = mf.kernel() kmf = pscf.KROHF(cell, [k], exxdiv='vcut_sph') kmf.max_cycle = 1 kmf.diis = None e2 = kmf.kernel() self.assertAlmostEqual(e1, e2, 9) self.assertAlmostEqual(e1, -3.3046228601655607, 9)
def test_getattr(self): from pyscf.pbc import scf, dft, cc, tdscf cell = pgto.M(atom='He', a=np.eye(3) * 4, basis={'He': [[0, (1, 1)]]}) self.assertEqual(cell.HF().__class__, scf.HF(cell).__class__) self.assertEqual(cell.KS().__class__, dft.KS(cell).__class__) self.assertEqual(cell.UKS().__class__, dft.UKS(cell).__class__) self.assertEqual(cell.KROHF().__class__, scf.KROHF(cell).__class__) self.assertEqual(cell.KKS().__class__, dft.KKS(cell).__class__) self.assertEqual(cell.CCSD().__class__, cc.ccsd.RCCSD) self.assertEqual(cell.TDA().__class__, tdscf.rhf.TDA) self.assertEqual(cell.TDBP86().__class__, tdscf.rks.TDDFTNoHybrid) self.assertEqual(cell.TDB3LYP().__class__, tdscf.rks.TDDFT) self.assertEqual(cell.KCCSD().__class__, cc.kccsd_rhf.KRCCSD) self.assertEqual(cell.KTDA().__class__, tdscf.krhf.TDA) self.assertEqual(cell.KTDBP86().__class__, tdscf.krks.TDDFTNoHybrid) self.assertRaises(AttributeError, lambda: cell.xyz) self.assertRaises(AttributeError, lambda: cell.TDxyz)
def test_init_guess_by_chkfile(self): np.random.seed(1) k = np.random.random(3) mf = pscf.KROHF(cell, [k], exxdiv='vcut_sph') mf.init_guess = 'hcore' mf.max_cycle = 1 mf.diis = None e1 = mf.kernel() self.assertAlmostEqual(e1, -3.4376090968645068, 9) mf1 = pscf.ROHF(cell, exxdiv='vcut_sph') mf1.chkfile = mf.chkfile mf1.init_guess = 'chkfile' mf1.diis = None mf1.max_cycle = 1 e1 = mf1.kernel() self.assertAlmostEqual(e1, -3.4190632006601662, 9) self.assertTrue(mf1.mo_coeff[0].dtype == np.double)
def setUpModule(): global cell, mf, kmf, kpts cell = pgto.Cell() cell.atom = ''' He 0 0 1 He 1 0 1 ''' cell.basis = '321g' cell.a = np.eye(3) * 3 cell.mesh = [8] * 3 cell.verbose = 7 cell.output = '/dev/null' cell.spin = 2 cell.build() nk = [2, 2, 1] kpts = cell.make_kpts(nk, wrap_around=True) kmf = pscf.KROHF(cell, kpts).run() mf = pscf.ROHF(cell).run()
def scf_run(pmol, method='KROHF', df_method='gdf', use_saved_eri=False, \ eri_fname='./gdf_ints_atom_full_basis.h5'): if method == 'KROHF': pmf = scf.KROHF(pmol) else: raise NotImplementedError pmf.max_cycle = 5000 pmf.conv_tol = 1e-10 if df_method == 'gdf': gdf = df.GDF(pmol, kpts=pmol.make_kpts([1, 1, 1])) else: raise NotImplementedError if not use_saved_eri: gdf._cderi_to_save = eri_fname gdf.build() pmf.with_df = gdf pmf.with_df._cderi = eri_fname pmf.scf() return pmf
def setUpModule(): global cell, kmf_ro, kmf_r, kmf_u, kmf_g, nao, kpts cell = pbcgto.Cell() cell.atom = ''' He 0 0 1 He 1 0 1 ''' cell.basis = [[0, [1., 1.]], [0, [0.5, 1]]] cell.a = numpy.eye(3) * 3 cell.mesh = [10] * 3 cell.verbose = 5 cell.output = '/dev/null' cell.build() nao = cell.nao_nr() kpts = cell.make_kpts([2,1,1]) kmf_ro = pscf.KROHF(cell, kpts=kpts).run() kmf_r = pscf.KRHF(cell, kpts=kpts).convert_from_(kmf_ro) kmf_u = pscf.addons.convert_to_uhf(kmf_r) kmf_g = pscf.addons.convert_to_ghf(kmf_r)
def init_scf(self, cell=None, method=None, verbose=None, damp=None, shift=None, kpts=None, grid_level=None, rho_cutoff=None, density_fit=None, auxbasis=None): """ Initializes the supersystem PySCF SCF object using given settings. Parameters ---------- cell : pyscf.pbc.gto.Cell object Concatenated supersystem Cell object fs_method : str Supersystem SCF method verbose : int PySCF verbosity parameter for output damp : float Damping parameter for SCF convergence shift : float Energy level shift parameter for convergence Returns ------- scf_obj : pyscf.pbc.SCF object SCF object for the supersystem """ import pyscf from pyscf.pbc import scf as pbcscf, df as pbcdf, dft as pbcdft if cell is None: cell = self.cell if method is None: method = self.fs_method if verbose is None: verbose = self.verbose if damp is None: damp = self.fs_damp if shift is None: shift = self.fs_shift if kpts is None: kpts = self.kpts if grid_level is None: grid_level = self.grid_level if rho_cutoff is None: rho_cutoff = self.rho_cutoff if density_fit is None: density_fit = self.density_fit if auxbasis is None: auxbasis = self.auxbasis # if self.pmem: # self.cell.max_memory = self.pmem nkpts = len(kpts) if self.unrestricted: if method in ('hf', 'hartree-fock'): scf_obj = pbcscf.KUHF(cell, kpts) else: scf_obj = pbcscf.KUKS(cell, kpts) scf_obj.xc = method elif cell.spin != 0: if method in ('hf', 'hartree-fock'): scf_obj = pbcscf.KROHF(cell, kpts) else: scf_obj = pbcscf.KROKS(cell, kpts) scf_obj.xc = method else: if method in ('hf', 'hartree-fock'): scf_obj = pbcscf.KRHF(cell, kpts) else: scf_obj = pbcscf.KRKS(cell, kpts) scf_obj.xc = method scf_obj.kpts = kpts scf_obj.verbose = verbose # build grids scf_obj.grids = pbcdft.gen_grid.BeckeGrids(cell) scf_obj.grids.level = grid_level scf_obj.grids.build() # density fitting (can be very time consuming) if density_fit == 'fftdf': DensityFit = pbcdf.FFTDF elif density_fit == 'mdf': DensityFit = pbcdf.MDF elif density_fit == 'pwdf': DensityFit = pbcdf.PWDF elif density_fit == 'gdf': DensityFit = pbcdf.GDF elif density_fit == 'aftdf': DensityFit = pbcdf.AFTDF else: DensityFit = pbcdf.DF scf_obj.with_df = DensityFit(cell) scf_obj.with_df.kpts = kpts scf_obj.with_df.auxbasis = auxbasis scf_obj.damp = damp self.smat = scf_obj.get_ovlp() return scf_obj
cell = pgto.Cell() cell.atom = ''' He 0 0 1 He 1 0 1 ''' cell.basis = '321g' cell.a = np.eye(3) * 3 cell.mesh = [8] * 3 cell.verbose = 7 cell.output = '/dev/null' cell.spin = 2 cell.build() nk = [2, 2, 1] kpts = cell.make_kpts(nk, wrap_around=True) kmf = pscf.KROHF(cell, kpts).run() mf = pscf.ROHF(cell).run() def tearDownModule(): global cell, kmf, mf cell.stdout.close() del cell, kmf, mf class KnownValues(unittest.TestCase): def test_krohf_kernel(self): self.assertAlmostEqual(kmf.e_tot, -4.569633030494753, 8) def test_rohf_kernel(self): self.assertAlmostEqual(mf.e_tot, -3.3633746534777718, 8) def test_krhf_vs_rhf(self):
cell.verbose = 5 cell.charge = 0 cell.spin = 0 cell.build() sp_twist = [0.07761248, 0.07761248, -0.07761248] kmesh = [2, 1, 1] kpts = array([[0.07761248, 0.07761248, -0.07761248], [0.54328733, 0.54328733, -0.54328733]]) mydf = df.GDF(cell, kpts) mydf.auxbasis = 'weigend' mydf._cderi_to_save = 'df_ints.h5' mydf.build() mf = scf.KROHF(cell, kpts).density_fit() mf.exxdiv = 'ewald' mf.max_cycle = 200 mf.with_df = mydf mf.chkfile = 'diamond-scf.chk' mf.with_df._cderi = 'df_ints.h5' e_scf = mf.kernel() ener = open('e_scf', 'w') ener.write('%s\n' % (e_scf)) print('e_scf', e_scf) ener.close() title = "C_diamond-twist" from PyscfToQmcpack import savetoqmcpack
import pyscf.pbc.scf as pscf cell = pbcgto.Cell() cell.atom = ''' He 0 0 1 He 1 0 1 ''' cell.basis = [[0, [1., 1.]], [0, [0.5, 1]]] cell.a = numpy.eye(3) * 3 cell.mesh = [10] * 3 cell.verbose = 5 cell.output = '/dev/null' cell.build() nao = cell.nao_nr() kpts = cell.make_kpts([2, 1, 1]) kmf_ro = pscf.KROHF(cell, kpts=kpts).run() kmf_r = pscf.KRHF(cell, kpts=kpts).convert_from_(kmf_ro) kmf_u = pscf.addons.convert_to_uhf(kmf_r) kmf_g = pscf.addons.convert_to_ghf(kmf_r) def tearDownModule(): global cell, kmf_ro, kmf_r, kmf_u, kmf_g cell.stdout.close() del cell, kmf_ro, kmf_r, kmf_u, kmf_g class KnowValues(unittest.TestCase): def test_krhf_smearing(self): mf = pscf.KRHF(cell, cell.make_kpts([2, 1, 1])) nkpts = len(mf.kpts)
def init_env_scf(self, cell=None, env_method=None, kpts=None, rho_cutoff=None, verbose=None, damp=None, shift=None, grid_level=None, density_fit=None, auxbasis=None): """ Initializes the environment pyscf:pbc:scf object. Paramters --------- cell : pyscf:pbc:Cell object, optional env_method : str, optional Subsystem method for calculation (default is None). kpts : ndarray, optional Kpoints (in inv. bohr) to use (default is None). rho_cutoff : float, optional DFT density/rho cutoff parameter (default is None). verbose : int, optional Verbosity parameter (default is None). damp : float, optional Damping parameter (default is None). shift : float, optional level shift parameter for convergence (default is None). grid_level : int, optional Grid_level for DFT and Coulomb integration (default is None). density_fit : str, optional The default desnity fit method to use (default is None). auxbasis : str, optional Auxillary basis for density fitting (default is None). Returns ------- cSCF : pyscf.pbc.SCF object """ import numpy as np from pyscf.pbc import dft as pbcdft, scf as pbcscf, df as pbcdf if cell is None: cell = self.cell if env_method is None: env_method = self.env_method.lower() if kpts is None: kpts = self.kpts if rho_cutoff is None: rho_cutoff = self.rho_cutoff if verbose is None: verbose = self.verbose if damp is None: damp = self.damp if shift is None: shift = self.shift if grid_level is None: grid_level = self.grid_level if density_fit is None: density_fit = self.density_fit density_fit = density_fit.lower() if auxbasis is None: auxbasis = self.auxbasis if self.unrestricted: if env_method in ('hf', 'hartree-fock'): cSCF = pbcscf.KUHF(cell, kpts) else: cSCF = pbcscf.KUKS(cell, kpts) cSCF.xc = env_method elif cell.spin != 0: if env_method in ('hf', 'hartree-fock'): cSCF = pbcscf.KROHF(cell, kpts) else: cSCF = pbcscf.KROKS(cell, kpts) cSCF.xc = env_method else: if env_method in ('hf', 'hartree-fock'): cSCF = pbcscf.KRHF(cell, kpts) else: cSCF = pbcscf.KRKS(cell, kpts) cSCF.xc = env_method cSCF.kpts = kpts cSCF.verbose = verbose # grids should probably be for the supersystem # Keep this for now, although its probably expensive # to calculate the grids for each subsystem cSCF.grids = pbcdft.gen_grid.BeckeGrids(cell) cSCF.grids.level = grid_level cSCF.grids.build() # density fitting (can be very time consuming) if density_fit == 'fftdf': DensityFit = pbcdf.FFTDF elif density_fit == 'mdf': DensityFit = pbcdf.MDF elif density_fit == 'pwdf': DensityFit = pbcdf.PWDF elif density_fit == 'gdf': DensityFit = pbcdf.GDF elif density_fit == 'aftdf': DensityFit = pbcdf.AFTDF else: DensityFit = pbcdf.DF cSCF.with_df = DensityFit(cell) cSCF.with_df.kpts = kpts cSCF.with_df.auxbasis = auxbasis # # only for local and semi-local functional for now # cSCF.with_df.build(j_only=True) return cSCF
def test_nr_krohf(self): mf = scf.KROHF(cell, cell.make_kpts([2,1,1])).newton() mf.conv_tol_grad = 1e-4 mf.kernel() self.assertAlmostEqual(mf.e_tot, -10.5309059210831, 8)
def test_krohf_kernel(self): nk = [1, 1, 3] kpts = cell.make_kpts(nk, wrap_around=True) mf = pscf.KROHF(cell, kpts) mf.kernel() self.assertAlmostEqual(mf.e_tot, -3.381819789636646, 8)