IMP  2.1.1
The Integrative Modeling Platform
_xml_parser.py
1 import os
2 import xml.dom.minidom
3 from _representation import Representation
4 from _representation import _RepUniverse
5 from _representation import _RepCollection
6 from _representation import _RepAssembly
7 from _representation import _RepMolecule
8 from _representation import _RepProtein
9 from _representation import _RepNucleicAcid
10 from _representation import _RepChain
11 from _representation import _RepFragment
12 from _representation import _RepAtomicRep
13 from _representation import _RepGeometricShapeRep
14 from _representation import _RepSphere
15 from _representation import _RepInitialPosition
16 from _restraint import Restraint
17 from _restraint import _RestraintY2H
18 from _restraint import _RestraintPulldown
19 from _restraint import _RestraintArray
20 from _restraint import _RestraintMSMS
21 from _restraint import _RestraintXrayStruc
22 from _restraint import _RestraintCopurification
23 from _restraint import _RestraintCrossLink
24 from _restraint import _RestraintDistance
25 from _restraint import _RestraintDiameter
26 from _restraint import _RestraintSAXS
27 from _restraint import _RestraintSANS
28 from _restraint import _RestraintEM
29 from _restraint import _RestraintExcludedVolume
30 from _restraint import _RestraintRestraint
31 from _restraint import _RestraintParticle
32 from _restraint import _RestraintSource
33 from _restraint import _RestraintAuthor
34 from _restraint import _RestraintJournal
35 from _restraint import _RestraintTitle
36 from _restraint import _RestraintYear
37 from _restraint import _RigidBodyRestraintNode
38 from _display import Display
39 from _display import _DisplayNode
40 from _display import _DisplayColor
41 from _display import _DisplayResidue
42 from _display import _DisplayUniverse
43 from _display import _DisplayCollection
44 from _display import _DisplayAssembly
45 from _display import _DisplaySegment
46 from _display import _DisplayMolecule
47 from _display import _DisplayProtein
48 from _display import _DisplayNucleicAcid
49 from _display import _DisplayChain
50 from _display import _DisplayFragment
51 from _optimization import Optimization
52 from _optimization import _OptimizationConjugateGradients
53 from _optimization import _OptimizationRestraint
54 
55 class XMLRepresentation(object):
56  """Construct Representation from XML file"""
57  def __init__(self, filename):
58  #Define a dictionary with tags as keys and functions as values
59  self.handlers = {
60  'Universe':self._handle_universe,
61  'Collection':self._handle_collection,
62  'Assembly':self._handle_assembly,
63  'Segment':self._handle_segment,
64  'Molecule':self._handle_molecule,
65  'Protein':self._handle_protein,
66  'NucleicAcid':self._handle_nucleic_acid,
67  'Chain':self._handle_chain,
68  'Fragment':self._handle_fragment,
69  'AtomicRep':self._handle_atomic_rep,
70  'GeometricShapeRep':self._handle_geometric_shape_rep,
71  'Sphere':self._handle_sphere,
72  'InitialPosition':self._handle_initial_position}
73  self.filename = filename
74  self.base_dir = os.path.dirname(filename)
75  _document = open(filename).read()
76  self.dom = xml.dom.minidom.parseString(_document)
77  self.depth = 0
78 
79  def run(self):
80  """Return
81  <a href="classIMP_1_1restrainer_1_1representation_1_1Representation.html">
82  Representation</a>
83  object such that each node in the representation
84  corresponds to the node in the XML nodes"""
85  try:
86  representation_dom = self.dom.getElementsByTagName('Representation')[0]
87  except:
88  print "\"%s\" does not contain <Representation> tag." %(
89  self.filename)
90  print "Please check the input file.\nExit..."
91  raise
92  result = Representation()
93  for node in representation_dom.childNodes:
94  r = self._handle_node(node)
95  if r:
96  result._children.append(r)
97  return result
98 
99  def _handle_node(self, node):
100  #Return a proper function for the node
101  handler = self.handlers.get(node.nodeName, self._handle_nothing)
102  return handler(node)
103 
104  def _get_attributes(self, node):
105  #To store node attributes in python dictionary
106  attr_dict = dict()
107  attr_map = node.attributes
108  if attr_map:
109  for i in xrange(attr_map.length):
110  attr = attr_map.item(i)
111  attr_name = str(attr.name)
112  # make sure filenames are relative to XML directory
113  if attr_name.endswith('filename'):
114  attr_value = os.path.abspath(os.path.join(self.base_dir,
115  str(attr.value)))
116  else:
117  attr_value = str(attr.value)
118  attr_dict[attr_name] = attr_value
119  return attr_dict
120 
121  def _print_node_info(self, node):
122  #Printing node info for debugging purposes
123  attrs = self._get_attributes(node)
124  attr_list = ['%s=%s' %
125  (at_name, at_val) for (at_name, at_val) in attrs.iteritems()]
126  print '%s%s' % (' '*(self.depth + 1), ','.join(attr_list))
127 
128  def _handle_nothing(self, node):
129  #To ignore unwanted nodes
130  pass
131 
132  def _handle_universe(self, node):
133  #To create object for universe and all of its descendents
134  self.depth += 1
135  attrs = self._get_attributes(node)
136  result = _RepUniverse(attrs)
137  for child in node.childNodes:
138  r = self._handle_node(child)
139  if r:
140  result._children.append(r)
141  self.depth -= 1
142  return result
143 
144  def _handle_collection(self, node):
145  #To create object for collection and all of its descendents
146  self.depth += 1
147  attrs = self._get_attributes(node)
148  result = _RepCollection(attrs)
149  for child in node.childNodes:
150  r = self._handle_node(child)
151  if r:
152  result._children.append(r)
153  self.depth -= 1
154  return result
155 
156  def _handle_assembly(self, node):
157  #To create object for assembly and all of its descendents
158  self.depth += 1
159  attrs = self._get_attributes(node)
160  result = _RepAssembly(attrs)
161  for child in node.childNodes:
162  r = self._handle_node(child)
163  if r:
164  result._children.append(r)
165  self.depth -= 1
166  return result
167 
168  def _handle_segment(self, node):
169  #To create object for segment and all of its descendents
170  self.depth += 1
171  attrs = self._get_attributes(node)
172  result = _RepSegment(attrs)
173  for child in node.childNodes:
174  r = self._handle_node(child)
175  if r:
176  result._children.append(r)
177  self.depth -= 1
178  return result
179 
180  def _handle_molecule(self, node):
181  #To create object for molecule and all of its descendents
182  self.depth += 1
183  attrs = self._get_attributes(node)
184  result = _RepMolecule(attrs)
185  for child in node.childNodes:
186  r = self._handle_node(child)
187  if r:
188  result._children.append(r)
189  self.depth -= 1
190  return result
191 
192  def _handle_protein(self, node):
193  #To create object for protein and all of its descendents
194  self.depth += 1
195  attrs = self._get_attributes(node)
196  result = _RepProtein(attrs)
197  for child in node.childNodes:
198  r = self._handle_node(child)
199  if r:
200  result._children.append(r)
201  self.depth -= 1
202  return result
203 
204  def _handle_nucleic_acid(self, node):
205  #To create object for nucleic acid and all of its descendents
206  self.depth += 1
207  attrs = self._get_attributes(node)
208  result = _RepNucleicAcid(attrs)
209  for child in node.childNodes:
210  r = self._handle_node(child)
211  if r:
212  result._children.append(r)
213  self.depth -= 1
214  return result
215 
216  def _handle_chain(self, node):
217  #To create object for chain and all of its descendents
218  self.depth += 1
219  attrs = self._get_attributes(node)
220  result = _RepChain(attrs)
221  for child in node.childNodes:
222  r = self._handle_node(child)
223  if r:
224  result._children.append(r)
225  self.depth -= 1
226  return result
227 
228  def _handle_fragment(self, node):
229  #To create object for fragment and all of its descendents
230  self.depth += 1
231  attrs = self._get_attributes(node)
232  result = _RepFragment(attrs)
233  for child in node.childNodes:
234  r = self._handle_node(child)
235  if r:
236  result._children.append(r)
237  self.depth -= 1
238  return result
239 
240  def _handle_atomic_rep(self, node):
241  #To create object for atomic rep and all of its descendents
242  self.depth += 1
243  attrs = self._get_attributes(node)
244  result = _RepAtomicRep(attrs)
245  for child in node.childNodes:
246  r = self._handle_node(child)
247  if r:
248  result._children.append(r)
249  self.depth -= 1
250  return result
251 
252  def _handle_geometric_shape_rep(self, node):
253  #To create object for geometric shape rep and all of its descendents
254  self.depth += 1
255  attrs = self._get_attributes(node)
256  result = _RepGeometricShapeRep(attrs)
257  for child in node.childNodes:
258  r = self._handle_node(child)
259  if r:
260  result._children.append(r)
261  self.depth -= 1
262  return result
263 
264 
265  def _handle_sphere(self, node):
266  #To create object for sphere and all of its descendents
267  self.depth += 1
268  attrs = self._get_attributes(node)
269  result = _RepSphere(attrs)
270  for child in node.childNodes:
271  r = self._handle_node(child)
272  if r:
273  result._children.append(r)
274  self.depth -= 1
275  return result
276 
277 
278  def _handle_initial_position(self, node):
279  #To create object for initial position and all of its descendents
280  self.depth += 1
281  attrs = self._get_attributes(node)
282  result = _RepInitialPosition(attrs)
283  for child in node.childNodes:
284  r = self._handle_node(child)
285  if r:
286  result._children.append(r)
287  self.depth -= 1
288  return result
289 
290 class XMLDisplay(object):
291  """Construct Display from XML file"""
292  def __init__(self, filename):
293  self.handlers = {
294  'Universe':self._handle_universe,
295  'Collection':self._handle_collection,
296  'Assembly':self._handle_assembly,
297  'Segment':self._handle_segment,
298  'Molecule':self._handle_molecule,
299  'Protein':self._handle_protein,
300  'NucleicAcid':self._handle_nucleic_acid,
301  'Chain':self._handle_chain,
302  'Fragment':self._handle_fragment,
303  'Color':self._handle_color,
304  'Residue':self._handle_residue}
305  _document = open(filename).read()
306  self.dom = xml.dom.minidom.parseString(_document)
307  self.depth = 0
308 
309  def run(self):
310  """Return
311  <a href="classIMP_1_1restrainer_1_1display_1_1Display.html">
312  Display</a> object such that each node in the display
313  corresponds to the node in the XML nodes"""
314  display_dom = self.dom.getElementsByTagName('Display')[0]
315  result = Display()
316  for node in display_dom.childNodes:
317  r = self._handle_node(node)
318  if r:
319  result._children.append(r)
320  return result
321 
322  def _handle_node(self, node):
323  handler = self.handlers.get(node.nodeName, self._handle_nothing)
324  return handler(node)
325 
326  def _get_attributes(self, node):
327  attr_dict = dict()
328  attr_map = node.attributes
329  if attr_map:
330  for i in xrange(attr_map.length):
331  attr = attr_map.item(i)
332  attr_dict[str(attr.name)] = str(attr.value)
333  return attr_dict
334 
335  def _print_node_info(self, node):
336  attrs = self._get_attributes(node)
337  attr_list = ['%s=%s' %
338  (at_name, at_val) for (at_name, at_val) in attrs.iteritems()]
339  print '%s%s' % (' '*(self.depth + 1), ','.join(attr_list))
340 
341  def _handle_nothing(self, node):
342  pass
343 
344  def _handle_universe(self, node):
345  self.depth += 1
346  attrs = self._get_attributes(node)
347  result = _DisplayUniverse(attrs)
348  for child in node.childNodes:
349  r = self._handle_node(child)
350  if r:
351  result._children.append(r)
352  self.depth -= 1
353  return result
354 
355  def _handle_collection(self, node):
356  self.depth += 1
357  attrs = self._get_attributes(node)
358  result = _DisplayCollection(attrs)
359  for child in node.childNodes:
360  r = self._handle_node(child)
361  if r:
362  result._children.append(r)
363  self.depth -= 1
364  return result
365 
366  def _handle_assembly(self, node):
367  self.depth += 1
368  attrs = self._get_attributes(node)
369  result = _DisplayAssembly(attrs)
370  for child in node.childNodes:
371  r = self._handle_node(child)
372  if r:
373  result._children.append(r)
374  self.depth -= 1
375  return result
376 
377  def _handle_segment(self, node):
378  self.depth += 1
379  attrs = self._get_attributes(node)
380  result = _DisplaySegment(attrs)
381  for child in node.childNodes:
382  r = self._handle_node(child)
383  if r:
384  result._children.append(r)
385  self.depth -= 1
386  return result
387 
388  def _handle_molecule(self, node):
389  self.depth += 1
390  attrs = self._get_attributes(node)
391  result = _DisplayMolecule(attrs)
392  for child in node.childNodes:
393  r = self._handle_node(child)
394  if r:
395  result._children.append(r)
396  self.depth -= 1
397  return result
398 
399  def _handle_protein(self, node):
400  self.depth += 1
401  attrs = self._get_attributes(node)
402  result = _DisplayProtein(attrs)
403  for child in node.childNodes:
404  r = self._handle_node(child)
405  if r:
406  result._children.append(r)
407  self.depth -= 1
408  return result
409 
410  def _handle_nucleic_acid(self, node):
411  self.depth += 1
412  attrs = self._get_attributes(node)
413  result = _DisplayNucleicAcid(attrs)
414  for child in node.childNodes:
415  r = self._handle_node(child)
416  if r:
417  result._children.append(r)
418  self.depth -= 1
419  return result
420 
421  def _handle_chain(self, node):
422  self.depth += 1
423  attrs = self._get_attributes(node)
424  result = _DisplayChain(attrs)
425  for child in node.childNodes:
426  r = self._handle_node(child)
427  if r:
428  result._children.append(r)
429  self.depth -= 1
430  return result
431 
432  def _handle_fragment(self, node):
433  self.depth += 1
434  attrs = self._get_attributes(node)
435  result = _DisplayFragment(attrs)
436  for child in node.childNodes:
437  r = self._handle_node(child)
438  if r:
439  result._children.append(r)
440  self.depth -= 1
441  return result
442 
443  def _handle_residue(self, node):
444  self.depth += 1
445  attrs = self._get_attributes(node)
446  result = _DisplayResidue(attrs)
447  for child in node.childNodes:
448  r = self._handle_node(child)
449  if r:
450  result._children.append(r)
451  self.depth -= 1
452  return result
453 
454  def _handle_color(self, node):
455  self.depth += 1
456  attrs = self._get_attributes(node)
457  result = _DisplayColor(attrs)
458  for child in node.childNodes:
459  r = self._handle_node(child)
460  if r:
461  result._children.append(r)
462  self.depth -= 1
463  return result
464 
465 class XMLRestraint(object):
466  """Construct Restraint from XML file"""
467  def __init__(self, filename):
468  self.handlers = {
469  'Y2H':self._handle_y2h,
470  'Pulldown':self._handle_pulldown,
471  'RigidBody':self._handle_rigidbody,
472  'XrayStruc':self._handle_xray_struc,
473  'MSMS':self._handle_msms,
474  'Array':self._handle_array,
475  'Copurification':self._handle_copurification,
476  'CrossLink':self._handle_crosslink,
477  'Distance':self._handle_distance,
478  'Diameter':self._handle_diameter,
479  'ExcludedVolume':self._handle_excluded_volume,
480  'SAS':self._handle_sas,
481  'SAXS':self._handle_saxs,
482  'SANS':self._handle_sans,
483  'EM':self._handle_em,
484  'Restraint':self._handle_restraint,
485  'Particle':self._handle_particle,
486  'Source':self._handle_source,
487  'Author':self._handle_author,
488  'Journal':self._handle_journal,
489  'Title':self._handle_title,
490  'Year':self._handle_year}
491  self.base_dir = os.path.dirname(filename)
492  _document = open(filename).read()
493  self.dom = xml.dom.minidom.parseString(_document)
494  self.depth = 0
495 
496  def run(self):
497  """Return
498  <a href="classIMP_1_1restrainer_1_1restraint_1_1Restraint.html">
499  Restraint</a>
500  object such that each node in the restraint
501  corresponds to the node in the XML nodes"""
502  restraint_dom = self.dom.getElementsByTagName('RestraintSet')[0]
503  result = Restraint()
504  for node in restraint_dom.childNodes:
505  r = self._handle_node(node)
506  if r:
507  result._children.append(r)
508  return result
509 
510  def _handle_node(self, node):
511  handler = self.handlers.get(node.nodeName, self._handle_nothing)
512  return handler(node)
513 
514  def _get_text(self, node):
515  return node.firstChild.wholeText
516 
517  def _get_attributes(self, node):
518  attr_dict = dict()
519  attr_map = node.attributes
520  if attr_map:
521  for i in xrange(attr_map.length):
522  attr = attr_map.item(i)
523  attr_name = str(attr.name)
524  # make sure filenames are relative to XML directory
525  if attr_name.endswith('filename'):
526  attr_value = os.path.abspath(os.path.join(self.base_dir,
527  str(attr.value)))
528  else:
529  attr_value = str(attr.value)
530  attr_dict[attr_name] = attr_value
531  return attr_dict
532 
533  def _print_node_info(self, node):
534  attrs = self._get_attributes(node)
535  attr_list = ['%s=%s' %
536  (at_name, at_val) for (at_name, at_val) in attrs.iteritems()]
537  print '%s%s' % (' '*(self.depth + 1), ','.join(attr_list))
538 
539  def _handle_nothing(self, node):
540  pass
541 
542  def _handle_y2h(self, node):
543  self.depth += 1
544  attrs = self._get_attributes(node)
545  result = _RestraintY2H(attrs)
546  for child in node.childNodes:
547  r = self._handle_node(child)
548  if r:
549  result._children.append(r)
550  self.depth -= 1
551  return result
552 
553  def _handle_rigidbody(self, node):
554  self.depth += 1
555  attrs = self._get_attributes(node)
556  result = _RigidBodyRestraintNode(attrs)
557  for child in node.childNodes:
558  r = self._handle_node(child)
559  if r:
560  result._children.append(r)
561  self.depth -= 1
562  return result
563 
564  def _handle_excluded_volume(self, node):
565  self.depth += 1
566  attrs = self._get_attributes(node)
567  result = _RestraintExcludedVolume(attrs)
568  for child in node.childNodes:
569  r = self._handle_node(child)
570  if r:
571  result._children.append(r)
572  self.depth -= 1
573  return result
574 
575  def _handle_pulldown(self, node):
576  self.depth += 1
577  attrs = self._get_attributes(node)
578  result = _RestraintPulldown(attrs)
579  for child in node.childNodes:
580  r = self._handle_node(child)
581  if r:
582  result._children.append(r)
583  self.depth -= 1
584  return result
585 
586  def _handle_xray_struc(self, node):
587  self.depth += 1
588  attrs = self._get_attributes(node)
589  result = _RestraintXrayStruc(attrs)
590  for child in node.childNodes:
591  r = self._handle_node(child)
592  if r:
593  result._children.append(r)
594  self.depth -= 1
595  return result
596 
597  def _handle_msms(self, node):
598  self.depth += 1
599  attrs = self._get_attributes(node)
600  result = _RestraintMSMS(attrs)
601  for child in node.childNodes:
602  r = self._handle_node(child)
603  if r:
604  result._children.append(r)
605  self.depth -= 1
606  return result
607 
608  def _handle_array(self, node):
609  self.depth += 1
610  attrs = self._get_attributes(node)
611  result = _RestraintArray(attrs)
612  for child in node.childNodes:
613  r = self._handle_node(child)
614  if r:
615  result._children.append(r)
616  self.depth -= 1
617  return result
618 
619  def _handle_copurification(self, node):
620  self.depth += 1
621  attrs = self._get_attributes(node)
622  result = _RestraintCopurification(attrs)
623  for child in node.childNodes:
624  r = self._handle_node(child)
625  if r:
626  result._children.append(r)
627  self.depth -= 1
628  return result
629 
630  def _handle_crosslink(self, node):
631  self.depth += 1
632  attrs = self._get_attributes(node)
633  result = _RestraintCrossLink(attrs)
634  for child in node.childNodes:
635  r = self._handle_node(child)
636  if r:
637  result._children.append(r)
638  self.depth -= 1
639  return result
640 
641  def _handle_distance(self, node):
642  self.depth += 1
643  attrs = self._get_attributes(node)
644  result = _RestraintDistance(attrs)
645  for child in node.childNodes:
646  r = self._handle_node(child)
647  if r:
648  result._children.append(r)
649  self.depth -= 1
650  return result
651 
652  def _handle_diameter(self, node):
653  self.depth += 1
654  attrs = self._get_attributes(node)
655  result = _RestraintDiameter(attrs)
656  for child in node.childNodes:
657  r = self._handle_node(child)
658  if r:
659  result._children.append(r)
660  self.depth -= 1
661  return result
662 
663  def _handle_sas(self, node):
664  self.depth += 1
665  attrs = self._get_attributes(node)
666  result = _RestraintSAS(attrs)
667  for child in node.childNodes:
668  r = self._handle_node(child)
669  if r:
670  result._children.append(r)
671  self.depth -= 1
672  return result
673 
674  def _handle_saxs(self, node):
675  self.depth += 1
676  attrs = self._get_attributes(node)
677  result = _RestraintSAXS(attrs)
678  for child in node.childNodes:
679  r = self._handle_node(child)
680  if r:
681  result._children.append(r)
682  self.depth -= 1
683  return result
684 
685  def _handle_sans(self, node):
686  self.depth += 1
687  attrs = self._get_attributes(node)
688  result = _RestraintSANS(attrs)
689  for child in node.childNodes:
690  r = self._handle_node(child)
691  if r:
692  result._children.append(r)
693  self.depth -= 1
694  return result
695 
696  def _handle_em(self, node):
697  self.depth += 1
698  attrs = self._get_attributes(node)
699  result = _RestraintEM(attrs)
700  for child in node.childNodes:
701  r = self._handle_node(child)
702  if r:
703  result._children.append(r)
704  self.depth -= 1
705  return result
706 
707  def _handle_restraint(self, node):
708  self.depth += 1
709  attrs = self._get_attributes(node)
710  result = _RestraintRestraint(attrs)
711  for child in node.childNodes:
712  r = self._handle_node(child)
713  if r:
714  result._children.append(r)
715  self.depth -= 1
716  return result
717 
718  def _handle_particle(self, node):
719  self.depth += 1
720  attrs = self._get_attributes(node)
721  result = _RestraintParticle(attrs)
722  for child in node.childNodes:
723  r = self._handle_node(child)
724  if r:
725  result._children.append(r)
726  self.depth -= 1
727  return result
728 
729  def _handle_source(self, node):
730  self.depth += 1
731  attrs = self._get_attributes(node)
732  result = _RestraintSource(attrs)
733  for child in node.childNodes:
734  r = self._handle_node(child)
735  if r:
736  result._children.append(r)
737  self.depth -= 1
738  return result
739 
740  def _handle_author(self, node):
741  self.depth += 1
742  attrs = self._get_attributes(node)
743  result = _RestraintAuthor(attrs)
744  for child in node.childNodes:
745  r = self._handle_node(child)
746  if r:
747  result._children.append(r)
748  self.depth -= 1
749  return result
750 
751  def _handle_journal(self, node):
752  self.depth += 1
753  attrs = self._get_attributes(node)
754  text = self._get_text(node)
755  result = _RestraintJournal(attrs, text)
756  for child in node.childNodes:
757  r = self._handle_node(child)
758  if r:
759  result._children.append(r)
760  self.depth -= 1
761  return result
762 
763  def _handle_title(self, node):
764  self.depth += 1
765  attrs = self._get_attributes(node)
766  text = self._get_text(node)
767  result = _RestraintTitle(attrs, text)
768  for child in node.childNodes:
769  r = self._handle_node(child)
770  if r:
771  result._children.append(r)
772  self.depth -= 1
773  return result
774 
775  def _handle_year(self, node):
776  self.depth += 1
777  attrs = self._get_attributes(node)
778  text = self._get_text(node)
779  result = _RestraintYear(attrs, text)
780  for child in node.childNodes:
781  r = self._handle_node(child)
782  if r:
783  result._children.append(r)
784  self.depth -= 1
785  return result
786 
787 
788 class XMLOptimization(object):
789  """Construct Optimization from XML file"""
790  def __init__(self, filename):
791  self.handlers = {
792  'ConjugateGradients':self._handle_conjugate_gradients,
793  'Restraint':self._handle_restraint}
794  _document = open(filename).read()
795  self.dom = xml.dom.minidom.parseString(_document)
796  self.depth = 0
797 
798  def run(self):
799  opt_dom = self.dom.getElementsByTagName('Optimization')[0]
800  result = Optimization()
801  for node in opt_dom.childNodes:
802  r = self._handle_node(node)
803  if r:
804  result._children.append(r)
805  return result
806 
807  def _handle_node(self, node):
808  handler = self.handlers.get(node.nodeName, self._handle_nothing)
809  return handler(node)
810 
811  def _get_attributes(self, node):
812  attr_dict = dict()
813  attr_map = node.attributes
814  if attr_map:
815  for i in xrange(attr_map.length):
816  attr = attr_map.item(i)
817  attr_dict[str(attr.name)] = str(attr.value)
818  return attr_dict
819 
820  def _get_text(self, node):
821  return ''
822 
823  def _print_node_info(self, node):
824  attrs = self._get_attributes(node)
825  attr_list = ['%s=%s' %
826  (at_name, at_val) for (at_name, at_val) in attrs.iteritems()]
827  print '%s%s' % (' '*(self.depth + 1), ','.join(attr_list))
828 
829  def _handle_nothing(self, node):
830  pass
831 
832  def _handle_conjugate_gradients(self, node):
833  self.depth += 1
834  attrs = self._get_attributes(node)
835  text = self._get_text(node)
836  result = _OptimizationConjugateGradients(attrs, text)
837  for child in node.childNodes:
838  r = self._handle_node(child)
839  if r:
840  result._children.append(r)
841  self.depth -= 1
842  return result
843 
844  def _handle_restraint(self, node):
845  self.depth += 1
846  attrs = self._get_attributes(node)
847  text = self._get_text(node)
848  result = _OptimizationRestraint(attrs, text)
849  for child in node.childNodes:
850  r = self._handle_node(child)
851  if r:
852  result._children.append(r)
853  self.depth -= 1
854  return result
IMP::kernel::Restraint Restraint