From 933d3eb2e4a5bc3ee55037d6bb435f9bb3831193 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Thu, 23 Mar 2023 17:36:01 -0700 Subject: [PATCH 1/3] fix ValueError: not enough values to unpack (expected 2, got 0) in PDPlotter: unstable_entries, unstable_coords = zip(*self.pd_plot_data[2].items()) --- pymatgen/analysis/phase_diagram.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pymatgen/analysis/phase_diagram.py b/pymatgen/analysis/phase_diagram.py index b6508633f61..bd91db7f511 100644 --- a/pymatgen/analysis/phase_diagram.py +++ b/pymatgen/analysis/phase_diagram.py @@ -3014,17 +3014,12 @@ def get_marker_props(coords, entries, stable=True): elif self._dim == 4: z.append(coord[2]) - return { - "x": x, - "y": y, - "z": z, - "texts": texts, - "energies": energies, - "uncertainties": uncertainties, - } + return {"x": x, "y": y, "z": z, "texts": texts, "energies": energies, "uncertainties": uncertainties} - stable_coords, stable_entries = zip(*self.pd_plot_data[1].items()) - unstable_entries, unstable_coords = zip(*self.pd_plot_data[2].items()) + stable_coords = list(self.pd_plot_data[1]) + stable_entries = self.pd_plot_data[1].values() + unstable_coords = list(self.pd_plot_data[2]) + unstable_entries = self.pd_plot_data[2].values() stable_props = get_marker_props(stable_coords, stable_entries) From f654d9f32c6035c412b977e645fe1ed1000feac1 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Thu, 23 Mar 2023 17:36:15 -0700 Subject: [PATCH 2/3] add test to prevent regression --- pymatgen/analysis/tests/test_phase_diagram.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pymatgen/analysis/tests/test_phase_diagram.py b/pymatgen/analysis/tests/test_phase_diagram.py index 07126dfdfdc..77f6350437c 100644 --- a/pymatgen/analysis/tests/test_phase_diagram.py +++ b/pymatgen/analysis/tests/test_phase_diagram.py @@ -878,6 +878,13 @@ def setUp(self): self.plotter_quaternary_mpl = PDPlotter(self.pd_quaternary, backend="matplotlib") self.plotter_quaternary_plotly = PDPlotter(self.pd_quaternary, backend="plotly") + def test_plot_pd_with_no_unstable(self): + # https://github.com/materialsproject/pymatgen/issues/2885 + pd_entries = [PDEntry(comp, 0) for comp in ["Li", "Co", "O"]] + pd = PhaseDiagram(pd_entries) + plotter = PDPlotter(pd, backend="plotly", show_unstable=False) + plotter.get_plot() + def test_pd_plot_data(self): lines, labels, unstable_entries = self.plotter_ternary_mpl.pd_plot_data assert len(lines) == 22 From 577507285544171cd0d10f855af141737036f0ca Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Thu, 23 Mar 2023 18:06:32 -0700 Subject: [PATCH 3/3] fix PDPlotterTest.test_plotly_plots self = def test_plotly_plots(self): # Also very basic tests. Ensures callability and 2D vs 3D properties. > self.plotter_binary_plotly.get_plot() pymatgen/analysis/tests/test_phase_diagram.py:914: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ pymatgen/analysis/phase_diagram.py:2226: in get_plot stable_marker_plot, unstable_marker_plot = self._create_plotly_markers(label_uncertainties) pymatgen/analysis/phase_diagram.py:3026: in _create_plotly_markers unstable_props = get_marker_props(unstable_coords, unstable_entries, stable=False) pymatgen/analysis/phase_diagram.py:2979: in get_marker_props energy = round(self._pd.get_form_energy_per_atom(entry), 3) pymatgen/analysis/phase_diagram.py:575: in get_form_energy_per_atom return self.get_form_energy(entry) / entry.composition.num_atoms --- pymatgen/analysis/phase_diagram.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymatgen/analysis/phase_diagram.py b/pymatgen/analysis/phase_diagram.py index bd91db7f511..366b828e991 100644 --- a/pymatgen/analysis/phase_diagram.py +++ b/pymatgen/analysis/phase_diagram.py @@ -3018,8 +3018,8 @@ def get_marker_props(coords, entries, stable=True): stable_coords = list(self.pd_plot_data[1]) stable_entries = self.pd_plot_data[1].values() - unstable_coords = list(self.pd_plot_data[2]) - unstable_entries = self.pd_plot_data[2].values() + unstable_entries = list(self.pd_plot_data[2]) + unstable_coords = self.pd_plot_data[2].values() stable_props = get_marker_props(stable_coords, stable_entries)