Skip to content

Commit 910e571

Browse files
committed
add test for TransformedStructure.set_parameter()
fix get_decomp_and_e_above_hull doc str ValueError condition
1 parent daa0bb0 commit 910e571

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ci:
88

99
repos:
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.3.1
11+
rev: v0.3.2
1212
hooks:
1313
- id: ruff
1414
args: [--fix, --unsafe-fixes]

pymatgen/alchemy/materials.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,20 @@ def __str__(self) -> str:
229229
output.extend(("\nOther parameters", "------------", str(self.other_parameters)))
230230
return "\n".join(output)
231231

232-
def set_parameter(self, key: str, value: Any) -> None:
232+
def set_parameter(self, key: str, value: Any) -> TransformedStructure:
233233
"""Sets a parameter.
234234
235235
Args:
236236
key (str): The string key.
237237
value (Any): The value.
238+
239+
Returns:
240+
TransformedStructure
238241
"""
239242
self.other_parameters[key] = value
240243

244+
return self
245+
241246
@property
242247
def was_modified(self) -> bool:
243248
"""Boolean describing whether the last transformation on the structure

pymatgen/analysis/phase_diagram.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ def get_decomp_and_e_above_hull(
753753
'ignore' just returns (None, None). Defaults to 'raise'.
754754
755755
Raises:
756-
ValueError: If no valid decomposition exists in this phase diagram for given entry.
756+
ValueError: If on_error is 'raise' and no valid decomposition exists in this
757+
phase diagram for given entry.
757758
758759
Returns:
759760
tuple[decomp, energy_above_hull]: The decomposition is provided
@@ -825,9 +826,9 @@ def get_equilibrium_reaction_energy(self, entry: PDEntry) -> float | None:
825826
return 0
826827

827828
entries = [e for e in self._get_stable_entries_in_space(frozenset(elem_space)) if e != entry]
828-
modpd = PhaseDiagram(entries, elements=elem_space)
829+
mod_pd = PhaseDiagram(entries, elements=elem_space)
829830

830-
return modpd.get_decomp_and_e_above_hull(entry, allow_negative=True)[1]
831+
return mod_pd.get_decomp_and_e_above_hull(entry, allow_negative=True)[1]
831832

832833
def get_decomp_and_phase_separation_energy(
833834
self,
@@ -1752,6 +1753,9 @@ def get_pd_for_entry(self, entry: Entry | Composition) -> PhaseDiagram:
17521753
17531754
Returns:
17541755
PhaseDiagram: phase diagram that the entry is part of
1756+
1757+
Raises:
1758+
ValueError: If no suitable PhaseDiagram is found for the entry.
17551759
"""
17561760
entry_space = frozenset(entry.elements) if isinstance(entry, Composition) else frozenset(entry.elements)
17571761

pymatgen/analysis/structure_analyzer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ def get_connections(self):
330330
def get_sitej(self, site_index, image_index):
331331
"""
332332
Assuming there is some value in the connectivity array at indices
333-
(1, 3, 12). sitei can be obtained directly from the input structure
334-
(structure[1]). sitej can be obtained by passing 3, 12 to this function.
333+
(1, 3, 12). site_i can be obtained directly from the input structure
334+
(structure[1]). site_j can be obtained by passing 3, 12 to this function.
335335
336336
Args:
337337
site_index (int): index of the site (3 in the example)

tests/alchemy/test_materials.py

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def test_undo_and_redo_last_change(self):
9595
ts.undo_last_change()
9696
ts.redo_next_change()
9797

98+
def test_set_parameter(self):
99+
trans = self.trans.set_parameter("author", "will")
100+
assert trans.other_parameters["author"] == "will"
101+
assert trans is self.trans
102+
98103
def test_as_dict(self):
99104
self.trans.set_parameter("author", "will")
100105
dct = self.trans.as_dict()

0 commit comments

Comments
 (0)