forked from lmorency/NRGsuite
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Sphere.py
executable file
·218 lines (161 loc) · 6.87 KB
/
Sphere.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
'''
NRGsuite: PyMOL molecular tools interface
Copyright (C) 2011 Gaudreault, F., Morency, LP. & Najmanovich, R.
This program is free 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.
This program 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import sys
if sys.version_info[0] < 3:
from Tkinter import *
else:
from tkinter import *
from pymol.wizard import Wizard
from pymol import cmd
import pymol
import SphereObj
import General_cmd
class Sphere(Wizard):
def __init__(self, top, queue, Sphere, SphereDisplay, SphereSize, ExtraPrompt):
#print "New instance of flexsphere Wizard"
Wizard.__init__(self)
self.top = top
self.queue = queue
self.App = self.top.top
self.App.WizardError = False
self.App.WizardResult = 0
self.Sphere = Sphere
self.SphereView = self.Sphere.Copy()
self.SphereSize = SphereSize
self.SphereDisplay = SphereDisplay
self.View = cmd.get_view()
self.ErrorCode = 0
self.Prompt = [ "Press Shift + Mouse3 (Wheel Click) to move the sphere.",
"Use the scaler in the " + self.App.Name + " interface to edit its radius." ]
if ExtraPrompt:
self.Prompt.append( ExtraPrompt )
#=======================================================================
''' Execute the first steps of the wizard '''
#=======================================================================
def Start(self):
# self.queue.put(lambda: self.top.top.root.withdraw())
cmd.window('hide')
cmd.refresh_wizard()
cmd.orient()
cmd.window('show')
# self.queue.put(lambda: cmd.window('show'))
self.ErrorCode = 1
try:
self.State = cmd.get_state()
self.config_mouse = General_cmd.get_config_mouse()
cmd.config_mouse('three_button_editing')
self.exc = [ self.SphereDisplay ]
General_cmd.mask_Objects(self.exc)
# success
self.ErrorCode = 0
except:
self.queue.put(lambda: self.App.DisplayMessage(" ERROR: Could not start the Sphere wizard", 1))
self.queue.put(lambda: self.App.DisplayMessage(" The wizard will abort prematurely", 1))
self.Quit_Wizard()
return
if self.DisplaySphere():
self.queue.put(lambda: self.App.DisplayMessage(" ERROR: Could not display the Sphere", 1))
self.queue.put(lambda: self.App.DisplayMessage(" The wizard will abort prematurely", 1))
self.Quit_Wizard()
return
#=======================================================================
''' Quits the wizard '''
#=======================================================================
def Quit_Wizard(self):
try:
# Delete Sphere object
General_cmd.unmask_Objects(self.exc)
cmd.config_mouse(self.config_mouse)
cmd.delete(self.SphereDisplay)
cmd.refresh()
except:
pass
# Catch error in App
if self.ErrorCode > 0:
self.App.WizardError = True
# Re-enable controls
self.App.ActiveWizard = None
cmd.set_wizard()
cmd.set_view(self.View)
cmd.refresh()
self.queue.put(lambda: self.top.SphereRunning(False))
self.queue.put(lambda: self.top.top.root.deiconify())
self.queue.put(lambda: self.top.top.root.update())
#=======================================================================
''' Display the Sphere in Pymol '''
#=======================================================================
def DisplaySphere(self):
try:
# Display the Sphere
cmd.delete(self.SphereDisplay)
cmd.refresh()
except:
pass
try:
cmd.pseudoatom(self.SphereDisplay,
pos=self.SphereView.Center,
vdw=self.SphereView.Radius,
state=self.State)
cmd.refresh()
cmd.color('oxygen', self.SphereDisplay)
cmd.refresh()
cmd.hide('everything', self.SphereDisplay)
cmd.refresh()
cmd.show('spheres', self.SphereDisplay)
cmd.refresh()
except:
self.ErrorCode = 1
return self.ErrorCode
#=======================================================================
''' Resize the sphere '''
#=======================================================================
def ResizeSphere(self):
self.SphereView.Set_Radius(self.SphereSize.get())
try:
cmd.alter(self.SphereDisplay,'vdw=' + str(self.SphereView.Radius))
cmd.rebuild(self.SphereDisplay)
cmd.refresh()
except:
self.queue.put(lambda: self.App.DisplayMessage(" ERROR: Could not resize the Sphere", 1))
self.queue.put(lambda: self.App.DisplayMessage(" The wizard will abort prematurely", 1))
self.Quit_Wizard()
def get_prompt(self):
return self.Prompt
def reset(self):
self.SphereView = self.Sphere.Copy()
self.SphereSize.set(self.SphereView.Radius)
if self.DisplaySphere():
self.queue.put(lambda: self.App.DisplayMessage(" ERROR: Could not display the Sphere", 1))
self.queue.put(lambda: self.App.DisplayMessage(" The wizard will abort prematurely", 1))
self.Quit_Wizard()
return
def cancel(self):
self.App.WizardResult = 1
self.Quit_Wizard()
def btn_Done(self):
Center = General_cmd.Get_CenterOfMass2(self.SphereDisplay, self.State)
if len(Center) > 0:
self.SphereView.Set_Center(Center)
self.Sphere.Set_Radius(self.SphereView.Radius)
self.Sphere.Set_Center(self.SphereView.Center)
self.App.WizardResult = 2
self.Quit_Wizard()
def get_panel(self):
return [
[ 1, '* Sphere Controls *',''],
[ 2, 'Reset','cmd.get_wizard().reset()'],
[ 2, 'Cancel','cmd.get_wizard().cancel()'],
[ 2, 'Done','cmd.get_wizard().btn_Done()'],
]