From e9c1b3c85d4610d1a479d19c0afac3f6736d23b2 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Wed, 16 Oct 2024 06:01:38 -0400 Subject: [PATCH] change EquationOfState.get_bulk_modulus exception type on bad unit to ValueError --- .pre-commit-config.yaml | 6 +++--- chgnet/model/dynamics.py | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a0de1493..5f0a13d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ default_install_hook_types: [pre-commit, commit-msg] repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.5 + rev: v0.6.9 hooks: - id: ruff args: [--fix] @@ -13,7 +13,7 @@ repos: types_or: [python, jupyter] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-case-conflict - id: check-symlinks @@ -48,7 +48,7 @@ repos: - svelte - repo: https://github.com/pre-commit/mirrors-eslint - rev: v9.10.0 + rev: v9.12.0 hooks: - id: eslint types: [file] diff --git a/chgnet/model/dynamics.py b/chgnet/model/dynamics.py index 45cc9e4b..dd63b26d 100644 --- a/chgnet/model/dynamics.py +++ b/chgnet/model/dynamics.py @@ -845,7 +845,7 @@ def fit( self.bm.fit() self.fitted = True - def get_bulk_modulus(self, unit: str = "eV/A^3") -> float: + def get_bulk_modulus(self, unit: Literal["eV/A^3", "GPa"] = "eV/A^3") -> float: """Get the bulk modulus of from the fitted Birch-Murnaghan equation of state. Args: @@ -853,7 +853,10 @@ def get_bulk_modulus(self, unit: str = "eV/A^3") -> float: Default = "eV/A^3" Returns: - Bulk Modulus (float) + float: Bulk Modulus + + Raises: + ValueError: If the equation of state is not fitted. """ if self.fitted is False: raise ValueError( @@ -863,7 +866,7 @@ def get_bulk_modulus(self, unit: str = "eV/A^3") -> float: return self.bm.b0 if unit == "GPa": return self.bm.b0_GPa - raise NotImplementedError("unit has to be eV/A^3 or GPa") + raise ValueError("unit has to be eV/A^3 or GPa") def get_compressibility(self, unit: str = "A^3/eV") -> float: """Get the bulk modulus of from the fitted Birch-Murnaghan equation of state.