-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
1680 lines (1525 loc) · 63.3 KB
/
plot.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
#!/bin/sh
# -*- coding:utf-8
import sys
sys.path.insert(0,'.')
import os
import copy
import wxversion
wxversion.select("2.8")
import wx
import wx.py.crust
#import psutil
import scipy
if int(scipy.__version__.split('.')[1]) >= 11:
from scipy.sparse.csgraph import _validation # for pyinstaller
from scipy.optimize import minimize # need for pyinstaller
import matplotlib # for pyinstaller
matplotlib.interactive( True ) # for pyinstaller
from matplotlib.figure import Figure # for pyinstaller
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas # for pyinstaller
from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx # for pyinstaller
import fumodel
import view
import ctrl
import rwfile
import lib
import subwin
import graph
import const
import cube
class Plot(wx.Frame):
# main program for draw FMO property graphs
def __init__(self,parent,id,winpos,winlabel):
winsize=lib.WinSize((390,275))
#print 'SYSTEM',const.SYSTEM
#if const.SYSTEM != const.WINDOWS: winsize=(400,300)
self.title='FMO Viewer'
wx.Frame.__init__(self,parent,id,self.title,pos=winpos,size=winsize,
style=wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.RESIZE_BORDER)
#
""" parent=None, model=None"""
self.mdlwin=None
self.model=None
""" """
self.draw=None
self.platform=lib.GetPlatform()
self.winsize=winsize
self.font=self.GetFont()
self.font.SetPointSize(8)
self.SetFont(self.font)
self.program='fuplot.exe'
self.inifile='fuplot.ini'
# program directory
self.exedir=lib.GetExeDir(self.program)
# change directory
#???self.curdir=lib.ChangeToPreviousDir(self.exedir,self.inifile)
self.curdir=os.getcwd()
# CtrlFlag instance
self.ctrlflag=ctrl.CtrlFlag()
# set Icon
#iconfile=lib.GetIconFile(self.exedir,"fuplot.ico")
#if os.path.exists(iconfile):
# icon=wx.Icon(iconfile,wx.BITMAP_TYPE_ICO)
# self.SetIcon(icon)
#
size=self.GetClientSize()
self.sashposition=size[0]/2
#
self.addmode=True
self.datadic={}
self.size=self.GetClientSize()
w=self.size[0]; h=self.size[1]
self.bgcolor="white"
self.SetBackgroundColour(self.bgcolor)
# Create Menu
self.menubar=self.MenuItems()
self.SetMenuBar(self.menubar)
self.Bind(wx.EVT_MENU,self.OnMenu)
#
self.datnam=''
self.pltprp=-1
#self.molint=False
self.piedadat=[]
self.onebody=[]
self.frgnam=[]
self.mulcharge=[]
self.ctcharge=[]
# files
self.openfiles=[]
self.fileout=[]
self.fileinp=[]
self.filepdb=[]
#
self.graphnam=[]
self.graph={}
self.idmax=0
self.fmodatadic={}
self.drvdatadic={}
#
self.datalist=[]
self.selected=''
self.opendrvpan=False
self.drvpan=None
self.pltpiedisable=False
self.pltctchgdisable=True
self.pltmulchgdisable=True
self.pltespotdisable=True
self.pltdendisable=True
self.pltorbdisable=True
self.pltpie=0
self.pltctchg=0
self.pltmulchg=0
self.pltespot=0
self.pltden=0
self.pltorb=0
# Create StatusBar
#self.statusbar=self.CreateStatusBar()
#self.CreateSplitWindow()
self.CreatePropertyPanel()
self.CreateSelectDataPanel()
#
self.Bind(wx.EVT_SIZE,self.OnResize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_CLOSE,self.OnClose)
def CreatePropertyPanel(self):
# create property choice panel on right hand side
[w,h]=self.GetClientSize() #self.GetSize()
xsize=w/2-25; ysize=h
hcb=const.HCBOX
#width=w/2-20; height=h
xpos=w/2; ypos=0
xloc=10; yloc=10
self.prppan=wx.Panel(self,-1,pos=(xpos,ypos),size=(w/2,h)) #ysize))
self.prppan.SetBackgroundColour("light gray")
wx.StaticText(self.prppan,wx.ID_ANY,'Selected data for plot',pos=(xloc,yloc),size=(150,20))
yloc += 20
self.tcsel=wx.TextCtrl(self.prppan,-1,"",pos=(xloc,yloc),size=(xsize,20),
style=wx.TE_READONLY|wx.TE_MULTILINE) #|wx.HSCROLL)
#self.tclsel.Bind(wx.EVT_TEXT_ENTER,self.OnSelected)
self.tcsel.SetToolTipString('Data for plot')
"""self.WriteRemark()"""
yloc += 30
wx.StaticText(self.prppan,wx.ID_ANY,'Computational details',pos=(xloc,yloc),size=(140,20))
self.btndetail=wx.Button(self.prppan,wx.ID_ANY,"View",pos=(xloc+135,yloc-2),size=(40,18))
self.btndetail.Bind(wx.EVT_BUTTON,self.OnViewDetails)
self.btndetail.SetToolTipString('View FMO options')
yloc += 20
wx.StaticText(self.prppan,wx.ID_ANY,'Total properties',pos=(xloc,yloc),size=(140,20))
self.btnresult=wx.Button(self.prppan,wx.ID_ANY,"View",pos=(xloc+135,yloc),size=(40,18))
self.btnresult.Bind(wx.EVT_BUTTON,self.OnViewResults)
self.btnresult.SetToolTipString('View FMO results')
xloc1=xloc+100
yloc += 20
wx.StaticText(self.prppan,wx.ID_ANY,'Plot FMO property',pos=(xloc,yloc),size=(100,20))
yloc += 20
self.cbprop=wx.ComboBox(self.prppan,-1,'',choices=[], \
pos=(xloc+10,yloc-3), size=(115,hcb),style=wx.CB_READONLY)
self.cbprop.Bind(wx.EVT_COMBOBOX,self.OnPlotFMOProp)
self.cbprop.SetToolTipString('Choose FMO property to plot')
self.btnviewprop=wx.Button(self.prppan,wx.ID_ANY,"View",pos=(xloc+135,yloc-2),size=(40,20))
self.btnviewprop.Bind(wx.EVT_BUTTON,self.OnViewFMOProp)
self.btnviewprop.SetToolTipString('View property by editor')
yloc += 25
self.btnplt=wx.Button(self.prppan,wx.ID_ANY,"Plot",pos=(40,yloc),size=(40,20))
self.btnplt.Bind(wx.EVT_BUTTON,self.OnPlotFMOProp)
self.btnplt.SetToolTipString('Plot property')
self.btncls=wx.Button(self.prppan,wx.ID_ANY,"Close",pos=(100,yloc),size=(50,20))
self.btncls.Bind(wx.EVT_BUTTON,self.OnCloseFMOProp)
self.btncls.SetToolTipString('Close plot')
"""
self.btnpie=wx.Button(self.prppan,wx.ID_ANY,"PIE/PIEDA",pos=(xloc+10,yloc),size=(75,20))
self.btnpie.Bind(wx.EVT_BUTTON,self.OnPIE)
self.btnpie.SetToolTipString('Plot PIE/PIEDA')
self.btnctc=wx.Button(self.prppan,wx.ID_ANY,"CT charge",pos=(xloc1,yloc),size=(75,20))
self.btnctc.Bind(wx.EVT_BUTTON,self.OnCTCharge)
self.btnctc.SetToolTipString('Plot transfered charge in dimer')
#self.ckbpie=wx.CheckBox(self.prppan,-1,"PIE/PIEDA",pos=(xloc+5,yloc),size=(80,18))
#self.ckbpie.SetValue(True)
#self.ckbctc=wx.CheckBox(self.prppan,-1,"CT charge",pos=(xloc1,yloc),size=(80,18))
yloc += 25
self.btnmul=wx.Button(self.prppan,wx.ID_ANY,"Mulliken",pos=(xloc+10,yloc),size=(75,20))
self.btnmul.Bind(wx.EVT_BUTTON,self.OnMulliken)
self.btnmul.SetToolTipString('Plot Mulliken charge')
self.btnmep=wx.Button(self.prppan,wx.ID_ANY,"MEP(ptc)",pos=(xloc1,yloc),size=(75,20))
self.btnmep.Bind(wx.EVT_BUTTON,self.OnMEP)
self.btnmep.SetToolTipString('Plot point charge eletrostatic potential')
#self.ckbmul=wx.CheckBox(self.prppan,-1,"Mulliken",pos=(xloc+5,yloc),size=(80,18))
#self.ckbesp=wx.CheckBox(self.prppan,-1,"MEP",pos=(xloc1,yloc),size=(80,18))
#self.ckbesp.Disable()
yloc += 25
self.btnden=wx.Button(self.prppan,wx.ID_ANY,"Density",pos=(xloc+10,yloc),size=(75,20))
self.btnden.Bind(wx.EVT_BUTTON,self.OnDensity)
self.btnden.SetToolTipString('Plot density ditribution')
self.btnorb=wx.Button(self.prppan,wx.ID_ANY,"Orbital",pos=(xloc1,yloc),size=(75,20))
self.btnorb.Bind(wx.EVT_BUTTON,self.OnOrbital)
self.btnorb.SetToolTipString('Plot monomer molecular orbital')
#self.ckbden=wx.CheckBox(self.prppan,-1,"Density",pos=(xloc+5,yloc),size=(80,18))
#self.ckbden.Disable()
#self.ckborb=wx.CheckBox(self.prppan,-1,"Orbital",pos=(xloc1,yloc),size=(80,18))
#self.ckborb.Disable()
yloc += 25
self.btnhomo=wx.Button(self.prppan,wx.ID_ANY,"HOMO-LUMO",pos=(xloc+10,yloc),size=(90,20))
self.btnhomo.Bind(wx.EVT_BUTTON,self.OnHOMOLUMO)
self.btnhomo.SetToolTipString('Plot monomer HOMO-LUMO energies')
self.btndos=wx.Button(self.prppan,wx.ID_ANY,"DOS",pos=(xloc1+15,yloc),size=(60,20))
self.btndos.Bind(wx.EVT_BUTTON,self.OnDos)
self.btndos.SetToolTipString('Plot monomer density of states')
#self.ckbden=wx.CheckBox(self.prppan,-1,"Monomers HOMO-LUMO s",pos=(xloc+5,yloc),size=(180,18))
#self.ckbden.SetToolTipString('Monomers HOMO-LUMO energies')
yloc += 25
self.btnchgc=wx.Button(self.prppan,wx.ID_ANY,"Charge coupling terms",pos=(xloc+10,yloc),size=(150,20))
self.btnchgc.Bind(wx.EVT_BUTTON,self.OnChargeCoupling)
self.btnchgc.SetToolTipString('Compute and plot charge coupling terms')
#self.ckbden=wx.CheckBox(self.prppan,-1,"Monomer density of states",pos=(xloc+5,yloc),size=(180,18))
#self.ckbden.SetToolTipString('Monomers density of states')
#yloc += 20
#self.ckbcup=wx.CheckBox(self.prppan,-1,"Charge coupling elements",pos=(xloc+5,yloc),size=(180,18))
#self.ckbcup.Disable()
#self.ckbcup.SetToolTipString('Compute and plot charge coupling integrals')
"""
yloc += 30
wx.StaticText(self.prppan,wx.ID_ANY,'Plot cube data',pos=(xloc,yloc),size=(90,20))
self.btncube=wx.Button(self.prppan,wx.ID_ANY,"Open panel",pos=(xloc+95,yloc-2),size=(80,20))
self.btncube.Bind(wx.EVT_BUTTON,self.OnOpenPlotCube)
self.btncube.SetToolTipString('Open panel for MEP/Density plot')
#btplt=wx.Button(self.prppan,wx.ID_ANY,"Plot",pos=(50,yloc1),size=(40,20))
#btplt.Bind(wx.EVT_BUTTON,self.OnPlot)
yloc += 25
wx.StaticLine(self.prppan,pos=(0,yloc),size=(w/2,2),style=wx.LI_HORIZONTAL)
yloc += 10
btclr=wx.Button(self.prppan,wx.ID_ANY,"Close all plots",pos=(60,yloc),size=(80,20))
btclr.Bind(wx.EVT_BUTTON,self.OnCloseAll)
#
self.btncube.Disable()
self.EnableFMOButtons(False)
#
def CreateSelectDataPanel(self):
# create select panel on left hand side
[w,h]=self.GetClientSize()
xpos=0; ypos=0
xsize=w/2+10; ysize=h
self.panel=wx.Panel(self,-1,pos=(xpos,ypos),size=(w/2,h))
self.panel.SetBackgroundColour("light gray")
width=w/2-20
xloc=10; yloc=10
wx.StaticText(self.panel,wx.ID_ANY,'Data list',pos=(xloc,yloc),size=(60,20))
self.btnadd=wx.RadioButton(self.panel,-1,'add',pos=(xloc+60,yloc-5),style=wx.RB_GROUP)
self.btnadd.Bind(wx.EVT_RADIOBUTTON,self.OnAddMode)
self.btnadd.SetToolTipString('Add data mode')
btnrep=wx.RadioButton(self.panel,-1,'replace',pos=(xloc+110,yloc-5))
btnrep.Bind(wx.EVT_RADIOBUTTON,self.OnAddMode)
btnrep.SetToolTipString('Replace data mode')
wclb=w/2-xpos-30; hclb=h-135 #140
yloc += 20
self.lbdat=wx.ListBox(self.panel,-1,pos=(xloc+5,yloc),size=(wclb,hclb),
style=wx.LB_HSCROLL|wx.LB_SORT) #
self.lbdat.SetToolTipString('List of data obtained by filer')
###self.lbdat.InsertItems(self.datalist,0)
"""self.lbdat.Bind(wx.EVT_LISTBOX,self.OnSelectData)"""
# command button
#xloc=wclb/2;
yloc1=yloc+hclb+10
btrmv=wx.Button(self.panel,wx.ID_ANY,"Remove",pos=(35,yloc1),size=(60,20))
btrmv.Bind(wx.EVT_BUTTON,self.OnRemoveData)
btrmv.SetToolTipString('Remove data from the list')
btnclr=wx.Button(self.panel,wx.ID_ANY,"Clear",pos=(115,yloc1),size=(40,20))
btnclr.Bind(wx.EVT_BUTTON,self.OnClearData)
btnclr.SetToolTipString('Clear all data')
yloc1 += 30
btnview=wx.Button(self.panel,wx.ID_ANY,"View",pos=(20,yloc1),size=(40,20))
btnview.Bind(wx.EVT_BUTTON,self.OnViewFile)
btnview.SetToolTipString('View file by editor')
btnset=wx.Button(self.panel,wx.ID_ANY,"Select for plot",pos=(80,yloc1),size=(100,20))
btnset.Bind(wx.EVT_BUTTON,self.OnSelectForPlot)
btnset.SetToolTipString('Set selected data to "Selected data for plot" window.')
yloc1 += 25
wx.StaticLine(self.panel,pos=(-1,yloc1),size=(w/2-5,2),style=wx.LI_HORIZONTAL)
# button to pop-up derived data creation panel
yloc1 += 10
self.tbdrv=wx.Button(self.panel,-1,label='Make derived data',
pos=(40,yloc1),size=(120,20))
self.tbdrv.SetToolTipString('Open panel to make derived data')
self.tbdrv.Bind(wx.EVT_BUTTON,self.OnOpenDerivedPanel)
yloc1 += 50
self.drvpanpos=[60,yloc1]; self.drvpansize=[wclb,80]
if self.opendrvpan: self.OnOpenDerivedPanel(0)
#
wx.StaticLine(self.panel,pos=(w/2-5,0),size=(2,h),style=wx.LI_VERTICAL)
def MessageSelect(self):
mess='Select a item'
lib.MessageBoxOK("Select an item by clicking mouse left button.","",style=wx.OK|wx.ICON_EXCLAMATION)
def GetCubeFile(self):
name=self.tcsel.GetValue()
filename=self.datadic[name]
#name=name.split(':',1)
#filename=name[1]
base,ext=os.path.splitext(filename)
if ext == '.mep' or ext == '.den' or ext == '.cub': return filename
else: return ''
def OnPIE(self,event):
curfmodat=self.GetCurrentFMOData()
nfrg=curfmodat.nfrg
if nfrg <=1:
dlg=lib.MessageBoxOK("No plot data, since the number of fragment=1.",
"",style=wx.OK|wx.ICON_EXCLAMATION)
return
if not curfmodat.pieda:
dlg=lib.MessageBoxOK("No plot data, probably non-PIEDA job.",
"",style=wx.OK|wx.ICON_EXCLAMATION)
return
self.pltpie=True
#self.pltpie=False; self.pltctchg=False; self.pltmulchg=False
#self.pltespot=False; self.pltden=False; self.pltorb=False
#
prop=[1,0,0,0,0,0] # flags: [pie,ctc,mul,esp,den,orb], 1:True,0:False
# draw graph
nprp=len(prop)-1
for i in range(nprp,-1,-1):
if prop[i]:
self.pltprp=i
name=self.graphnam[self.pltprp]
if self.ctrlflag.GetCtrlFlag(name):
self.graph[name].SetFocus(); continue
pos=(-1,-1); size=(660,360); oned=True; child=False
self.graph[name]= \
graph.fuGraph(self,-1,pos,size,oned,self.pltprp,child)
self.ctrlflag.SetCtrlFlag(name,True)
self.graph[name].Show()
#
self.SetGraphData(self.pltprp)
self.graph[self.graphnam[self.pltprp]].DrawGraph(True)
if self.ctrlflag.GetCtrlFlag('pycrustwin'):
self.RunMethod('fuplot.PrintFragmentName()')
def OnPlotFMOProp(self,event):
prop=self.cbprop.GetValue()
print 'prop in OnFMOProp',prop
if prop == 'PIE':
pass
elif prop == 'PIEDA':
pass
def OnCloseFMOProp(self,event):
prop=self.cbprop.GetValue()
def OnViewFMOProp(self,event):
pass
def OnCTCharge(self,event):
print 'btnctc'
def OnMulliken(self,event):
print 'btnmul'
def OnMEP(self,event):
print 'btnmep'
def OnDensity(self,event):
print 'btnden'
def OnOrbital(self,event):
print 'btnorb'
def OnHOMOLUMO(self,event):
print 'btnhomo'
def OnDos(self,event):
print 'btndos'
def OnChargeCoupling(self,event):
print 'btnchgc'
def OnOpenPlotCube(self,event):
# create model instance
fumode=1
self.model=fumodel.Model(fumode) # fumode=1
# create mdlwin
pos=self.GetPosition()
size=self.GetClientSize()
winpos=[pos[0]+size[0],pos[1]]
winsize=lib.WinSize([480,370])
self.model.OpenMdlWin(self,winpos,winsize) # parent
self.model.mdlwin.SetTitle('FMO viewer')
self.model.menuctrl.OnWindow("Open MolChoiceWin",False)
self.model.menuctrl.OnWindow("Open MouseModeWin",False)
#self.model.menuctrl.OnWindow("Open PyShell",False)
self.model.mdlwin.hideshlwin=True
self.model.winctrl.GetWin('Open PyShell').Hide()
self.mdlwin=self.model.mdlwin
self.draw=self.model.mdlwin.draw
# position of text message
pos=[150,50]
if lib.GetPlatform() == 'WINDOWS': pos=[150,70]
self.mdlwin.textmess.SetPos(pos)
self.mdlwin.textmess.SetSize([winsize[0]-pos[0]-10,25])
# open draw cube win
self.OpenDrawCubeWin()
def SaveCubeParams(self):
# params:[self.style,self.value,self.interpol,self.colorpos,self.colorneg,
# self.opacity,self.ondraw]
self.drwcubeparams=self.cubewin.GetDrawPanelParams()
def ResetCubeParams(self):
# params:[self.style,self.value,self.interpol,self.colorpos,self.colorneg,
# self.opacity,self.ondraw]
self.cubewin.SetDrawPanelParams(self.drwcubeparams)
def OpenDrawCubeWin(self):
mode=1 # no menu mode
winsize=lib.WinSize([85,325])
mdlwinpos=self.mdlwin.GetPosition()
mdlwinsize=self.mdlwin.GetClientSize()
winpos=[mdlwinpos[0],mdlwinpos[1]+50]
#if const.SYSTEM == const.MACOSX: winsize=[85,315]
if mode == 1: winsize[1] -= 25 # no menu in the case of mode=1
self.cubewin=cube.DrawCubeData_Frm(self.mdlwin,-1,winpos,winsize,self.model,self,mode) # mode=1
self.cubewin.Show()
def CloseDrawCubeWin(self):
self.cubewin.Destroy()
def OnCloseAll(self,event):
print 'OnCloseAll'
def OnClearData(self,event):
self.datadic={}
self.SetDataList()
self.tcsel.SetValue('')
def OnViewDetails(self,event):
pass
def OnViewResults(self,event):
pass
def OnSelectForPlot(self,event):
selected=self.lbdat.GetStringSelection()
if selected == '': self.MessageSelect()
else: self.tcsel.SetValue(selected)
base,ext=os.path.splitext(selected)
file=self.datadic[selected]
# open plot win
if ext == '.den' or ext == '.mep' or ext == '.cub':
self.btncube.Enable()
self.EnableFMOButtons(False)
#self.OnOpenPlotCube(1) #OpenPlotCubeWin(ext)
else:
self.btncube.Disable()
self.EnableFMOButtons(True)
self.tcsel.SetValue(selected)
fmoprop=FMOProperty(base,file)
fmoproplst=fmoprop.GetPropertyItems()
self.cbprop.SetItems(fmoproplst)
self.cbprop.SetSelection(0)
def EnableFMOButtons(self,on):
if on:
self.btndetail.Enable(); self.btnresult.Enable()
self.btnviewprop.Enable(); self.cbprop.Enable()
self.btnplt.Enable(); self.btncls.Enable()
#self.btnpie.Enable(); self.btnctc.Enable(); self.btnmul.Enable()
#self.btnmep.Enable(); self.btnden.Enable(); self.btnorb.Enable()
#self.btnhomo.Enable(); self.btndos.Enable(); self.btnchgc.Enable()
else:
self.btndetail.Disable(); self.btnresult.Disable()
self.btnviewprop.Disable(); self.cbprop.Disable()
self.btnplt.Disable(); self.btncls.Disable()
#self.btnpie.Disable(); self.btnctc.Disable(); self.btnmul.Disable()
#self.btnmep.Disable(); self.btnden.Disable(); self.btnorb.Disable()
#self.btnhomo.Disable(); self.btndos.Disable(); self.btnchgc.Disable()
def OnViewFile(self,event):
selected=self.lbdat.GetStringSelection()
if selected == '': self.MessageSelect()
else:
filename=self.datadic[selected]
lib.Editor1(self.platform,filename)
def OnAddMode(self,event):
value=self.btnadd.GetValue()
if value: self.addmode=True
else: self.addmode=False
def SetPropChoice(self):
# set enable/disable to property choicebox
self.pltpiedisable=True
self.pltctchgdisable=True
self.pltmulchgdisable=True
self.pltespotdisable=True
self.pltdendisable=True
self.pltorbdisable=True
# get fmodat of selected
curfmodat=self.GetCurrentFMOData()
if curfmodat.pieda: self.pltpiedisable=False
#if curfmodat.dft:
# self.pltpiedisable=True
# self.ckbctc.SetValue(True)
if curfmodat.ctchg: self.pltctchgdisable=False
if curfmodat.mulchg: self.pltmulchgdisable=False
if curfmodat.espot: self.pltespotdisable=False
if curfmodat.density: self.pltdendisable=False
if curfmodat.orbital: self.pltorbdisable=False
#
if self.pltpiedisable: self.ckbpie.Disable()
else: self.ckbpie.Enable()
if self.pltctchgdisable: self.ckbctc.Disable()
else: self.ckbctc.Enable()
if self.pltmulchgdisable: self.ckbmul.Disable()
else: self.ckbmul.Enable()
if self.pltespotdisable: self.ckbesp.Disable()
else: self.ckbesp.Enable()
if self.pltdendisable: self.ckbden.Disable()
else: self.ckbden.Enable()
if self.pltorbdisable: self.ckborb.Disable()
else: self.ckborb.Enable()
def SavePropChoice(self,on):
# save and recover checkbox states
# on: True for save, and False for recover
if on: # save
if self.ckbpie.GetValue(): self.pltpie=1
else: self.pltpie=0
if self.ckbctc.GetValue(): self.pltctchg=1
else: self.pltctchg=0
if self.ckbmul.GetValue(): self.pltmulchg=1
else: self.pltmulchg=0
if self.ckbesp.GetValue(): self.pltespot=1
else: self.pltespot=0
if self.ckbden.GetValue(): self.pltden=1
else:self.pltden=0
if self.ckborb.GetValue(): self.pltorb=1
else: self.pltorb=0
else: # recover
if self.pltpie == 1: self.ckbpie.SetValue(True)
else: self.ckbpie.SetValue(False)
if self.pltctchg == 1: self.ckbctc.SetValue(True)
else: self.ckbctc.SetValue(False)
if self.pltmulchg == 1: self.ckbmul.SetValue(True)
else: self.ckbmul.SetValue(False)
if self.pltespot == 1: self.ckbesp.SetValue(True)
else: self.ckbesp.SetValue(False)
if self.pltden == 1: self.ckbden.SetValue(True)
else: self.ckbden.SetValue(False)
if self.pltorb == 1: self.ckborb.SetValue(True)
else: self.ckborb.SetValue(False)
def SetGraphData(self,pltprp):
# set data on fuGraph instance
datnam=self.selected
onbody=[]; frgdist=[]
molint=False
if self.IsDerivedData(datnam): molint=True
name=self.graphnam[pltprp]
# graph data
curfmodat=self.GetCurrentFMOData()
nfrg=curfmodat.nfrg
frgnam=curfmodat.frgnam
frgdist=curfmodat.frgdist
bdabaa=curfmodat.bdabaa
indat=curfmodat.indat
pdbfile=curfmodat.pdbfile
pieda=curfmodat.pieda
corr=curfmodat.corr
natm=curfmodat.natm
#
if pltprp == 0: fmoprp=self.MakePIEDAPlotData()
if pltprp == 1: fmoprp=self.MakeCTChargePlotData()
if pltprp == 2: fmoprp=self.MakeMullikenPlotData()
# set plot data on fuGraph instance
piedacmp=[0,0,0,0,0]; mullbody=[0,0,0,0]
if self.pltprp == 0 or self.pltprp == 1:
if pieda: piedacmp=[1,1,1,0,0]
if corr: piedacmp[3]=1
if molint: piedacmp[4]=1
if self.pltprp == 2:
if len(fmoprp[0][0]) == 3: mullbody=[1,1,0,0]
if len(fmoprp[0][0]) == 4: mullbody=[1,1,1,1]
self.graph[name].SetFMOProp(self.pltprp,datnam,molint,piedacmp,mullbody)
self.graph[name].SetFMOPropData(natm,nfrg,frgnam,fmoprp,frgdist)
self.graph[name].SetMolViewFragmentData(pdbfile,indat,bdabaa)
def PrintFragmentName(self):
curfmodat=self.GetCurrentFMOData()
nfrg=curfmodat.nfrg
frgnam=curfmodat.frgnam
frgnamdic={}
for i in range(len(frgnam)):
frgnamdic[i+1]=frgnam[i]
def OnSplitWinChanged(self,event):
self.sashposition=self.splwin.GetSashPosition()
self.OnSize(0)
def OnPlot(self,event):
if len(self.selected) <= 0:
dlg=lib.MessageBoxOK("No data to plot. Open files first.",
"",style=wx.OK|wx.ICON_EXCLAMATION)
return
curfmodat=self.GetCurrentFMOData()
nfrg=curfmodat.nfrg
if nfrg <=1:
dlg=lib.MessageBoxOK("No plot data, since the number of fragment=1.",
"",style=wx.OK|wx.ICON_EXCLAMATION)
return
if not curfmodat.pieda:
dlg=lib.MessageBoxOK("No plot data, probably non-PIEDA job.",
"",style=wx.OK|wx.ICON_EXCLAMATION)
return
self.pltpie=False; self.pltctchg=False; self.pltmulchg=False
self.pltespot=False; self.pltden=False; self.pltorb=False
#
prop=[0,0,0,0,0,0] # flags: [pie,ctc,mul,esp,den,orb]
if self.ckbpie.IsEnabled() and self.ckbpie.GetValue(): prop[0]=1
if self.ckbctc.IsEnabled() and self.ckbctc.GetValue(): prop[1]=1
if self.ckbmul.IsEnabled() and self.ckbmul.GetValue(): prop[2]=1
#
if self.ckbesp.IsEnabled() and self.ckbesp.GetValue(): prop[3]=1
if self.ckbden.IsEnabled() and self.ckbden.GetValue(): prop[4]=1
if self.ckborb.IsEnabled() and self.ckborb.GetValue(): prop[5]=1
# draw graph
nprp=len(prop)-1
for i in range(nprp,-1,-1):
if prop[i]:
self.pltprp=i
name=self.graphnam[self.pltprp]
if self.ctrlflag.GetCtrlFlag(name):
self.graph[name].SetFocus(); continue
pos=(-1,-1); size=(660,360); oned=True; child=False
self.graph[name]= \
graph.fuGraph(self,-1,pos,size,oned,self.pltprp,child)
self.ctrlflag.SetCtrlFlag(name,True)
self.graph[name].Show()
#
self.SetGraphData(self.pltprp)
self.graph[self.graphnam[self.pltprp]].DrawGraph(True)
if self.ctrlflag.GetCtrlFlag('pycrustwin'):
self.RunMethod('fuplot.PrintFragmentName()')
def MouseLeftClick(self,pos):
if not self.ctrlflag.GetCtrlFlag('molviewwin'): return
if self.onedmode:
i=self.graph.GetXValue(pos)
if i < 0:
mess='Clicked at outside of plot region.'
self.molview.Message(mess,0,'black')
return
i=int(i); i=self.order[i]
if i >= 0 and i <= len(self.pltdat):
if self.ctrlflag.GetCtrlFlag('molviewwin'):
self.molview.SetSelectAll(False)
mess=self.MakeFragValueMess(i)
frgnam=self.frgnam[i]
self.molview.SelectFragNam(frgnam,True)
#mess="Fragment="+frgnam+', plot data=['
#for i in range(len(self.pltdat)):
#mess=mess+'['
#for j in range(1,len(self.pltdat[i])):
# mess=mess+'%7.2f' % self.pltdat[i][j]
#mess=mess+']'
self.molview.Message(mess,0,'black')
def GetCurrentFMOData(self):
# return curfmodat, the fmodat instance of selected data
if not self.IsDerivedData(self.selected):
curfmodat=self.fmodatadic[self.selected]
else:
drvdat=self.drvdatadic[self.selected]
fmodatlst,cmpsign=self.ResolveDerivedData(drvdat)
curfmodat=self.fmodatadic[fmodatlst[0]]
return curfmodat
def ListFMODataName(self):
for name in self.fmodatadic:
print self.fmodatadic[name].name
def MakePIEDAPlotData(self):
# make pieda for plot.
# if molint=True, subtract component energy from those of complex
tokcal=627.50 # Hartree to kcal/mol, for onbody energy conversion.
nlayer=1
onebody=[]
molint=False
if self.IsDerivedData(self.selected): molint=True
curfmodat=self.GetCurrentFMOData()
pieda=curfmodat.frgpieda
onebody=curfmodat.onebody
nfrg=curfmodat.nfrg
if not molint: return pieda
#
pieda=copy.deepcopy(pieda)
onebody=copy.deepcopy(onebody)
drvdat=self.drvdatadic[self.selected]
fmodat,cmpsign=self.ResolveDerivedData(drvdat)
nlen=len(pieda[0])
nf=0
for i in range(1,len(fmodat)):
datnam=fmodat[i]
tmppieda=self.fmodatadic[datnam].frgpieda
tmpone=self.fmodatadic[datnam].onebody
tmpnfrg=self.fmodatadic[datnam].nfrg
for j in range(len(tmpone)):
onebody[j+nf][1] += cmpsign[i]*tmpone[j][1]
for j in range(len(tmppieda)):
if tmpnfrg == 1:
nf += 1; break
for k in range(len(tmppieda[j])):
i0=j+nf;
j0=k+nf
for l in range(1,len(tmppieda[j][k])):
pieda[i0][j0][l] += cmpsign[i]*tmppieda[j][k][l]
nf += tmpnfrg
for i in range(len(pieda)):
obe=tokcal*onebody[i][1]
for j in range(len(pieda[i])):
if i == j: pieda[i][j].append(obe)
else: pieda[i][j].append(0.0)
return pieda
def MakeCTChargePlotData(self):
#ctcharge=[]
molint=False
if self.IsDerivedData(self.selected): molint=True
curfmodat=self.GetCurrentFMOData()
ctcharge=curfmodat.ctcharge
if not molint: return ctcharge
ctcharge=copy.deepcopy(ctcharge)
drvdat=self.drvdatadic[self.selected]
fmodat,cmpsign=self.ResolveDerivedData(drvdat)
nf=0
for i in range(1,len(fmodat)):
datnam=fmodat[i]
tmpchg=self.fmodatadic[datnam].ctcharge
tmpnfrg=self.fmodatadic[datnam].nfrg
for j in range(len(tmpchg)):
if tmpnfrg == 1:
nf += 1; break
for k in range(len(tmpchg[j])):
i0=j+nf
j0=k+nf
val=tmpchg[j][k][1]
ctcharge[i0][j0][1] += cmpsign[i]*val
nf += tmpnfrg
return ctcharge
def MakeMullikenPlotData(self):
curfmodat=self.GetCurrentFMOData()
mulcharge=curfmodat.mulliken
molint=False
if self.IsDerivedData(self.selected): molint=True
if not molint: return mulcharge
mulcharge=copy.deepcopy(mulcharge)
drvdat=self.drvdatadic[self.selected]
fmodat,cmpsign=self.ResolveDerivedData(drvdat)
nfrg=self.fmodatadic[fmodat[0]].nfrg
nbody=len(mulcharge[0][0])
nf=0
for i in range(1,len(fmodat)):
datnam=fmodat[i]
tmpmulchg=self.fmodatadic[datnam].mulliken
tmpnfrg=self.fmodatadic[datnam].nfrg
if tmpnfrg == 1: # GMS mulliken
for k in range(len(tmpmulchg)):
i0=nf; j0=k
for l in range(1,nbody):
mulcharge[i0][j0][l] += cmpsign[i]*tmpmulchg[k][1]
else:
for j in range(len(tmpmulchg)):
for k in range(len(tmpmulchg[j])):
i0=j+nf; j0=k+nf
for l in range(1,len(tmpmulchg[j][k])):
mulcharge[i0][j0][l] += cmpsign[i]*tmpmulchg[j][k][l]
nf += tmpnfrg
return mulcharge
def OnRemoveData(self,event):
selected=self.lbdat.GetStringSelection()
if self.datadic.has_key(selected): del self.datadic[selected]
self.SetDataList()
if selected == self.tcsel.GetValue(): self.tcsel.SetValue('')
"""
for i in range(len(self.datalist)):
if self.datalist[i] == self.selected:
del self.datalist[i]; break
self.lbdat.Set(self.datalist)
self.selected=''
self.tcrmk.Clear()
self.OnPropClear(0)
"""
def OnPropClear(self,event):
if self.ckbpie.GetValue(): self.ckbpie.SetValue(False)
if self.ckbctc.GetValue(): self.ckbctc.SetValue(False)
if self.ckbmul.GetValue(): self.ckbmul.SetValue(False)
if self.ckbesp.GetValue(): self.ckbesp.SetValue(False)
if self.ckbden.GetValue(): self.ckbden.SetValue(False)
if self.ckborb.GetValue(): self.ckborb.SetValue(False)
def XXOnSelectData(self,event):
self.selected=self.lbdat.GetStringSelection()
if self.selected == '': return
#
self.WriteRemark()
self.pltpie=1
self.SetPropChoice()
self.graph={}
def WriteRemark(self):
if not self.tcrmk: return
eol='\n'
self.tcrmk.Clear()
if self.selected != "":
self.tcrmk.WriteText('data ... '+self.selected+eol)
# derived data
if self.IsDerivedData(self.selected):
txt=''
for cmpo in self.drvdatadic[self.selected]:
txt=txt+' '+cmpo
self.tcrmk.WriteText('comp ...'+txt+eol)
drvnam=self.drvdatadic[self.selected]
cmpdat,cmpsign=self.ResolveDerivedData(drvnam)
#
for cmpnam in cmpdat:
id,name=self.GetIDAndName(cmpnam)
filout=self.fmodatadic[cmpnam].outfile
filinp=self.fmodatadic[cmpnam].inpfile
filpdb=self.fmodatadic[cmpnam].pdbfile
self.tcrmk.WriteText(id+': outfil ...'+filout+eol)
self.tcrmk.WriteText(id+': inpfil ...'+filinp+eol)
self.tcrmk.WriteText(id+': pdbfil ...'+filpdb+eol)
# original fmo data
if self.IsFMOProperty(self.selected):
txt=self.fmodatadic[self.selected].outfile
self.tcrmk.WriteText('outfile ...'+txt+eol)
txt=self.fmodatadic[self.selected].inpfile
self.tcrmk.WriteText('inpfile ...'+txt+eol)
txt=self.fmodatadic[self.selected].pdbfile
self.tcrmk.WriteText('pdbfile ...'+txt+eol)
txt=str(self.fmodatadic[self.selected].nfrg)
self.tcrmk.WriteText('nfrg ...'+txt+eol)
txt=str(self.fmodatadic[self.selected].natm)
self.tcrmk.WriteText('natm ...'+txt+eol)
txt=str(self.fmodatadic[self.selected].nbas)
self.tcrmk.WriteText('nbas ...'+txt+eol)
txt=str(self.fmodatadic[self.selected].tchg)
self.tcrmk.WriteText('tchg ...'+txt+eol)
self.tcrmk.ShowPosition(0)
def ResolveDerivedData(self,drvnam):
#
fmodat=[]; cmpsign=[]
for cmpnam in drvnam:
id,name=self.GetIDAndName(cmpnam)
idsgn=1
if cmpnam[0:1] == '-': idsgn=-1
datnam=self.GetFMOPropName(self.fmodatadic,id)
#
if self.fmodatadic.has_key(datnam):
fmodat.append(datnam)
cmpsign.append(idsgn)
else:
idv,namev=self.GetIDAndName(cmpnam)
drvnamv=self.GetFMOPropName(self.drvdatadic,idv)
if drvnamv == '': continue
cmpv=self.drvdatadic[drvnamv]
#
for cmpnamv in cmpv:
idd,named=self.GetIDAndName(cmpnamv)
iddsgn=1
if cmpnamv[0:1] == '-': iddsgn=-1
datnamd=self.GetFMOPropName(self.fmodatadic,idd)
if self.fmodatadic.has_key(datnamd):
fmodat.append(datnamd)
cmpsign.append(idsgn*iddsgn)
else:
fmodat=[]; cmpsign=[]
dlg=lib.MessageBoxOK("Failed to find components. "+cmpnam,"")
return fmodat,cmpsign
def GetFMOProp(self,dataname):
fmodat=None
if self.fmodatadic.has_key(dataname): fmodat=self.fmodatadic[dataname]
return fmodat
def GetFMOPropName(self,fmodatadic,id):
dataname=''
lst=fmodatadic.keys()
for name in lst:
ns=name.find(':')
iddat=name[:ns]
if iddat == id:
dataname=name; break
return dataname
def OnOpenDerivedPanel(self,event):
#
if self.opendrvpan:
self.drvpan.Destroy()
#
self.opendrvpan=True
#[posx,posy]=self.GetPosition(); [wsize,hsize]=self.GetSize()
#self.drvpanpos=[posx+wsize-100,posy+hsize-40]
self.drvpan=subwin.DeriveDataInput_Frm(self,-1,self.drvpanpos)
self.drvpan.Show()
def AddDerivedDataDic(self,drvnam,drvcmp):
if drvnam == '': return
drvnam.strip()
dup=self.IsDuplicateName(1,drvnam)
if dup: return
find=self.CheckDeriveComp(drvcmp)
if not find: return
#
dataname=self.MakeDataName(drvnam)
self.drvdatadic[dataname]=drvcmp
#
self.SetDataListInSelLB()
self.lbdat.SetStringSelection(dataname)
self.OnSelectData(0)
def IsDerivedData(self,dataname):
ret=False
if self.drvdatadic.has_key(dataname): ret=True
return ret
def IsFMOProperty(self,dataname):
ret=False
if self.fmodatadic.has_key(dataname): ret=True
return ret
def CheckDeriveComp(self,drvcmp):
find=False
for cmpo in drvcmp:
find=self.IsItemInDataDic(cmpo,self.fmodatadic)
#
if not find:
find=self.IsItemInDataDic(cmpo,self.drvdatadic)
if not find:
dlg=lib.MessageBoxOK("No component data. "+cmpo,"")
return find
def IsItemInDataDic(self,item,datadic):
ret=False
idc,namec=self.GetIDAndName(item)
lst=datadic.keys()
for datnam in lst:
id,name=self.GetIDAndName(datnam)
if idc == id:
ret=True; break
return ret
def GetIDAndName(self,dataname):
ns=dataname.find(':')
if ns < 0:
id=dataname; name=''
else:
id=dataname[:ns]; name=dataname[ns+1:]
if id[0:1] == '+' or id[0:1] == '-':
id=id[1:]
return id,name
def MakeDataName(self,name):
self.idmax += 1