Skip to content

Commit 9551b5a

Browse files
committed
make elements_ho classvar
1 parent c12fa70 commit 9551b5a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/pymatgen/analysis/pourbaix_diagram.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from pymatgen.util.string import Stringify
3232

3333
if TYPE_CHECKING:
34-
from typing import Any, Literal
34+
from typing import Any, Literal, ClassVar
3535

3636
import matplotlib.pyplot as plt
3737
from numpy.typing import NDArray
@@ -410,17 +410,18 @@ def ion_or_solid_comp_object(formula: str) -> Composition | Ion:
410410
Returns:
411411
Composition/Ion object
412412
"""
413+
# Formula for ion
413414
if re.match(r"\[([^\[\]]+)\]|\(aq\)", formula):
414415
comp_obj = Ion.from_formula(formula)
416+
417+
# Formula for solid
415418
elif re.search(r"\(s\)", formula):
416419
comp_obj = Composition(formula[:-3])
420+
417421
else:
418422
comp_obj = Composition(formula)
419-
return comp_obj
420-
421-
422-
ELEMENTS_HO: set[Element] = {Element("H"), Element("O")}
423423

424+
return comp_obj
424425

425426
# TODO: the solids filter breaks some of the functionality of the
426427
# heatmap plotter, because the reference states for decomposition
@@ -433,6 +434,9 @@ def ion_or_solid_comp_object(formula: str) -> Composition | Ion:
433434
class PourbaixDiagram(MSONable):
434435
"""Create a Pourbaix diagram from entries."""
435436

437+
438+
elements_ho: ClassVar[set[Element]] = {Element("H"), Element("O")}
439+
436440
def __init__(
437441
self,
438442
entries: list[PourbaixEntry] | list[MultiEntry],
@@ -466,7 +470,7 @@ def __init__(
466470

467471
# Get non-OH elements
468472
self.pbx_elts = list(
469-
set(itertools.chain.from_iterable([entry.composition.elements for entry in entries])) - ELEMENTS_HO
473+
set(itertools.chain.from_iterable([entry.composition.elements for entry in entries])) - self.elements_ho
470474
)
471475
self.dim = len(self.pbx_elts) - 1
472476

@@ -478,7 +482,7 @@ def __init__(
478482
self._unprocessed_entries = single_entries
479483
self._filtered_entries = single_entries
480484
self._conc_dict = None
481-
self._elt_comp = {k: v for k, v in entries[0].composition.items() if k not in ELEMENTS_HO}
485+
self._elt_comp = {k: v for k, v in entries[0].composition.items() if k not in self.elements_ho}
482486
self._multi_element = True
483487

484488
# Process single entry inputs
@@ -498,7 +502,7 @@ def __init__(
498502

499503
# If a conc_dict is specified, override individual entry concentrations
500504
for entry in ion_entries:
501-
ion_elts = list(set(entry.elements) - ELEMENTS_HO)
505+
ion_elts = list(set(entry.elements) - self.elements_ho)
502506
# TODO: the logic here for ion concentration setting is in two
503507
# places, in PourbaixEntry and here, should be consolidated
504508
if len(ion_elts) == 1:
@@ -869,7 +873,7 @@ def get_decomposition_energy(
869873
# Check composition consistency between entry and Pourbaix diagram:
870874
pbx_comp = Composition(self._elt_comp).fractional_composition
871875
entry_pbx_comp = Composition(
872-
{elt: coeff for elt, coeff in entry.composition.items() if elt not in ELEMENTS_HO}
876+
{elt: coeff for elt, coeff in entry.composition.items() if elt not in self.elements_ho}
873877
).fractional_composition
874878
if entry_pbx_comp != pbx_comp:
875879
raise ValueError("Composition of stability entry does not match Pourbaix Diagram")

0 commit comments

Comments
 (0)