Skip to content

Commit 17a8c34

Browse files
committed
Update recent changes for test deployment
1 parent f1fe212 commit 17a8c34

22 files changed

+445
-286
lines changed

app.py

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@
2828
# region SET UP APP
2929
################################################################################
3030

31-
app = dash.Dash()
31+
meta_tags = [
32+
{
33+
"name": "description",
34+
"content": "Crystal Toolkit allows you to import, view, analyze and transform "
35+
"crystal structures and molecules using the full power of the Materials "
36+
"Project.",
37+
}
38+
]
39+
40+
app = dash.Dash(meta_tags=meta_tags)
3241
app.config["suppress_callback_exceptions"] = True
3342
app.title = "Crystal Toolkit"
34-
app.scripts.config.serve_locally = True
43+
app.scripts.config.serve_locally = False
44+
app.scripts.append_script({"external_url": "https://buttons.github.io/buttons.js"})
45+
3546
app.server.secret_key = str(uuid4()) # TODO: will need to change this one day
3647
server = app.server
3748

@@ -60,6 +71,7 @@
6071

6172
# Enable for debug purposes:
6273
from mp_dash_components.components.core import DummyCache
74+
6375
cache = DummyCache()
6476

6577
# endregion
@@ -72,18 +84,31 @@
7284
MPComponent.register_app(app)
7385
MPComponent.register_cache(cache)
7486

75-
struct = MPRester().get_structure_by_material_id("mp-19306") #"mp-5020") # ("mp-804") # ("mp-123")
87+
struct = MPRester().get_structure_by_material_id(
88+
"mp-1078929"#"mp-804"
89+
) # 19306 #"mp-5020") # ("mp-804") # ("mp-123")
90+
91+
92+
json_editor_component = mpc.JSONEditor(struct)
7693

7794
struct_component = mpc.StructureMoleculeComponent(struct)
7895

7996
search_component = mpc.SearchComponent()
80-
editor_component = mpc.JSONComponent()
97+
8198
favorites_component = mpc.FavoritesComponent()
99+
favorites_component.attach_from(search_component, this_store_name="mpid-to-add")
82100

83101
literature_component = mpc.LiteratureComponent(origin_component=struct_component)
84102
robocrys_component = mpc.RobocrysComponent(origin_component=struct_component)
85103
magnetism_component = mpc.MagnetismComponent(origin_component=struct_component)
86104

105+
panels = [
106+
literature_component,
107+
robocrys_component,
108+
magnetism_component,
109+
json_editor_component,
110+
]
111+
87112
# endregion
88113

89114

@@ -93,19 +118,36 @@
93118

94119
footer = mpc.Footer(
95120
html.Div(
96-
dcc.Markdown(
97-
f"Bug reports and feature requests gratefully accepted, "
98-
f"contact [@mkhorton](mailto:[email protected]). \n"
99-
f"Created by [Crystal Toolkit Development Team]"
100-
f"(https://github.com/materialsproject/mash/), "
101-
f"powered by [The Materials Project](https://materialsproject.org) "
102-
f"and [pymatgen](http://pymatgen.org) v{pmg_version}."
103-
),
121+
[
122+
html.Iframe(
123+
src="https://ghbtns.com/github-btn.html?user=materialsproject&repo=mash&type=star&count=true",
124+
style={
125+
"frameborder": False,
126+
"scrolling": False,
127+
"width": "72px",
128+
"height": "20px",
129+
},
130+
),
131+
dcc.Markdown(
132+
f"Bug reports and feature requests gratefully accepted, "
133+
f"contact [@mkhorton](mailto:[email protected]). \n"
134+
f"Powered by [The Materials Project](https://materialsproject.org), "
135+
f"[pymatgen v{pmg_version}](http://pymatgen.org) and "
136+
f"[Dash by Plotly](https://plot.ly/products/dash/). "
137+
f"Deployed on [Spin](http://www.nersc.gov/users/data-analytics/spin/)."
138+
),
139+
],
104140
className="content has-text-centered",
105141
),
106142
style={"padding": "1rem 1rem 1rem", "background-color": "inherit"},
107143
)
108144

145+
panel_choices = dcc.Dropdown(
146+
options=[{"label": panel.title, "value": idx} for idx, panel in enumerate(panels)],
147+
multi=True,
148+
value=0,
149+
)
150+
109151
# endregion
110152

111153

@@ -168,10 +210,11 @@
168210
),
169211
Column(
170212
[
171-
# search_component.standard_layout,
172213
Reveal(
173-
[search_component.standard_layout,
174-
favorites_component.favorite_materials_layout],
214+
[
215+
search_component.standard_layout,
216+
favorites_component.favorite_materials_layout,
217+
],
175218
title="Load Crystal or Molecule",
176219
open=True,
177220
style={"line-height": "1"},
@@ -186,7 +229,7 @@
186229
],
187230
title="Summary",
188231
),
189-
#favorites_component.notes_layout,
232+
# favorites_component.notes_layout,
190233
],
191234
style={"max-width": "65vmin"},
192235
),
@@ -198,15 +241,23 @@
198241
[
199242
Column(
200243
[
201-
magnetism_component.panel_layout,
202-
robocrys_component.panel_layout,
203-
literature_component.panel_layout,
204-
Reveal(title="Bonding and Local Environments"),
205-
Reveal(
206-
"Coming soon! Matt needs coffee 😪☕️",
207-
title="Transform Crystal",
244+
dcc.Markdown(
245+
[
246+
"Crystal Toolkit offers various *panels* "
247+
"which each provide different ways "
248+
"of analyzing, transforming or retrieving information "
249+
"about a material using "
250+
"resources and tools available to "
251+
"The Materials Project. Some panels retrieve data or run algorithms on demand, "
252+
"so please allow some time for them to run. Explore these panels below."
253+
],
254+
className="mpc-panel-description",
255+
),
256+
# panel_choices,
257+
html.Div(
258+
[panel.panel_layout for panel in panels],
259+
id="panels",
208260
),
209-
Reveal(title="JSON Editor"),
210261
]
211262
)
212263
]
@@ -222,7 +273,7 @@
222273

223274

224275
################################################################################
225-
# region SET UP API ROUTES (to support creating viewer links)
276+
# region SET UP API ROUTES (to support creating viewer links in future)
226277
################################################################################
227278

228279

@@ -317,8 +368,7 @@ def update_url_pathname_from_search_term(data):
317368

318369

319370
@app.callback(
320-
Output(struct_component.id(), "data"),
321-
[Input(search_component.id(), "data")]
371+
Output(struct_component.id(), "data"), [Input(search_component.id(), "data")]
322372
)
323373
def update_structure(search_mpid):
324374

@@ -330,6 +380,7 @@ def update_structure(search_mpid):
330380

331381
return MPComponent.to_data(struct)
332382

383+
333384
# endregion
334385

335386

assets/styles.css

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/styles.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/styles.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,20 @@ details .input{
123123
}
124124

125125
@import "../node_modules/bulma/bulma.sass";
126+
127+
128+
// style dash_core_component Dropdown
129+
.Select--multi .Select-value {
130+
background-color: $primary;
131+
//background-color: rgba(0, 126, 255, .08);
132+
border-radius: 2px;
133+
border: 1px solid #c2e0ff;
134+
border: 1px solid rgba(0, 126, 255, .24);
135+
color: $white;
136+
display: inline-block;
137+
font-size: .9em;
138+
line-height: 1.4;
139+
margin-left: 5px;
140+
margin-top: 5px;
141+
vertical-align: top
142+
}

mp_dash_components/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@
3434

3535

3636
# convenience imports
37-
from mp_dash_components.components.json import JSONComponent
37+
from mp_dash_components.components.json import JSONEditor
3838
from mp_dash_components.components.search import SearchComponent
3939
from mp_dash_components.components.structure import StructureMoleculeComponent
4040
from mp_dash_components.components.favorites import FavoritesComponent
41+
from mp_dash_components.components.literature import LiteratureComponent
42+
from mp_dash_components.components.robocrys import RobocrysComponent
43+
from mp_dash_components.components.magnetism import MagnetismComponent
44+
#from mp_dash_components.components.bonding_graph import BondingGraphComponent
45+
from mp_dash_components.components.magnetism import MagnetismComponent
46+
from mp_dash_components.components.transformations.core import TransformationsComponent
4147
from mp_dash_components.helpers.layouts import *
4248
from mp_dash_components.helpers.scene import *
4349
from mp_dash_components.helpers.view import view

mp_dash_components/bundle.js

Lines changed: 75 additions & 107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mp_dash_components/components/bonding_graph.py

Whitespace-only changes.

mp_dash_components/components/core.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030

3131
from pymatgen.util.string import latexify_spacegroup
32-
32+
from pymatgen import MPRester
3333

3434
class DummyCache:
3535
@staticmethod
@@ -39,9 +39,6 @@ def memoize(*args, **kwargs):
3939

4040

4141
class MPComponent(ABC):
42-
"""
43-
44-
"""
4542

4643
_instances = {}
4744
_app_stores = []
@@ -61,7 +58,8 @@ def register_cache(cache):
6158
def all_app_stores():
6259
return html.Div(MPComponent._app_stores)
6360

64-
def __init__(self, id=None, origin_component=None, contents=None):
61+
def __init__(self, contents=None, id=None, origin_component=None,
62+
mprester_cache_timeout=60*60*24):
6563
"""
6664
:param id: a unique id for this component, if not specified a random
6765
one will be chosen
@@ -99,6 +97,17 @@ def __init__(self, id=None, origin_component=None, contents=None):
9997
f"using MPComponent.register_cache(cache)."
10098
)
10199

100+
self.mprester_cache_timeout = mprester_cache_timeout
101+
102+
# a cached MPRester for convenience
103+
@MPComponent.cache.memoize(timeout=mprester_cache_timeout)
104+
def mpr_query(criteria, properties):
105+
with MPRester() as mpr:
106+
entries = mpr.query(criteria=criteria, properties=properties)
107+
return entries
108+
109+
self.mpr_query = mpr_query
110+
102111
if origin_component is None:
103112
self._canonical_store_id = self._id
104113
self.create_store(name=None, initial_data=contents)
@@ -156,16 +165,16 @@ def from_data(data):
156165
return loads(data, cls=MontyDecoder)
157166

158167
def attach_from(
159-
self, origin_component, origin_store_suffix=None, this_store_suffix=None
168+
self, origin_component, origin_store_name=None, this_store_name=None
160169
):
161170
"""
162171
Link two MPComponents together.
163172
164173
:param origin_component: An MPComponent
165-
:param origin_store_suffix: The suffix for the Store layout in the
174+
:param origin_store_name: The suffix for the Store layout in the
166175
origin component, e.g. "structure" or "mpid", if None will link to
167176
the component's default Store
168-
:param this_store_suffix: The suffix for the Store layout in this
177+
:param this_store_name: The suffix for the Store layout in this
169178
component to be linked to, this is usually equal to the
170179
origin_store_suffix
171180
:return:
@@ -174,8 +183,8 @@ def attach_from(
174183
if MPComponent.app is None:
175184
raise AttributeError("No app defined, callbacks cannot be created.")
176185

177-
origin_store_id = origin_component.id(origin_store_suffix)
178-
dest_store_id = self.id(this_store_suffix)
186+
origin_store_id = origin_component.id(origin_store_name)
187+
dest_store_id = self.id(this_store_name)
179188

180189
@MPComponent.app.callback(
181190
Output(dest_store_id, "data"),
@@ -312,10 +321,6 @@ def help(self):
312321
# TODO: Implement
313322
return None
314323

315-
@property
316-
def warning(self):
317-
return None
318-
319324
@property
320325
def description(self):
321326
return None
@@ -337,15 +342,7 @@ def all_layouts(self):
337342
className="mpc-panel-description",
338343
)
339344

340-
if self.warning:
341-
warning = Tag(
342-
self.warning,
343-
tag_type="warning"
344-
)
345-
else:
346-
warning = html.Div()
347-
348-
contents = html.Div([message, warning, description, initial_contents])
345+
contents = html.Div([message, description, initial_contents])
349346

350347
panel = Reveal(
351348
title=self.title,
@@ -372,6 +369,7 @@ def update_message(self, new_store_contents):
372369
"An error was encountered when trying to load this component, "
373370
"please report this if it seems like a bug, thank you!"
374371
)
372+
# TODO: add Issue badge here
375373
return MessageContainer(
376374
[
377375
MessageHeader("Error"),
@@ -392,8 +390,9 @@ def update_contents(*args, **kwargs):
392390

393391
@app.callback(
394392
Output(self.id("contents"), "children"),
395-
[Input(self.id("panel") + "_summary", "n_clicks")],
396-
[State(self.id(), "data"), State(self.id("panel"), "open")],
393+
[Input(self.id("panel") + "_summary", "n_clicks"),
394+
Input(self.id(), "data")],
395+
[State(self.id("panel"), "open")],
397396
)
398397
def load_contents(panel_n_clicks, store_contents, panel_initially_open):
399398
"""

0 commit comments

Comments
 (0)