Skip to content

Commit

Permalink
NEED CONFIRM: replace BoltztrapError with more semantic exception
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Oct 4, 2024
1 parent 3e4fbad commit cec569f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
27 changes: 13 additions & 14 deletions src/pymatgen/electronic_structure/boltztrap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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])

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.!"
)
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions tests/electronic_structure/test_boltztrap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit cec569f

Please sign in to comment.