Пример #1
0
    def from_xml(self, diff_tensor_node, file_version=1):
        """Recreate the diffusion tensor data structure from the XML diffusion tensor node.

        @param diff_tensor_node:    The diffusion tensor XML node.
        @type diff_tensor_node:     xml.dom.minicompat.Element instance
        @keyword file_version:      The relax XML version of the XML file.
        @type file_version:         int
        """

        # First set the diffusion type.  Doing this first is essential for the proper reconstruction of the object.
        self.__dict__['type'] = str(diff_tensor_node.getAttribute('type'))

        # A temporary object to pack the structures from the XML data into.
        temp_obj = Element()

        # Recreate all the other data structures (into the temporary object).
        xml_to_object(diff_tensor_node, temp_obj, file_version=file_version)

        # Loop over all modifiable objects in the temporary object and make soft copies of them.
        for name in self._mod_attr:
            # Skip if missing from the object.
            if not hasattr(temp_obj, name):
                continue

            # The category.
            if search('_err$', name):
                category = 'err'
                param = name.replace('_err', '')
            elif search('_sim$', name):
                category = 'sim'
                param = name.replace('_sim', '')
            else:
                category = 'val'
                param = name

            # Get the object.
            value = getattr(temp_obj, name)

            # Normal parameters.
            if category == 'val':
                self.set(param=param, value=value)

            # Errors.
            elif category == 'err':
                self.set(param=param, value=value, category='err')

            # Simulation objects objects.
            else:
                # Recreate the list elements.
                for i in range(len(value)):
                    self.set(param=param,
                             value=value[i],
                             category='sim',
                             sim_index=i)

        # Delete the temporary object.
        del temp_obj
Пример #2
0
    def add(self, type=None):
        """Add a new analysis type.

        @keyword type:  The analysis type.  This can be currently one of 'noe', 'r1', 'r2', or 'model-free'.
        @type type:     str
        @return:        The index of the data container added to the list.
        @rtype:         int
        """

        # Append an empty element.
        self.append(Element(name='analysis', desc='GUI information for a relax analysis'))

        # Set the analysis type.
        self[-1].analysis_type = type

        # Return the index of the container.
        return len(self)-1
Пример #3
0
    def from_xml(self, align_tensor_super_node, file_version=1):
        """Recreate the alignment tensor data structure from the XML alignment tensor node.

        @param align_tensor_super_node:     The alignment tensor XML nodes.
        @type align_tensor_super_node:      xml.dom.minicompat.Element instance
        @keyword file_version:              The relax XML version of the XML file.
        @type file_version:                 int
        """

        # Recreate all the alignment tensor data structures.
        xml_to_object(align_tensor_super_node,
                      self,
                      file_version=file_version,
                      blacklist=['align_tensor'])

        # Get the individual tensors.
        align_tensor_nodes = align_tensor_super_node.getElementsByTagName(
            'align_tensor')

        # Loop over the child nodes.
        for align_tensor_node in align_tensor_nodes:
            # Add the alignment tensor data container.
            self.add_item(align_tensor_node.getAttribute('name'))

            # A temporary object to pack the structures from the XML data into.
            temp_obj = Element()

            # Recreate all the other data structures (into the temporary object).
            xml_to_object(align_tensor_node,
                          temp_obj,
                          file_version=file_version)

            # Loop over all modifiable objects in the temporary object and make soft copies of them.
            for name in self[-1]._mod_attr:
                # Skip if missing from the object.
                if not hasattr(temp_obj, name):
                    continue

                # The category.
                if search('_err$', name):
                    category = 'err'
                    param = name.replace('_err', '')
                elif search('_sim$', name):
                    category = 'sim'
                    param = name.replace('_sim', '')
                else:
                    category = 'val'
                    param = name

                # Get the object.
                value = getattr(temp_obj, name)

                # Normal parameters.
                if category == 'val':
                    self[-1].set(param=param,
                                 value=value,
                                 category=category,
                                 update=False)

                # Errors.
                elif category == 'err':
                    self[-1].set(param=param,
                                 value=value,
                                 category=category,
                                 update=False)

                # Simulation objects objects.
                else:
                    # Set the simulation number if needed.
                    if not hasattr(self[-1],
                                   '_sim_num') or self[-1]._sim_num == None:
                        self[-1].set_sim_num(len(value))

                    # Recreate the list elements.
                    for i in range(len(value)):
                        self[-1].set(param=param,
                                     value=value[i],
                                     category=category,
                                     sim_index=i,
                                     update=False)

                # Update the data structures.
                for target, update_if_set, depends in dependency_generator():
                    self[-1]._update_object(param, target, update_if_set,
                                            depends, category)

            # Delete the temporary object.
            del temp_obj