-
Notifications
You must be signed in to change notification settings - Fork 0
/
single_page_example.py
111 lines (92 loc) · 2.56 KB
/
single_page_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
Chemical Dashboard for reactions
Version 0.1.1 (Jan 03, 14:15:00 2023)
Update: Jan 20, 2023.
Oxy balance included
@author: Alexander Minidis (DocMinus)
license: MIT
Copyright (c) 2023 DocMinus
"""
import dash_bootstrap_components as dbc
from dash import Dash, Input, Output, State, ctx, dcc, html
from rdkit import RDLogger
from src.calculations.oxybalance import n_count, oxy_balance
from src.ids import *
from src.mol_img import mol_image
RDLogger.logger().setLevel(RDLogger.CRITICAL)
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = html.Div(
[
html.H1("Safety Calculations"),
html.Hr(),
html.Div(
[
html.H3("Enter compound as smiles:"),
html.Label(
"here TNT as test example: C1(C=C([N+](=O)[O-])C(C)=C([N+]([O-])=O)C=1)[N+]([O-])=O"
),
html.Br(),
dcc.Input(
id="input",
type="text",
value="C1(C=C([N+](=O)[O-])C(C)=C([N+]([O-])=O)C=1)[N+]([O-])=O",
debounce=True,
),
html.Button("Submit", id="button0"),
]
),
html.Br(),
html.Div(id="image"),
html.Span(id="o_balance"),
html.Div(id="num_of_n"),
html.Br(),
html.Div(
[
html.Button("Clear Form", id="reset", n_clicks=0),
]
),
]
)
@app.callback(
[
Output("o_balance", "children"),
Output("num_of_n", "children"),
Output("image", "children"),
],
[
Input("button0", "n_clicks"),
State("input", "value"),
Input("reset", "n_clicks"),
],
)
def update_image_0(button0, input, reset):
button_triggered = ctx.triggered_id
num_of_n = 0
o_balance = 0
image = mol_image(input)
alt_text = "No or invalid smiles. "
if len(image):
o_balance = oxy_balance(input)
num_of_n = n_count(input)
_i0 = html.Img(
src="data:image/svg+xml;base64,{}".format(image),
alt=alt_text,
)
if button_triggered == "reset":
o_balance = 0
image = ""
_i0 = html.Img(src="", alt=alt_text)
return (
f"Oxygene Balance = {o_balance} !Safe values > - 200!",
f"Nitrogen Count = {num_of_n}",
_i0,
)
@app.callback(
Output("input", "value"),
[Input("reset", "n_clicks")],
)
def clear(reset):
return ""
if __name__ == "__main__":
debug = True
app.run_server(debug=debug, port=8069)