diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7f02dcec708..3bf40e2da8b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.1 + rev: v0.3.2 hooks: - id: ruff args: [--fix, --unsafe-fixes] diff --git a/pymatgen/alchemy/materials.py b/pymatgen/alchemy/materials.py index da22c9008e2..f3f5e1efeff 100644 --- a/pymatgen/alchemy/materials.py +++ b/pymatgen/alchemy/materials.py @@ -229,15 +229,20 @@ def __str__(self) -> str: output.extend(("\nOther parameters", "------------", str(self.other_parameters))) return "\n".join(output) - def set_parameter(self, key: str, value: Any) -> None: + def set_parameter(self, key: str, value: Any) -> TransformedStructure: """Sets a parameter. Args: key (str): The string key. value (Any): The value. + + Returns: + TransformedStructure """ self.other_parameters[key] = value + return self + @property def was_modified(self) -> bool: """Boolean describing whether the last transformation on the structure diff --git a/pymatgen/analysis/phase_diagram.py b/pymatgen/analysis/phase_diagram.py index b32fb8cd987..5c754bbe538 100644 --- a/pymatgen/analysis/phase_diagram.py +++ b/pymatgen/analysis/phase_diagram.py @@ -753,7 +753,8 @@ def get_decomp_and_e_above_hull( 'ignore' just returns (None, None). Defaults to 'raise'. Raises: - ValueError: If no valid decomposition exists in this phase diagram for given entry. + ValueError: If on_error is 'raise' and no valid decomposition exists in this + phase diagram for given entry. Returns: tuple[decomp, energy_above_hull]: The decomposition is provided @@ -825,9 +826,9 @@ def get_equilibrium_reaction_energy(self, entry: PDEntry) -> float | None: return 0 entries = [e for e in self._get_stable_entries_in_space(frozenset(elem_space)) if e != entry] - modpd = PhaseDiagram(entries, elements=elem_space) + mod_pd = PhaseDiagram(entries, elements=elem_space) - return modpd.get_decomp_and_e_above_hull(entry, allow_negative=True)[1] + return mod_pd.get_decomp_and_e_above_hull(entry, allow_negative=True)[1] def get_decomp_and_phase_separation_energy( self, @@ -1752,6 +1753,9 @@ def get_pd_for_entry(self, entry: Entry | Composition) -> PhaseDiagram: Returns: PhaseDiagram: phase diagram that the entry is part of + + Raises: + ValueError: If no suitable PhaseDiagram is found for the entry. """ entry_space = frozenset(entry.elements) if isinstance(entry, Composition) else frozenset(entry.elements) diff --git a/pymatgen/analysis/structure_analyzer.py b/pymatgen/analysis/structure_analyzer.py index 295181d8ac0..08baab80817 100644 --- a/pymatgen/analysis/structure_analyzer.py +++ b/pymatgen/analysis/structure_analyzer.py @@ -330,8 +330,8 @@ def get_connections(self): def get_sitej(self, site_index, image_index): """ Assuming there is some value in the connectivity array at indices - (1, 3, 12). sitei can be obtained directly from the input structure - (structure[1]). sitej can be obtained by passing 3, 12 to this function. + (1, 3, 12). site_i can be obtained directly from the input structure + (structure[1]). site_j can be obtained by passing 3, 12 to this function. Args: site_index (int): index of the site (3 in the example) diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index d6669a6976e..ce6e702f32b 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -95,6 +95,11 @@ def test_undo_and_redo_last_change(self): ts.undo_last_change() ts.redo_next_change() + def test_set_parameter(self): + trans = self.trans.set_parameter("author", "will") + assert trans.other_parameters["author"] == "will" + assert trans is self.trans + def test_as_dict(self): self.trans.set_parameter("author", "will") dct = self.trans.as_dict()