Skip to content

Commit

Permalink
Updating Ternary and Quaternary Plots (#3948)
Browse files Browse the repository at this point in the history
* Update phase_diagram.py

Adds marker labels to 3D ternary plots

Adds additional spacing to 2D and 3D hovertext so it is easier to read.

Signed-off-by: JoshuaNgXY <jxng@lbl.gov>

* Update phase_diagram.py

Signed-off-by: JoshuaNgXY <jxng@lbl.gov>

* pre-commit auto-fixes

* Update phase_diagram.py

Variable name update

Signed-off-by: JoshuaNgXY <jxng@lbl.gov>

* Quaternary Plot functionality Added

Updated hovertext to specify "Formation energy" and "Energy above hull".

Updated Quaternary plot to have labels for atomic concentration of elements.

Added a label to quaternary plot which allows users to toggle the hull surfaces so that the inner points can be accessed.

Signed-off-by: JoshuaNgXY <jxng@lbl.gov>

* pre-commit auto-fixes

* Update phase_diagram.py

Small variable name change to fix pre-commit

Signed-off-by: JoshuaNgXY <jxng@lbl.gov>

* Update Voltage Graph

Added labels for the x value to points on the voltage graph so they are easier to read.

Signed-off-by: JoshuaNgXY <joshuang@g.ucla.edu>

* Update plotter.py

Trying to fix tests

Signed-off-by: JoshuaNgXY <joshuang@g.ucla.edu>

* pre-commit auto-fixes

* Update plotter.py

Barebones fix to pass tests

Signed-off-by: JoshuaNgXY <joshuang@g.ucla.edu>

* pre-commit auto-fixes

---------

Signed-off-by: JoshuaNgXY <jxng@lbl.gov>
Signed-off-by: JoshuaNgXY <joshuang@g.ucla.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
JoshuaNgXY and pre-commit-ci[bot] authored Aug 9, 2024
1 parent eb392d3 commit 289d281
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 26 deletions.
82 changes: 57 additions & 25 deletions src/pymatgen/analysis/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2781,18 +2781,36 @@ def _create_plotly_fill(self):
ys.append(y)
zs.append(z)

traces += [
go.Mesh3d(
x=xs,
y=ys,
z=zs,
opacity=0.05,
alphahull=-1,
flatshading=True,
hoverinfo="skip",
color=next(fillcolors),
)
]
if _idx == 1:
traces += [
go.Mesh3d(
x=xs,
y=ys,
z=zs,
opacity=0.05,
alphahull=-1,
flatshading=True,
hoverinfo="skip",
color=next(fillcolors),
legendgroup="facets",
showlegend=True,
name="Hull Surfaces (toggle to access points easier)",
)
]
else:
traces += [
go.Mesh3d(
x=xs,
y=ys,
z=zs,
opacity=0.05,
alphahull=-1,
flatshading=True,
hoverinfo="skip",
color=next(fillcolors),
legendgroup="facets",
)
]

return traces

Expand Down Expand Up @@ -2974,7 +2992,6 @@ def get_marker_props(coords, entries):
x, y, z, texts, energies, uncertainties = [], [], [], [], [], []

is_stable = [entry in self._pd.stable_entries for entry in entries]

for coord, entry, stable in zip(coords, entries, is_stable):
energy = round(self._pd.get_form_energy_per_atom(entry), 3)

Expand All @@ -2988,37 +3005,52 @@ def get_marker_props(coords, entries):

formula = comp.reduced_formula
clean_formula = htmlify(formula)
label = f"{clean_formula} ({entry_id}) <br> {energy} eV/atom"

label = f"{clean_formula} ({entry_id}) <br> Formation energy: {energy} eV/atom <br> "
if not stable:
e_above_hull = round(self._pd.get_e_above_hull(entry), 3)
if e_above_hull > self.show_unstable:
continue
label += f" ({e_above_hull:+} eV/atom)"
label += f" Energy Above Hull: ({e_above_hull:+} eV/atom)"
energies.append(e_above_hull)
else:
uncertainty = 0
label += " (Stable)"
if hasattr(entry, "correction_uncertainty_per_atom") and label_uncertainties:
uncertainty = round(entry.correction_uncertainty_per_atom, 4)
label += f"<br> (Error: +/- {uncertainty} eV/atom)"

uncertainties.append(uncertainty)
energies.append(energy)

texts.append(label)

if self._dim == 3 and self.ternary_style == "2d":
for el, axis in zip(self._pd.elements, [x, y, z]):
axis.append(entry.composition[el])
label += "<br>"
total_sum_el = sum(entry.composition[el] for el, _axis in zip(self._pd.elements, range(self._dim)))
for el, axis in zip(self._pd.elements, range(self._dim)):
_cartesian_positions = [x, y, z]
_cartesian_positions[axis].append(entry.composition[el])
label += f"<br> {el}: {round(entry.composition[el]/total_sum_el, 6)}"
elif self._dim == 3 and self.ternary_style == "3d":
x.append(coord[0])
y.append(coord[1])
z.append(energy)

label += "<br>"
total_sum_el = sum(entry.composition[el] for el, _axis in zip(self._pd.elements, range(self._dim)))
for el, _axis in zip(self._pd.elements, range(self._dim)):
label += f"<br> {el}: {round(entry.composition[el]/total_sum_el, 6)}"
elif self._dim == 4:
x.append(coord[0])
y.append(coord[1])
z.append(coord[2])

label += "<br>"
total_sum_el = sum(entry.composition[el] for el, _axis in zip(self._pd.elements, range(self._dim)))
for el, _axis in zip(self._pd.elements, range(self._dim)):
label += f"<br> {el}: {round(entry.composition[el]/total_sum_el, 6)}"
else:
x.append(coord[0])
y.append(coord[1])

if self._dim == 3:
z.append(energy)
elif self._dim == 4:
z.append(coord[2])
texts.append(label)

return {"x": x, "y": y, "z": z, "texts": texts, "energies": energies, "uncertainties": uncertainties}

Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/apps/battery/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_plotly_figure(
**kwargs: passed to plotly.graph_objects.Layout
"""
font_dict = font_dict or {"family": "Arial", "size": 24, "color": "#000000"}
hover_temp = "Voltage : %{y:.2f} V"
hover_temp = "Voltage (V): %{y:.2f}<br>x: %{x:.3f}"

data = []
working_ion_symbols = set()
Expand Down

0 comments on commit 289d281

Please sign in to comment.