예제 #1
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 = 'sto-3g'
        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)

        # K-points
        cls.model_krhf = model_krhf = KRHF(cell, k).density_fit()
        model_krhf.with_df._cderi = cls.df_file
        model_krhf.conv_tol = 1e-14
        model_krhf.kernel()

        cls.td_model_krhf = td_model_krhf = ktd.TDRHF(model_krhf)
        td_model_krhf.nroots = 10
        td_model_krhf.kernel()

        cls.gw_model_krhf = gw_model_krhf = kgw.GW(td_model_krhf)
        gw_model_krhf.kernel()
예제 #2
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)

        # K-points
        cls.model_krhf = model_krhf = KRHF(cell, k).density_fit()
        model_krhf.kernel()

        # Gamma
        cls.td_model_rhf_gamma = gtd.TDRHF(model_krhf)
        cls.td_model_rhf_gamma.kernel()
        cls.ref_m_gamma = cls.td_model_rhf_gamma.eri.tdhf_full_form()

        # Supercell
        cls.td_model_rhf_supercell = std.TDRHF(model_krhf)
        cls.td_model_rhf_supercell.kernel()
        cls.ref_m_supercell = cls.td_model_rhf_supercell.eri.tdhf_full_form()
예제 #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()

        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)
예제 #4
0
    def test_class(self):
        """Tests container behavior (frozen vs non-frozen)."""
        model = ktd.TDRHF(self.model_krhf, frozen=2)
        model.nroots = self.td_model_krhf.nroots
        model.kernel()

        gw_model = kgw.GW(model)
        gw_model.kernel()

        testing.assert_allclose(gw_model.mo_energy, self.gw_model_krhf.mo_energy[:, 2:], atol=1e-4)
예제 #5
0
 def test_class(self):
     """Tests container behavior."""
     model = ktd.TDRHF(self.model_krhf)
     model.nroots = self.td_model_rhf.nroots
     assert not model.fast
     model.kernel()
     testing.assert_allclose(model.e, self.td_model_rhf.e, atol=1e-5)
     nocc = nvirt = 4
     testing.assert_equal(model.xy.shape,
                          (len(model.e), 2, 1, 1, nocc, nvirt))
     assert_vectors_close(model.xy.squeeze(),
                          numpy.array(self.td_model_rhf.xy).squeeze(),
                          atol=1e-9)
예제 #6
0
 def test_class(self):
     """Tests container behavior."""
     model = ktd.TDRHF(self.model_krhf)
     model.nroots = self.td_model_rhf.nroots
     assert not model.fast
     model.kernel()
     testing.assert_allclose(model.e, self.td_model_rhf.e, atol=1e-5)
     nocc = nvirt = 4
     testing.assert_equal(model.xy.shape,
                          (len(model.e), 2, self.k, self.k, nocc, nvirt))
     vecs = model.xy.reshape(len(model.xy), -1)[:, self.ov_order]
     assert_vectors_close(vecs,
                          numpy.array(self.td_model_rhf.xy).squeeze(),
                          atol=1e-5)
     # Test real
     testing.assert_allclose(model.e.imag, 0, atol=1e-8)
예제 #7
0
 def test_class(self):
     """Tests container behavior."""
     model = ktd.TDRHF(self.model_krhf)
     model.nroots = self.td_model_krhf.nroots
     assert model.fast
     model.kernel()
     e, xy = model.kernel()
     model.fast = False
     model.kernel()
     # Slow vs fast
     testing.assert_allclose(model.e, e)
     assert_vectors_close(model.xy, xy)
     # ... vs ref
     testing.assert_allclose(model.e, self.td_model_krhf.e, atol=1e-5)
     assert_vectors_close(model.xy.squeeze(),
                          numpy.array(self.td_model_krhf.xy).squeeze(),
                          atol=1e-12)
예제 #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)

        # K-points
        cls.model_krhf = model_krhf = KRHF(cell, k).density_fit()
        model_krhf.conv_tol = 1e-14
        model_krhf.kernel()

        ke = numpy.concatenate(model_krhf.mo_energy)
        ke.sort()

        # Make sure no degeneracies are present
        testing.assert_array_less(1e-4, ke[1:] - ke[:-1])

        # TD
        cls.td_model_srhf = td_model_srhf = std.TDRHF(model_krhf)
        td_model_srhf.kernel()

        cls.td_model_krhf = td_model_krhf = ktd.TDRHF(model_krhf)
        td_model_krhf.kernel()

        # adjust_td_phase(td_model_srhf, td_model_krhf)

        # GW
        cls.gw = sgw.GW(td_model_srhf)
        cls.kgw = kgw.GW(td_model_krhf)
예제 #9
0
    def test_imds_frozen(self):
        """Tests intermediates: frozen vs non-frozen."""
        frozen = 2
        sample_ref = (0, 2)
        sample_frozen = (0, 0)

        td = ktd.TDRHF(self.model_krhf, frozen=frozen)
        td.nroots = self.td_model_krhf.nroots
        td.kernel()

        adjust_td_phase(self.td_model_krhf, td)

        testing.assert_allclose(self.td_model_krhf.e, td.e, atol=1e-4)
        testing.assert_allclose(self.td_model_krhf.xy[..., 2:, :], td.xy, atol=1e-3)

        gw_frozen = kgw.GW(td)
        gw_frozen.kernel()

        selection = gw_frozen.imds.eri.space
        selection_o = numpy.concatenate(tuple(i[:j] for i, j in zip(selection, self.gw_model_krhf.imds.eri.nocc)))
        selection_v = numpy.concatenate(tuple(i[j:] for i, j in zip(selection, self.gw_model_krhf.imds.eri.nocc)))
        selection = numpy.concatenate([selection_o, selection_v])

        imd_ref = self.gw_model_krhf.imds.tdm[..., selection, :][..., selection]
        testing.assert_allclose(gw_frozen.imds.tdm, imd_ref, atol=1e-4)

        test_energies = numpy.linspace(-2, 3, 300)
        ref_samples = numpy.array(tuple(
            self.gw_model_krhf.imds.get_sigma_element(i, sample_ref, 0.01)
            for i in test_energies
        ))
        frozen_samples = numpy.array(tuple(
            gw_frozen.imds.get_sigma_element(i, sample_frozen, 0.01)
            for i in test_energies
        ))

        testing.assert_allclose(ref_samples, frozen_samples, atol=1e-4)
        testing.assert_allclose(
            self.gw_model_krhf.imds.get_rhs(sample_ref),
            gw_frozen.imds.get_rhs(sample_frozen),
            atol=1e-14,
        )
예제 #10
0
    def test_class(self):
        """Tests container behavior (frozen vs non-frozen)."""
        for frozen in (1, [0, 1]):
            try:
                model = ktd.TDRHF(self.model_krhf, frozen=frozen)
                model.nroots = self.td_model_krhf.nroots
                model.kernel()
                mask_o, mask_v = tdhf_frozen_mask(model.eri, kind="o,v")
                testing.assert_allclose(model.e,
                                        self.td_model_krhf.e,
                                        atol=1e-4)
                assert_vectors_close(
                    model.xy,
                    numpy.array(self.td_model_krhf.xy)[..., mask_o, :][...,
                                                                       mask_v],
                    atol=1e-3,
                )

            except Exception:
                print(
                    "When testing class with frozen={} the following exception occurred:"
                    .format(repr(frozen)))
                raise
예제 #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])

        # K-points
        cls.model_krks = model_krks = KRKS(cell, k)
        model_krks.conv_tol = 1e-14
        model_krks.kernel()

        # TD
        cls.td_model_srks = td_model_srks = stdp.TDProxy(
            model_krks, "dft", [cls.k, 1, 1], KRKS)
        td_model_srks.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 = sgw.GW(td_model_srks, std.TDRHF(model_krks).ao2mo())
        cls.kgw = kgw.GW(td_model_krks, ktd.TDRHF(model_krks).ao2mo())
예제 #12
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])

        # K-points
        cls.model_krhf = model_krhf = KRHF(cell, k).density_fit()
        model_krhf.conv_tol = 1e-14
        model_krhf.kernel()

        # Add random phases
        numpy.random.seed(0)
        for i in model_krhf.mo_coeff:
            i *= numpy.exp(2.j * numpy.pi *
                           numpy.random.rand(i.shape[1]))[numpy.newaxis, :]

        # The slow supercell KTDHF
        cls.td_model_krhf = td_model_krhf = krhf_slow_supercell.TDRHF(
            model_krhf)
        td_model_krhf.kernel()
        cls.ref_m = td_model_krhf.eri.tdhf_full_form()
예제 #13
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)