Skip to content

Commit a9ab1ff

Browse files
committed
Merge remote-tracking branch 'origin/main' into MGComponent
2 parents 9f04e08 + 824b76e commit a9ab1ff

File tree

102 files changed

+17872
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+17872
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import json
2+
import os as _os
3+
from collections import defaultdict
4+
from pathlib import Path
5+
6+
# pleasant hack to support MSONable objects in Dash callbacks natively
7+
from monty.json import MSONable
8+
9+
from crystal_toolkit.renderables import *
10+
11+
__version__ = "2021.04.29"
12+
13+
MODULE_PATH = Path(__file__).parents[0]
14+
15+
16+
def to_plotly_json(self):
17+
return self.as_dict()
18+
19+
20+
MSONable.to_plotly_json = to_plotly_json
21+
22+
23+
# Populate the default values from the JSON file
24+
_DEFAULTS = defaultdict(lambda: None)
25+
default_js = _os.path.join(
26+
_os.path.join(_os.path.dirname(_os.path.abspath(__file__))), "./", "defaults.json"
27+
)
28+
29+
with open(default_js) as handle:
30+
_DEFAULTS.update(json.loads(handle.read()))
31+
32+
33+
def _repr_mimebundle_(self, include=None, exclude=None):
34+
"""
35+
Render Scenes using crystaltoolkit-extension for Jupyter Lab.
36+
"""
37+
# TODO: add Plotly, application/vnd.plotly.v1+json
38+
39+
help_text_ct = """If you see this text, the Crystal Toolkit Jupyter Lab \n
40+
extension is not installed. You can install it by running \n
41+
\"pip install crystaltoolkit-extension\" \n
42+
from the same environment you run \"jupyter lab\". \n
43+
This only works in Jupyter Lab 3.x or above.\n\n
44+
"""
45+
46+
help_text_plotly = """If you see this text, the Plotly Jupyter Lab extension
47+
is not installed, please consult Plotly documentation for information on how to
48+
install.
49+
"""
50+
51+
# TODO: to be strict here, we could use inspect.signature
52+
# and .return_annotation is either a Scene or a go.Figure respectively
53+
# and also check all .parameters .kind.name have no POSITIONAL_ONLY
54+
# in practice, fairly unlikely this will cause issues without strict checking
55+
56+
if hasattr(self, "get_scene"):
57+
return {
58+
"application/vnd.mp.ctk+json": self.get_scene().to_json(),
59+
"text/plain": help_text_ct + self.__repr__(),
60+
}
61+
elif hasattr(self, "get_plot"):
62+
return {
63+
"application/vnd.plotly.v1+json": self.get_plot().to_plotly_json(),
64+
"text/plain": help_text_plotly + self.__repr__(),
65+
}
66+
else:
67+
return {"application/json": self.as_dict(), "text/plain": self.__repr__()}
68+
69+
70+
MSONable._repr_mimebundle_ = _repr_mimebundle_
71+
72+
73+
def show_json(self):
74+
from IPython.display import display_json
75+
76+
return display_json(self.as_dict(), raw=True)
77+
78+
79+
MSONable.show_json = show_json
80+
81+
82+
def _ipython_display_(self):
83+
"""
84+
Render Scenes using crystaltoolkit-extension for Jupyter Lab.
85+
86+
This function ensures that objects are also printed in string format
87+
as previously.
88+
"""
89+
from IPython.display import publish_display_data
90+
91+
publish_display_data(self._repr_mimebundle_())
92+
93+
94+
MSONable._ipython_display_ = _ipython_display_

build/lib/crystal_toolkit/apps/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
4+
body, html, .body {
5+
background: #f3f3f3 !important;
6+
}
7+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}
112 KB
Binary file not shown.
43 KB
Loading
131 KB
Binary file not shown.

build/lib/crystal_toolkit/apps/assets/fonts/fa-brands-400.svg

Lines changed: 1260 additions & 0 deletions
Loading
131 KB
Binary file not shown.
85 KB
Binary file not shown.

0 commit comments

Comments
 (0)