diff --git a/src/pymatgen/electronic_structure/boltztrap2.py b/src/pymatgen/electronic_structure/boltztrap2.py index 40e54eefdff..dda4f3c8311 100644 --- a/src/pymatgen/electronic_structure/boltztrap2.py +++ b/src/pymatgen/electronic_structure/boltztrap2.py @@ -35,7 +35,6 @@ from tqdm import tqdm from pymatgen.electronic_structure.bandstructure import BandStructure, BandStructureSymmLine, Spin -from pymatgen.electronic_structure.boltztrap import BoltztrapError from pymatgen.electronic_structure.dos import CompleteDos, Dos, Orbital from pymatgen.electronic_structure.plotter import BSPlotter, DosPlotter from pymatgen.io.ase import AseAtomsAdaptor @@ -52,7 +51,7 @@ from BoltzTraP2 import bandlib as BL from BoltzTraP2 import fite, sphere, units except ImportError as exc: - raise BoltztrapError("BoltzTraP2 has to be installed and working") from exc + raise ImportError("BoltzTraP2 has to be installed and working") from exc __author__ = "Francesco Ricci" @@ -85,7 +84,7 @@ def __init__(self, obj, structure=None, nelect=None) -> None: elif isinstance(obj, BandStructure): bs_obj = obj else: - raise BoltztrapError("The object provided is neither a Bandstructure nor a Vasprun.") + raise TypeError("The object provided is neither a Bandstructure nor a Vasprun.") self.kpoints = np.array([kp.frac_coords for kp in bs_obj.kpoints]) @@ -94,7 +93,7 @@ def __init__(self, obj, structure=None, nelect=None) -> None: elif structure: self.structure = structure else: - raise BoltztrapError("A structure must be given.") + raise ValueError("A structure must be given.") self.atoms = AseAtomsAdaptor.get_atoms(self.structure) self.proj_all = None @@ -131,7 +130,7 @@ def __init__(self, obj, structure=None, nelect=None) -> None: elif self.vbm_idx: self.nelect_all = self.vbm_idx + self.cbm_idx + 1 else: - raise BoltztrapError("nelect must be given.") + raise ValueError("nelect must be given.") @classmethod def from_file(cls, vasprun_file: str | Path) -> Self: @@ -322,7 +321,7 @@ def __init__(self, vrun_obj=None) -> None: self.proj = next(iter(vrun_obj.projected_eigenvalues.values())) elif len(vrun_obj.eigenvalues) == 2: - raise BoltztrapError("spin bs case not implemented") + raise NotImplementedError("spin bs case not implemented") self.lattvec = self.atoms.get_cell().T * units.Angstrom @@ -466,7 +465,7 @@ def load(self, fname="bztInterp.json.gz"): self.equivalences, coeffs = loadfn(fname) bands_loaded = False else: - raise BoltztrapError("Something wrong reading the data file!") + raise RuntimeError("Something wrong reading the data file!") self.coeffs = coeffs[0] + coeffs[1] * 1j return bands_loaded @@ -582,7 +581,7 @@ def get_partial_doses(self, tdos, eband_ud, spins, enr, npts_mu, T, progress): progress: Default False, If True a progress bar is shown. """ if not self.data.proj: - raise BoltztrapError("No projections loaded.") + raise ValueError("No projections loaded.") bkp_data_ebands = np.copy(self.data.ebands) @@ -1036,13 +1035,13 @@ def plot_props( props_short = tuple(p[: len(prop_y)] for p in props) if prop_y not in props_short: - raise BoltztrapError("prop_y not valid") + raise ValueError("prop_y not valid") if prop_x not in {"mu", "doping", "temp"}: - raise BoltztrapError("prop_x not valid") + raise ValueError("prop_x not valid") if prop_z not in {"doping", "temp"}: - raise BoltztrapError("prop_z not valid") + raise ValueError("prop_z not valid") idx_prop = props_short.index(prop_y) @@ -1078,7 +1077,7 @@ def plot_props( plt.xlabel(r"$\mu$ (eV)", fontsize=30) plt.xlim(xlim) else: - raise BoltztrapError( + raise ValueError( "only prop_x=mu and prop_z=temp are \ available for c.c. and Hall c.c.!" ) @@ -1155,7 +1154,7 @@ def plot_props( def plot_bands(self): """Plot a band structure on symmetry line using BSPlotter().""" if self.bzt_interp is None: - raise BoltztrapError("BztInterpolator not present") + raise ValueError("BztInterpolator not present") sbs = self.bzt_interp.get_band_structure() @@ -1164,7 +1163,7 @@ def plot_bands(self): def plot_dos(self, T=None, npoints=10000): """Plot the total Dos using DosPlotter().""" if self.bzt_interp is None: - raise BoltztrapError("BztInterpolator not present") + raise ValueError("BztInterpolator not present") tdos = self.bzt_interp.get_dos(T=T, npts_mu=npoints) dosPlotter = DosPlotter() diff --git a/tests/electronic_structure/test_boltztrap2.py b/tests/electronic_structure/test_boltztrap2.py index cc606fd2484..cdb75a24532 100644 --- a/tests/electronic_structure/test_boltztrap2.py +++ b/tests/electronic_structure/test_boltztrap2.py @@ -9,7 +9,6 @@ from monty.tempfile import ScratchDir from pytest import approx -from pymatgen.electronic_structure.boltztrap import BoltztrapError from pymatgen.electronic_structure.core import OrbitalType, Spin from pymatgen.io.vasp import Vasprun from pymatgen.util.testing import TEST_FILES_DIR @@ -24,7 +23,7 @@ VasprunLoader, ) -except BoltztrapError: +except ImportError: pytest.skip("No boltztrap2", allow_module_level=True) TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/boltztrap2"