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
55 class XMLRepresentation(object):
56 """Construct Representation from XML file"""
57 def __init__(self, filename):
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)
81 <a href="classIMP_1_1restrainer_1_1representation_1_1Representation.html">
83 object such that each node in the representation
84 corresponds to the node in the XML nodes"""
86 representation_dom = self.dom.getElementsByTagName(
'Representation')[0]
88 print "\"%s\" does not contain <Representation> tag." %(
90 print "Please check the input file.\nExit..."
92 result = Representation()
93 for node
in representation_dom.childNodes:
94 r = self._handle_node(node)
96 result._children.append(r)
99 def _handle_node(self, node):
101 handler = self.handlers.get(node.nodeName, self._handle_nothing)
104 def _get_attributes(self, node):
107 attr_map = node.attributes
109 for i
in xrange(attr_map.length):
110 attr = attr_map.item(i)
111 attr_name = str(attr.name)
113 if attr_name.endswith(
'filename'):
114 attr_value = os.path.abspath(os.path.join(self.base_dir,
117 attr_value = str(attr.value)
118 attr_dict[attr_name] = attr_value
121 def _print_node_info(self, node):
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))
128 def _handle_nothing(self, node):
132 def _handle_universe(self, node):
135 attrs = self._get_attributes(node)
136 result = _RepUniverse(attrs)
137 for child
in node.childNodes:
138 r = self._handle_node(child)
140 result._children.append(r)
144 def _handle_collection(self, node):
147 attrs = self._get_attributes(node)
148 result = _RepCollection(attrs)
149 for child
in node.childNodes:
150 r = self._handle_node(child)
152 result._children.append(r)
156 def _handle_assembly(self, node):
159 attrs = self._get_attributes(node)
160 result = _RepAssembly(attrs)
161 for child
in node.childNodes:
162 r = self._handle_node(child)
164 result._children.append(r)
168 def _handle_segment(self, node):
171 attrs = self._get_attributes(node)
172 result = _RepSegment(attrs)
173 for child
in node.childNodes:
174 r = self._handle_node(child)
176 result._children.append(r)
180 def _handle_molecule(self, node):
183 attrs = self._get_attributes(node)
184 result = _RepMolecule(attrs)
185 for child
in node.childNodes:
186 r = self._handle_node(child)
188 result._children.append(r)
192 def _handle_protein(self, node):
195 attrs = self._get_attributes(node)
196 result = _RepProtein(attrs)
197 for child
in node.childNodes:
198 r = self._handle_node(child)
200 result._children.append(r)
204 def _handle_nucleic_acid(self, node):
207 attrs = self._get_attributes(node)
208 result = _RepNucleicAcid(attrs)
209 for child
in node.childNodes:
210 r = self._handle_node(child)
212 result._children.append(r)
216 def _handle_chain(self, node):
219 attrs = self._get_attributes(node)
220 result = _RepChain(attrs)
221 for child
in node.childNodes:
222 r = self._handle_node(child)
224 result._children.append(r)
228 def _handle_fragment(self, node):
231 attrs = self._get_attributes(node)
232 result = _RepFragment(attrs)
233 for child
in node.childNodes:
234 r = self._handle_node(child)
236 result._children.append(r)
240 def _handle_atomic_rep(self, node):
243 attrs = self._get_attributes(node)
244 result = _RepAtomicRep(attrs)
245 for child
in node.childNodes:
246 r = self._handle_node(child)
248 result._children.append(r)
252 def _handle_geometric_shape_rep(self, node):
255 attrs = self._get_attributes(node)
256 result = _RepGeometricShapeRep(attrs)
257 for child
in node.childNodes:
258 r = self._handle_node(child)
260 result._children.append(r)
265 def _handle_sphere(self, node):
268 attrs = self._get_attributes(node)
269 result = _RepSphere(attrs)
270 for child
in node.childNodes:
271 r = self._handle_node(child)
273 result._children.append(r)
278 def _handle_initial_position(self, node):
281 attrs = self._get_attributes(node)
282 result = _RepInitialPosition(attrs)
283 for child
in node.childNodes:
284 r = self._handle_node(child)
286 result._children.append(r)
290 class XMLDisplay(object):
291 """Construct Display from XML file"""
292 def __init__(self, filename):
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)
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]
316 for node
in display_dom.childNodes:
317 r = self._handle_node(node)
319 result._children.append(r)
322 def _handle_node(self, node):
323 handler = self.handlers.get(node.nodeName, self._handle_nothing)
326 def _get_attributes(self, node):
328 attr_map = node.attributes
330 for i
in xrange(attr_map.length):
331 attr = attr_map.item(i)
332 attr_dict[str(attr.name)] = str(attr.value)
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))
341 def _handle_nothing(self, node):
344 def _handle_universe(self, node):
346 attrs = self._get_attributes(node)
347 result = _DisplayUniverse(attrs)
348 for child
in node.childNodes:
349 r = self._handle_node(child)
351 result._children.append(r)
355 def _handle_collection(self, node):
357 attrs = self._get_attributes(node)
358 result = _DisplayCollection(attrs)
359 for child
in node.childNodes:
360 r = self._handle_node(child)
362 result._children.append(r)
366 def _handle_assembly(self, node):
368 attrs = self._get_attributes(node)
369 result = _DisplayAssembly(attrs)
370 for child
in node.childNodes:
371 r = self._handle_node(child)
373 result._children.append(r)
377 def _handle_segment(self, node):
379 attrs = self._get_attributes(node)
380 result = _DisplaySegment(attrs)
381 for child
in node.childNodes:
382 r = self._handle_node(child)
384 result._children.append(r)
388 def _handle_molecule(self, node):
390 attrs = self._get_attributes(node)
391 result = _DisplayMolecule(attrs)
392 for child
in node.childNodes:
393 r = self._handle_node(child)
395 result._children.append(r)
399 def _handle_protein(self, node):
401 attrs = self._get_attributes(node)
402 result = _DisplayProtein(attrs)
403 for child
in node.childNodes:
404 r = self._handle_node(child)
406 result._children.append(r)
410 def _handle_nucleic_acid(self, node):
412 attrs = self._get_attributes(node)
413 result = _DisplayNucleicAcid(attrs)
414 for child
in node.childNodes:
415 r = self._handle_node(child)
417 result._children.append(r)
421 def _handle_chain(self, node):
423 attrs = self._get_attributes(node)
424 result = _DisplayChain(attrs)
425 for child
in node.childNodes:
426 r = self._handle_node(child)
428 result._children.append(r)
432 def _handle_fragment(self, node):
434 attrs = self._get_attributes(node)
435 result = _DisplayFragment(attrs)
436 for child
in node.childNodes:
437 r = self._handle_node(child)
439 result._children.append(r)
443 def _handle_residue(self, node):
445 attrs = self._get_attributes(node)
446 result = _DisplayResidue(attrs)
447 for child
in node.childNodes:
448 r = self._handle_node(child)
450 result._children.append(r)
454 def _handle_color(self, node):
456 attrs = self._get_attributes(node)
457 result = _DisplayColor(attrs)
458 for child
in node.childNodes:
459 r = self._handle_node(child)
461 result._children.append(r)
465 class XMLRestraint(object):
466 """Construct Restraint from XML file"""
467 def __init__(self, filename):
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)
498 <a href="classIMP_1_1restrainer_1_1restraint_1_1Restraint.html">
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]
504 for node
in restraint_dom.childNodes:
505 r = self._handle_node(node)
507 result._children.append(r)
510 def _handle_node(self, node):
511 handler = self.handlers.get(node.nodeName, self._handle_nothing)
514 def _get_text(self, node):
515 return node.firstChild.wholeText
517 def _get_attributes(self, node):
519 attr_map = node.attributes
521 for i
in xrange(attr_map.length):
522 attr = attr_map.item(i)
523 attr_name = str(attr.name)
525 if attr_name.endswith(
'filename'):
526 attr_value = os.path.abspath(os.path.join(self.base_dir,
529 attr_value = str(attr.value)
530 attr_dict[attr_name] = attr_value
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))
539 def _handle_nothing(self, node):
542 def _handle_y2h(self, node):
544 attrs = self._get_attributes(node)
545 result = _RestraintY2H(attrs)
546 for child
in node.childNodes:
547 r = self._handle_node(child)
549 result._children.append(r)
553 def _handle_rigidbody(self, node):
555 attrs = self._get_attributes(node)
556 result = _RigidBodyRestraintNode(attrs)
557 for child
in node.childNodes:
558 r = self._handle_node(child)
560 result._children.append(r)
564 def _handle_excluded_volume(self, node):
566 attrs = self._get_attributes(node)
567 result = _RestraintExcludedVolume(attrs)
568 for child
in node.childNodes:
569 r = self._handle_node(child)
571 result._children.append(r)
575 def _handle_pulldown(self, node):
577 attrs = self._get_attributes(node)
578 result = _RestraintPulldown(attrs)
579 for child
in node.childNodes:
580 r = self._handle_node(child)
582 result._children.append(r)
586 def _handle_xray_struc(self, node):
588 attrs = self._get_attributes(node)
589 result = _RestraintXrayStruc(attrs)
590 for child
in node.childNodes:
591 r = self._handle_node(child)
593 result._children.append(r)
597 def _handle_msms(self, node):
599 attrs = self._get_attributes(node)
600 result = _RestraintMSMS(attrs)
601 for child
in node.childNodes:
602 r = self._handle_node(child)
604 result._children.append(r)
608 def _handle_array(self, node):
610 attrs = self._get_attributes(node)
611 result = _RestraintArray(attrs)
612 for child
in node.childNodes:
613 r = self._handle_node(child)
615 result._children.append(r)
619 def _handle_copurification(self, node):
621 attrs = self._get_attributes(node)
622 result = _RestraintCopurification(attrs)
623 for child
in node.childNodes:
624 r = self._handle_node(child)
626 result._children.append(r)
630 def _handle_crosslink(self, node):
632 attrs = self._get_attributes(node)
633 result = _RestraintCrossLink(attrs)
634 for child
in node.childNodes:
635 r = self._handle_node(child)
637 result._children.append(r)
641 def _handle_distance(self, node):
643 attrs = self._get_attributes(node)
644 result = _RestraintDistance(attrs)
645 for child
in node.childNodes:
646 r = self._handle_node(child)
648 result._children.append(r)
652 def _handle_diameter(self, node):
654 attrs = self._get_attributes(node)
655 result = _RestraintDiameter(attrs)
656 for child
in node.childNodes:
657 r = self._handle_node(child)
659 result._children.append(r)
663 def _handle_sas(self, node):
665 attrs = self._get_attributes(node)
666 result = _RestraintSAS(attrs)
667 for child
in node.childNodes:
668 r = self._handle_node(child)
670 result._children.append(r)
674 def _handle_saxs(self, node):
676 attrs = self._get_attributes(node)
677 result = _RestraintSAXS(attrs)
678 for child
in node.childNodes:
679 r = self._handle_node(child)
681 result._children.append(r)
685 def _handle_sans(self, node):
687 attrs = self._get_attributes(node)
688 result = _RestraintSANS(attrs)
689 for child
in node.childNodes:
690 r = self._handle_node(child)
692 result._children.append(r)
696 def _handle_em(self, node):
698 attrs = self._get_attributes(node)
699 result = _RestraintEM(attrs)
700 for child
in node.childNodes:
701 r = self._handle_node(child)
703 result._children.append(r)
707 def _handle_restraint(self, node):
709 attrs = self._get_attributes(node)
710 result = _RestraintRestraint(attrs)
711 for child
in node.childNodes:
712 r = self._handle_node(child)
714 result._children.append(r)
718 def _handle_particle(self, node):
720 attrs = self._get_attributes(node)
721 result = _RestraintParticle(attrs)
722 for child
in node.childNodes:
723 r = self._handle_node(child)
725 result._children.append(r)
729 def _handle_source(self, node):
731 attrs = self._get_attributes(node)
732 result = _RestraintSource(attrs)
733 for child
in node.childNodes:
734 r = self._handle_node(child)
736 result._children.append(r)
740 def _handle_author(self, node):
742 attrs = self._get_attributes(node)
743 result = _RestraintAuthor(attrs)
744 for child
in node.childNodes:
745 r = self._handle_node(child)
747 result._children.append(r)
751 def _handle_journal(self, node):
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)
759 result._children.append(r)
763 def _handle_title(self, node):
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)
771 result._children.append(r)
775 def _handle_year(self, node):
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)
783 result._children.append(r)
788 class XMLOptimization(object):
789 """Construct Optimization from XML file"""
790 def __init__(self, filename):
792 'ConjugateGradients':self._handle_conjugate_gradients,
793 'Restraint':self._handle_restraint}
794 _document = open(filename).read()
795 self.dom = xml.dom.minidom.parseString(_document)
799 opt_dom = self.dom.getElementsByTagName(
'Optimization')[0]
800 result = Optimization()
801 for node
in opt_dom.childNodes:
802 r = self._handle_node(node)
804 result._children.append(r)
807 def _handle_node(self, node):
808 handler = self.handlers.get(node.nodeName, self._handle_nothing)
811 def _get_attributes(self, node):
813 attr_map = node.attributes
815 for i
in xrange(attr_map.length):
816 attr = attr_map.item(i)
817 attr_dict[str(attr.name)] = str(attr.value)
820 def _get_text(self, node):
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))
829 def _handle_nothing(self, node):
832 def _handle_conjugate_gradients(self, node):
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)
840 result._children.append(r)
844 def _handle_restraint(self, node):
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)
852 result._children.append(r)