Skip to content
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
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fceeb21
initiation
hmlli Jul 21, 2022
9f04e08
Merge remote-tracking branch 'origin/main' into MGComponent
hmlli Sep 1, 2022
2275002
Auto stash before merge of "MGComponent" and "origin/main"
hmlli Sep 1, 2022
824b76e
Merge branch 'MGComponent' into origin/main
hmlli Sep 1, 2022
a9ab1ff
Merge remote-tracking branch 'origin/main' into MGComponent
hmlli Sep 1, 2022
c8d2046
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2022
4798d7b
Auto stash before merge of "MGComponent" and "hmlli/MGComponent"
hmlli Sep 1, 2022
3b1de94
Merge branch 'MGComponent' into hmlli/MGComponent
hmlli Sep 1, 2022
7e251c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2022
f4d43ba
add get_scene func for mg
hmlli Sep 1, 2022
31957e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2022
a0bf356
adjust radius
hmlli Sep 1, 2022
92f1e83
boundary double graphing
hmlli Sep 1, 2022
e8fe350
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2022
a5f3328
revert to whole structure + cleanup
hmlli Sep 1, 2022
4430cc7
Merge remote-tracking branch 'hmlli/MGComponent' into MGComponent
hmlli Sep 1, 2022
d7c97c5
Merge remote-tracking branch 'origin/main' into MGComponent
hmlli Sep 6, 2022
816b6e0
adjust radius, visual
hmlli Sep 6, 2022
519143c
init file change + example app setup
hmlli Sep 10, 2022
8b074b1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2022
e4cb6cf
add color coding & radius adjustment
hmlli Sep 14, 2022
07d2292
cwd for example app
hmlli Sep 14, 2022
05dea70
build dist egginfo gitignore
hmlli Sep 14, 2022
5b9da58
delete build dist egginfo
hmlli Sep 14, 2022
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
94 changes: 94 additions & 0 deletions build/lib/crystal_toolkit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import json
Copy link
Member

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 from git history since they're quite large.

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.
7 changes: 7 additions & 0 deletions build/lib/crystal_toolkit/apps/assets/crystaltoolkit.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@



body, html, .body {
background: #f3f3f3 !important;
}

1 change: 1 addition & 0 deletions build/lib/crystal_toolkit/apps/assets/doi_cache.json
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 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 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 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.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/lib/crystal_toolkit/apps/examples/GaN_bs.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/lib/crystal_toolkit/apps/examples/GaN_dos.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/lib/crystal_toolkit/apps/examples/Si_bs.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/lib/crystal_toolkit/apps/examples/Si_dos.json

Large diffs are not rendered by default.

Empty file.
51 changes: 51 additions & 0 deletions build/lib/crystal_toolkit/apps/examples/bandstructure.py
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 build/lib/crystal_toolkit/apps/examples/basic_hello_structure.py
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)
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 build/lib/crystal_toolkit/apps/examples/basic_hello_world.py
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)
38 changes: 38 additions & 0 deletions build/lib/crystal_toolkit/apps/examples/diffraction.py
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 build/lib/crystal_toolkit/apps/examples/diffraction_dynamic.py
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 build/lib/crystal_toolkit/apps/examples/diffraction_empty.py
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)
Loading