7 self._children = list()
9 def create_log(self, repr, log_name):
10 """Create Chimera log.
11 @param repr <a href="classIMP_1_1restrainer_1_1representation_1_1Representation.html">
12 Representation</a> object.
13 @param log_name Log name
14 @return IMP::display::WriteOptimizerState"""
19 for child
in self._children:
20 child.find_model_decorator(repr)
23 for child
in self._children:
26 for child
in self._children:
27 child.create_xyz(1.0, 1.0, 1.0, log)
29 for child
in self._children:
34 return '<Display>\n%s\n</Display>' %\
35 (
'\n'.join([child._to_str(1)
for child
in self._children]))
37 class _DisplayNode(object):
39 def __init__(self, attributes):
40 id = attributes.get(
'id')
44 self.id =
'object_%d' % _DisplayNode.counter
45 _DisplayNode.counter += 1
46 self._children = list()
49 for child
in self._children:
50 if isinstance(child, _DisplayColor):
54 def find_model_decorator(self, repr):
55 particle = repr.find_by_id(self.id)
56 if particle
and particle.model_decorator:
57 self.model_decorator = particle.model_decorator
59 self.model_decorator =
None
60 for child
in self._children:
61 child.find_model_decorator(repr)
63 def detach_parent(self):
64 if self.model_decorator:
65 self.parent = self.model_decorator.get_parent()
66 self.parent.remove_child(self.model_decorator)
67 for child
in self._children:
70 def attach_parent(self):
71 if self.model_decorator:
72 self.parent.add_child(self.model_decorator)
73 for child
in self._children:
76 def create_xyz(self, r, g, b, log):
77 color = self.get_color()
83 if self.model_decorator:
88 atom_list.append(atom)
92 geometry.set_name(self.id)
94 log.add_geometry(geometry)
95 for child
in self._children:
96 child.create_xyz(r, g, b, log)
98 def _attr_to_str(self):
99 return (
'DisplayNode',
'id="%s"' % self.id)
101 def _to_str(self, level):
103 name, strattr = self._attr_to_str()
104 if not self._children:
105 return '%s<%s %s/>' % (indent, name, strattr)
107 return '%s<%s %s>\n%s\n%s</%s>' %\
108 (indent, name, strattr,
109 '\n'.join([child._to_str(level + 1)
110 for child
in self._children]), indent, name)
113 return self._to_str(0)
116 class _DisplayColor(_DisplayNode):
117 def __init__(self, attributes):
118 _DisplayNode.__init__(self, attributes)
119 self.r = float(attributes.get(
'r', 0))
120 self.g = float(attributes.get('g', 0))
121 self.b = float(attributes.get(
'b', 0))
123 def _attr_to_str(self):
124 return (
'Color',
'id="%s" r="%s" g="%s" b="%s"' %
125 (self.id, self.r, self.g, self.b))
127 class _DisplayResidue(_DisplayNode):
128 def __init__(self, attributes):
129 _DisplayNode.__init__(self, attributes)
130 self.start = int(attributes.get(
'start', -1))
131 self.end = int(attributes.get(
'end', -1))
133 def _attr_to_str(self):
134 return (
'Residue',
'id="%s" start="%s" end="%s"' %
135 (self.id, self.start, self.end))
137 class _DisplayUniverse(_DisplayNode):
138 def __init__(self, attributes):
139 _DisplayNode.__init__(self, attributes)
141 def _attr_to_str(self):
142 return (
'Universe',
'id="%s"' % self.id)
144 class _DisplayCollection(_DisplayNode):
145 def __init__(self, attributes):
146 _DisplayNode.__init__(self, attributes)
148 def _attr_to_str(self):
149 return (
'Collection',
'id="%s"' % self.id)
151 class _DisplayAssembly(_DisplayNode):
152 def __init__(self, attributes):
153 _DisplayNode.__init__(self, attributes)
155 def _attr_to_str(self):
156 return (
'Assembly',
'id="%s"' % self.id)
158 class _DisplaySegment(_DisplayNode):
159 def __init__(self, attributes):
160 _DisplayNode.__init__(self, attributes)
162 def _attr_to_str(self):
163 return (
'Segment',
'id="%s"' % self.id)
165 class _DisplayMolecule(_DisplayNode):
166 def __init__(self, attributes):
167 _DisplayNode.__init__(self, attributes)
169 def _attr_to_str(self):
170 return (
'Molecule',
'id="%s"' % self.id)
172 class _DisplayProtein(_DisplayNode):
173 def __init__(self, attributes):
174 _DisplayNode.__init__(self, attributes)
176 def _attr_to_str(self):
177 return (
'Protein',
'id="%s"' % self.id)
179 class _DisplayNucleicAcid(_DisplayNode):
180 def __init__(self, attributes):
181 _DisplayNode.__init__(self, attributes)
183 def _attr_to_str(self):
184 return (
'NucleicAcid',
'id="%s"' % self.id)
186 class _DisplayChain(_DisplayNode):
187 def __init__(self, attributes):
188 _DisplayNode.__init__(self, attributes)
190 def _attr_to_str(self):
191 return (
'Chain',
'id="%s"' % self.id)
193 class _DisplayFragment(_DisplayNode):
194 def __init__(self, attributes):
195 _DisplayNode.__init__(self, attributes)
197 def _attr_to_str(self):
198 return (
'Fragment',
'id="%s"' % self.id)
Write geometry to a python file for Chimera to read.
Display an IMP::SingletonContainer of IMP::core::XYZR particles as balls.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
See IMP.display for more information.
Hierarchies get_leaves(const Selection &h)