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
|
# Copyright 2007-2008 Nanorex, Inc. See LICENSE file for details.
"""
NanotubeGroup.py - ...
@author: Bruce, Mark
@version: $Id$
@copyright: 2007-2008 Nanorex, Inc. See LICENSE file for details.
"""
from foundation.Group import Group
from utilities.constants import gensym
from utilities.icon_utilities import imagename_to_pixmap
from utilities import debug_flags
from utilities.debug import print_compact_stack
class NanotubeGroup(Group):
"""
Model object which packages together some Dna Segments, Dna Strands,
and other objects needed to represent all their PAM atoms and markers.
Specific kinds of Group member contents include:
- NanotubeSegments (optionally inside Groups)
- Groups (someday might be called Blocks when they occur in this context;
note that class Block is deprecated and should not be used for these)
- DnaMarkers (a kind of Jig, always inside an owning NanotubeSegment)
As other attributes:
- whatever other properties the user needs to assign, which are not
covered by the member nodes or superclass attributes. [nim?]
"""
# This should be a tuple of classifications that appear in
# files_mmp._GROUP_CLASSIFICATIONS, most general first.
# See comment in class Group for more info. [bruce 080115]
_mmp_group_classifications = ('NanotubeGroup',)
# Open/closed state of the Dna Group in the Model Tree --
# default closed.
open = False
autodelete_when_empty = True
# (but only if current command permits that for this class --
# see comment near Group.autodelete_when_empty for more info,
# and implems of Command.keep_empty_group)
def node_icon(self, display_prefs):
"""
Model Tree node icon for the nanotube group node
@see: Group.all_content_is_hidden()
"""
open = display_prefs.get('open', False)
if open:
if self.all_content_is_hidden():
return imagename_to_pixmap("modeltree/NanotubeGroup-expanded-hide.png")
else:
return imagename_to_pixmap("modeltree/NanotubeGroup-expanded.png")
else:
if self.all_content_is_hidden():
return imagename_to_pixmap("modeltree/NanotubeGroup-collapsed-hide.png")
else:
return imagename_to_pixmap("modeltree/NanotubeGroup-collapsed.png")
# Note: some methods below this point are examples or experiments or stubs,
# and are likely to be revised significantly or replaced.
# [bruce 080115 comment]
# example method:
def getSegments(self):
"""
Return a list of all our NanotubeSegment objects.
"""
return self.get_topmost_subnodes_of_class(self.assy.NanotubeSegment)
def isEmpty(self):
"""
Returns True if there are no nanotube chunks as its members
(Returns True even when there are empty NanotubeSegment objects inside)
@see: BuildNanotube_EditCommand._finalizeStructure where this test is used.
"""
#May be for the short term, we can use self.getAtomList()? But that
#doesn't ensure if the DnaGroup always has atom of type either
#'strand' or 'axis' .
if len(self.getSegments()) == 0:
return True
else:
return False
def addSegment(self, segment):
"""
Adds a new segment object for this dnaGroup.
@param segment: The NanotubeSegment to be added to this NanotubeGroup object
@type: B{NanotubeSegment}
"""
self.addchild(segment)
def getProps(self):
"""
Method to support Dna duplex editing. see Group.__init__ for
a comment
THIS IS THE DEFAULT IMPLEMENTATION. TO BE MODIFIED
"""
#Should it supply the Dna Segment list (children) and then add
#individual segments when setProps is called??
# [probably not; see B&N email discussion from when this comment was added]
if self.editCommand:
props = ()
return props
def setProps(self, props):
"""
Method to support Dna duplex editing. see Group.__init__ for
a comment
THIS IS THE DEFAULT IMPLEMENTATION. TO BE MODIFIED
"""
#Should it accept the Dna Segment list and then add individual segments?
pass
def edit(self):
"""
@see: Group.edit()
"""
commandSequencer = self.assy.w.commandSequencer
commandSequencer.userEnterCommand('BUILD_NANOTUBE', always_update = True)
currentCommand = commandSequencer.currentCommand
assert currentCommand.commandName == 'BUILD_NANOTUBE'
currentCommand.editStructure(self)
def getSelectedSegments(self):
"""
Returns a list of segments whose all members are selected.
@return: A list containing the selected strand objects
within self.
@rtype: list
"""
#TODO: This is a TEMPORARY KLUDGE until Dna model is fully functional.
#Must be revised. Basically it returns a list of NanotubeSegments whose
#all members are selected.
#See BuildDna_PropertyManager._currentSelectionParams() where it is used
#-- Ninad 2008-01-18
segmentList = self.getSegments()
selectedSegmentList = []
for segment in segmentList:
pickedNodes = []
unpickedNodes = []
def func(node):
if isinstance(node, self.assy.Chunk):
if not node.picked:
unpickedNodes.append(node)
else:
pickedNodes.append(node)
segment.apply2all(func)
if len(unpickedNodes) == 0 and pickedNodes:
selectedSegmentList.append(segment)
return selectedSegmentList
def getAtomList(self):
"""
Return a list of all atoms contained within this NanotubeGroup
"""
atomList = []
def func(node):
if isinstance(node, self.assy.Chunk):
atomList.extend(node.atoms.itervalues())
self.apply2all(func)
return atomList
def draw_highlighted(self, glpane, color):
"""
Draw the nanotube segment chunks as highlighted. (Calls the related
methods in the chunk class)
@param: GLPane object
@param color: The highlight color
@see: Chunk.draw_highlighted()
@see: SelectChunks_GraphicsMode.draw_highlightedChunk()
@see: SelectChunks_GraphicsMode._get_objects_to_highlight()
"""
for c in self.getSegments():
c.draw_highlighted(glpane, color)
pass # end of class NanotubeGroup
# ==
|