예제 #1
0
    def test_cplx(self):
        """Tests whether complex conjugation is handled correctly."""
        # Perform mf calculation
        model_rhf = RHF(self.cell)
        model_rhf.kernel()

        # Add random phases
        import numpy
        numpy.random.seed(0)
        p = numpy.exp(2.j * numpy.pi * numpy.random.rand(model_rhf.mo_coeff.shape[1]))
        model_rhf.mo_coeff = model_rhf.mo_coeff * p[numpy.newaxis, :]

        m_ref = PhysERI(model_rhf).tdhf_full_form()

        td_model_rhf = TDRHF(model_rhf)
        assert not td_model_rhf.fast
        td_model_rhf.kernel()
        with self.assertRaises(ValueError):
            td_model_rhf.fast = True
            td_model_rhf.kernel()

        self.assertIsInstance(td_model_rhf.eri, PhysERI4)
        m = td_model_rhf.eri.tdhf_full_form()

        testing.assert_allclose(m, m_ref, atol=1e-14)
예제 #2
0
    def test_tdhf_gamma_point(self):
        mf = RHF(cell).run()
        mf.exxdiv = None
        td_model = tdscf.TDHF(mf)
        td_model.conv_tol = 1e-4
        td_model.kernel()
        e1 = td_model.e

        kmf = KRHF(cell, cell.make_kpts([1, 1, 1])).run()
        kmf.exxdiv = None
        td_model = tdscf.KTDHF(kmf)
        td_model.conv_tol = 1e-4
        td_model.kernel()
        e2 = td_model.e
        self.assertAlmostEqual(abs(e1 - e2).max(), 0, 4)
예제 #3
0
    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()

        cls.model_rhf = model_rhf = RHF(cell)
        model_rhf.kernel()

        cls.td_model_rhf = td_model_rhf = TDHF(model_rhf)
        td_model_rhf.nroots = 5
        td_model_rhf.kernel()

        cls.ref_m_rhf = retrieve_m(td_model_rhf)
예제 #4
0
    def test_tdhf_gamma_point(self):
        mf = RHF(cell).run()
        td_model = tdscf.TDHF(mf)
        td_model.kernel()
        e1 = td_model.e

        kmf = KRHF(cell, cell.make_kpts([1, 1, 1])).run()
        td_model = tdscf.KTDHF(kmf)
        td_model.kernel()
        e2 = td_model.e
        self.assertAlmostEqual(abs(e1-e2).max(), 0, 6)
        self.assertAlmostEqual(abs(e1 - 1.0301736485136344).max(), 0, 6)
예제 #5
0
    def test_tda_gamma_point(self):
        mf = RHF(cell).run()
        td_model = tdscf.TDA(mf)
        td_model.kernel()
        e1 = td_model.e

        kmf = KRHF(cell, cell.make_kpts([1, 1, 1])).run()
        td_model = tdscf.KTDA(kmf)
        td_model.kernel()
        e2 = td_model.e
        self.assertAlmostEqual(abs(e1-e2).max(), 0, 6)
        self.assertAlmostEqual(abs(e1 - 1.0329858545904074).max(), 0, 6)
예제 #6
0
    def test_tdhf_gamma_point(self):
        mf = RHF(cell).run()
        td_model = tdscf.TDHF(mf)
        td_model.conv_tol = 1e-4
        td_model.kernel()
        e1 = td_model.e

        kmf = KRHF(cell, cell.make_kpts([1, 1, 1])).run()
        td_model = tdscf.KTDHF(kmf)
        td_model.conv_tol = 1e-4
        td_model.kernel()
        e2 = td_model.e
        self.assertAlmostEqual(abs(e1 - e2).max(), 0, 4)
        self.assertAlmostEqual(lib.finger(e1), 1.1580752883710259, 5)
예제 #7
0
    def test_tda_gamma_point(self):
        mf = RHF(cell).run()
        td_model = tdscf.TDA(mf)
        td_model.conv_tol = 1e-4
        td_model.kernel()
        e1 = td_model.e

        kmf = KRHF(cell, cell.make_kpts([1, 1, 1])).run()
        td_model = tdscf.KTDA(kmf)
        td_model.conv_tol = 1e-4
        td_model.kernel()
        e2 = td_model.e
        self.assertAlmostEqual(abs(e1 - e2).max(), 0, 4)
        self.assertAlmostEqual(lib.finger(e1), 1.1612366465054151, 5)
예제 #8
0
    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()
예제 #9
0
    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.get_abs_kpts((.1, .2, .3))

        # The Gamma-point reference
        cls.model_rhf = model_rhf = RHF(cell, k).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)

        testing.assert_allclose(model_rhf.mo_energy, model_krhf.mo_energy[0])
        testing.assert_allclose(model_rhf.mo_coeff, model_krhf.mo_coeff[0])

        # 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()
예제 #10
0
    alat0 = 3.6
    axes = (np.ones((3, 3)) - np.eye(3)) * alat0 / 2.0
    elem = ['C', 'C']
    pos = np.array([[0, 0, 0], [0.5, 0.5, 0.5]]) * alat0
    atoms = pqscf.atom_text(elem, pos)

    gs = np.array([mygs] * 3)
    basis = bfd_basis()

    cell = gto.M(a=axes,
                 atom=atoms,
                 verbose=3,
                 gs=gs,
                 pseudo={'C': 'bfd'},
                 basis=basis)
    mf = RHF(cell)
    mf.chkfile = chkfile_fname
    mf.conv_tol = 1e-6

    # run or load RHF
    if os.path.isfile(chkfile_fname):
        from pyscf import lib
        mf.__dict__.update(lib.chkfile.load(chkfile_fname, 'scf'))
    else:
        mf.kernel()
    # end if

    # grid density for molecular orbital
    mydgs = 16
    dgs = np.array([mydgs] * 3)
    moR_fname = 'gs%d_' % mydgs + moR_fname
예제 #11
0
    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)
예제 #12
0
  chkfile_fname = 'bfd.h5'
  moR_fname     = 'moR.dat'
  rho_fname     = 'rho.dat'
  alat0 = 3.6
  axes  = (np.ones((3,3))-np.eye(3))*alat0/2.0
  elem  = ['C','C']
  pos   = np.array([[0,0,0],[0.5,0.5,0.5]])*alat0
  atoms = pqscf.atom_text(elem,pos)

  gs    = np.array([mygs]*3)
  basis = bfd_basis()

  cell = gto.M(a=axes,atom=atoms,verbose=3
    ,gs=gs,pseudo={'C':'bfd'},basis=basis)
  mf = RHF(cell)
  mf.chkfile  = chkfile_fname
  mf.conv_tol = 1e-6

  # run or load RHF
  if os.path.isfile(chkfile_fname):
    from pyscf import lib
    mf.__dict__.update(lib.chkfile.load(chkfile_fname,'scf'))
  else:
    mf.kernel()
  # end if

  # grid density for molecular orbital
  mydgs = 16
  dgs = np.array([mydgs]*3)
  moR_fname = 'gs%d_'%mydgs+moR_fname