-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctrl.py
6351 lines (5833 loc) · 268 KB
/
ctrl.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
# fuctrl.py version history
# ver.0.2.0 (28Dec2014): the first version.
# Ctrl methods were collected from other modules.
import sys
#from nt import lstat
import cmd
sys.path.insert(0,'.')
import wxversion
wxversion.select("2.8")
import wx
import os
import shutil
#import psutil
import datetime
import time
import platform
import subprocess
import functools
import threading
import glob
import numpy
import copy
import cPickle as pickel
import wx.glcanvas
import wx.py.crust
import inspect
# fumodel menu handler
#from wx.lib.splitter import MultiSplitterWindow
import scipy
if int(scipy.__version__.split('.')[1]) >= 11:
from scipy.sparse.csgraph import _validation # need for pyinstaller
from scipy.optimize import minimize # need for pyinstaller
from operator import itemgetter
import fumodel
import const
import lib
import rwfile
import molec
import subwin
import ctrl
import draw
import graph
import cube
import build
import frag
#try: import fortlib
#except: pass
#import fmopdb
try: import fmopdb
except: pass
import view
import custom
class MenuCtrl():
def __init__(self,parent):
self.model=parent # Model
self.mdlwin=parent.mdlwin
self.setctrl=self.model.setctrl
self.classnam='MenuCtrl'
self.menubar=None
self.menulabeldic={} # {'label':[menuitem,toplabel],...]
self.projectmenuitems=[]
self.filehistorymenuitems=[]
self.fumode=0
self.shiftkeyDown=False
self.ctrlkeydown=False
self.mousleftdown=False
self.mouseoperationmode=''
self.selcirc=False; self.selrect=False
self.selcntatm=-1; self.selinipos=[]
self.focusselected=False
# popup menu status flags
self.secmod=self.model.mousectrl.GetSectionMode()
self.atmnmb=False
self.atmnam=False
self.resnam=False
self.xyzaxis=False
def CreateMenuBar(self,fumode,fmomenu,addon1menu,addon2menu):
""" Definition of menubar items
:param int fumode: 0 for fumolde, 1 for fuplot
:param bool fmomenu: True for activate, False for not.
:param lst addmenu1: menu items for add-on menu 1
:param lst addmenu2: menu items for add-on menu 2
"""
#submenud=self.FileMenu()
self.fumode=fumode
self.toplabel=''
mfil=self.CreateMenuFromList('File',self.FileMenu()) #self.FileMenu() # 'File' menus
medt=self.CreateMenuFromList('Edit',self.EditMenu()) # 'Edit' menus
mshw=self.CreateMenuFromList('Show',self.ShowMenu()) # 'Show' menus
msel=self.CreateMenuFromList('Select',self.SelectMenu()) # 'Select' menus
madd=self.CreateMenuFromList('Modeling',self.ModelingMenu()) # 'AddDel' mneus
#mchg=self.CreateMenuFromList('Change',self.ChangeMenu()) # 'Change' menus
mgrp=self.CreateMenuFromList('Group',self.GroupMenu()) # 'Group' mneus
mutl=self.CreateMenuFromList('Utility',self.UtilityMenu()) # 'Report' menus
mfmo=self.CreateMenuFromList('FMO',self.FMOMenu()) # 'FMO' menus
mwin=self.CreateMenuFromList('Window',self.WindowMenu()) # 'Window' mneus
mhlp=self.CreateMenuFromList('Help',self.HelpMenu()) # 'Help' menus
mtol=self.CreateMenuFromList('Tools',self.ToolsMenu()) # not used
mcmp=self.CreateMenuFromList('Compute',self.ComputeMenu()) # not used
#
if fumode == 1: # FMO Viewer mode
menulst=[['File',mfil],['Edit',medt],['Show',mshw],['Select',msel]]
elif fumode == 2: # simple viewer mode
menulst=[['File',mfil],['Edit',medt],['Show',mshw],['Select',msel]]
else: # fumode == 0:
menulst=[['File',mfil],['Edit',medt],['Show',mshw],['Select',msel],
['Modeling',madd],['Utility',mutl]]
if fmomenu: menulst.append(['FMO',mfmo])
# add add-on menus
if len(addon1menu) > 0:
addon1label=addon1menu[0]; menuitems=addon1menu[1]
self.toplabel=addon1label
maddon1=self.CreateMenuFromList(addon1label,menuitems)
menulst.append([addon1label,maddon1])
if len(addon2menu) > 0:
addon2label=addon2menu[0]; menuitems=addon2menu[1]
self.toplabel=addon2label
maddon2=self.CreateMenuFromList(addon2label,menuitems)
menulst.append([addon2label,maddon2])
# add mwin and mhlp
menulst.append(['Window',mwin])
menulst.append(['Help',mhlp])
# set menus to menubar
menubar=wx.MenuBar()
for toplabel,submenu in menulst: menubar.Append(submenu,toplabel)
#
self.menubar=menubar
#self.MakeMenuLabelDic()
def GetMenuLabel(self,menuid):
return self.menubar.GetLabel(menuid)
def GetMouseOperationMode(self):
return self.mouseoperationmode
def GetTopMenu(self,label):
# label(str): submenu label
# return topmenu(str): top menu label
toplabel=self.menulabeldic[label][1]
return toplabel
def CheckMenu(self,label,on):
""" Check menu item
:param str label: menu item label
:param bool on: True for check, False for uncheck
"""
if self.menulabeldic.has_key(label):
menuitem=self.menulabeldic[label][0]
if menuitem.IsCheckable(): menuitem.Check(on)
def IsChecked(self,label):
""" Return checked/unchecked status of menu item.
:param str label: menu item label
:return: True for checked, False for unchecked
"""
# item(str): menu label
# ret (bool): checked:True, unchecked:False
if self.menulabeldic.has_key(label):
menuitem=self.menulabeldic[label][0]
return menuitem.IsChecked()
else: False
def IsCheckable(self,label):
""" Return if a menu item is chackeable or not.
:param str label: menu item label
:return: True for checkable, False for uncheckable
"""
menuitem=self.menulabeldic[label][0]
return menuitem.IsCheckable()
def IsDefined(self,label):
""" Return a menu item is defined or not.
:param str label: menu item label
:return: True for defined, False for not defined
"""
if self.menulabeldic.has_key(label): return True
else: return False
def UncheckAll(self):
""" Uncheck all checkable menu items """
for label,menuitemlabel in self.menulabeldic.iteritems():
if not menuitemlabel[0].IsCheckable(): continue
menuitemlabel[0].Check(False)
def UncheckProjectMenuItems(self):
""" Uncheck all project submenu items('File'-'Project-xxx').
"""
for label,menuitemlabel in self.menulabeldic.iteritems():
for prjnam in self.projectmenuitems:
if prjnam == label: menuitemlabel[0].Check(False)
def EnableMenu(self,on):
""" Enable/disable top menu items excluding 'those in 'exclude'.
:param bool on: True to enabel all, False to disable except in 'exclude' list.
:note: this routine is killed at 11Nov2015
"""
return
exclude={'File':True,'Window':True,'Help':True,'Add-on':True}
nmb=self.menubar.GetMenuMoleculeInfo()
for i in range(nmb):
top=self.menubar.GetLabelTop(i)
self.menubar.EnableTop(i,True)
if not on and not exclude.has_key(top):
self.menubar.EnableTop(i,False)
def MenuHandlerDic(self):
""" Retrun top menu event handler object dictionary.
:return: menu handler object dictionary, {'menu label':event-handler-method-object,...}
:rtype: dic
"""
menuhandlerdic={"File": self.OnFile,"Edit": self.OnEdit,
"Show": self.OnShow,"Select": self.OnSelect,
"Modeling": self.OnModeling,"Utility": self.OnUtility,
"FMO": self.OnFMO,"Window": self.OnWindow,
"Help": self.OnHelp,"Hidden":self.OnHidden}
return menuhandlerdic
def OnMenu(self,event):
""" Menu event handler """
# menubar items
self.model.Message('')
menuid=event.GetId()
label=self.GetMenuLabel(menuid)
"""
lablst=['Open','New']
if not label in lablst:
if self.model.mol is None:
mess='No molecules. Please open molecule files'
lib.MessageBoxOK(mess,'MenuCtrl(OnMenu)')
return
"""
self.ExecMenu(label)
def ExecMenu(self,label,bChecked=None):
""" Execute menu item """
if label[:1] == "*":
self.model.Message("Sorry, this function is underconstruction.",
0,"black")
return
# Is item checked?
try: bChecked=self.IsChecked(label)
except: bChecked=False
# top menu label
try:
topmenu=self.menulabeldic[label][1]
menuhandlerdic=self.MenuHandlerDic()
except:
mess='Not found menu item label='+label
lib.MessageBoxOK(mess,'MenuCtrl(ExecMenu)')
return
#14Dec2015#if (topmenu != "File" and topmenu != 'Window' and topmenu != "Help" and topmenu != 'Add-on') and not self.model.Ready(): return
#
if menuhandlerdic.has_key(topmenu):
menuhandlerdic[topmenu](label,bChecked)
else: self.OnAddons(label,bChecked)
def OnFile(self,label,bChecked):
""" 'File' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
# echo and log
self.EchoAndLog('File',label,bChecked)
# wild card
wcard='pdb file(*.pdb;*.ent)|*.pdb;*.ent|xyz(*.xyz,*.xyzs,*.xyzfu)|'
wcard=wcard+'*.xyz;*.xyzs;*.xyzfu|mol file(*.mol;*.sdf)|*.mol;*.sdf|'
wcard=wcard+'zmatrix(*.zmt;*.zmtfu)|*.zmt;*.zmtfu|tinker(*.tin)|*.tin|'
wcard=wcard+'fufiles(*.fuf,*.spl,*.mrg)|*.fuf;*.spl;*.mrg|'
wcard=wcard+'fmoinput file(*.inp)|*.inp|'
wcard=wcard+'frame data(*.frm)|*.frm|' #fragment(*.frg)|*.frg|'
wcard=wcard+'gzip file(*.gz)|*.gz|All(*.*)|*.*'
# for "Save all as" menu
filetype=["pdb files","mol files","sdf file","xyz files","xyzs file",
"xyzfu files","zmt files","zmtfu files"]
# check menu
self.CheckMenu(label,bChecked)
name=self.model.setctrl.GetParam('defaultfilename')
self.model.setctrl.SetParam('defaultfilename','')
# File menu items
if label == "New":
self.model.NewMolecule()
elif label == "Open":
filenamelst=lib.GetFileNames(self.mdlwin,wcard,'r',True,
defaultname=name)
if len(filenamelst) > 0:
#root,ext=os.path.splitext(filename)
for filename in filenamelst:
head,ext=os.path.splitext(filename)
if ext == '.gz': filename=lib.ZipUnzipFile(filename,False)
self.model.ReadFiles(filename,True)
self.model.ChangePath(filename)
elif label == "Merge":
filename=lib.GetFileName(self.mdlwin,wcard,'r',True,
defaultname=name)
if len(filename) > 0: self.model.MergeToCurrent(filename)
elif label == "Close current":
self.model.RemoveMol(False) # current molecule
elif label == "Close All":
self.model.RemoveMol(True) # current molecule
elif label == "Save":
self.model.WriteFiles("",True,True)
# "Save all as menu "
elif label in filetype:
""" Save as menu """
dirname=lib.GetDirectoryName()
if dirname != '': self.model.WriteAllAs(label,dirname)
elif label == "Save As":
filename=""; wildcard='all(*.*)|*.*'
filename=lib.GetFileName(self.mdlwin,wildcard,'w',True,
defaultname=name)
if len(filename) < 0: return
self.model.WriteFiles(filename,False,True)
self.model.ChangeMolName(filename)
self.model.ChangePath(filename)
elif label == "Save Selected As":
filename=lib.GetFileName(self.mdlwin,wcard,'w',True,
defaultname=name)
if len(filename) < 0: return
self.model.WriteFiles(filename,False,False)
elif label == "Save All":
filename=""
if len(filename) < 0: return
self.model.MenuFiles(label,filename)
elif label == "Save All As":
filename=lib.GetFileName(self.mdlwin,wcard,'w',True,
defaultname=name)
if len(filename) < 0: return
self.model.MenuFiles(label,filename)
elif label == "Save canvas image":
wcard='image(*.bmp;*.png;*.jpeg)|*.bmp;*.png;*.jpeg'
filename=lib.GetFileName(self.mdlwin,wcard,'w',True,
defaultname=name)
self.model.SaveCanvasImage(filename)
elif label == "Print canvas image":
wildcard='image(*.bmp;*.png;*.pdf)|*.bmp;*.png;*.pdf'
filename=lib.GetFileName(self.mdlwin,wcard,'w',True,
defaultname=name)
self.model.PrintCanvasImage(filename)
elif label == "Save BDA data as":
filename=lib.GetFileName(self.mdlwin,wcard,'w',True,
defaultname=name)
if len(filename) < 0: return
self.model.SaveBDADataAs(filename)
elif label == "Save fragment data as":
filename=lib.GetFileName(self.mdlwin,wcard,'w',True,
defaultname=name)
if len(filename) < 0: return
self.model.SaveFragmentDataAs(filename)
#self.mdlmgr.MenuFiles(label,filename)
elif label == "Save log":
self.model.SaveLog(bChecked)
"""
logfile=""
if bChecked:
wcardlog='log file(*.log)|*.log'
dlg = wx.FileDialog(self.mdlwin, "Start log...", os.getcwd(),
style=wx.OPEN, wildcard=wcardlog)
if dlg.ShowModal() == wx.ID_OK:
logfile=dlg.GetPath()
#dlg.Destroy()
if len(logfile) < 0: return
self.model.SaveLog(logfile,True)
else:
self.model.SaveLog(logfile,False)
"""
elif label == "*Utility":
filename=""
self.model.MenuFiles(label,filename)
elif label == "Save bitmap": self.model.SaveMolBitmapOnFile()
elif label == "Quit": self.model.ExitModel()
elif label == 'New ...': # not used. moved to Hidden menu for future use
self.model.setctrl.ProjectSetting('New project')
elif label == 'Import': # not used. moved to Hidden menu for future use
self.model.setctrl.ProjectSetting('Import project')
#elif label == "Open existing": # project menu items
pass
elif label == "Enable MessageBox":
self.model.setctrl.SetMessageBoxFlag('',bChecked)
elif label == "Message level": self.model.setctrl.SetMessageLevel()
elif label == 'Clear history': self.model.ClearFileHistory()
elif os.path.dirname(label) != '':
filename=label
head,ext=os.path.splitext(filename)
if ext == '.gz': filename=lib.ZipUnzipFile(filename,False)
self.model.ReadFiles(filename,True)
self.model.ChangePath(filename)
else:
# project menu items?
try: idx=self.projectmenuitems.index(label)
except: idx=-1
if idx >= 0:
label=self.projectmenuitems[idx]
self.model.SwitchProject(label)
else:
mess=self.classnam+'(OnFile): '+'"'+label
mess=mess+'" menu item is not defined'
lib.MessageBoxOK(mess,"")
def OnEdit(self,label,bChecked):
""" 'Edit' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
ans=lib.IsMoleculeObj(self.model.mol)
if not ans: return
# echo and log
self.EchoAndLog('Edit',label,bChecked)
# check menu
self.CheckMenu(label,bChecked)
#
if label == "Copy mol object": self.model.CopyMolToClipboard(False)
elif label == "Cut and copy mol object":
self.model.CopyMolToClipboard(True)
elif label == "Paste mol object": self.model.PasteMolFromClipboard()
elif label == "Copy xyz text": self.model.CopyMolXYZToClipboard()
elif label == "Paste xyz text": self.model.PasteMolXYZFromClipboard()
elif label == "Copy canvas image":
self.model.CopyCanvasImageToClipboard()
elif label == "Clear clipboard": self.model.ClearClipboard()
else:
mess=self.classnam+'(OnEdit): '+'"'+label
mess=mess+'" menu item is not defined'
lib.MessageBoxOK(mess,"")
def OnShow(self,label,bChecked):
"""
'Show' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
ans=lib.IsMoleculeObj(self.model.mol)
if not ans: return
# echo and log
self.EchoAndLog('Show',label,bChecked)
# check menu
self.CheckMenu(label,bChecked)
# Show menu items
if label == "Fit to screen": self.model.FitToScreen(True,True)
elif label == "Reset rotation": self.model.ResetRotate()
elif label == "Hide selected": self.model.HideSelected(bChecked)
elif label == "Hide environment": self.model.HideEnvironment(bChecked)
#elif label == "Hide all peptide atoms":
# if not self.ctrlflag.ready: return #event.Skip()
# self.model.HidePeptideAtoms(bChecked)
# return
elif label == "Hide hydrogen": self.model.HideHydrogen(bChecked)
elif label == "Hide water": self.model.HideWater(bChecked)
elif label == "Hide all atoms": self.model.HideAllAtoms(bChecked)
elif label == "Selected only": self.model.ShowSelectedOnly(bChecked)
elif label == "Side chain only":
self.model.ShowAASideChainOnly(bChecked)
elif label == "Backbone only": self.model.ShowAABackboneOnly(bChecked)
elif label == "All atom ": self.model.ShowAllAtom()
# Main chain submanu
elif label == "Tube": self.model.DrawChainTube(bChecked)
elif label == "CAlpha": self.model.DrawChainCAlpha(bChecked)
elif label == "Kite train": self.model.DrawChainKite(bChecked)
# Label submenu in Show Menu
elif label == "Element": self.model.DrawLabelElm(bChecked,0)
elif label == "Atom number": self.model.DrawLabelAtm(bChecked,0)
elif label == "Atom name": self.model.DrawLabelAtm(bChecked,1)
elif label == "Atom name+number": self.model.DrawLabelAtm(bChecked,2)
elif label == "Residue name": self.model.DrawLabelRes(bChecked,0)
elif label == "Residue name+number":
self.model.DrawLabelRes(bChecked,1)
elif label == "Chain name": self.model.DrawLabelChain(bChecked)
elif label == "Formal charge":
self.model.DrawFormalCharge(bChecked)
elif label == "Remove all": self.model.DrawLabelRemoveAll(True)
# distance
elif label == "Mode(on/off)": self.model.SetDrawDistance(bChecked)
elif label == "Remove": self.model.ClearDrawDistance()
# Bond submenu in Show Menu
elif label == "Multiple bond": self.model.DrawMultipleBond(bChecked)
elif label == "Hydrogen Bonds": self.model.DrawHBOrVdwBond(bChecked)
#if label == "vdW contact":
# self.model.DrawVdwBond(bChecked)
elif label == "CH/pi contact":
if bChecked: self.model.MenuShow('CH/pi contact',1)
else: self.model.MenuShow('CH/pi contact',0)
# FMO related submenu
# Molecular model submenu in Show Menu
elif label == "Line": self.model.ChangeDrawModel(0)
elif label == "Stick": self.model.ChangeDrawModel(1)
elif label == "Ball and stick": self.model.ChangeDrawModel(2)
elif label == "CPK": self.model.ChangeDrawModel(3)
elif label == "vdW surface": self.model.MenuShow("vdW surface",-1)
elif label == "SA surface": self.model.MenuShow("SA surface",-1)
elif label == "Stereo":
if bChecked: self.model.SetStereo(True)
else: self.model.SetStereo(False)
elif label == "xyz-axis": self.model.DrawXYZAxis(bChecked)
# Color submenu in Show Menu
elif label == "by element": self.model.ChangeAtomColor(label)
elif label == "by residue": self.model.ChangeAtomColor(label)
#self.model.MenuShow("by residue")
elif label == "by fragment": self.model.ChangeAtomColor(label)
elif label == "by group": self.model.ChangeAtomColor(label)
elif label == "by chain": self.model.ChangeAtomColor(label)
elif label == "on color palette": self.model.ChangeAtomColor(label)
elif label == "Fog": self.model.FogEnable(bChecked)
elif label == "Opacity":
if bChecked: self.model.ChangeOpacity(0.5)
else: self.model.ChangeOpacity(1.0)
elif label == "Background color": self.model.ChangeBackgroundColor([])
elif label == 'Redraw': self.model.Redraw()
elif label == 'Dump view': self.model.DumpDrawItems()
elif label == 'Restore view': self.model.RestoreDrawItems()
elif label == "One-by-One":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
elif label == "SlideShowCtrl":
if bChecked: self.mdlwin.winctrl.Open(label)
else:
try:
self.model.winctrl.GetWin(label).RemoveMdlWinMess()
self.mdlwin.winctrl.Close(label)
except: pass
elif label == "Redraw": self.model.DrawMol(True)
else:
mess=self.classnam+'(OnShow): '+'"'+label
mess=mess+'" menu item is not defined'
lib.MessageBoxOK(mess,"")
def OnWindow(self,label,bChecked):
""" 'Window' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
# echo and log
self.EchoAndLog('Window',label,bChecked)
# check menu
self.CheckMenu(label,bChecked)
# excute menu item
if label == "Open ControlWin":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
elif label == "Open PyShell":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Hide(label)
elif label == "Show ToolsWin":
pyshell=self.model.winctrl.GetWin('Open PyShell')
if bChecked:
try: pyshell.shell.run('fum.ShowToolsWin()')
except: pass
else:
try: pyshell.shell.run('fum.HideToolsWin()')
except: pass
elif label == "Open EasyPlotWin":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
elif label == "ChildViewWin":
"""
if self.ctrlflag.Get('ChildViewWin'):
self.model.childwin.SetFocus()
self.Message('ChildMolView panel is open.',1,'black')
else: self.model.OpenChildMolView()
"""
return
elif label == "Open MatPlotLibWin":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
elif label == "Open MouseModeWin":
if bChecked:
self.mdlwin.muswin=True
self.mdlwin.OpenMouseModeWin()
else:
self.mdlwin.muswin=False
self.mdlwin.CloseMouseModeWin()
elif label == "Open MolChoiceWin":
if bChecked:
self.mdlwin.molwin=True
self.mdlwin.OpenMolChoiceWin()
else:
self.mdlwin.molwin=False
self.mdlwin.CloseMolChoiceWin()
#elif label == "Open ExecScriptWin":
# if bChecked:
# win=subwin.ExecuteScript_Frm(self.mdlwin,winpos=[0,0])
# self.model.winctrl.SetOpenWin(label,win)
# self.model.winctrl.Open(label)
# else: self.model.winctrl.Close(label)
#elif label == "Open ScriptEditor":
# if bChecked: self.model.winctrl.Open(label)
# else: self.model.winctrl.Close(label)
#elif label == "Operation guide":
# print 'Window Operation guide'
#if label == "Open SettingWin":
# self.model.winctrl.OpenSettingWin()
else:
mess=self.classnam+'(OnWindow): '+'"'+label
mess=mess+'" menu item is not defined'
lib.MessageBoxOK(mess,"")
def OnSelect(self,label,bChecked):
""" 'Select' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
ans=lib.IsMoleculeObj(self.model.mol)
if not ans: return
# echo and log
self.EchoAndLog('Select',label,bChecked)
# check menu
self.CheckMenu(label,bChecked)
if label == "Hydrogen atom": self.model.SelectHydrogen()
elif label == "Non bonded atom": self.model.SelectNonBonded()
elif label == "Water molecule": self.model.SelectWater()
elif label == "Non-AA residue": self.model.SelectNonAAResidue()
elif label == "AA residue": self.model.SelectAAResidue()
elif label == "Side chain": self.model.SelectAASideChain()
elif label == "Backbone": self.model.SelectAABackbone()
# Atoms/Residues
elif label == "Ball-and-stick model atoms":
self.model.SelectAtomByModel(2)
elif label == "CPK model atoms":
self.model.SelectAtomByModel(3)
elif label == "Atoms within distance":
self.model.SelectAtomsWithinDistance()
elif label == "Resdiues within distance":
self.model.SelectResiduesWithinDistance()
#elif label == "Residues with missing atoms":
# self.model.SelectResiduesWithMissingAtoms()
elif label == "Read select file": self.model.SelectByFile()
#
elif label == "Complement": self.model.SelectComplement()
elif label == "All show atoms": self.model.SelectAllShowAtom()
elif label == "Select all": self.model.SelectAll(1)
elif label == "Deselect all": self.model.SelectAll(0)
elif label == "Environment": self.model.SelectEnv()
# Object submenu in Select
elif label == "Atom":
self.model.mousectrl.OnSwitchMouseMode('selobj',0)
elif label == "Residue":
self.model.mousectrl.OnSwitchMouseMode('selobj',1)
elif label == "Peptide chain":
self.model.mousectrl.OnSwitchMouseMode('selobj',2)
elif label == "Group":
self.model.mousectrl.OnSwitchMouseMode('selobj',3)
elif label == "Fragment":
self.model.mousectrl.OnSwitchMouseMode('selobj',4)
elif label == "Molecule":
#self.model.mousectrl.OnSwitchMouseMode('selobj',???)
return
# Multiple selection submenu
elif label == "1-object":
self.model.mousectrl.OnSwitchMouseMode('selmod',0)
elif label == "2-objects":
self.model.mousectrl.OnSwitchMouseMode('selmod',1)
elif label == "3-objects":
self.model.mousectrl.OnSwitchMouseMode('selmod',2)
elif label == "4-objects":
self.model.mousectrl.OnSwitchMouseMode('selmod',3)
elif label == "Unlimited":
self.model.mousectrl.OnSwitchMouseMode('selmod',4)
elif label == "Box/Sphere(toggle)": # in "Sphere/Box selection":
self.model.mousectrl.OnSwitchMouseMode('selmod',5)
elif label == "Remove box/sphere":
self.model.RemoveSelectSphere()
self.model.RemoveSelectBox()
# section mode
elif label == 'Section mode':
self.secmod=bChecked; title='Open ControlWin'
if self.model.winctrl.IsOpened(title):
self.model.winctrl.GetWin(title).SetSectionMode(bChecked)
self.model.mousectrl.OnSwitchMouseMode('section',self.secmod)
self.model.SetSection(bChecked) #self.secmod)
elif label == "Preset color":
self.model.SetSelectedDisplayMethod(True)
elif label == "Bold line": self.model.SetSelectedDisplayMethod(False)
# "Selector" submenu
elif label == "Tree":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
elif label == "Name/Number":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
elif label == "Radius":
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
else:
mess=self.classnam+'(OnSelect): '+'"'+label
mess=mess+'" menu item is not defined'
lib.MessageBoxOK(mess,"")
def OnModeling(self,label,bChecked):
""" 'Modeling' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
ans=lib.IsMoleculeObj(self.model.mol)
if not ans: return
# echo and log
checkstr='True'
if not bChecked: checkstr='False'
mess='fum.menuctrl.OnModeling("'+label+'",'+checkstr+')'
if self.model.setctrl.GetEcho(): self.model.ConsoleMessage(mess)
#if lib.LOGGING: self.model.WriteLogging(mess)
#
self.CheckMenu(label,bChecked)
# save molecule object for undo
if label != "Undo": self.model.SaveMol()
# Undo
if label == "Undo": self.model.RecoverMol() # self.molde.Undo()
# Add hydrogen
elif label == "Open add hydrogen panel":
self.model.ExecuteAddOnScript('add-hydrogens.py',False)
#elif label == 'to all residues': self.model.AddHydrogenToAllResidues()
elif label == "to polypeptide": self.model.AddHydrogenToAAResidue()
elif label == "to water": self.model.AddHydrogenToWater()
elif label == "to non-polypeptide(use frame data)":
atmlst=self.model.ListNonAAResidueAtoms()
self.model.AddHydrogenUseFrameData(atmlst=atmlst)
elif label == "to non-polypeptide(use bond length)":
self.model.AddHydrogenUseBondLength()
elif label == "View summary": self.model.SummaryOfAddHydrogens()
elif label == "View message log": self.model.ViewMessageLog()
# Attach hydrogen(s)
elif label == "1H": self.model.AttachHydrogen(label)
elif label == "2H": self.model.AttachHydrogen(label)
elif label == "3H": self.model.AttachHydrogen(label)
# Replace hydrogen with
elif label == "CH3": self.model.ReplaceWithGroupAtoms(label)
elif label == "ACE": self.model.ReplaceWithGroupAtoms(label)
elif label == "NME": self.model.ReplaceWithGroupAtoms(label)
elif label == "GROUP":
self.model.ExecuteAddOnScript('model-builder.py',False)
elif label == "Merged molecule": self.model.ConnectMergedGroup()
#elif label == "with other resdiue": self.model.ReplaceNonAAResidue()
elif label == "Residue(s)": self.model.RepalceWithSameResdiue()
elif label == "Ligand in complex":
#self.model.ExecuteAddOnScript('replace-ligand.py',False)
build.ReplaceLigandInComplex(self.model)
elif label == "Residue coordinates":
self.model.RepalceResdiueCoordinates()
# Truncate protein
elif label == "Open panel":
build.TruncateProtein_Frm(self.model,-1)
elif label == "Cap with hydrogens":
build.TruncateProtein(cap=1,model=self.model)
elif label == "Cap with ACE/NME":
build.TruncateProtein(cap=0,model=self.model)
elif label == "Use frame data ": self.model.AddBondUseFrameData()
elif label == "Based on bond length ":
self.model.AddBondUseBondLength()
elif label == "Based on valence ": self.model.AddBondMultiplicity(0)
elif label == "S-S bond": self.model.AddSSBond()
elif label == "vdW contact": self.model.MakeVdwContact()
elif label == "Hydrogen bond": self.model.MakeHydrogenBond(True)
#
elif label == "Residue ": self.model.MenueAdd("residue")
# Bond submenu
elif label == "Bond multiplicity": self.model.AddBondMultiplicity()
elif label == "Based-on bond length": self.model.AddBondMultiplicity(1)
elif label == 'remove': self.model.RemoveBondMultiplicity()
#Del ---------------------------------
elif label == "Selected atoms": self.model.DeleteSelected()
elif label == "Non-bonded atoms": self.model.DeleteNonBonded()
elif label == "Hydrogen atoms": self.model.DeleteHydrogens()
elif label == "Waters": self.model.DeleteWater()
#elif label == "AA residues": self.model.DeleteAAResidue()
#elif label == "Non-AA residues": self.model.DeleteNonAAResidue()
elif label == "All bonds": self.model.DeleteBonds('all',True)
elif label == "Bond multiplicities":
self.model.RemoveBondMultiplicity()
elif label == "Hydrogen_bonds": self.model.DeleteHydrogenBond()
elif label == "vdW contacts": self.model.DeleteVdwBond()
elif label == "TER in PDB data": self.model.DeleteAllTers()
elif label == "Dummy atoms in ZMatrix":
self.model.DeleteAllDummyAtoms()
# Change
elif label == "Element ": self.model.ChangeElementAndLength()
elif label == "Atom name ": self.model.ChangeAtomName()
elif label == "Residue name ": self.model.ChangeResidueName()
elif label == "Chain name ": self.model.ChangeChainName()
elif label == "Group name ": self.model.ChangeGroupName()
#elif label == "Old atom names to new ones": self.model.ChangeAtmNamToNew()
#elif label == "New atom names to old ones": self.model.ChangeAtmNamToOld()
elif label == "Bond length": self.model.ChangeBondLength()
elif label == "Bond multiplicity":
#self.model.ChangeBondMultiplicity()
mess='Press 1,2,3,4 key to make multiple bond'
lib.MessageBoxOK(mess,'OnChange: Change bond multiplicity')
# Charge
elif label == "to AA residue": self.model.AssignAAAtomCharge()
elif label == "Ion charge": self.model.ChangeCharge()
elif label == "to selected atom(s)":
self.model.ChangeChargeOfSelectedAtoms()
elif label == "Clear ion chgrges": self.model.ClearAtomCharge()
elif label == "Group charge": self.model.ChangeGroupCharge()
elif label == "Conformation": self.model.winctrl.Open(label) # ZMatrixPanel()
#elif label == "Model builder": self.model.winctrl.Open(label)
elif label == "Replace water with ion":
self.model.ReplaceWaterWithIon()
# Build molecule
elif label == "Open Model Builder":
self.model.winctrl.Open('ModelBuilder')
elif label == "Open Peptide Builder":
self.model.winctrl.Open('PolypeptideBuilder')
# Mutation
elif label == "Open HIS Form Changer":
self.model.winctrl.Open('HisFormChanger')
elif label == "Open Mutate Panel":
self.model.winctrl.Open('MutateResidue')
# Edit conformation
elif label == "Open Rotate Bond Editor":
self.model.winctrl.Open('RotateBond')
elif label == "Open Torsion Editor": self.model.winctrl.Open(label)
elif label == "Open ZMatrix Editor":
self.model.winctrl.Open('ZMatrixEditor')
# "Box waters"
elif label == "Immerse in box waters":
self.model.winctrl.Open('BoxWater')
# Update coordinates
elif label == "from output file" or label == "from file":
coordfile=""
if label == "from output file":
wcard="optgeom(*.out;*.log)|*.out;*.log"
elif label == "from file": wcard="xyz(*.xyz)|*.xyz"
dlg=wx.FileDialog(self.mdlwin,"Open file...",os.getcwd(),
style=wx.OPEN,wildcard=wcard)
if dlg.ShowModal() == wx.ID_OK: coordfile=dlg.GetPath()
#dlg.Destroy()
if len(coordfile) > 0: self.model.UpdateCoordinates(coordfile)
elif label == "from clipboad(xyz)":
self.model.UpdateCoordinatesFromClipboad()
# ???
elif label == "Renumber residue":
print 'remuber resnmb'
elif label == "Renumber atom":
print 'renumber atmnmb'
elif label == "Utility geometry": self.model.MoleculeInfoGeometry()
else:
mess=self.classnam+'(OnModeling): '+'"'+label
mess=mess+'" menu item is not defined'
lib.MessageBoxOK(mess,"")
def OnGroup(self,label,bChecked):
"""
'Group' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
# echo and log
self.EchoAndLog('Group',label,bChecked)
# check menu
self.CheckMenu(label,bChecked)
# "Make group" submenu
if label == "Selected atoms ":
self.model.MenuGroup('selected atoms group')
elif label == "do. with environment":
self.model.MenuGroup('do. env selected atoms group')
elif label == "Split at TER":
self.model.MenuGroup('split at TER')
elif label == "do. with environment ":
self.model.MenuGroup('do. env split at TER')
elif label == "Split by chain":
self.model.MenuGroup('split at chain')
elif label == "do. with environment ":
self.model.MenuGroup('do. env split at chain')
# "Make molecule" submenu
elif label == "Selected atoms ":
self.model.MenuGroup('select atoms ') # three blanks
elif label == "Split at TER ":
self.model.MenuGroup('split at ter ')
elif label == "Split by chain ":
self.model.MenuGroup('split by chain ')
# "Combine" submenu
elif label == "all molecules":
self.model.MenuGroup('all molecules')
elif label == "all groups":
self.model.MenuGroup('all groups')
elif label == "By choose panel":
self.model.OpenJionGroupWin()
# "Rename/Remove" submenu
elif label == "Remove all groups":
self.model.MenuGroup('remove all groups')
elif label == "Remove all molecules":
self.model.MenuGroup('remove all molecules')
elif label == "By popup panel":
self.model.OpenRenameGroupWin()
else:
mess=self.classnam+'(OnGroup): '+'"'+label
mess=mess+'" menu item is not defined'
lib.MessageBoxOK(mess,"")
def EchoAndLog(self,topmenu,label,bChecked):
checkstr='True'
if not bChecked: checkstr='False'
mess='fum.menuctrl.On'+topmenu+'("'+label+'",'+checkstr+')'
if self.model.setctrl.GetParam('echo'): self.model.ConsoleMessage(mess)
# if lib.LOGGING: self.model.WriteLogging(mess)
def OnUtility(self,label,bChecked):
"""
'Utility' menu event handler.
:param str label: menu item label,
:param bool bChecked: True for checked, False for unchecked.
"""
ans=lib.IsMoleculeObj(self.model.mol)
if not ans: return
# echo and log
self.EchoAndLog('Utility',label,bChecked)
# check menu
self.CheckMenu(label,bChecked)
#
if label == "Molecule info": self.model.MoleculeInfo()
# Geometry
elif label == "Short contact":
self.model.ExecuteAddOnScript('short-contact-atoms.py',False)
elif label == "Bond lengths":
self.model.geom.Plot('Bond length')
elif label == "Bond angles":
self.model.geom.Plot('Bond angle')
elif label == "Hydrogen_bond":
self.model.geom.Plot('Hydrogen bond')
elif label == "Peptide angles":
self.model.UtilityGeometry(label)
elif label == "vdW contact":
self.model.UtilityGeometry(label)
elif label == "CH/pi bond":
self.model.UtilityGeometry(label)
# PDB data
elif label == "Plot B-factor":
self.model.ExecuteAddOnScript('plot-b-factor.py',False)
elif label == "Missing residue info":
self.model.PDBMissingResidueInfo()
elif label == "Change atom names to new":
self.model.ChangeAtmNamToNew()
elif label == "Change atom names to old":
self.model.ChangeAtmNamToOld()
elif label == "Delete TER's": self.model.DeleteAllTers()
#elif label == "Missing atom residues":
# self.model.ReportMissingAtomsInAAResidue()
#elif label == "Open PDB tools panel":
# self.model.ShowToolsWin()
#elif label == "Show ToolsWin":
# pyshell=self.model.winctrl.GetWin('Open PyShell')
# if bChecked:
# try: pyshell.shell.run('fum.ShowToolsWin()')
# except: pass
# else:
# try: pyshell.shell.run('fum.HideToolsWin()')
# except: pass
elif label == "Split, join and extract":
#self.model.ExecuteAddOnScript('split-and-join.py',False)
self.model.winctrl.Open('SplitJoin')
elif label == "Compare files":
lib.MessageBoxOK('Under construction','')
# others
elif label == "Open EasyPlotWin":
#if bChecked: self.model.winctrl.OpenEasyPlotWin()
#else: self.model.winctrl.CloseEasyPlotWin()
if bChecked: self.model.winctrl.Open(label)
else: self.model.winctrl.Close(label)
elif label == "ChildViewWin":
"""
if self.ctrlflag.Get('ChildViewWin'):
self.model.childwin.SetFocus()
self.Message('ChildMolView panel is open.',1,'black')
else: self.model.OpenChildMolView()