Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion other/materials_designer/uploads/0-Ni.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"external": {
"id": "mp-23",
"source": "Materials Project",
"source": "MaterialsProject",
"doi": "10.17188/1199153",
"url": "https://next-gen.materialsproject.org/materials/mp-23",
"origin": true
Expand Down
21 changes: 19 additions & 2 deletions utils/plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import io
import sys
from typing import Dict, List, Union

import matplotlib
import matplotlib.pyplot as plt
from mat3ra.made.material import Material
from mat3ra.made.tools.analyze.interface import ZSLMatchHolder
from mat3ra.made.tools.analyze.rdf import RadialDistributionFunction
Expand Down Expand Up @@ -60,8 +64,8 @@ def plot_twisted_interface_solutions(interfaces: List["Material"]) -> None:

x_values.append(angle)
y_values.append(size)
hover_texts.append(f"Interface {i+1}<br>Angle: {angle:.2f}°<br>Atoms: {size}<br>")
trace_names.append(f"Interface {i+1}")
hover_texts.append(f"Interface {i + 1}<br>Angle: {angle:.2f}°<br>Atoms: {size}<br>")
trace_names.append(f"Interface {i + 1}")

plot_settings = {"x_title": "Twist Angle (°)", "y_title": "Number of Atoms", "title": "Twisted Interface Solutions"}

Expand All @@ -73,7 +77,20 @@ def plot_rdf(material: "Material", cutoff: float = 10.0, bin_size: float = 0.1)
"""
Plot RDF for a material.
"""
is_pyodide = sys.platform == "emscripten"
if is_pyodide:
matplotlib.use("Agg")

rdf = RadialDistributionFunction.from_material(material, cutoff=cutoff, bin_size=bin_size)
plot_distribution_function(
rdf.bin_centers, rdf.rdf, xlabel="Distance (Å)", ylabel="g(r)", title="Radial Distribution Function (RDF)"
)

if is_pyodide:
from IPython.display import Image, display

buf = io.BytesIO()
plt.savefig(buf, format="png")
buf.seek(0)
display(Image(buf.read()))
plt.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if it's not pyodide? How do we plot RDF??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous function plot_distribution from utils

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining why this is needed