Example #1
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()

                e = numpy.concatenate(tuple(model.e[i] for i in range(self.k)))
                ref_e = numpy.concatenate(
                    tuple(self.td_model_krhf.e[i] for i in range(self.k)))
                testing.assert_allclose(e, ref_e, atol=1e-4)

                mask_o, mask_v = tdhf_frozen_mask(model.eri, kind="o,v")
                for k in range(self.k):
                    try:
                        assert_vectors_close(
                            model.xy[k],
                            numpy.array(
                                self.td_model_krhf.xy[k])[...,
                                                          mask_o, :][...,
                                                                     mask_v],
                            atol=1e-3)
                    except Exception:
                        print(
                            "When comparing vectors @k={:d} the following exception occurred:"
                            .format(k))
                        raise

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

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

        # The slow supercell KTDHF
        cls.td_model_krhf = td_model_krhf = krhf_slow.TDRHF(model_krhf)
        td_model_krhf.kernel()
        cls.ref_m = tuple(td_model_krhf.eri.tdhf_full_form(i) for i in range(cls.k))
Example #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 = '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_to_save = cls.df_file
        model_krhf.with_df._cderi = cls.df_file
        model_krhf.conv_tol = 1e-14
        model_krhf.kernel()

        cls.td_model_krhf = model_ktd = ktd.TDRHF(model_krhf)
        model_ktd.nroots = 5
        model_ktd.kernel()
Example #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)
Example #5
0
 def test_class_gamma(self):
     """Tests container behavior (gamma-point only)."""
     model = ktd.TDRHF(self.model_krhf)
     model.kernel(k=0)
     self.assertNotIn("__full_eri_k__", dir(model.eri))
     self.assertNotIn("__full_eri__", dir(model.eri))
     testing.assert_allclose(model.e[0],
                             self.td_model_rhf_gamma.e,
                             atol=1e-12)
     nocc = nvirt = 4
     testing.assert_equal(model.xy[0].shape,
                          (len(model.e[0]), 2, self.k, nocc, nvirt))
     assert_vectors_close(model.xy[0],
                          self.td_model_rhf_gamma.xy,
                          atol=1e-9)
Example #6
0
    def test_eig_kernel(self):
        """Tests container behavior (supercell)."""
        model = ktd.TDRHF(self.model_krhf)
        assert not model.fast
        model.kernel()
        o = v = 4

        # Concatenate everything
        ks = numpy.array(
            sum(([i] * len(model.e[i]) for i in range(self.k)), []))
        vals = numpy.concatenate(tuple(model.e[i] for i in range(self.k))).real
        vecs = numpy.concatenate(tuple(model.xy[i] for i in range(self.k)),
                                 axis=0)

        # Obtain order
        order = numpy.argsort(vals)

        # Sort
        vals = vals[order]
        vecs = vecs[order]
        ks = ks[order]

        # Verify
        testing.assert_allclose(vals, self.td_model_rhf_supercell.e, atol=1e-7)
        for k in range(self.k):
            # Prepare indexes
            r1, r2, c1, c2 = ktd.get_block_k_ix(model.eri, k)
            r = k2k(r1, r2)
            c = k2k(c1, c2)

            # Select roots
            selection = ks == k
            vecs_ref = self.td_model_rhf_supercell.xy[selection]
            vecs_test = vecs[selection]

            vecs_test_padded = numpy.zeros(
                (len(vecs_test), 2 * self.k * self.k, o, v),
                dtype=vecs_test.dtype)
            vecs_test_padded[:, c] = vecs_test.reshape(
                (len(vecs_test), 2 * self.k, o, v))
            vecs_test_padded = vecs_test_padded.reshape(vecs_ref.shape)

            testing.assert_equal(vecs_test.shape,
                                 (self.k * o * v, 2, self.k, o, v))
            testing.assert_equal(vecs_test_padded.shape,
                                 (self.k * o * v, 2, self.k, self.k, o, v))
            assert_vectors_close(vecs_test_padded, vecs_ref, atol=1e-7)
Example #7
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)

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

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

        selection = gw_frozen.imds.eri.space[0]

        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,
        )
Example #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)
Example #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.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())