-
Notifications
You must be signed in to change notification settings - Fork 5
Fix/rdf plot (SOF-7807) #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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"} | ||
|
|
||
|
|
@@ -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() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if it's not pyodide? How do we plot RDF??
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the previous function
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment explaining why this is needed |
||
Uh oh!
There was an error while loading. Please reload this page.