Skip to content

Commit 6b47c55

Browse files
committed
auto formatting
1 parent 70f577d commit 6b47c55

File tree

3 files changed

+51
-65
lines changed

3 files changed

+51
-65
lines changed

crystal_toolkit/apps/examples/diffraction_dynamic.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
# standard Dash imports
22
import dash
3-
from dash import html
4-
from dash import dcc
53
from dash.dependencies import Input, Output
64

5+
# create our crystal structure using pymatgen
6+
from pymatgen.core.lattice import Lattice
7+
from pymatgen.core.structure import Structure
8+
79
# standard Crystal Toolkit import
810
import crystal_toolkit.components as ctc
11+
from crystal_toolkit.helpers.layouts import H1, Button, Container
912
from crystal_toolkit.settings import SETTINGS
10-
from crystal_toolkit.helpers.layouts import H1, H2, Container, Button
1113

1214
# create Dash app as normal
1315
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH)
1416

15-
# create our crystal structure using pymatgen
16-
from pymatgen.core.structure import Structure
17-
from pymatgen.core.lattice import Lattice
18-
19-
xrd_component = ctc.XRayDiffractionComponent()
17+
xrd_component = ctc.XRayDiffractionComponent(id="xrd-diffraction")
2018

2119
# example layout to demonstrate capabilities of component
22-
my_layout = Container(
23-
[
24-
H1("XRDComponent Example (Structure Added After Loading)"),
25-
xrd_component.layout(),
26-
Button("Load XRD", id="load-xrd-button"),
27-
]
28-
)
20+
page_title = H1("XRDComponent Example (Structure Added After Loading)")
21+
load_btn = Button("Load XRD", id="load-xrd-button")
22+
my_layout = Container([page_title, xrd_component.layout(), load_btn])
2923

3024
# as explained in "preamble" section in documentation
3125
ctc.register_crystal_toolkit(app=app, layout=my_layout)
3226

3327

34-
@app.callback(
35-
Output(xrd_component.id(), "data"), [Input("load-xrd-button", "n_clicks")]
36-
)
37-
def load_structure(n_clicks):
28+
@app.callback(Output(xrd_component.id(), "data"), Input(load_btn.id, "n_clicks"))
29+
def load_structure(n_clicks: int) -> Structure:
3830
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]])
3931
return structure
4032

crystal_toolkit/components/structure.py

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
1-
from pathlib import Path
2-
3-
from tempfile import TemporaryDirectory
4-
5-
from base64 import b64encode
6-
7-
import json
8-
import os
91
import re
10-
import sys
112
import warnings
3+
from base64 import b64encode
124
from collections import OrderedDict
135
from itertools import chain, combinations_with_replacement
14-
from pymatgen.io.vasp.sets import MPRelaxSet
6+
from pathlib import Path
7+
from tempfile import TemporaryDirectory
158
from typing import Dict, Optional, Tuple, Union
169

17-
import dash
18-
from dash import dash_table as dt
1910
import numpy as np
20-
from dash.dependencies import Input, Output, State, MATCH
11+
from dash import dash_table as dt
12+
from dash.dependencies import Input, Output, State
2113
from dash.exceptions import PreventUpdate
2214
from dash_mp_components import CrystalToolkitScene
15+
from emmet.core.settings import EmmetSettings
2316
from pymatgen.analysis.graphs import MoleculeGraph, StructureGraph
2417
from pymatgen.analysis.local_env import NearNeighbors
2518
from pymatgen.core.composition import Composition
2619
from pymatgen.core.periodic_table import DummySpecie
2720
from pymatgen.core.structure import Molecule, Structure
21+
from pymatgen.io.vasp.sets import MPRelaxSet
2822
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
29-
from emmet.core.settings import EmmetSettings
3023

3124
from crystal_toolkit.core.legend import Legend
3225
from crystal_toolkit.core.mpcomponent import MPComponent
3326
from crystal_toolkit.core.scene import Scene
34-
from crystal_toolkit.helpers.layouts import *
27+
from crystal_toolkit.helpers.layouts import H2, Field, dcc, html
3528
from crystal_toolkit.settings import SETTINGS
3629

3730
try:
@@ -56,7 +49,7 @@
5649
"show_expand_button": True,
5750
"show_image_button": True,
5851
"show_export_button": True,
59-
"show_position_button": True
52+
"show_position_button": True,
6053
}
6154

6255

@@ -256,7 +249,7 @@ def generate_callbacks(self, app, cache):
256249
app.clientside_callback(
257250
"""
258251
function (bonding_strategy, custom_cutoffs_rows, unit_cell_choice) {
259-
252+
260253
const bonding_strategy_kwargs = {}
261254
if (bonding_strategy === 'CutOffDictNN') {
262255
const cut_off_dict = []
@@ -265,7 +258,7 @@ def generate_callbacks(self, app, cache):
265258
})
266259
bonding_strategy_kwargs.cut_off_dict = cut_off_dict
267260
}
268-
261+
269262
return {
270263
bonding_strategy: bonding_strategy,
271264
bonding_strategy_kwargs: bonding_strategy_kwargs,
@@ -299,7 +292,7 @@ def generate_callbacks(self, app, cache):
299292
app.clientside_callback(
300293
"""
301294
function (colorScheme, radiusStrategy, drawOptions, displayOptions) {
302-
295+
303296
const newDisplayOptions = Object.assign({}, displayOptions);
304297
newDisplayOptions.color_scheme = colorScheme
305298
newDisplayOptions.radius_strategy = radiusStrategy
@@ -462,7 +455,7 @@ def download_image(image_data_timestamp, image_data, data):
462455
spgrp = struct_or_mol.get_space_group_info()[0]
463456
else:
464457
spgrp = ""
465-
request_filename = "{}-{}-crystal-toolkit.png".format(formula, spgrp)
458+
request_filename = f"{formula}-{spgrp}-crystal-toolkit.png"
466459

467460
return {
468461
"content": image_data[len("data:image/png;base64,") :],
@@ -628,7 +621,7 @@ def get_font_color(hex_code):
628621
legend_elements,
629622
id=self.id("legend"),
630623
style={"display": "flex"},
631-
className="buttons"
624+
className="buttons",
632625
)
633626

634627
def _make_title(self, legend):
@@ -761,7 +754,9 @@ def _sub_layouts(self):
761754
),
762755
html.Div(
763756
[
764-
html.Label("Change bonding algorithm: ", className="mpc-label"),
757+
html.Label(
758+
"Change bonding algorithm: ", className="mpc-label"
759+
),
765760
bonding_algorithm,
766761
bonding_algorithm_custom_cutoffs,
767762
]
@@ -786,15 +781,20 @@ def _sub_layouts(self):
786781
html.Div(
787782
dcc.Dropdown(
788783
options=[
789-
{"label": "Ionic", "value": "specified_or_average_ionic"},
784+
{
785+
"label": "Ionic",
786+
"value": "specified_or_average_ionic",
787+
},
790788
{"label": "Covalent", "value": "covalent"},
791789
{"label": "Van der Waals", "value": "van_der_waals"},
792790
{
793791
"label": f"Uniform ({Legend.uniform_radius}Å)",
794792
"value": "uniform",
795793
},
796794
],
797-
value=self.initial_data["display_options"]["radius_strategy"],
795+
value=self.initial_data["display_options"][
796+
"radius_strategy"
797+
],
798798
clearable=False,
799799
persistence=SETTINGS.PERSISTENCE,
800800
persistence_type=SETTINGS.PERSISTENCE_TYPE,
@@ -875,10 +875,7 @@ def _sub_layouts(self):
875875
struct_layout = html.Div(
876876
[
877877
CrystalToolkitScene(
878-
[
879-
options_layout,
880-
legend_layout
881-
],
878+
[options_layout, legend_layout],
882879
id=self.id("scene"),
883880
className=self.className,
884881
data=self.initial_data["scene"],
@@ -893,7 +890,7 @@ def _sub_layouts(self):
893890
**self.scene_kwargs,
894891
),
895892
dcc.Download(id=self.id("download-image")),
896-
dcc.Download(id=self.id("download-structure"))
893+
dcc.Download(id=self.id("download-structure")),
897894
]
898895
)
899896

@@ -906,7 +903,7 @@ def _sub_layouts(self):
906903

907904
def layout(self, size: str = "500px") -> html.Div:
908905
"""
909-
:param size: a CSS string specifying width/height of Div
906+
:param size: a CSS dimension specifying width/height of Div
910907
:return: A html.Div containing the 3D structure or molecule
911908
"""
912909
return html.Div(
@@ -946,7 +943,7 @@ def _preprocess_input_to_graph(
946943

947944
if isinstance(input, Structure):
948945

949-
# ensure fractional co-ordinates are normalized to be in [0,1)
946+
# ensure fractional coordinates are normalized to be in [0,1)
950947
# (this is actually not guaranteed by Structure)
951948
try:
952949
input = input.as_dict(verbosity=0)
@@ -988,10 +985,10 @@ def _preprocess_input_to_graph(
988985
(x[0], x[1]): x[2]
989986
for x in bonding_strategy_kwargs["cut_off_dict"]
990987
}
991-
bonding_strategy = StructureMoleculeComponent.available_bonding_strategies[
992-
bonding_strategy
993-
](
994-
**bonding_strategy_kwargs
988+
bonding_strategy = (
989+
StructureMoleculeComponent.available_bonding_strategies[
990+
bonding_strategy
991+
](**bonding_strategy_kwargs)
995992
)
996993
try:
997994
with warnings.catch_warnings():

crystal_toolkit/helpers/utils.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
from crystal_toolkit import _DEFAULTS
22

3+
34
def update_object_args(d_args, object_name, allowed_args):
45
"""Read dafault properties and overwrite them if user input exists
5-
6+
67
Arguments:
78
d_args {dict} -- User defined properties
89
object_name {str} -- Name of object
910
allowed_kwargs {List[str]} -- Used to limit the data that is passed to pythreejs
10-
11+
1112
Returns:
1213
Dictionary -- Properties of object after userinput and default values are considered
1314
"""
14-
obj_args = {
15-
k: v
16-
for k, v in (_DEFAULTS['scene'][object_name] or {}).items()
17-
}
18-
obj_args.update({
19-
k: v
20-
for k, v in (d_args or {}).items() if k in allowed_args and v != None
21-
})
22-
return obj_args
15+
obj_args = {k: v for k, v in (_DEFAULTS["scene"][object_name] or {}).items()}
16+
obj_args.update(
17+
{k: v for k, v in (d_args or {}).items() if k in allowed_args and v != None}
18+
)
19+
return obj_args

0 commit comments

Comments
 (0)