-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add MigrationGraph
Renderable
#267
Open
hmlli
wants to merge
24
commits into
materialsproject:main
Choose a base branch
from
hmlli:MGComponent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fceeb21
initiation
hmlli 9f04e08
Merge remote-tracking branch 'origin/main' into MGComponent
hmlli 2275002
Auto stash before merge of "MGComponent" and "origin/main"
hmlli 824b76e
Merge branch 'MGComponent' into origin/main
hmlli a9ab1ff
Merge remote-tracking branch 'origin/main' into MGComponent
hmlli c8d2046
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4798d7b
Auto stash before merge of "MGComponent" and "hmlli/MGComponent"
hmlli 3b1de94
Merge branch 'MGComponent' into hmlli/MGComponent
hmlli 7e251c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f4d43ba
add get_scene func for mg
hmlli 31957e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a0bf356
adjust radius
hmlli 92f1e83
boundary double graphing
hmlli e8fe350
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a5f3328
revert to whole structure + cleanup
hmlli 4430cc7
Merge remote-tracking branch 'hmlli/MGComponent' into MGComponent
hmlli d7c97c5
Merge remote-tracking branch 'origin/main' into MGComponent
hmlli 816b6e0
adjust radius, visual
hmlli 519143c
init file change + example app setup
hmlli 8b074b1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e4cb6cf
add color coding & radius adjustment
hmlli 07d2292
cwd for example app
hmlli 05dea70
build dist egginfo gitignore
hmlli 5b9da58
delete build dist egginfo
hmlli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import json | ||
import os as _os | ||
from collections import defaultdict | ||
from pathlib import Path | ||
|
||
# pleasant hack to support MSONable objects in Dash callbacks natively | ||
from monty.json import MSONable | ||
|
||
from crystal_toolkit.renderables import * | ||
|
||
__version__ = "2021.04.29" | ||
|
||
MODULE_PATH = Path(__file__).parents[0] | ||
|
||
|
||
def to_plotly_json(self): | ||
return self.as_dict() | ||
|
||
|
||
MSONable.to_plotly_json = to_plotly_json | ||
|
||
|
||
# Populate the default values from the JSON file | ||
_DEFAULTS = defaultdict(lambda: None) | ||
default_js = _os.path.join( | ||
_os.path.join(_os.path.dirname(_os.path.abspath(__file__))), "./", "defaults.json" | ||
) | ||
|
||
with open(default_js) as handle: | ||
_DEFAULTS.update(json.loads(handle.read())) | ||
|
||
|
||
def _repr_mimebundle_(self, include=None, exclude=None): | ||
""" | ||
Render Scenes using crystaltoolkit-extension for Jupyter Lab. | ||
""" | ||
# TODO: add Plotly, application/vnd.plotly.v1+json | ||
|
||
help_text_ct = """If you see this text, the Crystal Toolkit Jupyter Lab \n | ||
extension is not installed. You can install it by running \n | ||
\"pip install crystaltoolkit-extension\" \n | ||
from the same environment you run \"jupyter lab\". \n | ||
This only works in Jupyter Lab 3.x or above.\n\n | ||
""" | ||
|
||
help_text_plotly = """If you see this text, the Plotly Jupyter Lab extension | ||
is not installed, please consult Plotly documentation for information on how to | ||
install. | ||
""" | ||
|
||
# TODO: to be strict here, we could use inspect.signature | ||
# and .return_annotation is either a Scene or a go.Figure respectively | ||
# and also check all .parameters .kind.name have no POSITIONAL_ONLY | ||
# in practice, fairly unlikely this will cause issues without strict checking | ||
|
||
if hasattr(self, "get_scene"): | ||
return { | ||
"application/vnd.mp.ctk+json": self.get_scene().to_json(), | ||
"text/plain": help_text_ct + self.__repr__(), | ||
} | ||
elif hasattr(self, "get_plot"): | ||
return { | ||
"application/vnd.plotly.v1+json": self.get_plot().to_plotly_json(), | ||
"text/plain": help_text_plotly + self.__repr__(), | ||
} | ||
else: | ||
return {"application/json": self.as_dict(), "text/plain": self.__repr__()} | ||
|
||
|
||
MSONable._repr_mimebundle_ = _repr_mimebundle_ | ||
|
||
|
||
def show_json(self): | ||
from IPython.display import display_json | ||
|
||
return display_json(self.as_dict(), raw=True) | ||
|
||
|
||
MSONable.show_json = show_json | ||
|
||
|
||
def _ipython_display_(self): | ||
""" | ||
Render Scenes using crystaltoolkit-extension for Jupyter Lab. | ||
|
||
This function ensures that objects are also printed in string format | ||
as previously. | ||
""" | ||
from IPython.display import publish_display_data | ||
|
||
publish_display_data(self._repr_mimebundle_()) | ||
|
||
|
||
MSONable._ipython_display_ = _ipython_display_ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
|
||
body, html, .body { | ||
background: #f3f3f3 !important; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"10.26434/chemrxiv.11294480.v1": "D. Waroquiers, J. George, M. Horton, S. Schenk, K. Persson, G.-M. Rignanese, X. Gonze, and G. Hautier, \u201cChemEnv\u202f: A Fast and Robust Coordination Environment Identification Tool,\u201d Dec. 2019.\n", "10.3389/fmats.2017.00034": "N. E. R. Zimmermann, M. K. Horton, A. Jain, and M. Haranczyk, \u201cAssessing Local Structure Motifs Using Order Parameters for Motif Recognition, Interstitial Identification, and Diffusion Path Characterization,\u201d Frontiers in Materials, vol. 4, Nov. 2017.\n"} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
1,260 changes: 1,260 additions & 0 deletions
1,260
build/lib/crystal_toolkit/apps/assets/fonts/fa-brands-400.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
471 changes: 471 additions & 0 deletions
471
build/lib/crystal_toolkit/apps/assets/fonts/fa-regular-400.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2,763 changes: 2,763 additions & 0 deletions
2,763
build/lib/crystal_toolkit/apps/assets/fonts/fa-solid-900.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
build/lib/crystal_toolkit/apps/assets/main.ecd1960277cfe37b135f.css
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# standard Dash imports | ||
import dash | ||
|
||
# standard Crystal Toolkit import | ||
import crystal_toolkit.components as ctc | ||
from crystal_toolkit.settings import SETTINGS | ||
from crystal_toolkit.helpers.layouts import Container, H1 | ||
|
||
# dos and bs data from local jsons | ||
from monty.serialization import loadfn | ||
import os | ||
|
||
|
||
# create Dash app as normal, assets folder set for visual styles only | ||
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH) | ||
|
||
# If callbacks created dynamically they cannot be statically checked at app startup. | ||
# For this simple example this IS a problem and, | ||
# nested layout this will need to be enabled -- consult Dash documentation | ||
# for more information. | ||
# app.config["suppress_callback_exceptions"] = True | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
bandstructure_symm_line = loadfn(path + "/GaN_bs.json") | ||
density_of_states = loadfn(path + "/GaN_dos.json") | ||
|
||
# # create the Crystal Toolkit component | ||
bsdos_component = ctc.BandstructureAndDosComponent( | ||
bandstructure_symm_line=bandstructure_symm_line, | ||
density_of_states=density_of_states, | ||
id="bs_dos", | ||
) | ||
|
||
# example layout to demonstrate capabilities of component | ||
my_layout = Container( | ||
[ | ||
H1("Band Structure and Density of States Example"), | ||
bsdos_component.layout(), | ||
] | ||
) | ||
|
||
# wrap your app.layout with crystal_toolkit_layout() | ||
# to ensure all necessary components are loaded into layout | ||
ctc.register_crystal_toolkit(app, layout=my_layout) | ||
|
||
|
||
# allow app to be run using "python structure.py" | ||
# in production, deploy behind gunicorn or similar | ||
# see Dash documentation for more information | ||
if __name__ == "__main__": | ||
app.run_server(debug=True, port=8050) |
23 changes: 23 additions & 0 deletions
23
build/lib/crystal_toolkit/apps/examples/basic_hello_structure.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# as explained in "preamble" section in documentation | ||
import dash | ||
import dash_html_components as html | ||
import crystal_toolkit.components as ctc | ||
|
||
app = dash.Dash() | ||
|
||
# create our crystal structure using pymatgen | ||
from pymatgen.core.structure import Structure | ||
from pymatgen.core.lattice import Lattice | ||
|
||
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]]) | ||
|
||
# create the Crystal Toolkit component | ||
structure_component = ctc.StructureMoleculeComponent(structure) | ||
|
||
# add the component's layout to our app's layout | ||
my_layout = html.Div([structure_component.layout()]) | ||
|
||
# as explained in "preamble" section in documentation | ||
ctc.register_crystal_toolkit(app=app, layout=my_layout) | ||
if __name__ == "__main__": | ||
app.run_server(debug=True, port=8050) |
48 changes: 48 additions & 0 deletions
48
build/lib/crystal_toolkit/apps/examples/basic_hello_structure_interactive.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# as above | ||
import dash | ||
import dash_html_components as html | ||
import crystal_toolkit.components as ctc | ||
|
||
# standard Dash imports for callbacks (interactivity) | ||
from dash.dependencies import Input, Output | ||
from dash.exceptions import PreventUpdate | ||
|
||
from pymatgen.core.structure import Structure | ||
from pymatgen.core.lattice import Lattice | ||
|
||
app = dash.Dash() | ||
|
||
# now we give a list of structures to pick from | ||
structures = [ | ||
Structure(Lattice.cubic(4), ["Na", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]), | ||
Structure(Lattice.cubic(5), ["K", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]), | ||
] | ||
|
||
# we show the first structure by default | ||
structure_component = ctc.StructureMoleculeComponent(structures[0]) | ||
|
||
# and we create a button for user interaction | ||
my_button = html.Button("Swap Structure", id="change_structure_button") | ||
|
||
# now we have two entries in our app layout, | ||
# the structure component's layout and the button | ||
my_layout = html.Div([structure_component.layout(), my_button]) | ||
|
||
ctc.register_crystal_toolkit(app=app, layout=my_layout, cache=None) | ||
|
||
# for the interactivity, we use a standard Dash callback | ||
@app.callback( | ||
Output(structure_component.id(), "data"), | ||
[Input("change_structure_button", "n_clicks")], | ||
) | ||
def update_structure(n_clicks): | ||
# on load, n_clicks will be None, and no update is required | ||
# after clicking on the button, n_clicks will be an int and incremented | ||
if not n_clicks: | ||
raise PreventUpdate | ||
return structures[n_clicks % 2] | ||
|
||
|
||
# as above | ||
if __name__ == "__main__": | ||
app.run_server(debug=True, port=8050) |
21 changes: 21 additions & 0 deletions
21
build/lib/crystal_toolkit/apps/examples/basic_hello_world.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# standard Dash imports | ||
import dash | ||
import dash_html_components as html | ||
|
||
# standard Crystal Toolkit import | ||
import crystal_toolkit.components as ctc | ||
|
||
# create Dash app as normal | ||
app = dash.Dash() | ||
|
||
# create your layout | ||
my_layout = html.Div(["Hello scientist!"]) | ||
|
||
# tell Crystal Toolkit about the app and layout we want to display | ||
ctc.register_crystal_toolkit(app=app, layout=my_layout, cache=None) | ||
|
||
# allow app to be run using "python app.py" | ||
# in production, deploy behind gunicorn or similar | ||
# see Dash documentation for more information | ||
if __name__ == "__main__": | ||
app.run_server(debug=True, port=8050) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# standard Dash imports | ||
import dash | ||
|
||
# standard Crystal Toolkit import | ||
import crystal_toolkit.components as ctc | ||
from crystal_toolkit.settings import SETTINGS | ||
from crystal_toolkit.helpers.layouts import H1, H3, Container | ||
|
||
# import for this example | ||
|
||
# create Dash app as normal | ||
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH) | ||
|
||
# create our crystal structure using pymatgen | ||
from pymatgen.core.structure import Structure | ||
from pymatgen.core.lattice import Lattice | ||
|
||
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]]) | ||
|
||
xrd_component = ctc.XRayDiffractionComponent(initial_structure=structure) | ||
|
||
# example layout to demonstrate capabilities of component | ||
my_layout = Container( | ||
[ | ||
H1("XRDComponent Example"), | ||
H3("Generated from Structure object"), | ||
xrd_component.layout(), | ||
] | ||
) | ||
|
||
# as explained in "preamble" section in documentation | ||
ctc.register_crystal_toolkit(app=app, layout=my_layout) | ||
|
||
# allow app to be run using "python structure.py" | ||
# in production, deploy behind gunicorn or similar | ||
# see Dash documentation for more information | ||
if __name__ == "__main__": | ||
app.run_server(debug=True, port=8050) |
44 changes: 44 additions & 0 deletions
44
build/lib/crystal_toolkit/apps/examples/diffraction_dynamic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# standard Dash imports | ||
import dash | ||
from dash.dependencies import Input, Output | ||
|
||
# standard Crystal Toolkit import | ||
import crystal_toolkit.components as ctc | ||
from crystal_toolkit.settings import SETTINGS | ||
from crystal_toolkit.helpers.layouts import Button, Container, H1 | ||
|
||
# create Dash app as normal | ||
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH) | ||
|
||
# create our crystal structure using pymatgen | ||
from pymatgen.core.structure import Structure | ||
from pymatgen.core.lattice import Lattice | ||
|
||
xrd_component = ctc.XRayDiffractionComponent() | ||
|
||
# example layout to demonstrate capabilities of component | ||
my_layout = Container( | ||
[ | ||
H1("XRDComponent Example (Structure Added After Loading)"), | ||
xrd_component.layout(), | ||
Button("Load XRD", id="load-xrd-button"), | ||
] | ||
) | ||
|
||
# as explained in "preamble" section in documentation | ||
ctc.register_crystal_toolkit(app=app, layout=my_layout) | ||
|
||
|
||
@app.callback( | ||
Output(xrd_component.id(), "data"), [Input("load-xrd-button", "n_clicks")] | ||
) | ||
def load_structure(n_clicks): | ||
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]]) | ||
return structure | ||
|
||
|
||
# allow app to be run using "python structure.py" | ||
# in production, deploy behind gunicorn or similar | ||
# see Dash documentation for more information | ||
if __name__ == "__main__": | ||
app.run_server(debug=True, port=8050) |
39 changes: 39 additions & 0 deletions
39
build/lib/crystal_toolkit/apps/examples/diffraction_empty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# standard Dash imports | ||
import dash | ||
|
||
# standard Crystal Toolkit import | ||
import crystal_toolkit.components as ctc | ||
from crystal_toolkit.settings import SETTINGS | ||
from crystal_toolkit.helpers.layouts import Container, H1 | ||
|
||
# import for this example | ||
from pymatgen.core.structure import Structure | ||
from pymatgen.core.lattice import Lattice | ||
|
||
# create Dash app as normal | ||
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH) | ||
|
||
# create our crystal structure using pymatgen | ||
from pymatgen.core.structure import Structure | ||
from pymatgen.core.lattice import Lattice | ||
|
||
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]]) | ||
|
||
xrd_component = ctc.XRayDiffractionComponent() | ||
|
||
# example layout to demonstrate capabilities of component | ||
my_layout = Container( | ||
[ | ||
H1("XRDComponent Example (Empty, No Structure Defined)"), | ||
xrd_component.layout(), | ||
] | ||
) | ||
|
||
# as explained in "preamble" section in documentation | ||
ctc.register_crystal_toolkit(app=app, layout=my_layout) | ||
|
||
# allow app to be run using "python structure.py" | ||
# in production, deploy behind gunicorn or similar | ||
# see Dash documentation for more information | ||
if __name__ == "__main__": | ||
app.run_server(debug=True, port=8050) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files in
build/*
should also be ignored, not committed. Might be worth purging these files fromgit
history since they're quite large.