Пример #1
0
    def to_xml(self, doc, element):
        """Create XML elements for each model.

        @param doc:     The XML document object.
        @type doc:      xml.dom.minidom.Document instance
        @param element: The element to add the displacement XML elements to.
        @type element:  XML element object
        """

        # Loop over the starting models.
        start_models = sorted(self._translation_vector.keys())
        for id_from in start_models:
            # Loop over the ending models.
            end_models = sorted(self._translation_vector[id_from].keys())
            for id_to in end_models:
                # Create an XML element for each pair.
                pair_element = doc.createElement('pair')
                element.appendChild(pair_element)

                # Set the attributes.
                pair_element.setAttribute('desc', 'The displacement from model %s to model %s' % (id_from, id_to))
                pair_element.setAttribute('id_from', id_from)
                pair_element.setAttribute('id_to', id_to)

                # The objects to store.
                obj_names = [
                    '_translation_vector',
                    '_translation_distance',
                    '_rotation_matrix',
                    '_rotation_axis',
                    '_rotation_angle'
                ]

                # Store the objects.
                for i in range(len(obj_names)):
                    # Create a new element for this object, and add it to the main element.
                    sub_elem = doc.createElement(obj_names[i][1:])
                    pair_element.appendChild(sub_elem)

                    # Get the sub-object.
                    subobj = getattr(self, obj_names[i])[id_from][id_to]

                    # Add the value to the sub element.
                    object_to_xml(doc, sub_elem, value=subobj)
Пример #2
0
    def to_xml(self, doc, element):
        """Create XML elements for each model.

        @param doc:     The XML document object.
        @type doc:      xml.dom.minidom.Document instance
        @param element: The element to add the displacement XML elements to.
        @type element:  XML element object
        """

        # Loop over the starting models.
        start_models = sorted(self._translation_vector.keys())
        for id_from in start_models:
            # Loop over the ending models.
            end_models = sorted(self._translation_vector[id_from].keys())
            for id_to in end_models:
                # Create an XML element for each pair.
                pair_element = doc.createElement('pair')
                element.appendChild(pair_element)

                # Set the attributes.
                pair_element.setAttribute(
                    'desc', 'The displacement from model %s to model %s' %
                    (id_from, id_to))
                pair_element.setAttribute('id_from', id_from)
                pair_element.setAttribute('id_to', id_to)

                # The objects to store.
                obj_names = [
                    '_translation_vector', '_translation_distance',
                    '_rotation_matrix', '_rotation_axis', '_rotation_angle'
                ]

                # Store the objects.
                for i in range(len(obj_names)):
                    # Create a new element for this object, and add it to the main element.
                    sub_elem = doc.createElement(obj_names[i][1:])
                    pair_element.appendChild(sub_elem)

                    # Get the sub-object.
                    subobj = getattr(self, obj_names[i])[id_from][id_to]

                    # Add the value to the sub element.
                    object_to_xml(doc, sub_elem, value=subobj)
Пример #3
0
    def to_xml(self, doc, element, pipe_type=None):
        """Create XML elements for each spin.

        @param doc:         The XML document object.
        @type doc:          xml.dom.minidom.Document instance
        @param element:     The element to add the spin XML elements to.
        @type element:      XML element object
        @keyword pipe_type: The type of the pipe being converted to XML.
        @type pipe_type:    str
        """

        # The specific analysis API object.
        api = specific_analyses.api.return_api(analysis_type=pipe_type)

        # Loop over the containers.
        for i in range(len(self)):
            # Create an XML element for this container and add it to the higher level element.
            interatom_element = doc.createElement('interatomic')
            element.appendChild(interatom_element)

            # Set the spin attributes.
            interatom_element.setAttribute('desc',
                                           'Interatomic data container')
            interatom_element.setAttribute('spin_id1', str(self[i].spin_id1))
            interatom_element.setAttribute('spin_id2', str(self[i].spin_id2))

            # Get the specific object names and loop over them to get their descriptions.
            object_info = []
            try:
                for name in api.data_names(error_names=True, sim_names=True):
                    # Get the description.
                    if hasattr(api, 'return_data_desc'):
                        desc = api.return_data_desc(name)
                    else:
                        desc = None

                    # Append the two.
                    object_info.append([name, desc])
            except RelaxImplementError:
                pass

            # Add the ordered objects.
            blacklist = []
            for name, desc in object_info:
                # Add the name to the blacklist.
                blacklist.append(name)

                # Skip the object if it is missing from the InteratomContainer.
                if not hasattr(self[i], name):
                    continue

                # Create a new element for this object, and add it to the main element.
                sub_element = doc.createElement(name)
                interatom_element.appendChild(sub_element)

                # Add the object description.
                if desc:
                    sub_element.setAttribute('desc', desc)

                # Get the object.
                object = getattr(self[i], name)

                # Convert to XML.
                object_to_xml(doc, sub_element, value=object)

            # Add all simple python objects within the InteratomContainer to the XML element.
            fill_object_contents(doc,
                                 interatom_element,
                                 object=self[i],
                                 blacklist=['spin_id1', 'spin_id2'] +
                                 blacklist +
                                 list(self[i].__class__.__dict__.keys()))
Пример #4
0
    def to_xml(self, doc, element, pipe_type=None):
        """Create XML elements for each spin.

        @param doc:         The XML document object.
        @type doc:          xml.dom.minidom.Document instance
        @param element:     The element to add the spin XML elements to.
        @type element:      XML element object
        @keyword pipe_type: The type of the pipe being converted to XML.
        @type pipe_type:    str
        """

        # The specific analysis API object.
        api = specific_analyses.api.return_api(analysis_type=pipe_type)

        # Loop over the spins.
        for i in range(len(self)):
            # Create an XML element for this spin and add it to the higher level element.
            spin_element = doc.createElement('spin')
            element.appendChild(spin_element)

            # Set the spin attributes.
            spin_element.setAttribute('desc', 'Spin container')
            spin_element.setAttribute('name', str(self[i].name))
            spin_element.setAttribute('num', str(self[i].num))

            # Get the spin specific object names and loop over them to get their descriptions.
            object_info = []
            try:
                for name in api.data_names(error_names=True, sim_names=True):
                    # Get the description.
                    if hasattr(api, 'return_data_desc'):
                        desc = api.return_data_desc(name)
                    else:
                        desc = None

                    # Append the two.
                    object_info.append([name, desc])
            except RelaxImplementError:
                pass

            # Add the ordered objects.
            blacklist = []
            for name, desc in object_info:
                # Add the name to the blacklist.
                blacklist.append(name)

                # Skip the object if it is missing from the SpinContainer.
                if not hasattr(self[i], name):
                    continue

                # Create a new element for this object, and add it to the main element.
                sub_element = doc.createElement(name)
                spin_element.appendChild(sub_element)

                # Add the object description.
                if desc:
                    sub_element.setAttribute('desc', desc)

                # Get the object.
                object = getattr(self[i], name)

                # Convert to XML.
                object_to_xml(doc, sub_element, value=object)

            # Add all simple python objects within the SpinContainer to the XML element.
            fill_object_contents(doc, spin_element, object=self[i], blacklist=['name', 'num', 'spin'] + blacklist + list(self[i].__class__.__dict__.keys()))