Skip to content

Commit 6577d32

Browse files
committed
remove id access on dash components passed to callbacks
complete CatalysisApp.modify_df() doc str can be passed directly in newer dash also auto-changes from docformatter --in-place --config setup.cfg crystal_toolkit
1 parent 0a383d2 commit 6577d32

17 files changed

+77
-89
lines changed

crystal_toolkit/apps/examples/diffraction_dynamic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ctc.register_crystal_toolkit(app=app, layout=my_layout)
2323

2424

25-
@app.callback(Output(xrd_component.id(), "data"), Input(load_btn.id, "n_clicks"))
25+
@app.callback(Output(xrd_component.id(), "data"), Input(load_btn, "n_clicks"))
2626
def load_structure(n_clicks: int) -> Structure:
2727
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]])
2828
return structure

crystal_toolkit/apps/examples/matbench_dielectric_datatable_xrd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
Output(structure_component.id(), "data"),
6565
# currently broken due to internal callback in XRayDiffractionComponent
6666
# Output(xrd_component.id(), "data"),
67-
Input(datatable_diel.id, "active_cell"),
67+
Input(datatable_diel, "active_cell"),
6868
)
6969
def update_structure(active_cell: dict[str, int | str]) -> Structure:
70-
"""Update StructureMoleculeComponent with pymatgen structure when user clicks on
71-
new scatter point.
70+
"""Update StructureMoleculeComponent with pymatgen structure when user clicks on new scatter
71+
point.
7272
"""
7373
row_idx = active_cell["row"]
7474
structure = df_diel.structure[row_idx]

crystal_toolkit/apps/examples/matbench_dielectric_structure_on_hover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def update_structure(
119119
click_data: dict[str, list[dict[str, Any]]], # needed only as callback trigger
120120
dropdown_value: str,
121121
) -> tuple[Structure, str]:
122-
"""Update StructureMoleculeComponent with pymatgen structure when user clicks or hovers
123-
a scatter point.
122+
"""Update StructureMoleculeComponent with pymatgen structure when user clicks or hovers a
123+
scatter point.
124124
"""
125125
triggered = dash.callback_context.triggered[0]
126126
if dropdown_value == "click" and triggered["prop_id"].endswith(".hoverData"):

crystal_toolkit/apps/examples/mpcontribs/catalysis.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ class CatalysisApp(MPApp):
4646
@staticmethod
4747
def modify_df(dataframe: pd.DataFrame) -> list[pd.DataFrame]:
4848
"""
49-
Filter DataFrame for binary visualization.
50-
:param dataframe:
51-
:return:
49+
Filter DataFrame for unary+binary materials visualization.
50+
51+
Args:
52+
dataframe (pd.DataFrame): the dataframe that you want to modify
53+
54+
Returns:
55+
list[pd.Dataframe): two dataframes, the input df filtered to unary or binary materials
56+
and one with the minimum energy of each material
5257
"""
5358

5459
# Extract the elements and number of them from formula
@@ -79,8 +84,8 @@ def get_plot(
7984
range_E,
8085
user_options,
8186
) -> go.Figure:
82-
"""
83-
Generate a 2D plot for binary visualization.
87+
"""Generate a 2D plot for binary visualization.
88+
8489
:param df_all_data:
8590
:param df_min_E:
8691
:param target_E:
@@ -100,7 +105,7 @@ def construct_grid(df, labels):
100105
custom_data = np.zeros((grid_dim, grid_dim), dtype=object)
101106
add_data = np.zeros((grid_dim, grid_dim), dtype=object)
102107
lookup_dict = df_min_E.set_index("element_tup").to_dict()
103-
el_combos = list(lookup_dict["energy"].keys())
108+
el_combos = list(lookup_dict["energy"])
104109
for i in range(len(labels)):
105110
for k in range(len(labels)):
106111
if i == k:

crystal_toolkit/apps/examples/transformations_minimal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454

5555

5656
@app.callback(
57-
Output("structure_out", "data"),
58-
Input(transformation_component.id(), "data"),
57+
Output("structure_out", "data"), Input(transformation_component.id(), "data")
5958
)
6059
def update_structure(struct):
6160
return struct

crystal_toolkit/apps/examples/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010

1111
def load_and_store_matbench_dataset(dataset_name: str) -> pd.DataFrame:
12-
"""Load, process and save Matbench datasets to disk to avoid having to re-process
13-
on subsequent app runs.
12+
"""Load, process and save Matbench datasets to disk to avoid having to re-process on subsequent
13+
app runs.
1414
"""
1515
data_path = os.path.join(os.path.dirname(__file__), f"{dataset_name}.json.gz")
1616

crystal_toolkit/components/bandstructure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def get_brillouin_zone_scene(bs: BandStructureSymmLine) -> Scene:
263263
)
264264
path += [start, end]
265265
cylinder_pairs += [[start, end]]
266-
# path_lines = Lines(positions=path, color="#ff4b5c",)
266+
# path_lines = Lines(positions=path, color="#ff4b5c")
267267
path_lines = Cylinders(
268268
positionPairs=cylinder_pairs, color="#5EB1BF", radius=0.01
269269
)
@@ -387,7 +387,7 @@ def get_bandstructure_traces(
387387
bs_traces += traces_for_segment
388388

389389
for entry_num in range(len(bs_data["ticks"]["label"])):
390-
for key in pretty_labels.keys():
390+
for key in pretty_labels:
391391
if key in bs_data["ticks"]["label"][entry_num]:
392392
bs_data["ticks"]["label"][entry_num] = bs_data["ticks"]["label"][
393393
entry_num

crystal_toolkit/components/diffraction_tem.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,7 @@ def generate_diffraction_pattern(structure, *args):
203203

204204

205205
class TEMDiffractionCalculator:
206-
"""
207-
Docstring
208-
"""
206+
"""Docstring."""
209207

210208
def __init__(self) -> None:
211209
# Initialize parameter caches to invalid so that on the first run,
@@ -233,9 +231,7 @@ def get_plot_2d(
233231
gamma,
234232
# **kwargs,
235233
) -> go:
236-
"""
237-
generate diffraction pattern using py4DSTEM and return as a plotly Figure object
238-
"""
234+
"""Generate diffraction pattern using py4DSTEM and return as a plotly Figure object."""
239235
t0 = time()
240236
# figure out what needs to be recomputed:
241237
new_crystal = py4DSTEM.process.diffraction.Crystal.from_pymatgen_structure(

crystal_toolkit/components/fermi_surface.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616

1717
class FermiSurfaceComponent(MPComponent):
18-
"""
19-
Component to display FermiSurface objects generated from ifermi.
18+
"""Component to display FermiSurface objects generated from ifermi.
2019
2120
Args:
2221
fermi_surface: An ifermi FermiSurface object.
@@ -35,8 +34,7 @@ def __init__(
3534

3635
@staticmethod
3736
def get_figure(fermi_surface: FermiSurface, **kwargs) -> Figure:
38-
"""
39-
Get a fermi surface figure.
37+
"""Get a fermi surface figure.
4038
4139
Args:
4240
fermi_surface: An ifermi FermiSurface object.

crystal_toolkit/components/phonon.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def get_brillouin_zone_scene(bs: PhononBandStructureSymmLine) -> Scene:
262262
)
263263
path += [start, end]
264264
cylinder_pairs += [[start, end]]
265-
# path_lines = Lines(positions=path, color="#ff4b5c",)
265+
# path_lines = Lines(positions=path, color="#ff4b5c")
266266
path_lines = Cylinders(
267267
positionPairs=cylinder_pairs, color="#5EB1BF", radius=0.01
268268
)
@@ -314,7 +314,7 @@ def get_ph_bandstructure_traces(bs, freq_range):
314314
bs_traces += traces_for_segment
315315

316316
for entry_num in range(len(bs_data["ticks"]["label"])):
317-
for key in pretty_labels.keys():
317+
for key in pretty_labels:
318318
if key in bs_data["ticks"]["label"][entry_num]:
319319
bs_data["ticks"]["label"][entry_num] = bs_data["ticks"]["label"][
320320
entry_num
@@ -702,8 +702,8 @@ def bs_dos_data(data, dos_select, label_select):
702702
Input(self.id("ph-bsdos-graph"), "clickData"),
703703
)
704704
def highlight_bz_on_hover_bs(hover_data, click_data, label_select):
705-
"""Highlight the corresponding point/edge of the Brillouin Zone when hovering
706-
the band structure plot.
705+
"""Highlight the corresponding point/edge of the Brillouin Zone when hovering the band
706+
structure plot.
707707
"""
708708

709709
# TODO: figure out what to return (CSS?) to highlight BZ edge/point

0 commit comments

Comments
 (0)