Esempio n. 1
0
    def from_xml(self, spin_nodes, file_version=None):
        """Recreate a spin list data structure from the XML spin nodes.

        @param spin_nodes:      The spin XML nodes.
        @type spin_nodes:       xml.dom.minicompat.NodeList instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Test if empty.
        if not self.is_empty():
            raise RelaxFromXMLNotEmptyError(self.__class__.__name__)

        # Loop over the spins.
        for spin_node in spin_nodes:
            # Get the spin details and add the spin to the SpinList structure.
            name = str(spin_node.getAttribute('name'))
            if name == 'None':
                name = None
            num = eval(spin_node.getAttribute('num'))
            self.add_item(spin_name=name, spin_num=num)

            # Recreate the current spin container.
            xml_to_object(spin_node, self[-1], file_version=file_version)

            # Backwards compatibility transformations.
            self[-1]._back_compat_hook(file_version)
Esempio n. 2
0
    def from_xml(self, spin_nodes, file_version=None):
        """Recreate a spin list data structure from the XML spin nodes.

        @param spin_nodes:      The spin XML nodes.
        @type spin_nodes:       xml.dom.minicompat.NodeList instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Test if empty.
        if not self.is_empty():
            raise RelaxFromXMLNotEmptyError(self.__class__.__name__)

        # Loop over the spins.
        for spin_node in spin_nodes:
            # Get the spin details and add the spin to the SpinList structure.
            name = str(spin_node.getAttribute('name'))
            if name == 'None':
                name = None
            num = eval(spin_node.getAttribute('num'))

            # Get the spin details and add the spin to the SpinList structure.
            self.add_item(spin_name=name, spin_num=num)

            # Recreate the current spin container.
            xml_to_object(spin_node, self[-1], file_version=file_version)

            # Backwards compatibility transformations.
            self[-1]._back_compat_hook(file_version)
Esempio n. 3
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
Esempio n. 4
0
    def from_xml(self, mol_node, file_version=1):
        """Recreate the MolContainer from the XML molecule node.

        @param mol_node:        The molecule XML node.
        @type mol_node:         xml.dom.minicompat.NodeList instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Recreate the current molecule container.
        xml_to_object(mol_node, self, file_version=file_version)
Esempio n. 5
0
    def from_xml(self, super_node, file_version=1):
        """Recreate the element data structure from the XML element node.

        @param super_node:      The element XML node.
        @type 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 other data structures.
        xml_to_object(super_node, self, file_version=file_version)
Esempio n. 6
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
Esempio n. 7
0
    def from_xml(self, super_node, file_version=1):
        """Recreate the element data structure from the XML element node.

        @param super_node:      The element XML node.
        @type 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 other data structures.
        xml_to_object(super_node, self, file_version=file_version)
Esempio n. 8
0
    def from_xml(self, mol_node, file_version=1):
        """Recreate the MolContainer from the XML molecule node.

        @param mol_node:        The molecule XML node.
        @type mol_node:         xml.dom.minicompat.NodeList instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Recreate the current molecule container.
        xml_to_object(mol_node, self, file_version=file_version)
Esempio n. 9
0
    def from_xml(self, str_node, dir=None, file_version=1):
        """Recreate the structural object from the XML structural object node.

        @param str_node:        The structural object XML node.
        @type str_node:         xml.dom.minicompat.Element instance
        @keyword dir:           The name of the directory containing the results file.
        @type dir:              str
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Get the pairs of displacements.
        pair_nodes = str_node.getElementsByTagName('pair')

        # Loop over the pairs.
        for pair_node in pair_nodes:
            # Get the two models.
            id_from = str(pair_node.getAttribute('id_from'))
            id_to = str(pair_node.getAttribute('id_to'))

            # Initialise structures if necessary.
            if not id_from in self._translation_vector:
                self._translation_vector[id_from] = {}
            if not id_from in self._translation_distance:
                self._translation_distance[id_from] = {}
            if not id_from in self._rotation_matrix:
                self._rotation_matrix[id_from] = {}
            if not id_from in self._rotation_axis:
                self._rotation_axis[id_from] = {}
            if not id_from in self._rotation_angle:
                self._rotation_angle[id_from] = {}

            # A temporary container to place the Python objects into.
            cont = ModelContainer()

            # Recreate the Python objects.
            xml_to_object(pair_node, cont, file_version=file_version)

            # Repackage the data.
            for name in [
                    'translation_vector', 'translation_distance',
                    'rotation_matrix', 'rotation_axis', 'rotation_angle'
            ]:
                # The objects.
                obj = getattr(self, '_' + name)
                obj_temp = getattr(cont, name)

                # Store.
                obj[id_from][id_to] = obj_temp
Esempio n. 10
0
    def from_xml(self, str_node, dir=None, file_version=1):
        """Recreate the structural object from the XML structural object node.

        @param str_node:        The structural object XML node.
        @type str_node:         xml.dom.minicompat.Element instance
        @keyword dir:           The name of the directory containing the results file.
        @type dir:              str
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Get the pairs of displacements.
        pair_nodes = str_node.getElementsByTagName('pair')

        # Loop over the pairs.
        for pair_node in pair_nodes:
            # Get the two models.
            id_from = str(pair_node.getAttribute('id_from'))
            id_to = str(pair_node.getAttribute('id_to'))

            # Initialise structures if necessary.
            if not id_from in self._translation_vector:
                self._translation_vector[id_from] = {}
            if not id_from in self._translation_distance:
                self._translation_distance[id_from] = {}
            if not id_from in self._rotation_matrix:
                self._rotation_matrix[id_from] = {}
            if not id_from in self._rotation_axis:
                self._rotation_axis[id_from] = {}
            if not id_from in self._rotation_angle:
                self._rotation_angle[id_from] = {}

            # A temporary container to place the Python objects into.
            cont = ModelContainer()

            # Recreate the Python objects.
            xml_to_object(pair_node, cont, file_version=file_version)

            # Repackage the data.
            for name in ['translation_vector', 'translation_distance', 'rotation_matrix', 'rotation_axis', 'rotation_angle']:
                # The objects.
                obj = getattr(self, '_'+name)
                obj_temp = getattr(cont, name)

                # Store.
                obj[id_from][id_to] = obj_temp
Esempio n. 11
0
    def from_xml(self, interatom_nodes, file_version=None):
        """Recreate an interatomic list data structure from the XML spin nodes.

        @param interatom_nodes: The spin XML nodes.
        @type interatom_nodes:  xml.dom.minicompat.NodeList instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Test if empty.
        if not self.is_empty():
            raise RelaxFromXMLNotEmptyError(self.__class__.__name__)

        # Loop over the containers.
        for interatom_node in interatom_nodes:
            # Get the interatomic spin details and add a container to the InteratomList structure.
            spin_id1 = str(interatom_node.getAttribute('spin_id1'))
            spin_id2 = str(interatom_node.getAttribute('spin_id2'))
            self.add_item(spin_id1=spin_id1, spin_id2=spin_id2)

            # Recreate the current container.
            xml_to_object(interatom_node, self[-1], file_version=file_version)
Esempio n. 12
0
    def from_xml(self, interatom_nodes, file_version=None):
        """Recreate an interatomic list data structure from the XML spin nodes.

        @param interatom_nodes: The spin XML nodes.
        @type interatom_nodes:  xml.dom.minicompat.NodeList instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        """

        # Test if empty.
        if not self.is_empty():
            raise RelaxFromXMLNotEmptyError(self.__class__.__name__)

        # Loop over the containers.
        for interatom_node in interatom_nodes:
            # Get the interatomic spin details and add a container to the InteratomList structure.
            spin_id1 = str(interatom_node.getAttribute('spin_id1'))
            spin_id2 = str(interatom_node.getAttribute('spin_id2'))
            self.add_item(spin_id1=spin_id1, spin_id2=spin_id2)

            # Recreate the current container.
            xml_to_object(interatom_node, self[-1], file_version=file_version)
Esempio n. 13
0
    def from_xml(self, super_node, file_version=1):
        """Recreate the data structure from the XML node.

        @param super_node:      The XML nodes.
        @type 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 data structures.
        xml_to_object(super_node, self, file_version=file_version, blacklist=self.blacklist)

        # Get the individual elements.
        nodes = super_node.getElementsByTagName(self.element_name)

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

            # Recreate all the other data structures.
            xml_to_object(node, self[-1], file_version=file_version)
Esempio n. 14
0
    def from_xml(self, super_node, file_version=1):
        """Recreate the data structure from the XML node.

        @param super_node:      The XML nodes.
        @type 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 data structures.
        xml_to_object(super_node, self, file_version=file_version, blacklist=self.blacklist)

        # Get the individual elements.
        nodes = super_node.getElementsByTagName(self.element_name)

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

            # Recreate all the other data structures.
            xml_to_object(node, self[-1], file_version=file_version)
Esempio n. 15
0
    def from_xml(self, exp_info_node, file_version=1):
        """Recreate the element data structure from the XML element node.

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

        # Recreate the list structures.
        list_node_names = ['citation_list', 'script_list', 'software_list']
        list_subnode_names = ['citation', 'script', 'software']
        list_str_names = ['citations', 'scripts', 'software']
        for i in range(len(list_node_names)):
            # Get the list node.
            list_node = exp_info_node.getElementsByTagName(list_node_names[i])

            # Necreate the structure, if the node exists.
            if list_node:
                # Initialise the data structure.
                setattr(self, list_str_names[i], RelaxListType())
                list_obj = getattr(self, list_str_names[i])

                # Get all the subnodes.
                list_nodes = list_node[0].getElementsByTagName(list_subnode_names[i])

                # Loop over the nodes.
                for node in list_nodes:
                    # Add a blank container.
                    list_obj.append(Element(name=node.tagName, desc=node.getAttribute('desc')))

                    # Recreate the element.
                    list_obj[-1].from_xml(node, file_version=file_version)

        # Recreate all the other data structures.
        xml_to_object(exp_info_node, self, file_version=file_version, blacklist=list_node_names)
Esempio n. 16
0
    def from_xml(self, gui_node, file_version=1):
        """Recreate the gui data structure from the XML gui node.

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

        # Init.
        self.analyses = Analyses()
        self.free_file_format = Free_file_format()

        # Get the analyses node and recreate the analyses structure.
        analyses_nodes = gui_node.getElementsByTagName('analyses')
        self.analyses.from_xml(analyses_nodes[0], file_version=file_version)

        # Get the file settings node and recreate the structure.
        format_nodes = gui_node.getElementsByTagName('free_file_format')
        if format_nodes:
            self.free_file_format.from_xml(format_nodes[0], file_version=file_version)

        # Recreate all the other data structures.
        xml_to_object(gui_node, self, file_version=file_version, blacklist=['analyses', 'free_file_format'])
Esempio n. 17
0
File: gui.py Progetto: tlinnet/relax
    def from_xml(self, gui_node, file_version=1):
        """Recreate the gui data structure from the XML gui node.

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

        # Init.
        self.analyses = Analyses()
        self.free_file_format = Free_file_format()

        # Get the analyses node and recreate the analyses structure.
        analyses_nodes = gui_node.getElementsByTagName('analyses')
        self.analyses.from_xml(analyses_nodes[0], file_version=file_version)

        # Get the file settings node and recreate the structure.
        format_nodes = gui_node.getElementsByTagName('free_file_format')
        if format_nodes:
            self.free_file_format.from_xml(format_nodes[0], file_version=file_version)

        # Recreate all the other data structures.
        xml_to_object(gui_node, self, file_version=file_version, blacklist=['analyses', 'free_file_format'])
Esempio n. 18
0
    def from_xml(self, pipe_node, file_version=None, dir=None):
        """Read a pipe container XML element and place the contents into this pipe.

        @param pipe_node:       The data pipe XML node.
        @type pipe_node:        xml.dom.minidom.Element instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        @keyword dir:           The name of the directory containing the results file (needed for loading external files).
        @type dir:              str
        """

        # Test if empty.
        if not self.is_empty():
            raise RelaxFromXMLNotEmptyError(self.__class__.__name__)

        # Get the global data node, and fill the contents of the pipe.
        global_node = pipe_node.getElementsByTagName('global')[0]
        xml_to_object(global_node, self, file_version=file_version)

        # Backwards compatibility transformations.
        self._back_compat_hook(file_version)

        # Get the hybrid node (and its sub-node), and recreate the hybrid object.
        hybrid_node = pipe_node.getElementsByTagName('hybrid')[0]
        pipes_node = hybrid_node.getElementsByTagName('pipes')[0]
        setattr(self, 'hybrid_pipes', node_value_to_python(pipes_node.childNodes[0]))

        # Get the experimental information data nodes and, if they exist, fill the contents.
        exp_info_nodes = pipe_node.getElementsByTagName('exp_info')
        if exp_info_nodes:
            # Create the data container.
            self.exp_info = ExpInfo()

            # Fill its contents.
            self.exp_info.from_xml(exp_info_nodes[0], file_version=file_version)

        # Get the diffusion tensor data nodes and, if they exist, fill the contents.
        diff_tensor_nodes = pipe_node.getElementsByTagName('diff_tensor')
        if diff_tensor_nodes:
            # Create the diffusion tensor object.
            self.diff_tensor = DiffTensorData()

            # Fill its contents.
            self.diff_tensor.from_xml(diff_tensor_nodes[0], file_version=file_version)

        # Get the alignment tensor data nodes and, if they exist, fill the contents.
        align_tensor_nodes = pipe_node.getElementsByTagName('align_tensors')
        if align_tensor_nodes:
            # Create the alignment tensor object.
            self.align_tensors = AlignTensorList()

            # Fill its contents.
            self.align_tensors.from_xml(align_tensor_nodes[0], file_version=file_version)

        # Recreate the interatomic data structure (this needs to be before the 'mol' structure as the backward compatibility hooks can create interatomic data containers!).
        interatom_nodes = pipe_node.getElementsByTagName('interatomic')
        self.interatomic.from_xml(interatom_nodes, file_version=file_version)

        # Recreate the molecule, residue, and spin data structure.
        mol_nodes = pipe_node.getElementsByTagName('mol')
        self.mol.from_xml(mol_nodes, file_version=file_version)

        # Get the structural object nodes and, if they exist, fill the contents.
        str_nodes = pipe_node.getElementsByTagName('structure')
        if str_nodes:
            # Create the structural object.
            fail = False
            self.structure = Internal()

            # Fill its contents.
            if not fail:
                self.structure.from_xml(str_nodes[0], dir=dir, file_version=file_version)
Esempio n. 19
0
    def from_xml(self, pipe_node, file_version=None, dir=None):
        """Read a pipe container XML element and place the contents into this pipe.

        @param pipe_node:       The data pipe XML node.
        @type pipe_node:        xml.dom.minidom.Element instance
        @keyword file_version:  The relax XML version of the XML file.
        @type file_version:     int
        @keyword dir:           The name of the directory containing the results file (needed for loading external files).
        @type dir:              str
        """

        # Test if empty.
        if not self.is_empty():
            raise RelaxFromXMLNotEmptyError(self.__class__.__name__)

        # Get the global data node, and fill the contents of the pipe.
        global_node = pipe_node.getElementsByTagName('global')[0]
        xml_to_object(global_node, self, file_version=file_version)

        # Backwards compatibility transformations.
        self._back_compat_hook(file_version)

        # Get the hybrid node (and its sub-node), and recreate the hybrid object.
        hybrid_node = pipe_node.getElementsByTagName('hybrid')[0]
        pipes_node = hybrid_node.getElementsByTagName('pipes')[0]
        setattr(self, 'hybrid_pipes',
                node_value_to_python(pipes_node.childNodes[0]))

        # Get the experimental information data nodes and, if they exist, fill the contents.
        exp_info_nodes = pipe_node.getElementsByTagName('exp_info')
        if exp_info_nodes:
            # Create the data container.
            self.exp_info = ExpInfo()

            # Fill its contents.
            self.exp_info.from_xml(exp_info_nodes[0],
                                   file_version=file_version)

        # Get the diffusion tensor data nodes and, if they exist, fill the contents.
        diff_tensor_nodes = pipe_node.getElementsByTagName('diff_tensor')
        if diff_tensor_nodes:
            # Create the diffusion tensor object.
            self.diff_tensor = DiffTensorData()

            # Fill its contents.
            self.diff_tensor.from_xml(diff_tensor_nodes[0],
                                      file_version=file_version)

        # Get the alignment tensor data nodes and, if they exist, fill the contents.
        align_tensor_nodes = pipe_node.getElementsByTagName('align_tensors')
        if align_tensor_nodes:
            # Create the alignment tensor object.
            self.align_tensors = AlignTensorList()

            # Fill its contents.
            self.align_tensors.from_xml(align_tensor_nodes[0],
                                        file_version=file_version)

        # Recreate the interatomic data structure (this needs to be before the 'mol' structure as the backward compatibility hooks can create interatomic data containers!).
        interatom_nodes = pipe_node.getElementsByTagName('interatomic')
        self.interatomic.from_xml(interatom_nodes, file_version=file_version)

        # Recreate the molecule, residue, and spin data structure.
        mol_nodes = pipe_node.getElementsByTagName('mol')
        self.mol.from_xml(mol_nodes, file_version=file_version)

        # Get the structural object nodes and, if they exist, fill the contents.
        str_nodes = pipe_node.getElementsByTagName('structure')
        if str_nodes:
            # Create the structural object.
            fail = False
            self.structure = Internal()

            # Fill its contents.
            if not fail:
                self.structure.from_xml(str_nodes[0],
                                        dir=dir,
                                        file_version=file_version)
Esempio n. 20
0
    def from_xml(self, file, dir=None, pipe_to=None, verbosity=1):
        """Parse a XML document representation of a data pipe, and load it into the relax data store.

        @param file:                The open file object.
        @type file:                 file
        @keyword dir:               The name of the directory containing the results file (needed for loading external files).
        @type dir:                  str
        @keyword pipe_to:           The data pipe to load the XML data pipe into (the file must only contain one data pipe).
        @type pipe_to:              str
        @keyword verbosity:         A flag specifying the amount of information to print.  The higher the value, the greater the verbosity.
        @type verbosity:            int
        @raises RelaxError:         If pipe_to is given and the file contains multiple pipe elements;  or if the data pipes in the XML file already exist in the relax data store;  or if the data pipe type is invalid;  or if the target data pipe is not empty.
        @raises RelaxNoPipeError:   If pipe_to is given but the data pipe does not exist.
        @raises RelaxError:         If the data pipes in the XML file already exist in the relax data store, or if the data pipe type is invalid.
        @raises RelaxPipeError:     If the data pipes of the XML file are already present in the relax data store.
        """

        # Create the XML document from the file.
        doc = xml.dom.minidom.parse(file)

        # Get the relax node.
        relax_node = doc.childNodes[0]

        # Get the relax version of the XML file.
        file_version = relax_node.getAttribute('file_version')
        if file_version == '':
            file_version = 1
        else:
            file_version = int(file_version)

        # Get the pipe nodes.
        pipe_nodes = relax_node.getElementsByTagName('pipe')

        # Structure for the names of the new pipes.
        pipes = []

        # Target loading to a specific pipe (for pipe results reading).
        if pipe_to:
            # Check if there are multiple pipes in the XML file.
            if len(pipe_nodes) > 1:
                raise RelaxError(
                    "The pipe_to target pipe argument '%s' cannot be given as the file contains multiple pipe elements."
                    % pipe_to)

            # The pipe type.
            pipe_type = pipe_nodes[0].getAttribute('type')

            # Check that the pipe already exists.
            if not pipe_to in self:
                raise RelaxNoPipeError(pipe_to)

            # Check if the pipe type matches.
            if pipe_type != self[pipe_to].pipe_type:
                raise RelaxError(
                    "The XML file pipe type '%s' does not match the pipe type '%s'"
                    % (pipe_type, self[pipe_to].pipe_type))

            # Check if the pipe is empty.
            if not self[pipe_to].is_empty():
                raise RelaxError("The data pipe '%s' is not empty." % pipe_to)

            # Load the data.
            self[pipe_to].from_xml(pipe_nodes[0],
                                   dir=dir,
                                   file_version=file_version)

            # Store the pipe name.
            pipes.append(pipe_to)

        # Load the state.
        else:
            # Get the GUI nodes.
            gui_nodes = relax_node.getElementsByTagName('relax_gui')
            if gui_nodes:
                self.relax_gui.from_xml(gui_nodes[0],
                                        file_version=file_version)

            # Get the sequence alignment nodes.
            seq_align_nodes = relax_node.getElementsByTagName(
                'sequence_alignments')
            if seq_align_nodes:
                # Initialise the object.
                self.sequence_alignments = Sequence_alignments()

                # Populate it.
                self.sequence_alignments.from_xml(seq_align_nodes[0],
                                                  file_version=file_version)

            # Recreate all the data store data structures.
            xml_to_object(
                relax_node,
                self,
                file_version=file_version,
                blacklist=['pipe', 'relax_gui', 'sequence_alignments'])

            # Checks.
            for pipe_node in pipe_nodes:
                # The pipe name and type.
                pipe_name = str(pipe_node.getAttribute('name'))
                pipe_type = pipe_node.getAttribute('type')

                # Existence check.
                if pipe_name in self:
                    raise RelaxPipeError(pipe_name)

                # Valid type check.
                if not pipe_type in pipe_control.pipes.VALID_TYPES:
                    raise RelaxError(
                        "The data pipe type '%s' is invalid and must be one of the strings in the list %s."
                        % (pipe_type, pipe_control.pipes.VALID_TYPES))

            # Load the data pipes.
            for pipe_node in pipe_nodes:
                # The pipe name and type.
                pipe_name = str(pipe_node.getAttribute('name'))
                pipe_type = pipe_node.getAttribute('type')

                # Add the data pipe.
                switch = False
                if self.current_pipe == None:
                    switch = True
                self.add(pipe_name, pipe_type, switch=switch)

                # Fill the pipe.
                self[pipe_name].from_xml(pipe_node,
                                         file_version=file_version,
                                         dir=dir)

                # Store the pipe name.
                pipes.append(pipe_name)

            # Set the current pipe.
            if self.current_pipe in self:
                builtins.cdp = self[self.current_pipe]

        # Finally update the molecule, residue, and spin metadata for each data pipe.
        for pipe in pipes:
            pipe_control.mol_res_spin.metadata_update(pipe=pipe)

        # Backwards compatibility transformations.
        self._back_compat_hook(file_version, pipes=pipes)
Esempio n. 21
0
    def from_xml(self, file, dir=None, pipe_to=None, verbosity=1):
        """Parse a XML document representation of a data pipe, and load it into the relax data store.

        @param file:                The open file object.
        @type file:                 file
        @keyword dir:               The name of the directory containing the results file (needed for loading external files).
        @type dir:                  str
        @keyword pipe_to:           The data pipe to load the XML data pipe into (the file must only contain one data pipe).
        @type pipe_to:              str
        @keyword verbosity:         A flag specifying the amount of information to print.  The higher the value, the greater the verbosity.
        @type verbosity:            int
        @raises RelaxError:         If pipe_to is given and the file contains multiple pipe elements;  or if the data pipes in the XML file already exist in the relax data store;  or if the data pipe type is invalid;  or if the target data pipe is not empty.
        @raises RelaxNoPipeError:   If pipe_to is given but the data pipe does not exist.
        @raises RelaxError:         If the data pipes in the XML file already exist in the relax data store, or if the data pipe type is invalid.
        @raises RelaxPipeError:     If the data pipes of the XML file are already present in the relax data store.
        """

        # Create the XML document from the file.
        doc = xml.dom.minidom.parse(file)

        # Get the relax node.
        relax_node = doc.childNodes[0]

        # Get the relax version of the XML file.
        file_version = relax_node.getAttribute('file_version')
        if file_version == '':
            file_version = 1
        else:
            file_version = int(file_version)

        # Get the pipe nodes.
        pipe_nodes = relax_node.getElementsByTagName('pipe')

        # Structure for the names of the new pipes.
        pipes = []

        # Target loading to a specific pipe (for pipe results reading).
        if pipe_to:
            # Check if there are multiple pipes in the XML file.
            if len(pipe_nodes) > 1:
                raise RelaxError("The pipe_to target pipe argument '%s' cannot be given as the file contains multiple pipe elements." % pipe_to)

            # The pipe type.
            pipe_type = pipe_nodes[0].getAttribute('type')

            # Check that the pipe already exists.
            if not pipe_to in self:
                raise RelaxNoPipeError(pipe_to)

            # Check if the pipe type matches.
            if pipe_type != self[pipe_to].pipe_type:
                raise RelaxError("The XML file pipe type '%s' does not match the pipe type '%s'" % (pipe_type, self[pipe_to].pipe_type))

            # Check if the pipe is empty.
            if not self[pipe_to].is_empty():
                raise RelaxError("The data pipe '%s' is not empty." % pipe_to)

            # Load the data.
            self[pipe_to].from_xml(pipe_nodes[0], dir=dir, file_version=file_version)

            # Store the pipe name.
            pipes.append(pipe_to)

        # Load the state.
        else:
            # Get the GUI nodes.
            gui_nodes = relax_node.getElementsByTagName('relax_gui')
            if gui_nodes:
                self.relax_gui.from_xml(gui_nodes[0], file_version=file_version)

            # Get the sequence alignment nodes.
            seq_align_nodes = relax_node.getElementsByTagName('sequence_alignments')
            if seq_align_nodes:
                # Initialise the object.
                self.sequence_alignments = Sequence_alignments()

                # Populate it.
                self.sequence_alignments.from_xml(seq_align_nodes[0], file_version=file_version)

            # Recreate all the data store data structures.
            xml_to_object(relax_node, self, file_version=file_version, blacklist=['pipe', 'relax_gui', 'sequence_alignments'])

            # Checks.
            for pipe_node in pipe_nodes:
                # The pipe name and type.
                pipe_name = str(pipe_node.getAttribute('name'))
                pipe_type = pipe_node.getAttribute('type')

                # Existence check.
                if pipe_name in self:
                    raise RelaxPipeError(pipe_name)

                # Valid type check.
                if not pipe_type in pipe_control.pipes.VALID_TYPES:
                    raise RelaxError("The data pipe type '%s' is invalid and must be one of the strings in the list %s." % (pipe_type, pipe_control.pipes.VALID_TYPES))

            # Load the data pipes.
            for pipe_node in pipe_nodes:
                # The pipe name and type.
                pipe_name = str(pipe_node.getAttribute('name'))
                pipe_type = pipe_node.getAttribute('type')

                # Add the data pipe.
                switch = False
                if self.current_pipe == None:
                    switch = True
                self.add(pipe_name, pipe_type, switch=switch)

                # Fill the pipe.
                self[pipe_name].from_xml(pipe_node, file_version=file_version, dir=dir)

                # Store the pipe name.
                pipes.append(pipe_name)

            # Set the current pipe.
            if self.current_pipe in self:
                builtins.cdp = self[self.current_pipe]

        # Finally update the molecule, residue, and spin metadata for each data pipe.
        for pipe in pipes:
            pipe_control.mol_res_spin.metadata_update(pipe=pipe)

        # Backwards compatibility transformations.
        self._back_compat_hook(file_version, pipes=pipes)
Esempio n. 22
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
Esempio n. 23
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