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
|
# Copyright 2006-2008 Nanorex, Inc. See LICENSE file for details.
"""
PM_MolecularModelingKit.py - Atom Chooser widget
@version: $Id$
@copyright: 2006-2008 Nanorex, Inc. All rights reserved.
"""
from model.elements import PeriodicTable
from PyQt4.Qt import SIGNAL
from PM.PM_GroupBox import PM_GroupBox
from PM.PM_ToolButtonGrid import PM_ToolButtonGrid
from utilities.constants import diTUBES
from utilities.debug import print_compact_traceback
from utilities.exception_classes import AbstractMethod
class PM_MolecularModelingKit( PM_GroupBox ):
"""
The PM_MolecularModelingKit widget provides an Atom Chooser widget,
contained in its own group box, for a Property Manager dialog. (see
subclasses for details)
A PM_MolecularModelingKit is a selection widget that displays all elements,
pseudo-atoms supported in NE1.
@cvar element: The current element.
@type element: Elem
@cvar atomType: The current atom type of the current element.
@type atomType: str
@see: B{elements.py}
@see: B{PM.PM_ElementChooser}
"""
element = None
atomType = ""
_periodicTable = PeriodicTable
viewerDisplay = diTUBES
def __init__(self,
parentWidget,
parentPropMgr = None,
title = "Molecular Modeling Kit",
element = "",
elementViewer = None,
):
"""
Appends a AtomChooser widget (see subclasses) to the bottom of
I{parentWidget}, a Property Manager dialog.
(or as a sub groupbox for Atom Chooser GroupBox.)
@param parentWidget: The parent PM_Dialog or PM_groupBox containing this
widget.
@type parentWidget: PM_Dialog or PM_GroupBox
@param parentPropMgr: The parent Property Manager
@type parentPropMgr: PM_Dialog or None
@param title: The button title on the group box containing the
Element Chooser.
@type title: str
@param element: The initially selected element. It can be either an
element symbol or name.
@type element: str
"""
PM_GroupBox.__init__(self, parentWidget, title)
self.element = self._periodicTable.getElement(element)
self.elementViewer = elementViewer
self.updateElementViewer()
if parentPropMgr:
self.parentPropMgr = parentPropMgr
else:
self.parentPropMgr = parentWidget
self._addGroupBoxes()
self.connect_or_disconnect_signals(True)
def _addGroupBoxes(self):
"""
Subclasses should add various groupboxes present inside the Atom chooser
groupbox.
AbstractMethod
"""
raise AbstractMethod()
def _addElementsGroupBox(self, inPmGroupBox):
"""
Creates a grid of tool buttons containing all elements supported
in NE1.
@param inPmGroupBox: The parent group box to contain the element
buttons.
@type inPmGroupBox: PM_GroupBox
"""
self._elementsButtonGroup = \
PM_ToolButtonGrid( inPmGroupBox,
title = "",
buttonList = self.getElementsButtonList(),
checkedId = self.element.eltnum,
setAsDefault = True
)
self.connect( self._elementsButtonGroup.buttonGroup,
SIGNAL("buttonClicked(int)"),
self.setElement )
def _updateAtomTypesButtons(self):
"""
Updates the hybrid buttons based on the currently selected
element button.
Subclasses should override this method
"""
pass
def restoreDefault(self):
"""
Restores the default checked (selected) element and atom type buttons.
"""
PM_GroupBox.restoreDefault(self)
self._updateAtomTypesButtons()
return
def getElementNumber(self):
"""
Returns the element number of the currently selected element.
@return: Selected element number
@rtype: int
"""
return self._elementsButtonGroup.checkedId()
def getElementSymbolAndAtomType(self):
"""
Returns the symbol and atom type of the currently selected element.
@return: element symbol, atom type
@rtype: str, str
"""
currentElementNumber = self.getElementNumber()
element = self._periodicTable.getElement(currentElementNumber)
return element.symbol, self.atomType
def getElement(self):
"""
Get the current element.
@return: element
@rtype: Elem
@see: B{element.py}
"""
return self.element
def setElement(self, elementNumber):
"""
Set the current element in the MMKit to I{elementNumber}.
@param elementNumber: Element number. (i.e. 6 = carbon)
@type elementNumber: int
"""
self.element = self._periodicTable.getElement(elementNumber)
self._updateAtomTypesButtons()
self.updateElementViewer()
self._updateParentPropMgr()
return
def updateElementViewer(self):
"""
Update the view in the element viewer (if present)
"""
if not self.elementViewer:
return
from graphics.widgets.ThumbView import MMKitView
assert isinstance(self.elementViewer, MMKitView)
self.elementViewer.resetView()
self.elementViewer.changeHybridType(self.atomType)
self.elementViewer.refreshDisplay(self.element, self.viewerDisplay)
return
def _updateParentPropMgr(self):
"""
Update things in the parentWidget if necessary.
(The parentWidget should be a property manager, although not necessary)
Example: In Build Atoms Mode, the Property manager message groupbox
needs to be updated if the element is changed in the element chooser.
Similarly, the selection filter list should be updated in this mode.
"""
parentPropMgrClass = self.parentPropMgr.__class__
if hasattr(parentPropMgrClass, 'updateMessage'):
try:
self.parentPropMgr.updateMessage()
except AttributeError:
print_compact_traceback("Error calling updateMessage()")
if hasattr(parentPropMgrClass, 'update_selection_filter_list'):
try:
self.parentPropMgr.update_selection_filter_list()
except AttributeError:
msg = "Error calling update_selection_filter_list()"
print_compact_traceback(msg)
def connect_or_disconnect_signals(self, isConnect):
"""
Connect or disconnect widget signals sent to their slot methods.
@param isConnect: If True the widget will send the signals to the slot
method.
@type isConnect: boolean
"""
#Not implemented yet
return
def getElementsButtonList(self):
"""
Subclasses should override this and return the list of buttons in the
Atom chooser.
"""
raise AbstractMethod()
|