diff --git a/ramannoodle/exceptions.py b/ramannoodle/exceptions.py index 866d929..1047382 100644 --- a/ramannoodle/exceptions.py +++ b/ramannoodle/exceptions.py @@ -29,7 +29,7 @@ class SymmetryException(Exception): """Symmetry operation failed.""" -class UsageError(Exception): +class UserError(Exception): """The user has done something they shouldn't. This exception is used sparingly, as (ideally) the structure of the API should @@ -135,7 +135,7 @@ def verify_positions(name: str, array: NDArray) -> None: raise ValueError(f"{name} has coordinates that are not between 0 and 1") -def get_torch_missing_error() -> UsageError: +def get_torch_missing_error() -> UserError: """Get error indicating that torch is not installed.""" required_modules = "'torch', 'torch-scatter', and 'torch-sparse' modules" - return UsageError(f"torch functionality requires {required_modules}") + return UserError(f"torch functionality requires {required_modules}") diff --git a/ramannoodle/io/generic.py b/ramannoodle/io/generic.py index 3558c1b..b42bdc8 100644 --- a/ramannoodle/io/generic.py +++ b/ramannoodle/io/generic.py @@ -16,13 +16,13 @@ from ramannoodle.dynamics.phonon import Phonons from ramannoodle.dynamics.trajectory import Trajectory from ramannoodle.structure.reference import ReferenceStructure -from ramannoodle.exceptions import UsageError, get_torch_missing_error +from ramannoodle.exceptions import UserError, get_torch_missing_error import ramannoodle.io.vasp as vasp_io TORCH_PRESENT = True try: from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset -except UsageError: +except UserError: TORCH_PRESENT = False # These map between file formats and appropriate IO functions. diff --git a/ramannoodle/io/io_utils.py b/ramannoodle/io/io_utils.py index 9515c99..0877152 100644 --- a/ramannoodle/io/io_utils.py +++ b/ramannoodle/io/io_utils.py @@ -14,14 +14,14 @@ verify_list_len, IncompatibleStructureException, get_torch_missing_error, - UsageError, + UserError, ) from ramannoodle.globals import ATOM_SYMBOLS TORCH_PRESENT = True try: from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset -except UsageError: +except UserError: TORCH_PRESENT = False diff --git a/ramannoodle/io/vasp/outcar.py b/ramannoodle/io/vasp/outcar.py index 7baae6e..2a3258e 100644 --- a/ramannoodle/io/vasp/outcar.py +++ b/ramannoodle/io/vasp/outcar.py @@ -12,14 +12,14 @@ ) from ramannoodle.exceptions import InvalidFileException, NoMatchingLineFoundException from ramannoodle.globals import ATOMIC_WEIGHTS, ATOMIC_NUMBERS -from ramannoodle.exceptions import get_type_error, UsageError +from ramannoodle.exceptions import get_type_error, UserError from ramannoodle.dynamics.phonon import Phonons from ramannoodle.dynamics.trajectory import Trajectory from ramannoodle.structure.reference import ReferenceStructure try: from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset -except UsageError: +except UserError: pass diff --git a/ramannoodle/io/vasp/vasprun.py b/ramannoodle/io/vasp/vasprun.py index c2b0287..3a85ae2 100644 --- a/ramannoodle/io/vasp/vasprun.py +++ b/ramannoodle/io/vasp/vasprun.py @@ -9,7 +9,7 @@ from numpy.typing import NDArray from ramannoodle.io.io_utils import pathify, _read_polarizability_dataset -from ramannoodle.exceptions import InvalidFileException, UsageError +from ramannoodle.exceptions import InvalidFileException, UserError from ramannoodle.globals import ATOMIC_WEIGHTS, ATOMIC_NUMBERS from ramannoodle.dynamics.phonon import Phonons from ramannoodle.dynamics.trajectory import Trajectory @@ -17,7 +17,7 @@ try: from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset -except UsageError: +except UserError: pass diff --git a/ramannoodle/polarizability/art.py b/ramannoodle/polarizability/art.py index c03a462..8f7c3d5 100644 --- a/ramannoodle/polarizability/art.py +++ b/ramannoodle/polarizability/art.py @@ -15,7 +15,7 @@ get_shape_error, verify_ndarray_shape, InvalidDOFException, - UsageError, + UserError, ) @@ -88,7 +88,7 @@ def add_dof( # pylint: disable=too-many-arguments :meta private: """ - raise UsageError("add_dof should not be used; use add_art instead") + raise UserError("add_dof should not be used; use add_art instead") def add_dof_from_files( self, @@ -104,7 +104,7 @@ def add_dof_from_files( :meta private: """ - raise UsageError( + raise UserError( "add_dof_from_files should not be used; use add_art_from_files instead" ) diff --git a/ramannoodle/polarizability/interpolation.py b/ramannoodle/polarizability/interpolation.py index 7fee0a1..96d50ca 100644 --- a/ramannoodle/polarizability/interpolation.py +++ b/ramannoodle/polarizability/interpolation.py @@ -28,7 +28,7 @@ get_shape_error, verify_ndarray_shape, DOFWarning, - UsageError, + UserError, ) import ramannoodle.io.generic as generic_io from ramannoodle.io.io_utils import pathify_as_list @@ -237,7 +237,7 @@ def calc_polarizabilities( ) except ValueError as err: if self._is_dummy_model: - raise UsageError( + raise UserError( "dummy model cannot calculate polarizabilities" ) from err raise err diff --git a/ramannoodle/polarizability/torch/gnn.py b/ramannoodle/polarizability/torch/gnn.py index 2ed4956..6bd589d 100644 --- a/ramannoodle/polarizability/torch/gnn.py +++ b/ramannoodle/polarizability/torch/gnn.py @@ -12,7 +12,7 @@ from ramannoodle.structure.reference import ReferenceStructure from ramannoodle.exceptions import ( get_torch_missing_error, - UsageError, + UserError, verify_ndarray_shape, ) from ramannoodle.polarizability.abstract import PolarizabilityModel @@ -33,7 +33,7 @@ from torch_geometric.nn.models.schnet import ShiftedSoftplus from torch_geometric.utils import scatter import ramannoodle.polarizability.torch.utils as rn_torch_utils -except (ModuleNotFoundError, UsageError) as exc: +except (ModuleNotFoundError, UserError) as exc: raise get_torch_missing_error() from exc # pylint: disable=not-callable diff --git a/ramannoodle/polarizability/torch/train.py b/ramannoodle/polarizability/torch/train.py index 1feee2e..bf31a31 100644 --- a/ramannoodle/polarizability/torch/train.py +++ b/ramannoodle/polarizability/torch/train.py @@ -5,7 +5,7 @@ from ramannoodle.exceptions import ( # pylint: disable=ungrouped-imports get_torch_missing_error, - UsageError, + UserError, ) try: @@ -16,7 +16,7 @@ from ramannoodle.polarizability.torch.gnn import PotGNN from ramannoodle.polarizability.torch.dataset import PolarizabilityDataset -except (ModuleNotFoundError, UsageError) as exc: +except (ModuleNotFoundError, UserError) as exc: raise get_torch_missing_error() from exc diff --git a/test/tests/test_art.py b/test/tests/test_art.py index 33365c6..cf3edb1 100644 --- a/test/tests/test_art.py +++ b/test/tests/test_art.py @@ -7,7 +7,7 @@ import pytest from ramannoodle.polarizability.art import ARTModel -from ramannoodle.exceptions import InvalidDOFException, UsageError +from ramannoodle.exceptions import InvalidDOFException, UserError from ramannoodle.structure.reference import ReferenceStructure # pylint: disable=protected-access @@ -355,15 +355,15 @@ def test_dummy_art( assert "atomic Raman tensors are masked" in repr(model) assert len(model.cart_basis_vectors) == known_dof_added assert np.isclose(np.linalg.norm(model.cart_basis_vectors[0]), 1) - with pytest.raises(UsageError) as err: + with pytest.raises(UserError) as err: model.add_dof(np.array([]), np.array([]), np.array([]), 1, False) assert "add_dof should not be used; use add_art instead" in str(err.value) - with pytest.raises(UsageError) as err: + with pytest.raises(UserError) as err: model.add_dof_from_files(["blah"], "blah", 1) assert ( "add_dof_from_files should not be used; use add_art_from_files instead" in str(err.value) ) - with pytest.raises(UsageError) as err: + with pytest.raises(UserError) as err: model.calc_polarizabilities(np.array([ref_structure.positions])) assert "dummy model cannot calculate polarizabilities" in str(err.value)