예제 #1
0
    def read_doses(self):
        """
        Return a |AttrDict| with the DOSes available in the file. Empty dict if
        DOSes are not available.
        """
        if "gruns_nomega" not in self.rootgrp.dimensions:
            cprint("File `%s` does not contain ph-DOSes, returning empty dict" % self.path, "yellow")
            return {}

        # Read q-point sampling used to compute DOSes.
        qptrlatt = self.read_value("gruns_qptrlatt")
        shifts = self.read_value("gruns_shiftq")
        qsampling = KSamplingInfo.from_kptrlatt(qptrlatt, shifts, kptopt=1)

        frac_coords_ibz = self.read_value("gruns_qibz")
        weights = self.read_value("gruns_wtq")
        qpoints = IrredZone(self.structure.reciprocal_lattice, frac_coords_ibz,
                            weights=weights, names=None, ksampling=qsampling)

        # DOSes are in 1/Hartree.
        d = AttrDict(wmesh=self.read_value("gruns_omega_mesh") * abu.Ha_eV, qpoints=qpoints)

        for dos_name in _ALL_DOS_NAMES:
            dos_idos = self.read_value(dos_name)
            dos_idos[0] *= abu.eV_Ha  # Here we convert to eV. IDOS are not changed.
            d[dos_name] = dos_idos

        return d
예제 #2
0
파일: gruneisen.py 프로젝트: gmatteo/abipy
    def read_doses(self):
        """
        Return a |AttrDict| with the DOSes available in the file. Empty dict if
        DOSes are not available.
        """
        if "gruns_nomega" not in self.rootgrp.dimensions:
            cprint("File `%s` does not contain ph-DOSes, returning empty dict" % self.path, "yellow")
            return {}

        # Read q-point sampling used to compute DOSes.
        qptrlatt = self.read_value("gruns_qptrlatt")
        shifts = self.read_value("gruns_shiftq")
        qsampling = KSamplingInfo.from_kptrlatt(qptrlatt, shifts, kptopt=1)

        frac_coords_ibz = self.read_value("gruns_qibz")
        weights = self.read_value("gruns_wtq")
        qpoints = IrredZone(self.structure.reciprocal_lattice, frac_coords_ibz,
                            weights=weights, names=None, ksampling=qsampling)

        # DOSes are in 1/Hartree.
        d = AttrDict(wmesh=self.read_value("gruns_omega_mesh") * abu.Ha_eV, qpoints=qpoints)

        for dos_name in _ALL_DOS_NAMES:
            dos_idos = self.read_value(dos_name)
            dos_idos[0] *= abu.eV_Ha  # Here we convert to eV. IDOS are not changed.
            d[dos_name] = dos_idos

        return d
예제 #3
0
    def test_ksampling(self):
        """Test KsamplingInfo API."""
        # from_mpdivs constructor
        mpdivs, shifts = [2, 3, 4], [0.5, 0.5, 0.5]
        kptopt = 1
        ksi = KSamplingInfo.from_mpdivs(mpdivs, shifts, kptopt)
        self.assert_equal(ksi.mpdivs, mpdivs)
        self.assert_equal(ksi.kptrlatt, np.diag(mpdivs))
        self.assert_equal(ksi.shifts.flatten(), shifts)
        assert ksi.kptopt == kptopt
        assert ksi.is_homogeneous
        print(ksi)

        # from kptrlatt constructor
        kptrlatt = np.diag(mpdivs)
        ksi = KSamplingInfo.from_kptrlatt(kptrlatt, shifts, kptopt)
        self.assert_equal(ksi.kptrlatt, np.diag(mpdivs))
        self.assert_equal(ksi.mpdivs, np.diag(ksi.kptrlatt))
        self.assert_equal(ksi.shifts.flatten(), shifts)
        assert ksi.kptopt == kptopt
        assert ksi.is_homogeneous
        print(ksi)

        # kptrlatt with non-zero off-diagonal elements.
        shifts = [0.5, 0.5, 0.5]
        kptrlatt = [1, 1, 1, 2, 2, 2, 3, 3, 3]
        kptopt = 1
        ksi = KSamplingInfo.from_kptrlatt(kptrlatt, shifts, kptopt)
        assert ksi.mpdivs is None
        print(ksi)

        # from_kbounds constructor
        kbounds = [0, 0, 0, 1, 1, 1]
        ksi = KSamplingInfo.from_kbounds(kbounds)
        assert (ksi.mpdivs, ksi.kptrlatt, ksi.kptrlatt_orig, ksi.shifts,
                ksi.shifts_orig) == 5 * (None, )
        assert ksi.kptopt == 1
        assert not ksi.is_homogeneous
        print(ksi)

        with self.assertRaises(ValueError):
            foo = KSamplingInfo(foo=1)
예제 #4
0
    def test_ksampling(self):
        """Test KsamplingInfo API."""
        with self.assertRaises(ValueError):
            KSamplingInfo(foo=1)

        # from_mpdivs constructor
        mpdivs, shifts = [2, 3, 4], [0.5, 0.5, 0.5]
        kptopt = 1
        ksi = KSamplingInfo.from_mpdivs(mpdivs, shifts, kptopt)
        repr(ksi)
        str(ksi)
        self.assert_equal(ksi.mpdivs, mpdivs)
        self.assert_equal(ksi.kptrlatt, np.diag(mpdivs))
        self.assert_equal(ksi.shifts.flatten(), shifts)
        assert ksi.shifts.shape == (1, 3)
        assert ksi.kptopt == kptopt
        assert ksi.is_mesh
        assert ksi.has_diagonal_kptrlatt
        assert not ksi.is_path

        # from kptrlatt constructor
        kptrlatt = np.diag(mpdivs)
        ksi = KSamplingInfo.from_kptrlatt(kptrlatt, shifts, kptopt)
        repr(ksi)
        str(ksi)
        assert ksi.kptrlatt.shape == (3, 3)
        self.assert_equal(ksi.kptrlatt, np.diag(mpdivs))
        self.assert_equal(ksi.mpdivs, np.diag(ksi.kptrlatt))
        self.assert_equal(ksi.shifts.flatten(), shifts)
        assert ksi.kptopt == kptopt
        assert ksi.is_mesh
        assert ksi.has_diagonal_kptrlatt
        assert not ksi.is_path

        # kptrlatt with non-zero off-diagonal elements.
        shifts = [0.5, 0.5, 0.5]
        kptrlatt = [1, 1, 1, 2, 2, 2, 3, 3, 3]
        kptopt = 1
        ksi = KSamplingInfo.from_kptrlatt(kptrlatt, shifts, kptopt)
        repr(ksi)
        str(ksi)
        assert ksi.mpdivs is None
        assert not ksi.has_diagonal_kptrlatt
        assert not ksi.is_path

        # from_kbounds constructor
        kbounds = [0, 0, 0, 1, 1, 1]
        ksi = KSamplingInfo.from_kbounds(kbounds)
        repr(ksi)
        str(ksi)
        assert (ksi.mpdivs, ksi.kptrlatt, ksi.kptrlatt_orig, ksi.shifts,
                ksi.shifts_orig) == 5 * (None, )
        assert ksi.kptopt == -1
        assert ksi.kptrlatt is None
        assert not ksi.is_mesh
        assert not ksi.has_diagonal_kptrlatt
        assert ksi.is_path

        assert ksi is KSamplingInfo.as_ksampling(ksi)

        ksi_from_dict = KSamplingInfo.as_ksampling(
            {k: v
             for k, v in ksi.items()})
        assert ksi_from_dict.kptopt == ksi.kptopt

        ksi_none = KSamplingInfo.as_ksampling(None)
        repr(ksi_none)
        str(ksi_none)
        assert ksi_none.kptopt == 0
        assert not ksi_none.is_mesh
        assert not ksi_none.is_path
예제 #5
0
    def test_ksampling(self):
        """Test KsamplingInfo API."""
        with self.assertRaises(ValueError):
            KSamplingInfo(foo=1)

        # from_mpdivs constructor
        mpdivs, shifts = [2, 3, 4], [0.5, 0.5, 0.5]
        kptopt = 1
        ksi = KSamplingInfo.from_mpdivs(mpdivs, shifts, kptopt)
        repr(ksi); str(ksi)
        self.assert_equal(ksi.mpdivs, mpdivs)
        self.assert_equal(ksi.kptrlatt, np.diag(mpdivs))
        self.assert_equal(ksi.shifts.flatten(), shifts)
        assert ksi.shifts.shape == (1, 3)
        assert ksi.kptopt == kptopt
        assert ksi.is_mesh
        assert ksi.has_diagonal_kptrlatt
        assert not ksi.is_path

        # from kptrlatt constructor
        kptrlatt = np.diag(mpdivs)
        ksi = KSamplingInfo.from_kptrlatt(kptrlatt, shifts, kptopt)
        repr(ksi); str(ksi)
        assert ksi.kptrlatt.shape == (3, 3)
        self.assert_equal(ksi.kptrlatt, np.diag(mpdivs))
        self.assert_equal(ksi.mpdivs, np.diag(ksi.kptrlatt))
        self.assert_equal(ksi.shifts.flatten(), shifts)
        assert ksi.kptopt == kptopt
        assert ksi.is_mesh
        assert ksi.has_diagonal_kptrlatt
        assert not ksi.is_path

        # kptrlatt with non-zero off-diagonal elements.
        shifts = [0.5, 0.5, 0.5]
        kptrlatt = [1, 1, 1, 2, 2, 2, 3, 3, 3]
        kptopt = 1
        ksi = KSamplingInfo.from_kptrlatt(kptrlatt, shifts, kptopt)
        repr(ksi); str(ksi)
        assert ksi.mpdivs is None
        assert not ksi.has_diagonal_kptrlatt
        assert not ksi.is_path

        # from_kbounds constructor
        kbounds = [0, 0, 0, 1, 1, 1]
        ksi = KSamplingInfo.from_kbounds(kbounds)
        repr(ksi); str(ksi)
        assert (ksi.mpdivs, ksi.kptrlatt, ksi.kptrlatt_orig, ksi.shifts, ksi.shifts_orig) == 5 * (None,)
        assert ksi.kptopt == -1
        assert ksi.kptrlatt is None
        assert not ksi.is_mesh
        assert not ksi.has_diagonal_kptrlatt
        assert ksi.is_path

        assert ksi is KSamplingInfo.as_ksampling(ksi)

        ksi_from_dict = KSamplingInfo.as_ksampling({k: v for k, v in ksi.items()})
        assert ksi_from_dict.kptopt == ksi.kptopt

        ksi_none = KSamplingInfo.as_ksampling(None)
        repr(ksi_none); str(ksi_none)
        assert ksi_none.kptopt == 0
        assert not ksi_none.is_mesh
        assert not ksi_none.is_path