-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcapsim_object_types.py
2518 lines (1913 loc) · 101 KB
/
capsim_object_types.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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
#
#This file contains the "CapSimWindow", "Chemical," "System" and "Layer" classes
#that are used to build the sediment capping system that is fed to the capsim
#solver.
import tkMessageBox as tkmb, cPickle as pickle, sys, os, warnings
import _winreg as wreg
if sys.path[0][-3:] == 'zip':
os.chdir(sys.path[0][:-12])
path = sys.path[0][:-12]
warnings.filterwarnings('ignore')
else: path = sys.path[0]
CapSimReg = wreg.ConnectRegistry(None, wreg.HKEY_CURRENT_USER)
CapSimKey = wreg.OpenKey(CapSimReg, r'Software\CapSim')
Filepath =wreg.QueryValueEx(CapSimKey, 'FilePath')[0]
CapSimKey.Close()
from capsim_functions import freundlich, langmuir, millquirk, boudreau, notort, round_to_n
from Tkinter import Tk, Toplevel, Canvas, Frame, Label, Entry, Text, \
Button, Scrollbar, OptionMenu, StringVar, \
DoubleVar, IntVar, FLAT, RAISED, Checkbutton
import tkFont
class AutoScrollbar(Scrollbar):
"""A scrollbar that hides itself if it's not needed (borrowed from
Fredrik Lundh)."""
def set(self, lo, hi):
if float(lo) <= 0 and float(hi) >= 1:
self.grid_remove()
self.exist = 0
else:
self.grid()
self.exist = 1
Scrollbar.set(self, lo, hi)
class CapSimWindow:
"""Makes a CapSim window that looks good and has all the properties it
needs."""
def __init__(self, master = None, buttons = None, left_frame = None):
"""Constructor method. Makes a Tk root window with horizontal and
vertical scrollbars that appear if desired and sets whether it is root
or a toplevel window. The "buttons" keyword can be used to make the
"OK," "Mainmenu," and "Exit" buttons."""
self.master = master
self.buttons = buttons
self.left_frame = left_frame
if master is None: self.tk = Tk()
else: self.tk = Toplevel(master.tk)
self.main = IntVar(value = 0)
self.step = IntVar(value = 0)
self.vscrollbar = AutoScrollbar(self.tk)
self.hscrollbar = AutoScrollbar(self.tk, orient = 'horizontal')
self.canvas = Canvas(self.tk, highlightthickness = 0)
self.canvas.config(xscrollcommand = self.hscrollbar.set, yscrollcommand = self.vscrollbar.set)
self.tframe = Frame(self.tk)
self.frame = Frame(self.canvas)
self.bframe = Frame(self.tk)
self.lframe = Frame(self.tk)
self.vscrollbar.config(command = self.canvas.yview)
self.hscrollbar.config(command = self.canvas.xview)
self.tk.grid_rowconfigure( 1, weight = 1)
self.tk.grid_columnconfigure(0, weight = 1)
self.frame.rowconfigure(1, weight=1)
self.frame.columnconfigure(1, weight=1)
if left_frame == None:
self.tframe.grid(row = 0, column = 0, sticky = 'NWE', columnspan = 2)
self.bframe.grid(row = 3, column = 0, sticky = 'N', columnspan = 2)
self.canvas.grid(row = 1, column = 0, sticky = 'NSWE')
self.vscrollbar.grid(row = 1, column = 1, sticky = 'NS')
self.hscrollbar.grid(row = 2, column = 0, sticky = 'WE')
else:
self.tframe.grid(row = 0, column = 0, sticky = 'NWE', columnspan = 3)
self.bframe.grid(row = 3, column = 0, sticky = 'N', columnspan = 3)
self.lframe.grid(row = 1, column = 0, sticky = 'W')
self.canvas.grid(row = 1, column = 1, sticky = 'NSWE')
self.vscrollbar.grid(row = 1, column = 2, sticky = 'NS')
self.hscrollbar.grid(row = 2, column = 1, sticky = 'WE')
def make_window(self, window):
"""Creates a frame to put the widgets from "window" into later, adds
the appropriate method to the "x" in the window, puts the correct title
and icon, places the widgets from "window" into the frame, centers the
window, and places the focus on the window and the "OK" button."""
self.window = window
self.tk.option_add('*font', self.window.fonttype)
self.tk.title('CapSim ' + self.window.version)
try: self.tk.iconbitmap(path + r'/capsimicon.ico')
except: pass
self.frame.grid(sticky = 'NSWE', row = 0, column = 0)
self.window.tframe.grid(sticky = 'N', row = 0, column = 0)
self.window.frame.grid( sticky = 'NSWE', row = 0, column = 0)
self.window.bframe.grid(sticky = 'N', row = 0, column = 0)
try: self.window.lframe.grid(sticky = 'E', row = 0, column = 0)
except: pass
if self.master is None: self.tk.protocol('WM_DELETE_WINDOW', self.exit)
else: self.tk.protocol('WM_DELETE_WINDOW', self.closetop)
if self.buttons is not None: self.make_buttonframe()
self.window.make_widgets()
self.tk.update()
if self.tframe.bbox('all')[2] > (self.frame.bbox('all')[2] + 16 * self.vscrollbar.exist):
self.canvas.create_window((self.tframe.bbox('all')[2]-self.frame.bbox('all')[2] - 16 * self.vscrollbar.exist)/2, 0, anchor = 'nw', window = self.frame)
elif self.bframe.bbox('all')[2] > (self.frame.bbox('all')[2] + 16 * self.vscrollbar.exist):
self.canvas.create_window((self.bframe.bbox('all')[2]-self.frame.bbox('all')[2] - 16 * self.vscrollbar.exist)/2, 0, anchor = 'nw', window = self.frame)
else:
self.canvas.create_window(0, 0, anchor = 'nw', window = self.frame)
self.geometry()
self.center()
def geometry(self):
"""Makes the window the right size for the frame."""
self.tk.update()
if self.left_frame == None:
self.tk.geometry('%dx%d' % (max(self.tframe.bbox('all')[2], self.frame.bbox('all')[2], self.bframe.bbox('all')[2]),
min(self.tframe.bbox('all')[3] + self.frame.bbox('all')[3] + self.bframe.bbox('all')[3], self.tk.winfo_screenheight()*3/4) ))
else:
self.tk.geometry('%dx%d' % (max(self.tframe.bbox('all')[2], self.frame.bbox('all')[2], self.bframe.bbox('all')[2])+self.lframe.bbox('all')[2],
min(self.tframe.bbox('all')[3] + self.frame.bbox('all')[3] + self.bframe.bbox('all')[3], self.tk.winfo_screenheight()*3/4) ))
self.tk.update()
self.focus()
def center(self):
"""Moves the window into the center of the screen."""
ws = self.tk.winfo_screenwidth()
hs = self.tk.winfo_screenheight()
w = self.tk.winfo_width()
h = self.tk.winfo_height()
if ws > w:
if hs > h: self.tk.geometry('%dx%d+%d+%d' % (w, h, ws / 2. - w / 2., hs / 2. - h / 2))
else: self.tk.geometry('%dx%d+%d+%d' % (w, h, ws / 2. - w / 2., hs))
elif hs > h: self.tk.geometry('%dx%d+%d+%d' % (w, h, ws, hs / 2. - h / 2.))
else: self.tk.geometry('%dx%d+%d+%d' % (w, h, ws, hs))
self.tk.update_idletasks()
self.tk.focus_force()
self.canvas.config(scrollregion = (self.frame.bbox('all')[0],self.frame.bbox('all')[1],self.frame.bbox('all')[2]-17, self.frame.bbox('all')[3]-17))
self.focus()
def make_buttonframe(self):
"""Creates a frame to put the mainmenu, ok, and exit buttons on."""
self.buttonframe = Frame(self.bframe)
self.okbutton = Button(self.buttonframe, text = 'OK', width = 20, command = self.OK)
self.nextbutton = Button(self.buttonframe, text = 'Next', width = 20, command = self.Next)
self.backbutton = Button(self.buttonframe, text = 'Back', width = 20, command = self.Back)
self.mainbutton = Button(self.buttonframe, text = 'Return to Main Menu', width = 20, command = self.mainmenu)
self.exitbutton = Button(self.buttonframe, text = 'Exit CapSim', width = 20, command = self.exit)
self.blank = Label(self.buttonframe, text = '')
if self.master is None and self.buttons == 1: # The window with
self.nextbutton.grid(row = 0, pady = 1)
self.backbutton.grid(row = 1)
self.mainbutton.grid(row = 2, pady = 1)
self.exitbutton.grid(row = 3)
self.blank.grid( row = 4)
elif self.master is None and self.buttons == 2:
self.mainbutton.grid(row = 0, pady = 1, sticky = 'N')
self.exitbutton.grid(row = 1, sticky = 'N')
self.blank.grid( row = 2, sticky = 'N')
elif self.master is None and self.buttons == 3:
self.okbutton.grid( row = 0)
self.mainbutton.grid(row = 1, pady = 1, sticky = 'N')
self.exitbutton.grid(row = 2, sticky = 'N')
self.blank.grid(row = 3, sticky = 'N')
elif self.buttons == 2:
self.blank.grid(row = 1)
else:
self.okbutton.grid(row = 0)
self.blank.grid(row = 1)
#bind the Return key to the buttons
self.nextbutton.bind('<Return>', self.Next)
self.backbutton.bind('<Return>', self.Back)
self.okbutton.bind('<Return>', self.OK)
self.mainbutton.bind('<Return>', self.mainmenu)
self.exitbutton.bind('<Return>', self.exit)
self.buttonframe.grid(row = 1, sticky = 'NS')
def mainloop(self):
"""Points to the correct mainloop method."""
self.tk.mainloop()
def destroy(self):
"""Points to the correct destroy method."""
self.tk.destroy()
def mainmenu(self, event = None):
"""Return to the main menu."""
if self.window.top is not None: self.open_toplevel()
else:
self.main.set(1)
self.tk.quit()
def OK(self, event = None):
"""Finish and move on."""
try: error = self.window.error_check()
except: error = 0
if self.window.top is not None: self.open_toplevel()
elif error == 1: self.window.warning()
else: self.tk.quit()
def Next(self, event = None):
"""Finish and move on."""
try: error = self.window.error_check()
except: error = 0
if self.window.top is not None: self.open_toplevel()
elif error == 1: self.window.warning()
else:
self.step.set(1)
self.tk.quit()
def Back(self, event = None):
"""Finish and move on."""
if self.window.top is not None: self.open_toplevel()
else:
self.step.set(-1)
self.tk.quit()
def exit(self, event = None):
"""Exit CapSim."""
if tkmb.askyesno(self.window.version, 'Do you really want to exit CapSim?') == 1: sys.exit()
if self.window.top is not None: self.window.top.okbutton.focus()
def open_toplevel(self):
"""Forces the user to close any existing toplevel widgets before doing
anything else."""
tkmb.showerror(title = self.window.system.version, message = 'Please ' +
'close the existing parameter input window first.')
self.window.top.tk.focus()
def closetop(self):
"""Sets the toplevel widget to None if it is destoyed."""
self.tk.quit()
self.tk.destroy()
self.master.window.top = None
def focus(self, event = None):
"""Puts the focus on the "OK" button after clicking the OptionMenu."""
if self.window.focusbutton is None:
if self.master is None:
if self.buttons != 3: self.nextbutton.focus_force()
else: self.okbutton.focus_force()
else: self.okbutton.focus_force()
else: self.window.focusbutton.focus_force()
class Chemical:
"""Stores basic properties of a chemical."""
def __init__(self, number, soluable):
"""Constructor method. Uses the "layertype" and the number in the
capping system and the system's chemical properties to set default
values for the parameters."""
self.number = number
self.soluable = soluable
def copy(self):
"""Copy method. Copies everything needed to a new Chemical instance."""
chemical = Chemical(self.number, self.soluable)
chemical.number = self.number
chemical.soluable = self.soluable
chemical.name = self.name
chemical.formula = self.formula
chemical.MW = self.MW
chemical.Ref = self.Ref
chemical.temp = self.temp
chemical.Dw = self.Dw
chemical.Koc = self.Koc
chemical.Kdoc = self.Kdoc
chemical.Kf = self.Kf
chemical.N = self.N
try:
chemical.component_name = self.component_name
chemical.chemical_name = self.chemical_name
except: pass
return chemical
def chemicalwidgets(self, frame, row, master):
"""Makes Tkinter widgets for a layer for an instance of the
"systemproperties" class."""
self.master = master
self.row = row
self.editwidget = Button(frame, width = 5, justify = 'center', text = 'Edit', command = self.editchemical, relief = FLAT, overrelief = RAISED)
self.delwidget = Button(frame, width = 5, justify = 'center', text = 'Delete', command = self.delchemical, relief = FLAT, overrelief = RAISED)
self.numberlabel = Label(frame, width = 2, justify = 'center', text = self.number)
self.namelabel = Label(frame, width = 16, justify = 'center', text = self.name)
self.MWlabel = Label(frame, width = 8, justify = 'center', text = self.MW)
self.templabel = Label(frame, width = 8, justify = 'center', text = self.temp)
self.Dwlabel = Label(frame, width = 10, justify = 'center', text = self.Dw)
self.Koclabel = Label(frame, width = 10, justify = 'center', text = self.Koc)
self.Kdoclabel = Label(frame, width = 10, justify = 'center', text = self.Kdoc)
self.Reflabel = Label(frame, justify = 'center', text = self.Ref)
self.editwidget.grid( row = row, column = 1, padx = 2)
self.delwidget.grid( row = row, column = 2, padx = 2)
self.numberlabel.grid(row = row, column = 3, padx = 2, sticky = 'WE')
self.namelabel.grid( row = row, column = 4, padx = 2, sticky = 'WE')
self.MWlabel.grid( row = row, column = 5, padx = 2, sticky = 'WE')
self.templabel.grid( row = row, column = 6, padx = 2, sticky = 'WE')
self.Dwlabel.grid ( row = row, column = 7, padx = 2)
self.Koclabel.grid ( row = row, column = 8, padx = 2)
self.Kdoclabel.grid( row = row, column = 9, padx = 2)
self.Reflabel.grid( row = row, column = 10, padx = 1)
def editchemical(self):
self.master.window.editchemical(self.number)
def delchemical(self):
self.master.window.deletechemical(self.number)
def sorptionwidgets(self, master, row):
"""Makes Tkinter widgets for a layer for an instance of the
"LayerModels" class."""
self.sorptionwidget = Label(master, text ='%s' %(self.name))
self.sorptionwidget.grid (row =row, column = 2, padx = 4, pady = 2, sticky = 'WE')
def ICwidgets(self, frame, column):
self.ICwidget = Label(frame, text =self.name, justify = 'center')
self.ICwidget.grid(row = 2, column = column, padx = 4, pady = 1, sticky ='WE')
def get_chemical(self, chemicaleditor):
self.name = chemicaleditor.name.get()
self.MW = chemicaleditor.MW.get()
self.formula = chemicaleditor.formula.get()
self.Ref = chemicaleditor.Ref.get()
self.temp = chemicaleditor.temp.get()
self.Dw = chemicaleditor.Dw.get()
self.Koc = chemicaleditor.Koc.get()
self.Kdoc = chemicaleditor.Kdoc.get()
self.Kf = chemicaleditor.Kf.get()
self.N = chemicaleditor.N.get()
def remove_chemicalwidgets(self):
self.numberlabel.grid_forget()
self.namelabel.grid_forget()
self.MWlabel.grid_forget()
self.templabel.grid_forget()
self.Dwlabel.grid_forget()
self.Koclabel.grid_forget()
self.Kdoclabel.grid_forget()
self.Reflabel.grid_forget()
self.editwidget.grid_forget()
self.delwidget.grid_forget()
self.row = 0
self.master = 0
self.numberlabel = 0
self.namelabel = 0
self.MWlabel = 0
self.templabel = 0
self.Dwlabel = 0
self.Koclabel = 0
self.Kdoclabel = 0
self.Reflabel = 0
self.editwidget = 0
self.delwidget = 0
self.soluablelabel= 0
def remove_sorptionwidgets(self):
"""Removes all the Tkinter property widgets from the layer.
Necessary to pickle the System instance."""
self.sorptionwidget.grid_forget()
self.sorptionwidget = 0
def remove_ICwidgets(self):
"""Removes all the Tkinter property widgets from the layer.
Necessary to pickle the System instance."""
self.ICwidget.grid_forget()
self.ICwidget = 0
def get_solid_chemical(self, component_name, chemical_name, MW):
self.name = component_name + '_' + chemical_name
self.component_name = component_name
self.chemical_name = chemical_name
self.MW = MW
self.formula = 0
self.temp = 0
self.Dw = 0
self.Koc = 0
self.Kdoc = 0
self.Kf = 0
self.Ref = ''
self.N = 0
class MatrixComponent:
def __init__(self, number):
self.number = number
def copy(self):
component = MatrixComponent(self.number)
component.name = self.name
component.mfraction = self.mfraction
component.fraction = self.fraction
component.e = self.e
component.rho = self.rho
component.foc = self.foc
component.tort = self.tort
component.sorp = self.sorp
return component
def propertieswidgets(self, frame, row, master, database, matrices):
self.master = master
self.database = database
self.material_list = database.keys()
self.material_list.sort()
try: self.mfraction = DoubleVar(value = self.mfraction)
except: self.mfraction = DoubleVar(value = 0.5)
try:
self.name = StringVar(value = self.name)
self.e = DoubleVar(value = self.e)
self.rho = DoubleVar(value = self.rho)
self.foc = DoubleVar(value = self.foc)
except:
e = self.database[self.material_list[0]].e
rho = self.database[self.material_list[0]].rho
foc = self.database[self.material_list[0]].foc
for matrix in matrices[:-1]:
for component in matrix.components:
if component.name == self.material_list[0]:
e = component.e
rho = component.rho
foc = component.foc
self.name = StringVar(value = self.material_list[0])
self.e = DoubleVar(value = e)
self.rho = DoubleVar(value = rho)
self.foc = DoubleVar(value = foc)
self.delwidget = Button(frame, width = 5, justify = 'center', text = 'Delete', command = self.del_component, relief = FLAT, overrelief = RAISED)
if self.material_list.count(self.name.get()) > 0:
self.namewidget = OptionMenu(frame, self.name, *self.material_list, command = self.click_name)
self.namewidget.grid( row = row, column = 2, padx = 2, pady = 1, sticky = 'WE')
else:
self.namewidget = Entry( frame, width = 18, justify = 'center', textvariable = self.name)
self.namewidget.grid( row = row, column = 2, padx = 2, pady = 1)
self.fractionwidget = Entry( frame, width = 10, justify = 'center', textvariable = self.mfraction)
self.elabel = Entry( frame, width = 10, justify = 'center', textvariable = self.e)
self.rhowlabel = Entry( frame, width = 10, justify = 'center', textvariable = self.rho)
self.foclabel = Entry( frame, width = 10, justify = 'center', textvariable = self.foc)
self.delwidget.grid( row = row, column = 1, padx = 2 ,pady = 1)
self.fractionwidget.grid(row = row, column = 3, padx = 2 ,pady = 1)
self.elabel.grid( row = row, column = 4, padx = 2, pady = 1)
self.rhowlabel.grid( row = row, column = 5, padx = 2 ,pady = 1)
self.foclabel.grid ( row = row, column = 6, padx = 2 ,pady = 1)
def click_name(self, event = None):
"""Pulls up the contaminant properties from the database after selecting
a compound."""
self.e.set (self.database[self.name.get()].e)
self.rho.set(self.database[self.name.get()].rho)
self.foc.set(self.database[self.name.get()].foc)
def del_component(self):
self.master.window.del_component(self.number)
def get_component(self):
self.mfraction = self.mfraction.get()
self.name = self.name.get()
self.e = self.e.get()
self.rho = self.rho.get()
self.foc = self.foc.get()
try:
self.tort = self.database[self.name].tort
self.sorp = self.database[self.name].sorp
except:
self.tort = 'Millington & Quirk'
self.sorp = 'Linear--Kd specified'
def remove_propertieswidgets(self):
self.delwidget.grid_forget()
self.fractionwidget.grid_forget()
self.namewidget.grid_forget()
self.elabel.grid_forget()
self.rhowlabel.grid_forget()
self.foclabel.grid_forget()
self.master = 0
self.delwidget = 0
self.namewidget = 0
self.fractionwidget = 0
self.elabel = 0
self.rhowlabel = 0
self.foclabel = 0
def sorptionwidgets(self, master, row):
"""Makes Tkinter widgets for a layer for an instance of the
"LayerModels" class."""
# Title widgets
self.sorptionwidget = Label(master, text ='%s' %(self.name))
self.sorptionwidget.grid (row = row, column = 1, padx = 4, sticky = 'WE')
def remove_sorptionwidgets(self):
self.sorptionwidget.grid_forget()
self.sorptionwidget = 0
def SolidICswidgets(self, frame, row):
self.SolidICswidget = Label(frame, text ='%s' %(self.name), justify = 'center' )
self.SolidICswidget.grid (row = row, column = 2, padx = 4, pady = 2, sticky = 'WE')
def remove_SolidICswidgets(self):
try:
self.SolidICswidget.grid_forget()
self.SolidICswidget = 0
except: pass
class Matrix:
"""Stores solid properties for CapSim."""
def __init__(self, number):
self.number = number
def copy(self):
"""Copy method. Copies everything needed to a new Chemical instance."""
matrix = Matrix(self.number)
matrix.number = self.number
matrix.name = self.name
matrix.components = [component.copy() for component in self.components]
matrix.model = self.model
matrix.e = self.e
matrix.rho = self.rho
matrix.foc = self.foc
return matrix
def propertieswidgets(self, frame, row, master):
self.master = master
self.row = row
materialtext = ''
self.editwidget = Button(frame, width = 5, justify = 'center', text = 'Edit', command = self.editmatrix , relief = FLAT, overrelief = RAISED)
self.delwidget = Button(frame, width = 5, justify = 'center', text = 'Delete', command = self.delmatrix , relief = FLAT, overrelief = RAISED)
self.namelabel = Label( frame, width = 16, justify = 'center', text = self.name)
self.elabel = Label( frame, width = 8, justify = 'center', text = self.e)
self.rhowlabel = Label( frame, width = 10, justify = 'center', text = self.rho)
self.foclabel = Label( frame, width = 10, justify = 'center', text = self.foc)
self.editwidget.grid( row = row, column = 1, padx = 2 ,pady = 1)
self.delwidget.grid( row = row, column = 2, padx = 2 ,pady = 1)
self.namelabel.grid( row = row, column = 3, padx = 2, pady = 1, sticky = 'WE')
self.elabel.grid( row = row, column = 4, padx = 2, pady = 1, sticky = 'WE')
self.rhowlabel.grid( row = row, column = 5, padx = 2 ,pady = 1)
self.foclabel.grid ( row = row, column = 6, padx = 2 ,pady = 1)
def editmatrix(self):
self.master.window.editmatrix(self.number)
def delmatrix(self):
self.master.window.deletematrix(self.number)
def get_matrix(self, matrixeditor):
self.name = matrixeditor.name.get()
self.e = matrixeditor.e.get()
self.rho = matrixeditor.rho.get()
self.foc = matrixeditor.foc.get()
self.model = matrixeditor.model.get()
self.components = matrixeditor.components
def remove_propertieswidgets(self):
self.editwidget.grid_forget()
self.delwidget.grid_forget()
self.namelabel.grid_forget()
self.elabel.grid_forget()
self.rhowlabel.grid_forget()
self.foclabel.grid_forget()
self.row = 0
self.master = 0
self.editwidget = 0
self.delwidget = 0
self.numberlabel = 0
self.namelabel = 0
self.elabel = 0
self.rhowlabel = 0
self.foclabel = 0
class Sorption:
"""Stores basic properties of a sorption for [layernumber]layer and [chemicalnumber] chemical"""
def __init__(self, matrix, chemical, unit = u'\u03BCg/L'):
"""Constructor method. Uses the "sorptiontype" and the number in the
capping system to set default values for the parameters."""
self.chemical = chemical
self.matrix = matrix
self.isotherms = ['Linear--Kd specified', 'Linear--Kocfoc', 'Freundlich', 'Langmuir']
self.kinetics = ['Equilibrium', 'Transient']
self.isotherm = matrix.sorp
self.kinetic = self.kinetics[0]
self.foc = matrix.foc
self.Koc = chemical.Koc
self.Kf = chemical.Kf
self.N = chemical.N
if unit == 'mg/L': self.Kf = round_to_n(chemical.Kf * 1000 ** (self.N-1), 3)
if unit == 'g/L': self.Kf = round_to_n(chemical.Kf * 1000000 ** (self.N-1), 3)
if unit == u'\u03BCmol/L': self.Kf = round_to_n(chemical.Kf * (1./chemical.MW) ** (self.N-1), 3)
if unit == 'mmol/L': self.Kf = round_to_n(chemical.Kf * (1000./chemical.MW) ** (self.N-1), 3)
if unit == 'mol/L': self.Kf = round_to_n(chemical.Kf * (1000000./chemical.MW) ** (self.N-1), 3)
self.K = 0.
self.qmax = 0.
self.b = 0.
self.thalf = 0.
self.ksorp = 0.
self.kdesorp = 0.
self.thalf = 0.
self.cinit = 0.
self.qinit = 0.
try:
self.qmax = chemical.qmax
self.b = chemical.b
except: pass
if chemical.soluable == 0:
self.isotherm = self.isotherms[0]
def copy(self):
sorption = Sorption(self.matrix, self.chemical)
sorption.isotherms = self.isotherms
sorption.isotherm = self.isotherm
sorption.kinetics = self.kinetics
sorption.kinetic = self.kinetic
sorption.foc = self.foc
sorption.K = self.K
sorption.Koc = self.Koc
sorption.Kf = self.Kf
sorption.N = self.N
sorption.qmax = self.qmax
sorption.b = self.b
sorption.thalf = self.thalf
sorption.cinit = self.cinit
sorption.qinit = self.qinit
sorption.ksorp = self.ksorp
sorption.kdesorp = self.kdesorp
return sorption
def propertieswidgets(self, frame, row, master, timeunit, concunit):
self.master = master
self.row = row
bgcolor = frame.cget('bg')
self.editwidget = Button(frame, width = 4, justify = 'center', text = 'Edit', command = self.editsorption, relief = FLAT, overrelief = RAISED)
self.isothermlabel = Label( frame, width = 16, justify = 'center', text = self.isotherm)
self.kinetcilabel = Label( frame, width = 16, justify = 'center', text = self.kinetic)
if self.isotherm == self.isotherms[0]:
self.coef1label = Text(frame, width = 5, height = 1)
self.coef1label.insert('end', u'K')
self.coef1label.insert('end', 'd', 'sub')
self.coef1label.insert('end', ' =')
self.coef1value = Label(frame, text = str(self.K))
self.coef1unit = Label(frame, text = 'L/kg')
self.coef2label = Label(frame, text = ' ')
self.coef2value = Label(frame, text = ' ')
self.coef2unit = Label(frame, text = ' ')
if self.isotherm == self.isotherms[1]:
self.coef1label = Text(frame, width = 5, height = 1)
self.coef1label.insert('end', u'K')
self.coef1label.insert('end', 'oc', 'sub')
self.coef1label.insert('end', ' =')
self.coef1value = Label(frame, text = str(self.Koc))
self.coef1unit = Label(frame, text = 'log(L/kg)')
self.coef2label = Text(frame, width = 4, height = 1)
self.coef2label.insert('end', u'f')
self.coef2label.insert('end', 'oc', 'sub')
self.coef2label.insert('end', ' =')
self.coef2value = Label(frame, text = str(self.matrix.foc))
self.coef2unit = Label(frame, text = ' ')
self.coef2label.tag_config('sub', offset = -2, font = 'Arial 8')
self.coef2label.tag_config('right', justify = 'right')
self.coef2label.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
if self.isotherm == self.isotherms[2]:
self.coef1label = Text(frame, width = 5, height = 1)
self.coef1label.insert('end', u'K')
self.coef1label.insert('end', 'F', 'sub')
self.coef1label.insert('end', ' =')
self.coef1value = Label(frame, text = str(self.Kf))
self.coef1unit = Label(frame, text = concunit[:-1]+'kg/('+ concunit +')'+ u'\u1d3a')
self.coef2label = Label(frame, text = 'N =')
self.coef2value = Label(frame, text = str(self.N))
self.coef2unit = Label(frame, text = ' ')
if self.isotherm == self.isotherms[3]:
self.coef1label = Text(frame, width = 5, height = 1)
self.coef1label.insert('end', u'q')
self.coef1label.insert('end', 'max', 'sub')
self.coef1label.insert('end', ' =')
self.coef1value = Label(frame, text = str(self.qmax))
self.coef1unit = Label(frame, text = concunit[:-1] + 'kg')
self.coef2label = Label(frame, text = 'b =')
self.coef2value = Label(frame, text = str(self.b))
self.coef2unit = Label(frame, text = 'L/'+ concunit[:-2])
self.coef1label.tag_config('sub', offset = -2, font = 'Arial 8')
self.coef1label.tag_config('right', justify = 'right')
self.coef1label.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
if self.kinetic == self.kinetics[0]:
self.coef3label = Label(frame, width = 10, justify = 'center', text = 'Equilibrium')
if self.kinetic == self.kinetics[1]:
self.coef3label = Text(frame, width = 6, height = 1)
self.coef3label.insert('end', u'k')
self.coef3label.insert('end', 'sorp', 'sub')
self.coef3label.insert('end', ' =')
self.coef3value = Label(frame, text = str(self.ksorp))
if self.isotherm == self.isotherms[0] or self.isotherm == self.isotherms[1]:
self.coef3unit = Label(frame, text = timeunit + u'\u207B\u00b9')
if self.isotherm == self.isotherms[2]:
self.coef3unit = Label(frame, text = timeunit + u'\u207B\u00b9')
if self.isotherm == self.isotherms[3]:
self.coef3unit = Label(frame, text = '(' + concunit[:-1] +'kg)'+u'\u207B\u00b9 ' +timeunit + u'\u207B\u00b9')
self.coef3label.tag_config('sub', offset = -2, font = 'Arial 8')
self.coef3label.tag_config('right', justify = 'right')
self.coef3label.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
self.editwidget.grid( row = row, column = 3, padx = 0 ,pady = 1)
self.isothermlabel.grid( row = row, column = 4, padx = 0, pady = 3, sticky = 'WE')
self.coef1label.grid ( row = row, column = 5, pady = 3, sticky = 'SE')
self.coef1value.grid ( row = row, column = 6, pady = 3, sticky = 'SWE')
self.coef1unit.grid ( row = row, column = 7, pady = 1, sticky = 'W')
self.coef2label.grid ( row = row, column = 8, pady = 1, sticky = 'E')
self.coef2value.grid ( row = row, column = 9, pady = 1, sticky = 'WE')
self.coef2unit.grid ( row = row, column = 10, pady = 1, sticky = 'W')
if self.kinetic == self.kinetics[0]:
self.coef3label.grid( row = row, column = 11, padx = 0 ,pady = 1, columnspan = 3, sticky = 'WE')
else:
self.coef3label.grid ( row = row, column = 11, pady = 3, sticky = 'SE')
self.coef3value.grid ( row = row, column = 12, pady = 3, sticky = 'WE')
self.coef3unit.grid ( row = row, column = 13, pady = 1, sticky = 'W')
def editsorption(self):
self.master.window.editsorption(self.matrix.name, self.chemical.name)
def get_sorption(self, sorptioneditor):
self.isotherm = sorptioneditor.isotherm.get()
self.kinetic = sorptioneditor.kinetic.get()
self.K = sorptioneditor.K.get()
self.Koc = sorptioneditor.Koc.get()
self.Kf = sorptioneditor.Kf.get()
self.N = sorptioneditor.N.get()
self.qmax = sorptioneditor.qmax.get()
self.b = sorptioneditor.b.get()
self.ksorp = sorptioneditor.ksorp.get()
self.thalf = sorptioneditor.thalf
self.cinit = sorptioneditor.cinit
self.qinit = sorptioneditor.qinit
if self.kinetic == self.kinetics[1]:
if self.isotherm == self.isotherms[0]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/self.K
if self.isotherm == self.isotherms[1]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/(10**self.Koc)/self.matrix.foc
if self.isotherm == self.isotherms[2]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/(self.Kf**(1/self.N))
if self.isotherm == self.isotherms[3]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/self.b
def update_material(self):
if self.kinetic == self.kinetics[1]:
if self.isotherm == self.isotherms[0]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/self.K
if self.isotherm == self.isotherms[1]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/(10**self.Koc)/self.matrix.foc
if self.isotherm == self.isotherms[2]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/(self.Kf**(1/self.N))
if self.isotherm == self.isotherms[3]: self.kdesorp = self.matrix.e*self.ksorp/self.matrix.rho/self.b
def remove_propertieswidgets(self):
self.editwidget.grid_forget()
self.isothermlabel.grid_forget()
self.kinetcilabel.grid_forget()
self.coef1label.grid_forget()
self.coef1value.grid_forget()
self.coef1unit.grid_forget()
self.coef2label.grid_forget()
self.coef2value.grid_forget()
self.coef2unit.grid_forget()
try:
self.coef3label.grid_forget()
self.coef3value.grid_forget()
self.coef3unit.grid_forget()
except: pass
self.master = 0
self.row = 0
self.editwidget = 0
self.isothermlabel = 0
self.kinetcilabel = 0
self.coef1label = 0
self.coef1value = 0
self.coef1unit = 0
self.coef2label = 0
self.coef2value = 0
self.coef2unit = 0
self.coef3label = 0
self.coef3value = 0
self.coef3unit = 0
def get_K(self, component, C, Cmax):
"""Takes the concentration "C" for the chemical "chemical" at
temperature "temp" and returns the partition coefficient at a point."""
if self.kinetic == self.kinetics[0]:
if self.isotherm == self.isotherms[0]:
K = self.K
if self.isotherm == self.isotherms[1]:
K = component.foc * 10**self.Koc
if self.isotherm == self.isotherms[2]:
Fmin = 0.0001
if Cmax < 0.0001: Cmax = 0.0001
if C <= Fmin * Cmax: K = freundlich(Fmin * Cmax, self.Kf, self.N)[0]
else: K = freundlich(C, self.Kf, self.N)[0]
if self.isotherm == self.isotherms[3]:
K = langmuir(C, self.qmax, self.b)[0]
else:
K = 0
return K
def get_NR(self, C, Cmax):
"""Takes the concentration "C" for the chemical "chemical" at
temperature "temp" and returns the partition coefficient at a point."""
if self.isotherm == self.isotherms[2]:
Fmin = 0.0001
if Cmax < 0.0001: Cmax = 0.0001
if C <=Fmin * Cmax: K_diff = freundlich(Fmin * Cmax, self.Kf, self.N)[1]
else: K_diff = freundlich(C, self.Kf, self.N)[1]
if self.isotherm == self.isotherms[3]:
K_diff = langmuir(C, self.qmax, self.b)[1]
return K_diff
def get_q(self, C):
"""Takes the pore water concentrations "C" for the "Chemical" instance
at "temp" and returns the solid-phase concentrations "q." """
if self.kinetic == self.kinetics[0]:
if self.isotherm == self.isotherms[0]:
q = self.K * C
if self.isotherm == self.isotherms[1]:
q = self.foc * 10**self.Koc * C
if self.isotherm == self.isotherms[2]:
if C <= 0:
q = 0
else:
q = freundlich(C, self.Kf, self.N)[0] * C
if self.isotherm == self.isotherms[3]:
q = langmuir(C, self.qmax, self.b)[0] * C
else:
q = 0
return q
class Layer:
"""Stores basic properties of a layer."""
def __init__(self, number):
"""Constructor method. Uses the "layertype" and the number in the
capping system and the system's chemical properties to set default
values for the parameters."""
self.number = number
self.torts = ['Millington & Quirk', 'Boudreau', 'None']
self.ICtypes = ['Uniform', 'Linear']
self.ICtype = self.ICtypes[0]
if number == 0: self.name = 'Deposition'
else: self.name = 'Layer ' + str(number)
self.delz = 0
self.delt = 0
def copy(self):
"""Copy method. Copies everything needed to a new Layer instance."""
layer = Layer(self.number)
layer.name = self.name
layer.number = self.number
layer.type = self.type