Skip to content

Commit

Permalink
Merge cc690eb into dcbbe00
Browse files Browse the repository at this point in the history
  • Loading branch information
peikai committed Jan 23, 2023
2 parents dcbbe00 + cc690eb commit fe0f6e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pymatgen/analysis/phase_diagram.py
Expand Up @@ -416,6 +416,8 @@ def _compute(self) -> dict[str, Any]:
dim = len(elements)

entries = sorted(self.entries, key=lambda e: e.composition.reduced_composition)
if len(entries) == 0:
raise ValueError("Unable to build phase diagram without entries.")

el_refs: dict[Element, PDEntry] = {}
min_entries: list[PDEntry] = []
Expand Down
6 changes: 6 additions & 0 deletions pymatgen/analysis/tests/test_phase_diagram.py
Expand Up @@ -630,6 +630,12 @@ def test_el_refs(self):
# Check the keys in el_refs dict have been updated to Element object via PhaseDiagram class.
assert all(isinstance(el, Element) for el in pd.el_refs)

def test_entries_length_error(self):
# Assert PhaseDiagram class raises ValueError when building phase diagram with no entries
entriesList = []
with pytest.raises(ValueError, match="Unable to build phase diagram without entries."):
PhaseDiagram(entriesList)


class GrandPotentialPhaseDiagramTest(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit fe0f6e0

Please sign in to comment.