-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
823 lines (663 loc) · 35.5 KB
/
GUI.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 22 20:08:19 2023
@author: viola
"""
# import necessary modules
from DBM_Dirac import *
from DBM_Parabolic import *
from SBM_Parabolic import *
from plots import *
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import PySimpleGUI as sg
import sys
# define functions to generate GUI
def make_window0():
"""
Make the initial window of the GUI
in which the user can enter the configuration file
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text('Configuration File Path:'), sg.Input(key='-FILE-'), sg.FileBrowse()],
[sg.Button('Load Configuration'),sg.Button('Next >')]]
window = sg.Window("Thermoelectric materials performance - Configuration",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window1(): # model selection
"""
Make the first window of the GUI, where the model is selected.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance")],
# select model (DBMD,DBMP, SBMP)
[sg.Text('Model to apply'), sg.InputText(key='-IN_Model-')],
[sg.Button('Next >')],
]
window = sg.Window("Thermoelectric materials performance",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window2(): # DBMD, dependency on the energy gap and the chemical potential
"""
Make the window of the GUI to insert parameters for Double-Dirac-Band Model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the energy gap and the chemical potential - Double-Dirac-Band Model")],
# set energy gap parameters
[sg.Text('Minimum energy gap'), sg.InputText(key='-IN_delta_min-')],
[sg.Text('Maximum energy gap'), sg.InputText(key='-IN_delta_max-')],
[sg.Text('Energy gap step'), sg.InputText(key='-IN_delta_step-')],
# set chemical potential parameters
[sg.Text('Minimum chemical potential'), sg.InputText(key='-IN_eta_min-')],
[sg.Text('Maximum chemical potential'), sg.InputText(key='-IN_eta_max-')],
[sg.Text('Chemical potential step'), sg.InputText(key='-IN_eta_step-')],
# set thermal lattice conductivity
[sg.Text('Lattice thermal conductivity'), sg.InputText(key='-IN_rk-')],
# space for 2D plots
[sg.Canvas(key='-FIG0-')],
[sg.Button('< Choose Model'),sg.Button('Show 2D Plots'), sg.Button('Save'), sg.Button('Show 3D Plots >'),sg.Button('Second Part >')],
]
window = sg.Window("Thermoelectric materials performance",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window2_3d(): # DBMD, 3D plot
"""
Make the window of the GUI to visualize 3D plots of Double-Dirac-band model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the energy gap and the chemical potential - Double-Dirac-Band Model")],
[sg.Text('3D plots')],
# spaces for 3D plots
[sg.Canvas(key='-FIG1-'),sg.Canvas(key='-FIG2-')],
[sg.Canvas(key='-FIG3-'),sg.Canvas(key='-FIG4-')],
[sg.Button('< Prev'),sg.Button('Show 3D Plots'),sg.Button('Save'),sg.Button('Seond Part >')],
]
window = sg.Window('3D plots',
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window3(): # DBMP, dependency on the energy gap and the chemical potential
"""
Make the window of the GUI to insert parameters for Double-Parabolic-Band Model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the energy gap and the chemical potential - Double-Parabolic-Band Model")],
# set energy gap parameters
[sg.Text('Minimum energy gap'), sg.InputText(key='-IN_delta_min-')],
[sg.Text('Maximum energy gap'), sg.InputText(key='-IN_delta_max-')],
[sg.Text('Energy gap step'), sg.InputText(key='-IN_delta_step-')],
# set chemical potential parameters
[sg.Text('Minimum chemical potential'), sg.InputText(key='-IN_eta_min-')],
[sg.Text('Maximum chemical potential'), sg.InputText(key='-IN_eta_max-')],
[sg.Text('Chemical potential step'), sg.InputText(key='-IN_eta_step-')],
# set thermal lattice conductivity
[sg.Text('Lattice thermal conductivity'), sg.InputText(key='-IN_rk-')],
# space for 2D plots
[sg.Canvas(key='-FIG0-')],
[sg.Button('< Choose Model'),sg.Button('Show 2D Plots'), sg.Button('Save'), sg.Button('Show 3D Plots >'),sg.Button('Second Part >')],
]
window = sg.Window("Thermoelectric materials performance",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window3_3d(): # DBMP, 3D plot
"""
Make the window of the GUI to visualize 3D plots of Double-Parabolic-band model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the energy gap and the chemical potential - Double-Parabolic-Band Model")],
[sg.Text('3D plots')],
# spaces for 3D plots
[sg.Canvas(key='-FIG1-'),sg.Canvas(key='-FIG2-')],
[sg.Canvas(key='-FIG3-'),sg.Canvas(key='-FIG4-')],
[sg.Button('< Prev'),sg.Button('Show 3D Plots'), sg.Button('Save'),sg.Button('Second Part >')],
]
window = sg.Window('3D plots of the free energy in the different spaces',
layout,location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window4(): # SBMP, dependency on the energy gap and the chemical potential
"""
Make the window of the GUI to insert parameters for Single-Parabolic-Band Model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the energy gap and the chemical potential - Single-Parabolic-Band Model")],
# set chemical potential parameters
[sg.Text('Minimum chemical potential'), sg.InputText(key='-IN_eta_min-')],
[sg.Text('Maximum chemical potential'), sg.InputText(key='-IN_eta_max-')],
[sg.Text('Chemical potential step'), sg.InputText(key='-IN_eta_step-')],
# set thermal lattice conductivity
[sg.Text('Lattice thermal conductivity'), sg.InputText(key='-IN_rk-')],
# space for 2D plots
[sg.Canvas(key='-FIG0-')],
[sg.Button('< Choose Model'),sg.Button('Show Plots'), sg.Button('Save'),sg.Button('Second Part >')],
]
window = sg.Window("Thermoelectric materials performance",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window5(): # DBMD, dependency on the thermal lattice conductivity
"""
Make the window of the GUI to insert r_k parameter for Double-Dirac-Band Model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the phonon thermal conductivity - Double-Dirac-Band Model")],
# set thermal lattice conductivity parameters
[sg.Text('Minimum lattice conductivity'), sg.InputText(key='-IN_rk_min-')],
[sg.Text('Maximum lattice conductivity'), sg.InputText(key='-IN_rk_max-')],
[sg.Text('Lattice conductivity step'), sg.InputText(key='-IN_rk_step-')],
# space for 3D plot
[sg.Canvas(key='-FIG0-')],
[sg.Button('< Choose Model'),sg.Button('Show Plot'), sg.Button('Save')],
]
window = sg.Window("Thermoelectric materials performance",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window6(): # DBMP, dependency on the thermal lattice conductivity
"""
Make the window of the GUI to insert r_k parameter for Double-Parabolic-Band Model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the phonon thermal conductivity - Double-Parabolic-Band Model")],
# set thermal lattice conductivity parameters
[sg.Text('Minimum lattice conductivity'), sg.InputText(key='-IN_rk_min-')],
[sg.Text('Maximum lattice conductivity'), sg.InputText(key='-IN_rk_max-')],
[sg.Text('Lattice conductivity step'), sg.InputText(key='-IN_rk_step-')],
# space for 3D plot
[sg.Canvas(key='-FIG0-')],
[sg.Button('< Choose Model'),sg.Button('Show Plot'), sg.Button('Save')],
]
window = sg.Window("Thermoelectric materials performance",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window7(): # SBMP, dependency on the thermal lattice conductivity
"""
Make the window of the GUI to insert r_k parameter for Single-Parabolic-Band Model.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text("Thermoelectric materials performance: dependency on the phonon thermal conductivity - Single-Parabolic-Band Model")],
# set thermal lattice conductivity parameters
[sg.Text('Minimum lattice conductivity'), sg.InputText(key='-IN_rk_min-')],
[sg.Text('Maximum lattice conductivity'), sg.InputText(key='-IN_rk_max-')],
[sg.Text('Lattice conductivity step'), sg.InputText(key='-IN_rk_step-')],
# space for 3D plot
[sg.Canvas(key='-FIG0-')],
[sg.Button('< Choose Model'), sg.Button('Show Plot'), sg.Button('Save')],
]
window = sg.Window("Thermoelectric materials performance",
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
def make_window8():
"""
Make the window of the GUI to save data.
Returns
-------
window: TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. Window created
"""
layout = [[sg.Text('Save data')],
# indicate where to save the data
[sg.Text('Path of the directory for the txt data file:'), sg.InputText(key='-IN_txt_path-')],
[sg.Text('Name of the txt file:'), sg.InputText(key='-IN_txt_model'), sg.InputText(key='-IN_txt_part'), sg.InputText(key='-IN_txt_file-')],
[sg.Button('Save Data'), sg.Button('Done')],
]
window = sg.Window('Thermoelectric materials performance - Save data',
layout,
location=(0, 0),
finalize=True,
element_justification="center")
return window
# define functions to manage operations in GUI windows
def load_configuration(file_path):
"""
Function that loads the configuration file from a specific path given by the user
Parameters
----------
file_path : TYPE str
DESCRIPTION. Path of the configuration file
Returns
-------
Names : TYPE list of str
DESCRIPTION. List of the names of the values
Values : TYPE list of floats
DESCRIPTION. List of the values
"""
Names = []
Values = []
try:
with open(file_path, 'r') as file:
for line in file:
# Ignoring the lines in the configuration file starting with %
if not line.startswith("%"):
values = line.strip().split(",")
if len(values) >= 2:
Names.append(values[0].strip())
Values.append(float(values[1].strip()))
return Names, Values
except FileNotFoundError:
print('File not found:', file_path)
return [], []
def user_operations(current_window):
"""
Manages standard user operations: go back to first window to choose model, save data or close.
Parameters
----------
window : TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. current window where the user choice are made
"""
if event == '< Choose Model': # if user clicks on button '< Choose Model',
current_window.close() # close current window
window1.un_hide() # and go back to model selection
elif event == 'Save': # if user clicks on button 'Save',
current_window.hide() # hide current window
global window8
window8 = make_window8() # and open window to save data
elif event == sg.WIN_CLOSED: # if user closes window, close the programm
current_window.close()
sys.exit()
else:
pass
def get_inputs_first_part(window):
"""
Reads the inputs from specific window, for the first part.
Parameters
----------
window : TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. window where the inputs to read have been written by the user
Returns
-------
TYPE list
DESCRIPTION. list containing the arrays for the energy gap and the chemical potential and the value of rk
"""
inputs = {}
for key in values:
if key != '-FIG0-':
inputs[key] = float(values[key])
if window == window2 or window == window3: # for double-band models
delta_min = inputs['-IN_delta_min-'] # minimum energy gap value
delta_max = inputs['-IN_delta_max-'] # maximum energy gap value
delta_st = inputs['-IN_delta_step-'] # energy gap step
delta=np.arange(delta_min, delta_max, delta_st) #create array for energy gap
else: # for single-band model
delta = None
eta_min = inputs['-IN_eta_min-'] # minimum chemical potential value
eta_max = inputs['-IN_eta_max-'] # maximum chemical potential value
eta_st = inputs['-IN_eta_step-'] # chemical potential step
eta=np.arange(eta_min, eta_max, eta_st) #create array for chemical potential
rk = inputs['-IN_rk-'] # thermal lattice conductivity (fixed)
return [delta, eta, rk]
def get_inputs_second_part():
"""
Reads the inputs from specific window, for the second part.
Parameters
----------
window : TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. window where the inputs to read have been written by the user
Returns
-------
rk : TYPE nd.array
DESCRIPTION. array for thermal lattice conductivity
"""
inputs = {}
for key in values:
if key != '-FIG0-':
inputs[key] = float(values[key])
rk_min = inputs['-IN_rk_min-'] # minimum thermal lattice conductivity value
rk_max = inputs['-IN_rk_max-'] # maximum thermal lattice conductivity value
rk_st = inputs['-IN_rk_step-'] # energy thermal lattice conductivity
rk = np.arange(rk_min, rk_max, rk_st) # create array for thermal lattice consuctivity
return rk
def draw_figure(canvas,
figure):
"""
Function that draws the wanted figure in the empty canvas of the window.
Parameters
----------
canvas: TYPE PySimpleGUI.Canvas(canvas, background_color, size)
DESCRIPTION. drawable panel on the surface of the PySimpleGUI application window
figure: TYPE matplotlib.figure.Figure()
DESCRIPTION. Figure we want to draw on the panel
Returns
-------
figure_canvas_agg: TYPE FigureCanvasTkAgg(figure, canvas)
DESCRIPTION. Figure drawn on the canvas
"""
figure_canvas_agg = FigureCanvasTkAgg(figure,canvas)
figure_canvas_agg.draw()
figure_canvas_agg.get_tk_widget().pack(side="top", fill="both", expand=1)
return figure_canvas_agg
def delete_fig_agg(fig_agg):
"""
Function to delete the figure drawn on the canvas.
Parameters
----------
fig_agg: TYPE FigureCanvasTkAgg(figure, canvas)
DESCRIPTION. Figure drawn on the canvas
Returns
-------
None.
"""
fig_agg.get_tk_widget().forget()
plt.close('all')
def plot_clear_draw(plot, params, figure_canvas, figure):
"""
Creates plot, clears canvas to plot it.
Parameters
----------
plot : TYPE function to create plot (from plots.py)
DESCRIPTION. figure containing the plot
params : TYPE parameters useful for the plotting function
DESCRIPTION. list of parameters (physical quantities to plot and labels to put on the axis)
figure_canvas : TYPE PySimpleGUI.Canvas(canvas, background_color, size)
DESCRIPTION. drawable panel on the surface of the PySimpleGUI application window to clear
figure : TYPE matplotlib.figure.Figure()
DESCRIPTION. Figure we want to draw on the panel
"""
if plot == plot_anim_3d: # for 3D plots
graph = plot(params[0], params[1], params[2], params[3], params[4], params[5], params[6]) # use associated function from plots.py (depending on 7 parameters)
elif plot == complete_2d_plot: # 2D plots
graph = plot(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7]) # use associated function from plots.py (depending on 8 parameters)
if figure_canvas is not None: # clear space and draw plot
delete_fig_agg(figure_canvas)
figure_canvas = draw_figure(window[figure].TKCanvas, graph)
def write_txt(model, part, inputs, outputs):
"""
Saves data associated model and part of interest.
Parameters
----------
model : TYPE string
DESCRIPTION. string indicating the used model ('DBMD', 'DBMP', 'SBMP')
part : TYPE string
DESCRIPTION. string indicating the part of the study ('1', '2')
inputs : TYPE list
DESCRIPTION. list containing input data (energy gap, chemical potential, thermal lattice conductivity)
outputs : TYPE list
DESCRIPTION. list containing output data (thermoelectric quantities)
"""
with open(path_to_file, 'w') as f:
if (part == '1' and (model == 'DBMD' or model == 'DBMP')) or (part == '2'): # inputs = [delta, eta, rk]
if part == '1' and (model == 'DBMD' or model == 'DBMP'):
f.write('delta' + ',' + 'eta' + ',' + 'rk' + ',' + 'sigma' + ',' + 'S' + ',' + 'k_e' + ',' + 'ZT' + '\n')
inputs[-1] = [inputs[-1]]*np.ones((int(inputs[0].size/inputs[0][0].size), inputs[0][0].size))
elif part == '2' and (model == 'DBMD' or model == 'DBMP'):
f.write('delta' + ',' + 'rk' + ',' + 'ZT' + '\n')
elif part == '2' and model == 'SBMP':
f.write('eta' + ',' + 'rk' + ',' + 'ZT' + '\n')
for i in range(len(inputs)): # go through input data
for j in range(inputs[i][0].size): # go through columns
for k in range(int(inputs[i].size/inputs[i][0].size)): # go through rows
for i in range(len(inputs)): # write an input data at a time
f.write(str(inputs[i][k][j]) + ',')
for h in range(len(outputs)):
f.write(str(outputs[h][k][j]) + ',')
f.write('\n')
elif part == '1' and model == 'SBMP': # inputs = [eta, rk]
f.write('eta' + ',' + 'rk' + ',' + 'sigma' + ',' + 'S' + ',' + 'k_e' + ',' + 'ZT' + '\n')
inputs[-1] = [inputs[-1]]*np.ones(int(inputs[0].size))
for i in range(len(inputs)): # go through input data
for j in range(inputs[i].size): # go through array elements
for i in range(len(inputs)): # write an input data at a time
f.write(str(inputs[i][j]) + ',')
for h in range(len(outputs)): # write an output data at a time
f.write(str(outputs[h][j]) + ',')
f.write('\n')
f.close()
print('Data saved!')
def open_previous_window(previous_window):
"""
Reopens previous window after the user has save the data.
Parameters
----------
previous_window : TYPE PySimpleGUI.Window(title, layout, location, finalize, element_justification)
DESCRIPTION. previous window, to reopen
"""
window8.close() # close current window
previous_window.un_hide() # reopen previous window
# make the first window and set the others windows to none
window0, window1, window2, window2_3d, window3, window3_3d, window4, window5, window6, window7, window8 = make_window0(), None, None, None, None, None, None, None, None, None, None
# set the figure drawings to None in order to be able to update them each time
figure_canvas_agg0, figure_canvas_agg1, figure_canvas_agg2, figure_canvas_agg3, figure_canvas_agg4 = None, None, None, None, None
# set the color bar to None in order to be able to update it later
cbar = None
while True:
# read all the events, windows and values entered on the windows
window, event, values = sg.read_all_windows()
if window==window0:
if event== sg.WIN_CLOSED : # if user closes window close the programm
break
elif event == 'Load Configuration':
file_path = values['-FILE-']
names, load_values=load_configuration(file_path)
#assigning the values from the configuration file
#1st part
delta_1 = np.arange(load_values[0], load_values[1], load_values[2])
eta_1 = np.arange(load_values[3], load_values[4], load_values[5])
rk_1 = load_values[6]
#2nd part
rk_2 = np.arange(load_values[7], load_values[8], load_values[9])
print('Configuration done!')
elif event == 'Next >':
delta_1, eta_1, rk_1, rk_2 = None, None, None, None
window0.hide()
window1 = make_window1()
if window == window1:
user_operations(window1)
delta_1, eta_1, rk_1, rk_2 = None, None, None, None
if event == 'Next >': # if user clicks on the button 'Next >'
model = (values['-IN_Model-'])
window1.hide()
if model == 'DBMD' : # if DBMD is selected,
window2 = make_window2() # and open associated window
elif model == 'DBMP': # if DBMP is selected,
window3 = make_window3() # and open associated window
elif model == 'SBMP': # if SBMP is selected,
window4 = make_window4() # and open associated window
# DBMD
if window == window2:
user_operations(window2)
if event == 'Second Part >': # if user clicks on button 'Next >',
window2.hide() # skip/end the first part
window5 = make_window5() # and go to second part
else:
# take input data and compute thermoelectric quantities as outputs
if all(item is None for item in [delta_1, eta_1, rk_1]): # if load_data file not used in the configuration, get input data
delta_1, eta_1, rk_1 = get_inputs_first_part(window2)[0], get_inputs_first_part(window2)[1], get_inputs_first_part(window2)[2]
delta, eta = np.meshgrid(delta_1, eta_1)
S = create_matrix(S_DBMD, [delta, eta], None)
sigma = create_matrix(sigma_DBMD, [delta, eta], None)
ke = create_matrix(ke_DBMD, [delta, eta], None)
ZT = create_matrix(ZT_DBMD, [delta, eta], rk_1)
inputs = [delta, eta, rk_1]
outputs = [sigma, S, ke, ZT]
if event == 'Show 2D Plots': # if user clicks on button 'Show 2D Plots', show plot
plot_clear_draw(complete_2d_plot, [S, sigma, ke, ZT, delta, eta, rk_1, 'TE quantities of 2D Dirac double-band material'], figure_canvas_agg0, '-FIG0-')
if event == 'Show 3D Plots >': #if user clicks on button 'Show 3D Plots >',
window2.hide() # hide current window
window2_3d = make_window2_3d() # open window to show 3D plot
if window == window2_3d:
user_operations(window2_3d)
if event == '< Prev': # if user clicks on button '< Prev'
window2_3d.close() # close current window
window2.un_hide() # and re-open the previous window
if event == 'Second Part >': # if user clicks on button 'Next >',
window2_3d.hide() # hide current window
window5 = make_window5() # and open next one to start the second part
if event == 'Show 3D Plots': # if user wants to visualize 3D plots
plot_clear_draw(plot_anim_3d, [delta, eta, sigma, '$\eta$', '$\Delta$', '$\sigma$($\eta$,$\Delta$)', '$\sigma$($\eta$,$\Delta$)'], figure_canvas_agg1, '-FIG1-')
plot_clear_draw(plot_anim_3d, [delta, eta, S, '$\eta$', '$\Delta$', 'S($\eta$,$\Delta$)', 'S($\eta$,$\Delta$)'], figure_canvas_agg2, '-FIG2-')
plot_clear_draw(plot_anim_3d, [delta, eta, ke, '$\eta$', '$\Delta$', '$\kappa_{e}$($\eta$,$\Delta$)','$\kappa_{e}$($\eta$,$\Delta$)'], figure_canvas_agg2, '-FIG3-')
plot_clear_draw(plot_anim_3d, [delta, eta, ZT, '$\eta$', '$\Delta$', 'ZT($\eta$,$\Delta$)','ZT($\eta$,$\Delta$)'], figure_canvas_agg4, '-FIG4-')
if window == window5:
user_operations(window5)
# take input data and compute figure of merit as output
if rk_2 is None: # if load_data file not used in the configuration, get input data
rk_2 = get_inputs_second_part()
delta, eta, rk = np.meshgrid(generate_arrays(21)[0], generate_arrays(21)[1], rk_2)
ZT = create_matrix(ZT_DBMD, [delta, eta, rk], None)
ZT = find_ZTmax(delta, eta, rk, ZT)
rk, delta = np.meshgrid(rk_2, generate_arrays(21)[0])
inputs = [delta, rk]
outputs = [ZT]
if event == 'Show Plot': # if the user wants to visualize data, show plot
plot_clear_draw(plot_anim_3d, [delta, rk, ZT, '$E_{g}$','$\kappa_{L}$', '$ZT_{max}$($\Delta$,$\kappa_{L}$)', '$ZT_{max}$($\Delta$,$\kappa_{L}$)'], figure_canvas_agg1, '-FIG0-')
# DBMP
if window == window3:
user_operations(window3)
if event == 'Second Part >': # if user clicks on button 'Next >',
window3.hide() # skip/end the first part
window6 = make_window6() # and go to the second part
else:
# take input data and compute thermoelectric quantities as outputs
if all(item is None for item in [delta_1, eta_1, rk_1]): # if load_data file not used in the configuration, get input data
delta_1, eta_1, rk_1 = get_inputs_first_part(window3)[0], get_inputs_first_part(window3)[1], get_inputs_first_part(window3)[2]
delta, eta = np.meshgrid(delta_1, eta_1)
S = create_matrix(S_DBMP, [delta, eta], None)
sigma = create_matrix(sigma_DBMP, [delta, eta], None)
ke = create_matrix(ke_DBMP, [delta, eta], None)
ZT = create_matrix(ZT_DBMP, [delta, eta], rk_1)
inputs = [delta, eta, rk_1]
outputs = [sigma, S, ke, ZT]
if event == 'Show 2D Plots': #if user clicks on button 'Show 2D plots', show plot
plot_clear_draw(complete_2d_plot, [S, sigma, ke, ZT, delta, eta, rk_1, 'TE quantities of 2D double-parabolic-band material'], figure_canvas_agg0, '-FIG0-')
if event == 'Show 3D Plots >': # if user clicks on button 'Show 3D plots >',
window3.hide() # hide current window
window3_3d = make_window3_3d() # and open window to show 3D plots
if window == window3_3d:
user_operations(window3_3d)
if event =='Second Part >': # if user clicks on button 'Next >'
window3_3d.hide() #hide current window
window6 = make_window6() # and open next one to start the second part
if event == 'Show 3D Plots': # create and show 3D plots
plot_clear_draw(plot_anim_3d, [delta, eta, sigma, '$\eta$', '$\Delta$', '$\sigma$($\eta$,$\Delta$)', '$\sigma$($\eta$,$\Delta$)'], figure_canvas_agg1, '-FIG1-')
plot_clear_draw(plot_anim_3d, [delta, eta, S, '$\eta$', '$\Delta$', 'S($\eta$,$\Delta$)', 'S($\eta$,$\Delta$)'], figure_canvas_agg2, '-FIG2-')
plot_clear_draw(plot_anim_3d, [delta, eta, ke, '$\eta$', '$\Delta$', '$\kappa_{e}$($\eta$,$\Delta$)','$\kappa_{e}$($\eta$,$\Delta$)'], figure_canvas_agg2, '-FIG3-')
plot_clear_draw(plot_anim_3d, [delta, eta, ZT, '$\eta$', '$\Delta$', 'ZT($\eta$,$\Delta$)','ZT($\eta$,$\Delta$)'], figure_canvas_agg4, '-FIG4-')
if window == window6:
user_operations(window6)
# take input data and compute figure of merit as output
if rk_2 is None: # if load_data file not used in the configuration, get input data
rk_2 = get_inputs_second_part()
delta, eta, rk = np.meshgrid(generate_arrays(21)[0], generate_arrays(21)[1], rk_2)
ZT = create_matrix(ZT_DBMD, [delta, eta, rk], None)
ZT = find_ZTmax(delta, eta, rk, ZT)
rk, delta = np.meshgrid(rk_2, generate_arrays(51)[0])
inputs = [delta, rk]
outputs = [ZT]
if event == 'Show Plot': # if the user wants to visualize data, show plot
plot_clear_draw(plot_anim_3d, [delta, rk, ZT, '$E_{g}$','$\kappa_{L}$', '$ZT_{max}$($\Delta$,$\kappa_{L}$)', '$ZT_{max}$($\Delta$,$\kappa_{L}$)'], figure_canvas_agg1, '-FIG0-')
# SBMP
if window == window4:
user_operations(window4)
delta = None
if event =='Second Part >': # if user clicks on button 'Next >',
window4.hide() # skip/end the first part
window7 = make_window7() # and go to second part
else:
# take input data and compute thermoelectric quantities as outputs
if all(item is None for item in [eta_1, rk_1]): # if load_data file not used in the configuration, get input data
eta_1, rk_1 = get_inputs_first_part(window4)[1], get_inputs_first_part(window4)[2]
#eta, rk = np.meshgrid(eta_1, rk_1)
eta, rk = eta_1, rk_1
S = create_matrix(S_SBMP, [eta], None)
sigma = create_matrix(sigma_SBMP, [eta], None)
ke = create_matrix(ke_SBMP, [eta], None)
ZT = create_matrix(ZT_SBMP, [eta], rk)
inputs = [eta, rk]
outputs = [sigma, S, ke, ZT]
if event =='Show Plots': # if user clicks on button 'Show Plots', show plot
plot_clear_draw(complete_2d_plot, [S, sigma, ke, ZT, delta, eta, rk, 'TE quantities of 2D single-parabolic-band material'], figure_canvas_agg0, '-FIG0-')
if window == window7:
user_operations(window7)
# take input data and compute figure of merit as output
if rk_2 is None: # if load_data file not used in the configuration, get input data
rk_2 = get_inputs_second_part()
eta, rk = np.meshgrid(generate_arrays(51)[1], rk_2)
ZT = create_matrix(ZT_SBMP, [eta, rk], None)
inputs = [eta, rk]
outputs = [ZT]
if event == 'Show Plot': # if the user wants to visualize data, show plot
plot_clear_draw(plot_anim_3d, [eta, rk, ZT, '$\eta$', '$\kappa_L$', 'ZT($\eta$,$\kappa_l$)', '3D plot: 2D single-parabolic-band material'], figure_canvas_agg1, '-FIG0-')
# SAVE DATA
if window == window8:
if event == sg.WIN_CLOSED: # if user closes window,
window8.close() # close the program
break
# set parameters to values entered by the user
path_txt = values['-IN_txt_path-'] # path to save the .txt file
title_model = values['-IN_txt_model'] # first part of the title: model (DBMD, DBMP, SBMP)
title_part = values['-IN_txt_part'] # second part of the title: part of the study (1 for 1st part, 2 for 2nd part)
title_txt = values['-IN_txt_file-'] # third part of the title: additional specification desired by the user
if event == 'Save Data': # if user wants to save data
path_to_file = path_txt + title_model + title_part + title_txt + '.txt' # create path to new txt file
write_txt(title_model, title_part, inputs, outputs) # write data in new txt file
if event == 'Done': # if user clicks on button 'Done', reopen previous window
if title_model == 'DBMD' and title_part == '1':
open_previous_window(window2)
if title_model == 'DBMD' and title_part == '2':
open_previous_window(window5)
if title_model == 'DBMP' and title_part == '1':
open_previous_window(window3)
if title_model == 'DBMP' and title_part == '2':
open_previous_window(window6)
if title_model == 'SBMP' and title_part == '1':
open_previous_window(window4)
if title_model == 'SBMP' and title_part == '2':
open_previous_window(window7)
window.close()