Beispiel #1
0
    def read_wggmat(self, kpoint, spin1=0, spin2=0, cls=None):
        """
        Read data at the given k-point and return an instance of ``cls`` where
        ``cls`` is a subclass of :class:`_AwggMatrix`
        """
        cls = _AwggMatrix.class_from_netcdf_name(
            self.netcdf_name) if cls is None else cls

        var = self.rootgrp.variables[
            "reduced_coordinates_plane_waves_dielectric_function"]
        # Use ik=0 because the basis set is not k-dependent.
        ik0 = 0
        gvecs = var[ik0, :]
        #print("gvecs", gvecs)

        kpoint, ik = self.find_kpoint_fileindex(kpoint)

        # FIXME ecuteps is missing
        # TODO: Gpshere.find is very slow if we don't take advantage of shells
        ecuteps = 2
        gsphere = GSphere(ecuteps, self.structure.reciprocal_lattice, kpoint,
                          gvecs)

        # Exchange spin due to F --> C
        values = self.rootgrp.variables[self.netcdf_name][ik, :, spin2,
                                                          spin1, :, :, :]
        wggmat = values[:, :, :, 0] + 1j * values[:, :, :, 1]

        return cls(self.wpoints, gsphere, wggmat, inord="F")
Beispiel #2
0
    def test_awggmat_api(self):
        """Testing AwggMat API"""
        ecut = 2
        lattice = np.reshape(np.array([1., 0, 0, 0, 1, 0, 0, 0, 1]), (3, 3))
        kpoint = [0, 0, 0]
        gvecs = np.array([[0, 0, 0], [1, 0, 0]])
        gsphere = GSphere(ecut, lattice, kpoint, gvecs, istwfk=1)
        ng = len(gsphere)
        assert ng == len(gvecs)

        wpoints = [0, 1, 2, 3j, 4j]
        nw = len(wpoints)
        data = np.empty((nw, ng, ng), dtype=complex)

        f = _AwggMatrix(wpoints, gsphere, data, inord="C")
        repr(f)
        str(f)

        assert _AwggMatrix.class_from_netcdf_name(
            "inverse_dielectric_function") is InverseDielectricFunction
        with self.assertRaises(ValueError):
            _AwggMatrix.class_from_netcdf_name("foobar")

        assert f.kpoint == gsphere.kpoint
        assert f.ng == len(gsphere)
        assert f.nw == len(wpoints)
        assert f.nrew == 3 and f.nimw == 2 and f.nw == 5
        assert np.all(f.real_wpoints == [0, 1, 2])
        assert np.all(f.imag_wpoints == [3j, 4j])
        self.assert_equal(f.wggmat_realw, f.wggmat[:f.nrew])
        self.assert_equal(f.wggmat_imagw, f.wggmat[f.nrew:])
        assert f.windex(2) == 2
        assert f.windex(3j) == 3
        assert f.gindex([1, 0, 0]) == 1
        assert f.gindex(0) == 0

        for cplx_mode in ("re", "im", "abs", "angle"):
            assert len(f.latex_label(cplx_mode))

        if self.has_matplotlib():
            assert f.plot_freq(gvec1=0,
                               gvec2=None,
                               waxis="real",
                               cplx_mode="re-im",
                               show=False)
            assert f.plot_freq(gvec1=[0, 0, 0],
                               gvec2=[1, 0, 0],
                               waxis="imag",
                               cplx_mode="re-im",
                               show=False)
Beispiel #3
0
    def read_wggfunc(self, qpoint, cls):
        """
        Read data at the given q-point and return an instance
        of `cls` where `cls` is a subclass of `WGGFunction`
        """
        qpoint, iq = self.find_qpoint_fileindex(qpoint)
        # TODO: I don't remember how to slice in python-netcdf
        # ecuteps
        all_gvecs = self.read_value(
            "reduced_coordinates_plane_waves_dielectric_function")
        ecuteps = 2
        # TODO: Gpshere.find is very slow if we don't take advantage of shells
        gsphere = GSphere(ecuteps, self.structure.reciprocal_lattice, qpoint,
                          all_gvecs[iq])

        full_wggmat = self.read_value(cls.etsf_name, cmode="c")
        wggmat = full_wggmat[iq]

        return cls(qpoint, self.wpts, gsphere, wggmat, inord="F")