-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCaPP_3.12.py
1552 lines (1390 loc) · 77.2 KB
/
CaPP_3.12.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
## CaPP A.B ##
## ##
## Copyright 2020, ##
## Andreas Larsen ##
## andreas.larsen@bioch.ox.ac.uk ##
## This file is part of CaPP. ##
## ##
## CaPP is free a software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## CaPP is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## <http://www.gnu.org/licenses/> ##
## ##
## If you use this software in ##
## your work, please write: ##
## CaPP, source code freely available at github.com/Niels-Bohr-Institute-XNS-StructBiophys/CaPP ##
### import Libraries
import re
import os
import sys
import math
import linecache
import re
import platform
import ntpath
import numpy as np
try:
import wx
except:
print("")
print("******************************************************************")
print(" CaPP failed to import wxPython - is it correctly installed...? ")
print("******************************************************************")
print("")
sys.exit(1)
import wx.lib.scrolledpanel
### ignore "Future Warnings"
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
print('x' in np.arange(5)) #returns False, without Warning
### check OS and use correct binary. Check location of binary
if platform.system() == "Darwin":
capp_version = "capp_mac"
elif platform.system() == "Windows":
capp_version = "capp/capp.exe"
if programpath.count(" ") > 0:
print("")
print("****************************************************************************************")
print("Found path is: ", programpath)
print("Path must not contain spaces!")
print("****************************************************************************************")
sys.exit(1)
else:
capp_version = "capp"
programpath = os.path.dirname(os.path.realpath(__file__))
capp_executable_location = programpath + "/" + capp_version
print(capp_executable_location)
if os.path.exists(capp_executable_location):
print("CaPP initiated correctly")
elif capp_version == "capp":
print("")
print("****************************************************************************************")
print(" Cannot find the executable: %s. It should be in the same folder as CaPP.py " % capp_version)
print(" If you are not running MacOS, then:")
print(" 1) compile the source code Mainfunction.c with output called capp")
print(" e.g. gcc Mainfunction.c -o capp -lm")
print(" 2) place the executable, capp, in the same folder as CaPP.py")
print(" 3) re-run CaPP with: python CaPP.py")
print("****************************************************************************************")
print("")
sys.exit(1)
elif capp_version == "capp/capp.exe":
print("")
print("****************************************************************************************")
print("Could not find Windows executables. Compile (gcc Mainfunction.c -o capp -lm) and place capp.exe here: ", programpath + "/" + capp_version)
print("****************************************************************************************")
sys.exit(1)
else:
print("")
print("****************************************************************************************")
print(" Cannot find the executable: %s. It should be in the same folder as CaPP.py " % capp_version)
print("****************************************************************************************")
print("")
sys.exit(1)
## Import plotting libraries
import matplotlib
matplotlib.interactive(True)
matplotlib.use('WXAgg')
import pylab
## import fitting libraries
from scipy.optimize import curve_fit
## Define main class and text
class MainCls(wx.Frame):
##################################### Function that creates the GUI ###########################################
def __init__(self, parent, id):
### Overall frame for widgets
width = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X)
height = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)
position = (width/3.0, height/30.0)
wx.Frame.__init__(self, parent, id, title = 'CaPP - Calculate p(r) for Proteins (PDB format)', pos = position)
BoxSizer = wx.BoxSizer(wx.VERTICAL)
self.Panel = wx.lib.scrolledpanel.ScrolledPanel(self, -1)
self.Panel.SetupScrolling(False, True)
self.Bind(wx.EVT_CLOSE, self.CloseWindowFnc) # close pylab explicitely for to avoid crash
BoxSizer.AddSpacer(3) # vertical spacing
### Widgets for PDB-file import
PDBTextSizer = wx.BoxSizer(wx.HORIZONTAL)
PDBTextSizer.AddSpacer(10)
PDBText = wx.StaticText(self.Panel, -1, 'Location of PDB file:', size = (330, -1))
PDBTextSizer.Add(PDBText)
BoxSizer.Add(PDBTextSizer, 0, wx.EXPAND|wx.HORIZONTAL)
PDBPathSizer = wx.BoxSizer(wx.HORIZONTAL)
PDBPathSizer.AddSpacer(10)
self.PDBPathTxt = wx.StaticText(self.Panel, -1, '')
self.PDBPathStr = 'N/A'
PDBPathSizer.Add(self.PDBPathTxt)
BoxSizer.Add(PDBPathSizer, 0, wx.EXPAND|wx.HORIZONTAL)
PDBBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
PDBBtnSizer.AddSpacer(10)
BrowsePDBBtn = wx.Button(self.Panel, label = 'Browse')
self.Bind(wx.EVT_BUTTON, self.BrowsePDBFnc, BrowsePDBBtn)
PDBBtnSizer.Add(BrowsePDBBtn, 1, wx.EXPAND)
PDBBtnSizer.AddSpacer(10)
BoxSizer.Add(PDBBtnSizer, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
LinePDB = wx.StaticLine(self.Panel, -1)
BoxSizer.Add(LinePDB, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
### Widgets for Data-file import
DataTextSizer = wx.BoxSizer(wx.HORIZONTAL)
DataTextSizer.AddSpacer(10)
DataText = wx.StaticText(self.Panel, -1, 'Location of Data file (optional, for q-range and fit):', size = (330, -1))
DataTextSizer.Add(DataText)
BoxSizer.Add(DataTextSizer, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
DataPathSizer = wx.BoxSizer(wx.HORIZONTAL)
DataPathSizer.AddSpacer(10)
self.DataPathTxt = wx.StaticText(self.Panel, -1, '')
self.DataPathStr = 'Non'
DataPathSizer.Add(self.DataPathTxt)
BoxSizer.Add(DataPathSizer, 0, wx.EXPAND|wx.HORIZONTAL)
DataBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
DataBtnSizer.AddSpacer(10)
self.BrowseDataBtn = wx.Button(self.Panel, label = 'Browse')
self.Bind(wx.EVT_BUTTON, self.BrowseDataFnc, self.BrowseDataBtn)
DataBtnSizer.Add(self.BrowseDataBtn, 1, wx.EXPAND)
DataBtnSizer.AddSpacer(10)
BoxSizer.Add(DataBtnSizer, 0, wx.EXPAND|wx.HORIZONTAL)
self.BrowseDataBtn.Disable()
nm_button = wx.BoxSizer(wx.HORIZONTAL)
self.nm_button = wx.CheckBox(self.Panel, -1, 'q in data is in [1/nm] (default: [1/aa])', size = (350, -1))
nm_button.Add(self.nm_button)
BoxSizer.Add(nm_button, 0, wx.ALIGN_CENTER, wx.EXPAND|wx.HORIZONTAL)
self.Bind(wx.EVT_CHECKBOX, self.nmFnc, self.nm_button)
self.nm_button.Disable()
BoxSizer.AddSpacer(5)
LineData = wx.StaticLine(self.Panel, -1)
BoxSizer.Add(LineData, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
### Widgets used to choose between SAXS and SANS
SAXS_button = wx.BoxSizer(wx.HORIZONTAL) # prepare for SAXS button
SAXS_button.AddSpacer(10)
self.SAXS_button = wx.RadioButton(self.Panel, -1, 'SAXS',style=wx.RB_GROUP) # make SAXS button
SAXS_button.Add(self.SAXS_button)
BoxSizer.Add(SAXS_button, 0, wx.EXPAND|wx.HORIZONTAL) # position SAXS button
self.Bind(wx.EVT_RADIOBUTTON, self.EnableSAXSFnc, self.SAXS_button)
SAXS_solvent_box = wx.BoxSizer(wx.HORIZONTAL) # prepare for SAXS solvent box
SAXS_solvent_box.AddSpacer(10)
self.left_SAXS = wx.StaticText(self.Panel, -1, "Sucrose content =")
SAXS_solvent_box.Add(self.left_SAXS)
self.left_SAXS.Disable()
self.SAXS_solvent_box = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SAXS solvent box
self.SAXS_solvent_box.SetValue('0')
SAXS_solvent_box.Add(self.SAXS_solvent_box) # add SAXS botton to its own line
BoxSizer.Add(SAXS_solvent_box) # position SAXS solvent box
self.SAXS_solvent_box.Disable()
self.right_SAXS = wx.StaticText(self.Panel, -1, "g/100 ml (%)")
SAXS_solvent_box.Add(self.right_SAXS)
self.right_SAXS.Disable()
SANS_button = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS button
SANS_button.AddSpacer(10) # vertical spacing
self.SANS_button = wx.RadioButton(self.Panel, -1, 'SANS') # make SANS button
SANS_button.Add(self.SANS_button) # add SANS_button to its own line
BoxSizer.Add(SANS_button, 0, wx.EXPAND|wx.HORIZONTAL) # position SANS button
self.Bind(wx.EVT_RADIOBUTTON, self.EnableSANSFnc, self.SANS_button)
SANS_solvent_box = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS solvent box
SANS_solvent_box.AddSpacer(10)
self.left_SANS = wx.StaticText(self.Panel, -1, "D2O content, solvent =")
SANS_solvent_box.Add(self.left_SANS)
self.left_SANS.Disable()
self.SANS_solvent_box = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS solvent box
self.SANS_solvent_box.SetValue('100')
SANS_solvent_box.Add(self.SANS_solvent_box) # add SANS solven box to its own line
BoxSizer.Add(SANS_solvent_box) # position SANS solvent box
self.SANS_solvent_box.Disable()
self.right_SANS = wx.StaticText(self.Panel, -1, "%")
SANS_solvent_box.Add(self.right_SANS)
self.right_SANS.Disable()
SANS_perdeut_box_A = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS perdeuteration box A
SANS_perdeut_box_A.AddSpacer(10)
self.left_SANS_d = wx.StaticText(self.Panel, -1, "Perdeut., chain A,B,...,G =")
SANS_perdeut_box_A.Add(self.left_SANS_d)
self.left_SANS_d.Disable()
self.SANS_perdeut_box_A = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS perdeuteration box
self.SANS_perdeut_box_A.SetValue('0')
SANS_perdeut_box_A.Add(self.SANS_perdeut_box_A) # add SANS_perdeut_box_A to its own line
BoxSizer.Add(SANS_perdeut_box_A) # position SANS perdeuteration box
self.SANS_perdeut_box_A.Disable()
SANS_perdeut_box_B = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS perdeuteration box B
self.SANS_perdeut_box_B = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS perdeuteration box
self.SANS_perdeut_box_B.SetValue('0')
SANS_perdeut_box_A.Add(self.SANS_perdeut_box_B) # add SANS_perdeut_box_B to same line as SANS_perdeut_box_A
BoxSizer.Add(SANS_perdeut_box_B) # position SANS perdeuteration box B
self.SANS_perdeut_box_B.Disable()
SANS_perdeut_box_C = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS perdeuteration box C
self.SANS_perdeut_box_C = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS perdeuteration box
self.SANS_perdeut_box_C.SetValue('0')
SANS_perdeut_box_A.Add(self.SANS_perdeut_box_C) # add SANS_perdeut_box_C to same line as SANS_perdeut_box_A
BoxSizer.Add(SANS_perdeut_box_C) # position SANS perdeuteration box C
self.SANS_perdeut_box_C.Disable()
SANS_perdeut_box_D = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS perdeuteration box D
self.SANS_perdeut_box_D = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS perdeuteration box
self.SANS_perdeut_box_D.SetValue('0')
SANS_perdeut_box_A.Add(self.SANS_perdeut_box_D) # add SANS_perdeut_box_D to same line as SANS_perdeut_box_A
BoxSizer.Add(SANS_perdeut_box_D) # position SANS perdeuteration box D
self.SANS_perdeut_box_D.Disable()
SANS_perdeut_box_E = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS perdeuteration box E
self.SANS_perdeut_box_E = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS perdeuteration box
self.SANS_perdeut_box_E.SetValue('0')
SANS_perdeut_box_A.Add(self.SANS_perdeut_box_E) # add SANS_perdeut_box_E to same line as SANS_perdeut_box_A
BoxSizer.Add(SANS_perdeut_box_E) # position SANS perdeuteration box E
self.SANS_perdeut_box_E.Disable()
SANS_perdeut_box_F = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS perdeuteration box E
self.SANS_perdeut_box_F = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS perdeuteration box
self.SANS_perdeut_box_F.SetValue('0')
SANS_perdeut_box_A.Add(self.SANS_perdeut_box_F) # add SANS_perdeut_box_F to same line as SANS_perdeut_box_A
BoxSizer.Add(SANS_perdeut_box_F) # position SANS perdeuteration box F
self.SANS_perdeut_box_F.Disable()
SANS_perdeut_box_G = wx.BoxSizer(wx.HORIZONTAL) # prepare for SANS perdeuteration box E
self.SANS_perdeut_box_G = wx.TextCtrl(self.Panel, -1, '', size = (40, -1)) # make SANS perdeuteration box
self.SANS_perdeut_box_G.SetValue('0')
SANS_perdeut_box_A.Add(self.SANS_perdeut_box_G) # add SANS_perdeut_box_G to same line as SANS_perdeut_box_A
BoxSizer.Add(SANS_perdeut_box_G) # position SANS perdeuteration box F
self.SANS_perdeut_box_G.Disable()
self.right_SANS_d = wx.StaticText(self.Panel, -1, "%")
SANS_perdeut_box_A.Add(self.right_SANS_d)
self.right_SANS_d.Disable()
Perdeut_text = wx.BoxSizer(wx.HORIZONTAL)
Perdeut_text.AddSpacer(10)
self.Perdeut_text = wx.StaticText(self.Panel, -1, 'Enter a number between 0 and 100 %, OBS:', size = (450, -1))
Perdeut_text.Add(self.Perdeut_text)
BoxSizer.Add(Perdeut_text, 0, wx.EXPAND|wx.HORIZONTAL)
self.Perdeut_text.Disable()
Perdeut_text2 = wx.BoxSizer(wx.HORIZONTAL)
Perdeut_text2.AddSpacer(10)
self.Perdeut_text2 = wx.StaticText(self.Panel, -1, 'For single-chain proteins (no chain labels), value in "chain A" box is global.', size = (450, -1))
Perdeut_text2.Add(self.Perdeut_text2)
BoxSizer.Add(Perdeut_text2, 0, wx.EXPAND|wx.HORIZONTAL)
self.Perdeut_text2.Disable()
BoxSizer.AddSpacer(10)
RES_button = wx.BoxSizer(wx.HORIZONTAL)
self.RES_button = wx.CheckBox(self.Panel, -1, 'Include resolution effects (from 4th column in data)', size = (350, -1))
RES_button.Add(self.RES_button)
BoxSizer.Add(RES_button, 0, wx.ALIGN_CENTER, wx.EXPAND|wx.HORIZONTAL)
self.Bind(wx.EVT_CHECKBOX, self.resFnc, self.RES_button)
self.RES_button.SetValue(0)
self.RES_button.Disable()
Line_after_contrast_widget = wx.StaticLine(self.Panel, -1) # make line after widget
BoxSizer.Add(Line_after_contrast_widget, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
### Widgets used to add Water Layer
Water_layer_button = wx.BoxSizer(wx.HORIZONTAL)
self.Water_layer_button = wx.CheckBox(self.Panel, -1, 'Add Water Layer (WL):', size = (350, -1))
Water_layer_button.Add(self.Water_layer_button)
BoxSizer.Add(Water_layer_button, 0, wx.ALIGN_CENTER, wx.EXPAND|wx.HORIZONTAL)
self.Bind(wx.EVT_CHECKBOX, self.EnableWLButtonsFnc, self.Water_layer_button)
Water_layer_contrast_box = wx.BoxSizer(wx.HORIZONTAL)
Water_layer_contrast_box.AddSpacer(29)
self.left_WL = wx.StaticText(self.Panel, -1, "WL contrast =")
Water_layer_contrast_box.Add(self.left_WL)
self.left_WL.Disable()
self.Water_layer_contrast_box = wx.TextCtrl(self.Panel, -1, '', size = (40, -1))
self.Water_layer_contrast_box.SetValue('6')
Water_layer_contrast_box.Add(self.Water_layer_contrast_box)
BoxSizer.Add(Water_layer_contrast_box)
self.Water_layer_contrast_box.Disable()
self.right_WL = wx.StaticText(self.Panel, -1, "% of solvent scattering")
Water_layer_contrast_box.Add(self.right_WL)
self.right_WL.Disable()
BoxSizer.AddSpacer(5) # vertical spacing
### Widgets to exclude water layer from TMD
WLText = wx.BoxSizer(wx.HORIZONTAL)
WLText.AddSpacer(10)
self.WLText = wx.StaticText(self.Panel, -1, 'If the protein has a Transmembrane Domain (TMD):', size = (330, -1))
WLText.Add(self.WLText)
BoxSizer.Add(WLText, 0, wx.EXPAND|wx.HORIZONTAL)
self.WLText.Disable()
No_Exclude_water_layer_button = wx.BoxSizer(wx.HORIZONTAL)
No_Exclude_water_layer_button.AddSpacer(10)
self.No_Exclude_water_layer_button = wx.RadioButton(self.Panel, -1, 'Do not exclude the WL from the TMD', style=wx.RB_GROUP)
No_Exclude_water_layer_button.Add(self.No_Exclude_water_layer_button)
BoxSizer.Add(No_Exclude_water_layer_button, 0, wx.EXPAND|wx.HORIZONTAL)
self.No_Exclude_water_layer_button.Disable()
self.Bind(wx.EVT_RADIOBUTTON, self.DisableBilayerThicknessFnc, self.No_Exclude_water_layer_button)
Exclude_water_layer_OPM_button = wx.BoxSizer(wx.HORIZONTAL)
Exclude_water_layer_OPM_button.AddSpacer(10)
self.Exclude_water_layer_OPM_button = wx.RadioButton(self.Panel, -1, 'Exclude the WL from the TMD, using OPM(*)')
Exclude_water_layer_OPM_button.Add(self.Exclude_water_layer_OPM_button)
BoxSizer.Add(Exclude_water_layer_OPM_button, 0, wx.EXPAND|wx.HORIZONTAL)
self.Exclude_water_layer_OPM_button.Disable()
self.Bind(wx.EVT_RADIOBUTTON, self.DisableBilayerThicknessFnc, self.Exclude_water_layer_OPM_button)
Exclude_water_layer_M_button = wx.BoxSizer(wx.HORIZONTAL)
Exclude_water_layer_M_button.AddSpacer(10)
self.Exclude_water_layer_M_button = wx.RadioButton(self.Panel, -1, 'Exclude WL from TMD, manually(**):')
Exclude_water_layer_M_button.Add(self.Exclude_water_layer_M_button)
BoxSizer.Add(Exclude_water_layer_M_button, 0, wx.EXPAND|wx.HORIZONTAL)
self.Exclude_water_layer_M_button.Disable()
self.Bind(wx.EVT_RADIOBUTTON, self.EnableBilayerThicknessFnc, self.Exclude_water_layer_M_button)
Bilayer_thickness_box = wx.BoxSizer(wx.HORIZONTAL)
Bilayer_thickness_box.AddSpacer(29)
self.left_thick = wx.StaticText(self.Panel, -1, "Bilayer Thickness =")
Bilayer_thickness_box.Add(self.left_thick)
self.left_thick.Disable()
self.Bilayer_thickness_box = wx.TextCtrl(self.Panel, -1, '', size = (40, -1))
self.Bilayer_thickness_box.SetValue('30.0')
Bilayer_thickness_box.Add(self.Bilayer_thickness_box)
BoxSizer.Add(Bilayer_thickness_box, 0)
self.Bilayer_thickness_box.Disable()
self.right_thick = wx.StaticText(self.Panel, -1, "Angstrom")
Bilayer_thickness_box.Add(self.right_thick)
self.right_thick.Disable()
OPMText = wx.BoxSizer(wx.HORIZONTAL)
OPMText.AddSpacer(10)
self.OPMText = wx.StaticText(self.Panel, -1, '(*) Orientations of Proteins in Membranes Database', size = (330, -1))
OPMText.Add(self.OPMText)
BoxSizer.Add(OPMText, 0, wx.EXPAND|wx.HORIZONTAL)
self.OPMText.Disable()
MText1 = wx.BoxSizer(wx.HORIZONTAL)
MText1.AddSpacer(10)
self.MText1 = wx.StaticText(self.Panel, -1, '(**) Align protein with TMD perp. to xy-plane, and TMD-center in z=0.', size = (430, -1))
MText1.Add(self.MText1)
BoxSizer.Add(MText1, 0, wx.EXPAND|wx.HORIZONTAL)
self.MText1.Disable()
BoxSizer.AddSpacer(5)
Line_after_exclude_WL_widget = wx.StaticLine(self.Panel, -1) # make line after widget
BoxSizer.Add(Line_after_exclude_WL_widget, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
### Widgets for calculation buttons
CalculateButtonSpace = wx.BoxSizer(wx.HORIZONTAL)
CalculateButtonSpace.AddSpacer(10)
self.CalculateButton = wx.Button(self.Panel, label = 'Calculate p(r), Rg, and P(q)')
self.Bind(wx.EVT_BUTTON, self.cappFnc, self.CalculateButton)
self.CalculateButton.Disable()
CalculateButtonSpace.Add(self.CalculateButton, 1, wx.EXPAND)
CalculateButtonSpace.AddSpacer(10)
BoxSizer.Add(CalculateButtonSpace, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
Line_after_widget = wx.StaticLine(self.Panel, -1) # make line after widget
BoxSizer.Add(Line_after_widget, 0, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(5)
### Widgets for fitting
FitButtonSpace = wx.BoxSizer(wx.HORIZONTAL)
FitButtonSpace.AddSpacer(10)
self.FitButton = wx.Button(self.Panel, label = 'Fit P(q) to data')
self.Bind(wx.EVT_BUTTON, self.FitFnc, self.FitButton)
FitButtonSpace.Add(self.FitButton, 1, wx.EXPAND)
FitButtonSpace.AddSpacer(10)
BoxSizer.Add(FitButtonSpace, 0, wx.EXPAND|wx.HORIZONTAL)
self.FitButton.Disable()
BoxSizer.AddSpacer(1)
BoxSizer.AddSpacer(4)
Skip_box = wx.BoxSizer(wx.HORIZONTAL)
Skip_box.AddSpacer(5)
self.left_skip = wx.StaticText(self.Panel, -1, "Skip the first ")
Skip_box.Add(self.left_skip)
self.left_skip.Disable()
self.Skip_box = wx.TextCtrl(self.Panel, -1, '', size = (40, -1))
self.Skip_box.SetValue('0')
Skip_box.Add(self.Skip_box)
BoxSizer.Add(Skip_box)
self.Skip_box.Disable()
self.right_skip = wx.StaticText(self.Panel, -1, " points in q (default: 0)")
Skip_box.Add(self.right_skip)
self.right_skip.Disable()
fitWL_button = wx.BoxSizer(wx.HORIZONTAL)
self.fitWL_button = wx.CheckBox(self.Panel, -1, 'Fit WL contrast? (default: fixed to chosen value)', size = (350, -1))
fitWL_button.Add(self.fitWL_button)
BoxSizer.Add(fitWL_button, 0, wx.ALIGN_CENTER, wx.EXPAND|wx.HORIZONTAL)
self.fitWL_button.Disable()
fitPDB2_button = wx.BoxSizer(wx.HORIZONTAL)
self.fitPDB2_button = wx.CheckBox(self.Panel, -1, 'Fit with 2 PDBs? Location of 2nd PDB file:', size = (350, -1))
fitPDB2_button.Add(self.fitPDB2_button)
self.Bind(wx.EVT_CHECKBOX, self.EnableBrowsePDB2Fnc, self.fitPDB2_button)
BoxSizer.Add(fitPDB2_button, 0, wx.ALIGN_CENTER, wx.EXPAND|wx.HORIZONTAL)
self.fitPDB2_button.Disable()
PDB2PathSizer = wx.BoxSizer(wx.HORIZONTAL)
PDB2PathSizer.AddSpacer(10)
self.PDB2PathTxt = wx.StaticText(self.Panel, -1, '')
self.PDB2PathStr = 'N/A'
PDB2PathSizer.Add(self.PDB2PathTxt)
BoxSizer.Add(PDB2PathSizer, 0, wx.EXPAND|wx.HORIZONTAL)
PDB2BtnSizer = wx.BoxSizer(wx.HORIZONTAL)
PDB2BtnSizer.AddSpacer(10)
self.BrowsePDB2Btn = wx.Button(self.Panel, label = 'Browse')
self.Bind(wx.EVT_BUTTON, self.BrowsePDB2Fnc, self.BrowsePDB2Btn)
PDB2BtnSizer.Add(self.BrowsePDB2Btn, 1, wx.EXPAND)
PDB2BtnSizer.AddSpacer(10)
BoxSizer.Add(PDB2BtnSizer, 0, wx.EXPAND|wx.HORIZONTAL)
self.BrowsePDB2Btn.Disable()
BoxSizer.AddSpacer(5)
Line_after_widget = wx.StaticLine(self.Panel, -1) # make line after widget
BoxSizer.Add(Line_after_widget, 0, wx.EXPAND|wx.HORIZONTAL)
#BoxSizer.AddSpacer(5)
### Widgets to change resolution (binsize)
Change_resolution_button = wx.BoxSizer(wx.HORIZONTAL)
self.Change_resolution_button = wx.CheckBox(self.Panel, -1, 'Change resolution (binsize) of the p(r):', size = (270, -1))
Change_resolution_button.Add(self.Change_resolution_button)
BoxSizer.Add(Change_resolution_button, 0, wx.ALIGN_CENTER, wx.EXPAND|wx.HORIZONTAL)
self.Bind(wx.EVT_CHECKBOX, self.EnableResolutionBoxFnc, self.Change_resolution_button)
Resolution_box = wx.BoxSizer(wx.HORIZONTAL)
self.Resolution_box = wx.TextCtrl(self.Panel, -1, '', size = (40, -1))
self.Resolution_box.SetValue('1.0')
Change_resolution_button.Add(self.Resolution_box)
self.Resolution_box.Disable()
self.right_res = wx.StaticText(self.Panel, -1, "A")
Change_resolution_button.Add(self.right_res)
self.right_res.Disable()
### Widgets to choose explicit H and D
Explicit_button = wx.BoxSizer(wx.HORIZONTAL)
self.Explicit_button = wx.CheckBox(self.Panel, -1, 'Account for H and D explicitely? (default: no)', size = (320, -1))
self.Bind(wx.EVT_CHECKBOX, self.ExplicitFnc, self.Explicit_button)
Explicit_button.Add(self.Explicit_button)
BoxSizer.Add(Explicit_button, 0, wx.ALIGN_CENTER, wx.EXPAND|wx.HORIZONTAL)
BoxSizer.AddSpacer(10)
### Conclusion of init-function
self.Panel.SetSizerAndFit(BoxSizer)
self.SetSizerAndFit(BoxSizer)
self.SetAutoLayout(True)
self.Panel.Layout()
self.Layout()
##################################### FUNCTIONS related to GUI ###########################################
### define function for closing GUI
def onClose(self,event):
self.Destroy()
### define function for printing q unit
def nmFnc(self,event):
if self.nm_button.GetValue():
print("q in data is in [1/nm]")
else:
print("q in data is in [1/aa]")
### define function for printing if resution effects are included
def resFnc(self,event):
if self.RES_button.GetValue():
print("SANS resolution effects included (from 4th column in data)")
else:
print("SANS resolutioin effects not included (default)")
### define funciton for enable/disable "Browse PDB 2" botton
def EnableBrowsePDB2Fnc(self,event):
if self.fitPDB2_button.GetValue():
self.BrowsePDB2Btn.Enable()
else:
self.BrowsePDB2Btn.Disable()
### define function for enable/disable GUI related to WL
def EnableWLButtonsFnc(self, event):
if self.Water_layer_button.GetValue():
self.left_WL.Enable()
self.Water_layer_contrast_box.Enable()
self.right_WL.Enable()
self.Exclude_water_layer_OPM_button.Enable()
self.Exclude_water_layer_M_button.Enable()
self.WLText.Enable()
self.No_Exclude_water_layer_button.Enable()
self.OPMText.Enable()
self.MText1.Enable()
self.fitWL_button.Enable()
else:
self.left_WL.Disable()
self.Water_layer_contrast_box.Disable()
self.right_WL.Disable()
self.Exclude_water_layer_OPM_button.Disable()
self.Exclude_water_layer_M_button.Disable()
self.Bilayer_thickness_box.Disable()
self.WLText.Disable()
self.No_Exclude_water_layer_button.Disable()
self.right_thick.Disable()
self.left_thick.Disable()
self.OPMText.Disable()
self.MText1.Disable()
self.Exclude_water_layer_M_button.SetValue(False)
self.Exclude_water_layer_OPM_button.SetValue(False)
self.No_Exclude_water_layer_button.SetValue(False)
self.fitWL_button.Disable()
self.fitWL_button.SetValue(0)
### define function for enable/disable GUI related to resolutions of p(r), i.e binsize
def EnableResolutionBoxFnc(self, event):
if self.Change_resolution_button.GetValue():
self.Resolution_box.Enable()
self.right_res.Enable()
Message = 'If you have calculated with other resolution before, then you need to manually delete/rename/move those output files to get the right results. Keep plot windows open for easy comparison.'
print(Message)
wx.MessageBox(Message, "Changing resolution/binsize of p(r)", wx.OK | wx.ICON_INFORMATION)
else:
self.Resolution_box.Disable()
self.right_res.Disable()
### define function for explicit H/D button
def ExplicitFnc(self, event):
if self.Explicit_button.GetValue():
Message = 'If you have calculated with implicit H/D before, then you need to manually delete/rename/move those output files to get the right results. Keep plot windows open for easy comparison.'
print(Message)
wx.MessageBox(Message, "Changing to explicit H/D", wx.OK | wx.ICON_INFORMATION)
else:
Message = 'If you have calculated with explicit H/D before, then you need to manually delete/rename/move those output files to get the right results. Keep plot windows open for easy comparison.'
print(Message)
wx.MessageBox(Message, "Changing to implicit H/D", wx.OK | wx.ICON_INFORMATION)
### define function for enable GUI related to bilayer thickness
def EnableBilayerThicknessFnc(self, event):
self.Bilayer_thickness_box.Enable()
self.right_thick.Enable()
self.left_thick.Enable()
### define function for disable GUI related to bilayer thickness
def DisableBilayerThicknessFnc(self, event):
self.Bilayer_thickness_box.Disable()
self.right_thick.Disable()
self.left_thick.Disable()
### define function for enable/disable GUI related to SANS
def EnableSANSFnc(self, event):
self.left_SANS.Enable()
self.left_SANS_d.Enable()
self.SANS_solvent_box.Enable()
self.SANS_perdeut_box_A.Enable()
self.SANS_perdeut_box_B.Enable()
self.SANS_perdeut_box_C.Enable()
self.SANS_perdeut_box_D.Enable()
self.SANS_perdeut_box_E.Enable()
self.SANS_perdeut_box_F.Enable()
self.SANS_perdeut_box_G.Enable()
self.Perdeut_text.Enable()
self.Perdeut_text2.Enable()
self.right_SANS.Enable()
self.right_SANS_d.Enable()
if self.DataPathStr == 'Non':
self.RES_button.Disable()
else:
self.RES_button.Enable()
self.left_SAXS.Disable()
self.SAXS_solvent_box.Disable()
self.right_SAXS.Disable()
### define function for enable/disable GUI related to SAXS
def EnableSAXSFnc(self, event):
self.left_SAXS.Enable()
self.SAXS_solvent_box.Enable()
self.right_SAXS.Enable()
self.left_SANS.Disable()
self.left_SANS_d.Disable()
self.SANS_solvent_box.Disable()
self.SANS_perdeut_box_A.Disable()
self.SANS_perdeut_box_B.Disable()
self.SANS_perdeut_box_C.Disable()
self.SANS_perdeut_box_D.Disable()
self.SANS_perdeut_box_E.Disable()
self.SANS_perdeut_box_F.Disable()
self.SANS_perdeut_box_G.Disable()
self.Perdeut_text.Disable()
self.Perdeut_text2.Disable()
self.right_SANS.Disable()
self.right_SANS_d.Disable()
self.RES_button.SetValue(0)
self.RES_button.Disable()
### Define function for filebrowsing for PDB
def BrowsePDBFnc(self,event):
FileDialogWindow = wx.FileDialog(None, 'Please select PDB file...', os.getcwd(), defaultFile = '')
if FileDialogWindow.ShowModal() == wx.ID_OK:
self.PDBPathStr = FileDialogWindow.GetPath()
PDBPathDisplayStr = str(self.PDBPathStr)
while len(PDBPathDisplayStr) > 49:
PDBPathDisplayStr = PDBPathDisplayStr[1:]
if len(self.PDBPathStr) > 49:
PDBPathDisplayStr = '...' + PDBPathDisplayStr
self.PDBPathTxt.SetLabel(PDBPathDisplayStr)
DirectoryStr = os.path.dirname(self.PDBPathStr) # get current directory
os.chdir(DirectoryStr) # cd to current directory
self.CalculateButton.Enable()
self.BrowseDataBtn.Enable()
self.nm_button.Enable()
FileDialogWindow.Destroy()
### Define function for filebrowsing for PDB2
def BrowsePDB2Fnc(self,event):
FileDialogWindow = wx.FileDialog(None, 'Please select second PDB file...', os.getcwd(), defaultFile = '')
if FileDialogWindow.ShowModal() == wx.ID_OK:
self.PDB2PathStr = FileDialogWindow.GetPath()
PDB2PathDisplayStr = str(self.PDB2PathStr)
while len(PDB2PathDisplayStr) > 49:
PDB2PathDisplayStr = PDB2PathDisplayStr[1:]
if len(self.PDB2PathStr) > 49:
PDB2PathDisplayStr = '...' + PDB2PathDisplayStr
self.PDB2PathTxt.SetLabel(PDB2PathDisplayStr)
DirectoryStr = os.path.dirname(self.PDB2PathStr) # get current directory
os.chdir(DirectoryStr) # cd to current directory
FileDialogWindow.Destroy()
### Define function for filebrowsing for data
def BrowseDataFnc(self, event):
FileDialogWindow = wx.FileDialog(None, 'Please select Data-file...', os.getcwd(), defaultFile = '')
if FileDialogWindow.ShowModal() == wx.ID_OK:
self.DataPathStr = FileDialogWindow.GetPath()
DataPathDisplayStr = str(self.DataPathStr)
while len(DataPathDisplayStr) > 49:
DataPathDisplayStr = DataPathDisplayStr[1:]
if len(self.DataPathStr) > 49:
DataPathDisplayStr = '...' + DataPathDisplayStr
self.DataPathTxt.SetLabel(DataPathDisplayStr)
self.FitButton.Enable()
self.left_skip.Enable()
self.Skip_box.Enable()
self.right_skip.Enable()
self.fitPDB2_button.Enable()
if self.SANS_button.GetValue():
self.RES_button.Enable()
FileDialogWindow.Destroy()
### Define exit function
def CloseWindowFnc(self, event):
try:
pylab.close()
except:
pass
sys.exit(0)
### Define funciton to extract file name from a file path
def path_leaf(self,path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
##################################### FUNCTIONS for calculations ###########################################
### define function for running CaPP (c-part) to calculate p(r)
def cappFnc(self, event):
# open pop-up window
width = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X)
height = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)
position = (width/3.0, height/3.0)
self.second_window = wx.Frame(None, title="Calculating p(r) - see Progression in the Terminal window...", size=(450,50), pos = position)
self.second_window.Show()
# import options from GUI
XN_choice = ""
solvent = ""
Perdeut_choice_A = ""
Perdeut_choice_B = ""
Perdeut_choice_C = ""
Perdeut_choice_D = ""
Perdeut_choice_E = ""
Perdeut_choice_F = ""
Perdeut_choice_G = ""
perdeut_A = ""
perdeut_B = ""
perdeut_C = ""
perdeut_D = ""
perdeut_E = ""
perdeut_F = ""
perdeut_G = ""
X_choice = ""
PrcSucrose = ""
WL_choice = ""
WL_contrast = ""
Exclude_WL_choice = ""
Bilayer_thickness = ""
Resolution_choice = ""
Resolution = ""
Explicit_choice = ""
if self.Water_layer_button.GetValue():
WL_choice = "-c"
WL_contrast_tmp = float(self.Water_layer_contrast_box.GetValue())/100.0
WL_contrast = "%6.4f" % WL_contrast_tmp
if self.Exclude_water_layer_OPM_button.GetValue():
Exclude_WL_choice = "-d"
if self.Exclude_water_layer_M_button.GetValue():
Exclude_WL_choice = "-m"
Bilayer_thickness = self.Bilayer_thickness_box.GetValue()
if self.Change_resolution_button.GetValue():
Resolution_choice = "-r"
Resolution = self.Resolution_box.GetValue()
if self.Explicit_button.GetValue():
Explicit_choice = "-H"
if self.SAXS_button.GetValue():
X_choice = "-x"
PrcSucrose_tmp = float(self.SAXS_solvent_box.GetValue())
PrcSucrose = "%5.2f" % PrcSucrose_tmp
if PrcSucrose_tmp > 200:
Message = 'Maximum solubility of sucrose in water is 200%, i.e 200g/100ml'
print(Message)
wx.MessageBox(Message, "CaPP", wx.OK | wx.ICON_INFORMATION)
elif self.SANS_button.GetValue():
XN_choice = "-s"
solvent_tmp = float(self.SANS_solvent_box.GetValue())/100.0
solvent = "%4.3f" % solvent_tmp
perdeut_tmp = float(self.SANS_perdeut_box_A.GetValue())/100.0
Perdeut_choice_A = "-A"
perdeut_A = "%4.3f" % perdeut_tmp
perdeut_tmp = float(self.SANS_perdeut_box_B.GetValue())/100.0
if perdeut_tmp > 0.0:
Perdeut_choice_B = "-B"
perdeut_B = "%4.3f" % perdeut_tmp
perdeut_tmp = float(self.SANS_perdeut_box_C.GetValue())/100.0
if perdeut_tmp > 0.0:
Perdeut_choice_C = "-C"
perdeut_C = "%4.3f" % perdeut_tmp
perdeut_tmp = float(self.SANS_perdeut_box_D.GetValue())/100.0
if perdeut_tmp > 0.0:
Perdeut_choice_D = "-D"
perdeut_D = "%4.3f" % perdeut_tmp
perdeut_tmp = float(self.SANS_perdeut_box_E.GetValue())/100.0
if perdeut_tmp > 0.0:
Perdeut_choice_E = "-E"
perdeut_E = "%4.3f" % perdeut_tmp
perdeut_tmp = float(self.SANS_perdeut_box_F.GetValue())/100.0
if perdeut_tmp > 0.0:
Perdeut_choice_F = "-F"
perdeut_F = "%4.3f" % perdeut_tmp
perdeut_tmp = float(self.SANS_perdeut_box_G.GetValue())/100.0
if perdeut_tmp > 0.0:
Perdeut_choice_G = "-G"
perdeut_G = "%4.3f" % perdeut_tmp
else:
X_choice = "-x"
PrcSucrose_tmp = float(self.SAXS_solvent_box.GetValue())
PrcSucrose = "%5.2f" % PrcSucrose_tmp
Message = 'SAXS chosen as default'
print(Message)
wx.MessageBox(Message, "CaPP", wx.OK | wx.ICON_INFORMATION)
# assemble options into a command line and run the command line
Output = "%s/%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s" % (programpath, capp_version, XN_choice, solvent, Perdeut_choice_A, perdeut_A, Perdeut_choice_B, perdeut_B, Perdeut_choice_C, perdeut_C, Perdeut_choice_D, perdeut_D, Perdeut_choice_E, perdeut_E, Perdeut_choice_F, perdeut_F, Perdeut_choice_G, perdeut_G, X_choice, PrcSucrose, WL_choice, WL_contrast, Exclude_WL_choice, Bilayer_thickness, Resolution_choice, Resolution, Explicit_choice, self.PDBPathStr)
if self.fitWL_button.GetValue() == 0:
print("Command generated by the GUI and sent to terminal:")
print(Output)
print("")
os.system(Output)
if self.fitPDB2_button.GetValue():
Output = "%s/%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s" % (programpath, capp_version, XN_choice, solvent, Perdeut_choice_A, perdeut_A, Perdeut_choice_B, perdeut_B, Perdeut_choice_C, perdeut_C, Perdeut_choice_D, perdeut_D, Perdeut_choice_E, perdeut_E, Perdeut_choice_F, perdeut_F, Perdeut_choice_G, perdeut_G, X_choice, PrcSucrose, WL_choice, WL_contrast, Exclude_WL_choice, Bilayer_thickness, Resolution_choice, Resolution, Explicit_choice, self.PDB2PathStr)
if self.fitWL_button.GetValue() == 0:
print("Command generated by the GUI and sent to terminal (2nd PDB):")
print(Output)
print("")
os.system(Output)
## close pop-up window
self.second_window.Destroy()
# generate filenames, plot p(r), calculate and plot P(q)
filename,filename_nowater,short_filename,PDBID = self.GenerateFilenamesFnc(1)
self.PlotprFnc(filename,PDBID) # plot p(r)
self.CalcPqFnc(filename,filename_nowater,short_filename,PDBID) # calculate and plot P(q)
if self.fitPDB2_button.GetValue():
filename,filename_nowater,short_filename,PDBID = self.GenerateFilenamesFnc(2)
self.PlotprFnc(filename,PDBID) # plot p(r)
self.CalcPqFnc(filename,filename_nowater,short_filename,PDBID) # calculate and plot P(q)
### define function for generating filenames
def GenerateFilenamesFnc(self,PDBnumber):
if PDBnumber == 2:
short_filename = os.path.splitext(self.PDB2PathStr)[0]
PDBID = os.path.splitext(os.path.basename(self.PDB2PathStr))[0]
else:
short_filename = os.path.splitext(self.PDBPathStr)[0]
PDBID = os.path.splitext(os.path.basename(self.PDBPathStr))[0]
# check if user has taken pdb with water
if short_filename[-2:] == '_w':
if self.Water_layer_button.GetValue():
Message = 'Your input PDB name ends with "_w", used by CaPP to denote PDB with water layer added. Please use the PDB without water if it is PDB generated by CaPP, or rename the PDB.'
print(Message)
wx.MessageBox(Message, "Error: PDB name with \"_w\" ending", wx.OK | wx.ICON_INFORMATION)
else:
Message = 'Warning: your input PDB name ends with "_w", used by CaPP to denote PDB with water layer added. If it is a PDB generated by CaPP, then use the PDB without water, else consider renaming the PDB to avoid potential mistakes regarding added water layer. '
print(Message)
wx.MessageBox(Message, "Warning: PDB name with \"_w\" ending", wx.OK | wx.ICON_INFORMATION)
if short_filename[-7:] == '_w_only':
Message = 'Error: You are trying to calculate p(r) and P(q) for water layer alone. Not possible this way. p(r) for water alone has been calculated already (output file \"PDBname_w_only_pr.dat\").'
print(Message)
wx.MessageBox(Message, "Error: PDB name with \"_w_only\" ending", wx.OK | wx.ICON_INFORMATION)
if self.Water_layer_button.GetValue():
filename = short_filename + "_w"
else:
filename = short_filename
if self.SANS_button.GetValue():
string_value_B = ""
string_value_C = ""
string_value_D = ""
string_value_E = ""
string_value_F = ""
string_value_G = ""
value = float(self.SANS_solvent_box.GetValue())
string_value1 = "%1.0f" % value
value = float(self.SANS_perdeut_box_A.GetValue())
string_value_A = "%1.0f" % value
value = float(self.SANS_perdeut_box_B.GetValue())
if value > 0.0:
string_value_B = "_B%1.0f" % value
value = float(self.SANS_perdeut_box_C.GetValue())
if value > 0.0:
string_value_C = "_C%1.0f" % value
value = float(self.SANS_perdeut_box_D.GetValue())
if value > 0.0:
string_value_D = "_D%1.0f" % value
value = float(self.SANS_perdeut_box_E.GetValue())
if value > 0.0:
string_value_E = "_E%1.0f" % value
value = float(self.SANS_perdeut_box_F.GetValue())
if value > 0.0:
string_value_F = "_F%1.0f" % value
value = float(self.SANS_perdeut_box_G.GetValue())
if value > 0.0:
string_value_G = "_G%1.0f" % value
filename = filename + "_N" + string_value1 + "_P" + string_value_A + string_value_B + string_value_C + string_value_D + string_value_E + string_value_F + string_value_G
filename_nowater = short_filename + "_N" + string_value1 + "_P" + string_value_A + string_value_B + string_value_C + string_value_D + string_value_E + string_value_F + string_value_G
else:
value = float(self.SAXS_solvent_box.GetValue())
string_value = "%1.0f" % value
filename = filename + "_X" + string_value
filename_nowater = short_filename + "_X" + string_value
return filename,filename_nowater,short_filename,PDBID
### define function for plotting p(r)
def PlotprFnc(self,filename,PDBID):
#import p(r)
pr_filename = filename + "_pr.dat"
r,pr = np.genfromtxt(pr_filename, skip_header=10,usecols=[0,1],unpack=True)
# normalize p(r)
pr = pr / max(pr)
#plot p(r)
if self.fitWL_button.GetValue() == 0:
self.Figure1 = pylab.figure(1)
Subplot = pylab.subplot(111)
if self.Water_layer_button.GetValue():
if self.Exclude_water_layer_M_button.GetValue() or self.Exclude_water_layer_OPM_button.GetValue():
structure_name = PDBID + " + WL " + self.Water_layer_contrast_box.GetValue() + "% (Excl. TMD)"
else:
structure_name = PDBID + " + WL " + self.Water_layer_contrast_box.GetValue() + "%"
else:
structure_name = PDBID
if self.SANS_button.GetValue():
structure_name = structure_name + ", SANS " + self.SANS_solvent_box.GetValue() + "% D2O, [" + self.SANS_perdeut_box_A.GetValue() + "," + self.SANS_perdeut_box_B.GetValue() + "," + self.SANS_perdeut_box_C.GetValue() + "," + self.SANS_perdeut_box_D.GetValue() + "," + self.SANS_perdeut_box_E.GetValue() + "," + self.SANS_perdeut_box_F.GetValue() + "," + self.SANS_perdeut_box_G.GetValue() + "] % Deut."
else:
structure_name = structure_name + ", SAXS " + self.SAXS_solvent_box.GetValue() + "% Sucr."
Subplot.plot(r, pr, label=structure_name)
Subplot.legend(fontsize=9)
Subplot.set_xlabel('r [$\AA$]',fontsize=14)
Subplot.set_ylabel('p(r)',fontsize=14)
pylab.suptitle('Pair Distance Distribution for the structure(s)',fontsize=14)
pylab.show()
### define function to calculate, plot and export P(q)
def CalcPqFnc(self,filename,filename_nowater,short_filename,PDBID):
# import p(r) protein
pr_filename = filename + "_pr.dat"
r = np.genfromtxt(pr_filename, skip_header=10,usecols=[0],unpack=True)
grp = r
hrp = r
jrp = r
krp = r
grw = r
hrw = r
jrw = r
krw = r
grc = r
hrc = r
jrc = r
krc = r
gr = r
hr = r
jr = r
kr = r
prw_filename = ""
prc_filename = ""
prt_filename = ""
if self.Water_layer_button.GetValue():
pr_filename = filename_nowater + "_pr.dat" #protein (no water)
grp,hrp,jrp,krp = np.genfromtxt(pr_filename, skip_header=10,usecols=[2,3,4,5],unpack=True)
prw_filename = short_filename + "_w_only_pr.dat" #water layer