Skip to content

Commit

Permalink
Merge pull request #108 from RemDelaporteMathurin/sieverts-henry
Browse files Browse the repository at this point in the history
Choose between Sievert and Henry when adding a property
  • Loading branch information
RemDelaporteMathurin authored Nov 9, 2024
2 parents ea85ae6 + 954bc43 commit 7b80953
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 32 deletions.
54 changes: 38 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,44 @@ def toggle_modal(n1, is_open):
prevent_initial_call=True,
)(cb.make_toggle_modal_function(group))

app.callback(
dash.Output(f"material_filter_{group}", "options"),
dash.Output(f"author_filter_{group}", "options"),
dash.Output(f"error_message_new_{group}", "children"),
dash.Input(f"submit_new_{group}", "n_clicks"),
dash.Input(f"material_filter_{group}", "value"),
dash.State(f"new_{group}_pre_exp", "value"),
dash.State(f"new_{group}_act_energy", "value"),
dash.State(f"new_{group}_author", "value"),
dash.State(f"new_{group}_year", "value"),
dash.State(f"new_{group}_isotope", "value"),
dash.State(f"new_{group}_material", "value"),
dash.State(f"new_{group}_range_low", "value"),
dash.State(f"new_{group}_range_high", "value"),
prevent_initial_call=True,
)(cb.make_add_property(group))
# add property form
# since an additional parameter is needed for solubility and permeability
# we need to check the group
if group in ["solubility", "permeability"]:
app.callback(
dash.Output(f"material_filter_{group}", "options"),
dash.Output(f"author_filter_{group}", "options"),
dash.Output(f"error_message_new_{group}", "children"),
dash.Input(f"submit_new_{group}", "n_clicks"),
dash.Input(f"material_filter_{group}", "value"),
dash.State(f"new_{group}_pre_exp", "value"),
dash.State(f"new_{group}_act_energy", "value"),
dash.State(f"new_{group}_author", "value"),
dash.State(f"new_{group}_year", "value"),
dash.State(f"new_{group}_isotope", "value"),
dash.State(f"new_{group}_material", "value"),
dash.State(f"new_{group}_range_low", "value"),
dash.State(f"new_{group}_range_high", "value"),
dash.State(f"new_{group}_law", "value"),
prevent_initial_call=True,
)(cb.make_add_property(group))
else:
app.callback(
dash.Output(f"material_filter_{group}", "options"),
dash.Output(f"author_filter_{group}", "options"),
dash.Output(f"error_message_new_{group}", "children"),
dash.Input(f"submit_new_{group}", "n_clicks"),
dash.Input(f"material_filter_{group}", "value"),
dash.State(f"new_{group}_pre_exp", "value"),
dash.State(f"new_{group}_act_energy", "value"),
dash.State(f"new_{group}_author", "value"),
dash.State(f"new_{group}_year", "value"),
dash.State(f"new_{group}_isotope", "value"),
dash.State(f"new_{group}_material", "value"),
dash.State(f"new_{group}_range_low", "value"),
dash.State(f"new_{group}_range_high", "value"),
prevent_initial_call=True,
)(cb.make_add_property(group))

app.callback(
dash.Output(f"table_{group}", "data"),
Expand Down
3 changes: 2 additions & 1 deletion htm_dashboard/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def add_property(
new_material,
new_range_low,
new_range_high,
new_sol_law=None,
):
changed_id = [p["prop_id"] for p in dash.callback_context.triggered][0]
if changed_id == f"submit_new_{group}.n_clicks":
Expand All @@ -244,7 +245,7 @@ def add_property(
new_property = htm.Solubility(
S_0=new_pre_exp,
E_S=new_act_energy,
law="sievert", # TODO expose this (see #68)
law=new_sol_law,
)
elif group == "recombination_coeff":
new_property = htm.RecombinationCoeff(
Expand Down
48 changes: 33 additions & 15 deletions htm_dashboard/new_property_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ def make_form(property_type: str):
pre_exp_label = f"D_0 ({htm.Diffusivity().units:~P})"
act_energy_label = "E_D (eV)"
elif property_type == "solubility":
sample_prop = htm.Solubility(law="sievert")
pre_exp_label = f"S_0 ({sample_prop.units:~P})"
pre_exp_label = f"S_0 (Sievert: {htm.Solubility(law='sievert').units:~P}, Henry: {htm.Solubility(law='henry').units:~P})"
act_energy_label = "E_S (eV)"
elif property_type == "permeability":
pre_exp_label = f"P_0 ({htm.Permeability(law='sievert').units:~P})"
pre_exp_label = f"P_0 (Sievert: {htm.Permeability(law='sievert').units:~P}, Henry: {htm.Permeability(law='henry').units:~P})"
act_energy_label = "E_P (eV)"
elif property_type == "recombination_coeff":
pre_exp_label = f"Kr_0 ({htm.RecombinationCoeff().units:~P})"
act_energy_label = "E_Kr (eV)"
elif property_type == "dissociation_coeff":
pre_exp_label = f"Kd_0 ({htm.DissociationCoeff().units:~P})"
act_energy_label = "E_Kd (eV)"

preexponential_input = html.Div(
[
dbc.Label(pre_exp_label, width=2),
dbc.Label(pre_exp_label, width=10),
dbc.Col(
dbc.Input(
type="number",
Expand Down Expand Up @@ -139,15 +139,33 @@ def make_form(property_type: str):
),
],
)
form = dbc.Form(
[
preexponential_input,
activation_energy_input,
author_input,
year_input,
isotope_input,
material_input,
temperature_input,
]
)

inputs = [
preexponential_input,
activation_energy_input,
author_input,
year_input,
isotope_input,
material_input,
temperature_input,
]
if property_type in ["solubility", "permeability"]:
solubility_law_input = html.Div(
[
dbc.Label("Law", width=2),
dbc.Col(
dbc.RadioItems(
id=f"new_{property_type}_law",
value="sievert",
options=[
{"label": "Sievert", "value": "sievert"},
{"label": "Henry", "value": "henry"},
],
),
width=10,
),
],
)
inputs.insert(0, solubility_law_input)
form = dbc.Form(inputs)
return form

0 comments on commit 7b80953

Please sign in to comment.