99from openmc .data import REACTION_MT
1010from openmc .data .reaction import REACTION_NAME
1111
12- app = dash .Dash (__name__ )
12+ app = dash .Dash (
13+ __name__ ,
14+ prevent_initial_callbacks = True ,
15+ meta_tags = [
16+ {
17+ "name" : "title" ,
18+ "content" : "XSPlot material cross section plotter"
19+ },
20+ {
21+ "name" : "description" ,
22+ "content" : "Online graph plotting tool for neutron macroscopic cross sections of materials" ,
23+ },
24+ {
25+ "name" : "keywrds" ,
26+ "keywords" : "plot neutron nuclear cross section energy barns database plotter" ,
27+ },
28+ {
29+ "name" : "author" ,
30+ "content" : "Jonathan Shimwell"
31+ },
32+ {
33+ "http-equiv" : "X-UA-Compatible" ,
34+ "content" : "IE=edge"
35+ },
36+ {
37+ "name" : "viewport" ,
38+ "content" : "width=device-width, initial-scale=1.0"
39+ },
40+ ],
41+ )
42+ app .title = "XSPlot neutron cross section plotter"
43+ app .description = "Plot neutron cross sections. Nuclear data from the TENDL library."
44+
1345
1446
1547server = app .server
1648
1749
18- app .layout = html .Div ([
19- html .Div ([
20- dcc .Dropdown (
21- # id='demo-dropdown',
22- options = element_names ,
23- placeholder = 'Enter an element...' ,
24- style = {'width' : 200 , "display" : "inline-block" },
25- # labelStyle={"display": "inline-block"}
26- id = 'element_name' ,
27- ),
28- dcc .Input (
29- id = 'fraction_value' ,
30- placeholder = 'Mass fraction' ,
31- value = '' ,
32- type = 'number' ,
33- style = {'padding' : 10 },
34- min = 0 ,
35- max = 1 ,
36- step = 0.01 ,
37- ),
38- # does not allow step size
39- # daq.NumericInput(
40- # id='fraction_value',
41- # label='Enter a fraction value...',
42- # value=0,
43- # min=0,
44- # max=1,
45- # # step=0.01,
46- # size=50,
47- # style={'width': 200, "display": "inline-block"},
48- # # style={'padding': 10}
49- # ),
50- html .Button ('Add Element' , id = 'editing-rows-button' , n_clicks = 0 ),
51- ], style = {'height' : 50 }),
50+ app .layout = html .Div (
51+ [
52+ html .Table (
53+ [
54+ html .Tr (
55+ [
56+ html .Th (
57+ dcc .Dropdown (
58+ # id='demo-dropdown',
59+ options = element_names ,
60+ placeholder = "Select an element..." ,
61+ style = {"width" : 200 , "display" : "inline-block" },
62+ # labelStyle={"display": "inline-block"}
63+ id = "element_name" ,
64+ # style={"height": 50}
65+ ),
66+ ),
67+ html .Th (
68+ dcc .Input (
69+ id = "fraction_value" ,
70+ placeholder = "Mass fraction" ,
71+ value = "" ,
72+ type = "number" ,
73+ style = {"padding" : 10 },
74+ min = 0 ,
75+ max = 1 ,
76+ step = 0.01 ,
77+ # style={"height": 50}
78+ ),
79+ ),
80+ html .Th (
81+ html .Button (
82+ "Add Element" ,
83+ id = "editing-rows-button" ,
84+ n_clicks = 0 ,
85+ style = {"height" : 40 , "width" :200 }
86+ ),
87+ ),
88+ ]
89+ ),
90+ ],
91+ style = {"width" : "100%" },
92+ ),
93+ # style={},
94+ # style={"height": 50, "text-align": "center"},
95+
5296 html .Br (),
5397 dash_table .DataTable (
54- id = 'adding-rows-table' ,
55- columns = [{
56- 'name' : 'Elements' ,
57- 'id' : 'Elements' ,
58- }, {
59- 'name' : 'Fractions' ,
60- 'id' : 'Fractions' ,
61-
62- }],
98+ id = "adding-rows-table" ,
99+ style_cell = {'textAlign' : 'center' },
100+ columns = [
101+ {
102+ "name" : "Elements" ,
103+ "id" : "Elements" ,
104+ },
105+ {
106+ "name" : "Fractions" ,
107+ "id" : "Fractions" ,
108+ },
109+ ],
63110 data = [],
64111 editable = True ,
65- row_deletable = True
112+ row_deletable = True ,
66113 ),
67- dcc .Input (
68- id = 'density_value' ,
69- placeholder = 'density in g/cm3' ,
70- value = '' ,
71- type = 'number' ,
72- style = {'padding' : 10 },
73- min = 0 ,
74- step = 0.01 ,
114+ html .Br (),
115+ html .Table (
116+ [
117+ html .Tr (
118+ [
119+ html .Th (
120+ dcc .Input (
121+ id = "density_value" ,
122+ placeholder = "density in g/cm3" ,
123+ value = "" ,
124+ type = "number" ,
125+ style = {"padding" : 10 },
126+ min = 0 ,
127+ step = 0.01 ,
128+ ),
129+ ),
130+ html .Th (
131+ dcc .Dropdown (
132+ # id='demo-dropdown',
133+ options = reaction_names ,
134+ placeholder = "Select reaction(s) to plot" ,
135+ style = {"width" : 400 , "display" : "inline-block" },
136+ # labelStyle={"display": "inline-block"}
137+ id = "reaction_names" ,
138+ multi = True ,
139+ ),
140+ ),
141+ ]
142+ )
143+ ],
144+ style = {"width" : "100%" },
75145 ),
76- dcc .Dropdown (
77- # id='demo-dropdown',
78- options = reaction_names ,
79- placeholder = 'Select reactions to plot' ,
80- style = {'width' : 700 , "display" : "inline-block" },
81- # labelStyle={"display": "inline-block"}
82- id = 'reaction_names' ,
83- multi = True
146+ html .Br (),
147+ html .Div (
148+ [
149+ html .Button (
150+ "Plot material" ,
151+ id = "update_plot" ,
152+ title = "Click to create or refresh the plot" ,
153+ style = {"height" : 40 , "width" :200 }
154+ ),
155+ ],
156+ style = {"height" : 50 , "text-align" : "center" },
84157 ),
85- html .Button ('Plot material' , id = 'update_plot' , title = 'Click to create or refresh the plot' ),
86158 # dcc.Graph(id='graph-container')
87159 html .Div (id = "graph_container" ),
88- ])
160+ ]
161+ )
162+
89163
90164@app .callback (
91- dash .dependencies .Output (' graph_container' , "children" ),
165+ dash .dependencies .Output (" graph_container" , "children" ),
92166 [
93167 Input ("update_plot" , "n_clicks" ),
94168 Input ("reaction_names" , "value" ),
98172 ],
99173 # [dash.dependencies.Input('update_plot', 'n_clicks')],
100174 # [dash.dependencies.State('input-on-submit', 'value')]
101- )
175+ )
102176def update_output (n_clicks , reaction_names , rows , density_value ):
103177 if n_clicks is None :
104178 raise dash .exceptions .PreventUpdate
@@ -107,29 +181,25 @@ def update_output(n_clicks, reaction_names, rows, density_value):
107181
108182 if trigger_id == "update_plot" :
109183
110- print (' reaction_names' , reaction_names )
111- print (' rows' , rows )
112- print (' density_value' , density_value )
184+ print (" reaction_names" , reaction_names )
185+ print (" rows" , rows )
186+ print (" density_value" , density_value )
113187
114- my_mat = openmc .Material (name = ' my_mat' )
188+ my_mat = openmc .Material (name = " my_mat" )
115189
116190 for entry in rows :
117191 # for key, values in entry.items():
118192 print (entry )
119193 # print('key',key, 'values',values)
120194
121195 my_mat .add_element (
122- entry ['Elements' ],
123- entry ['Fractions' ],
124- percent_type = 'ao'
196+ entry ["Elements" ], entry ["Fractions" ], percent_type = "ao"
125197 )
126-
127- my_mat .set_density (' g/cm3' , density_value )
198+
199+ my_mat .set_density (" g/cm3" , density_value )
128200
129201 energy , xs_data_set = openmc .calculate_cexs (
130- my_mat ,
131- 'material' ,
132- reaction_names
202+ my_mat , "material" , reaction_names
133203 )
134204
135205 all_x_y_data = []
@@ -140,33 +210,33 @@ def update_output(n_clicks, reaction_names, rows, density_value):
140210 "y" : xs_data ,
141211 "x" : energy ,
142212 "type" : "scatter" ,
143- "name" : f' MT { reaction_name } '
213+ "name" : f" MT { reaction_name } "
144214 # "marker": {"color": colors},
145215 }
146216 )
147- energy_units = 'eV'
148- xs_units = ' Macroscopic cross section $m^-1$'
217+ energy_units = "eV"
218+ xs_units = " Macroscopic cross section $m^-1$"
149219 return [
150220 dcc .Graph (
151221 config = dict (showSendToCloud = True ),
152222 figure = {
153223 "data" : all_x_y_data ,
154224 "layout" : {
155- "height" :800 ,
225+ "height" : 800 ,
156226 # "width":1600,
157227 "margin" : {"l" : 3 , "r" : 2 , "t" : 15 , "b" : 60 },
158228 "xaxis" : {
159229 "title" : {"text" : f"Energy { energy_units } " },
160230 # "type": xaxis_scale,
161- "type" : ' log' ,
231+ "type" : " log" ,
162232 "tickformat" : ".1e" ,
163233 "tickangle" : 45 ,
164234 },
165235 "yaxis" : {
166236 "automargin" : True ,
167237 # "title": {"text": f"Cross Section {xs_units}"},
168238 "title" : {"text" : xs_units },
169- "type" : ' log' ,
239+ "type" : " log" ,
170240 # "type": yaxis_scale,
171241 "tickformat" : ".1e" ,
172242 },
@@ -178,26 +248,26 @@ def update_output(n_clicks, reaction_names, rows, density_value):
178248 )
179249 ]
180250
181-
182251 # print('energy',energy)
183252 # print('xs_data',xs_data)
184253
254+
185255@app .callback (
186- Output (' adding-rows-table' , ' data' ),
187- Input (' editing-rows-button' , ' n_clicks' ),
188- State (' adding-rows-table' , ' data' ),
189- State (' element_name' , ' value' ),
190- State (' fraction_value' , ' value' ),
191- )
256+ Output (" adding-rows-table" , " data" ),
257+ Input (" editing-rows-button" , " n_clicks" ),
258+ State (" adding-rows-table" , " data" ),
259+ State (" element_name" , " value" ),
260+ State (" fraction_value" , " value" ),
261+ )
192262def add_row (n_clicks , rows , element_name , fraction_value ):
193263 if n_clicks > 0 :
194- if element_name == None :
195- print (' no elements selected' )
264+ if element_name == None :
265+ print (" no elements selected" )
196266 return rows
197- if fraction_value == '' :
198- print (' no fraction_value provided' )
267+ if fraction_value == "" :
268+ print (" no fraction_value provided" )
199269 return rows
200- rows .append ({' Elements' : element_name , ' Fractions' : fraction_value })
270+ rows .append ({" Elements" : element_name , " Fractions" : fraction_value })
201271 return rows
202272
203273
@@ -215,7 +285,7 @@ def add_row(n_clicks, rows, element_name, fraction_value):
215285# return existing_rows
216286
217287
218- #adapt to plot cross sections on table update
288+ # adapt to plot cross sections on table update
219289# @app.callback(
220290# Output('adding-rows-graph', 'figure'),
221291# Input('adding-rows-table', 'data'),
@@ -266,6 +336,5 @@ def add_row(n_clicks, rows, element_name, fraction_value):
266336# return fig
267337
268338
269-
270- if __name__ == '__main__' :
271- app .run_server (debug = True )
339+ if __name__ == "__main__" :
340+ app .run_server (debug = True )
0 commit comments