mailr12705 - in /branches/relax_data/data: __init__.py pipe_container.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on March 02, 2011 - 12:20:
Author: bugman
Date: Wed Mar  2 12:20:44 2011
New Revision: 12705

URL: http://svn.gna.org/viewcvs/relax?rev=12705&view=rev
Log:
Added backwards compatibility for the old relaxation data structures in the 
data pipe.

The methods _back_compat_hook() and _back_compat_hook_ri_data() have been 
added to allow the base
data structures of the relax data pipe to be updated to the new structures.  
The version
information is now being passed from the relax data store from_xml() method.


Modified:
    branches/relax_data/data/__init__.py
    branches/relax_data/data/pipe_container.py

Modified: branches/relax_data/data/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_data/data/__init__.py?rev=12705&r1=12704&r2=12705&view=diff
==============================================================================
--- branches/relax_data/data/__init__.py (original)
+++ branches/relax_data/data/__init__.py Wed Mar  2 12:20:44 2011
@@ -240,7 +240,7 @@
         relax_node = doc.childNodes[0]
 
         # Get the relax version of the XML file.
-        relax_version = str(relax_node.getAttribute('version'))
+        file_version = str(relax_node.getAttribute('version'))
 
         # Get the GUI nodes.
         gui_nodes = relax_node.getElementsByTagName('relax_gui')
@@ -307,7 +307,7 @@
                 self.add(pipe_name, pipe_type)
 
                 # Fill the pipe.
-                self[pipe_name].from_xml(pipe_node, dir=dir)
+                self[pipe_name].from_xml(pipe_node, 
file_version=file_version, dir=dir)
 
 
     def to_xml(self, file, pipes=None):

Modified: branches/relax_data/data/pipe_container.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_data/data/pipe_container.py?rev=12705&r1=12704&r2=12705&view=diff
==============================================================================
--- branches/relax_data/data/pipe_container.py (original)
+++ branches/relax_data/data/pipe_container.py Wed Mar  2 12:20:44 2011
@@ -100,14 +100,77 @@
         return text
 
 
-    def from_xml(self, pipe_node, dir=None):
+    def _back_compat_hook(self, file_version=None):
+        """Method for converting old data structures to the new ones.
+
+        @keyword file_version:  The relax version used to create the XML 
file.
+        @type file_version:     str
+        """
+
+        # Relaxation data.
+        self._back_compat_hook_ri_data()
+
+
+    def _back_compat_hook_ri_data(self):
+        """Converting the old relaxation data structures to the new ones."""
+
+        # Nothing to do.
+        if not (hasattr(cdp, 'frq_labels') and hasattr(cdp, 'noe_r1_table') 
and hasattr(cdp, 'remap_table')):
+            return
+
+        # Initialise the new structures.
+        cdp.ri_ids = []
+        cdp.ri_type = {}
+        frq = {}    # This will be placed into cdp later as cdp.frq still 
exists.
+
+        # Generate the new structures.
+        for i in range(cdp.num_ri):
+            # The ID.
+            ri_id = "%s_%s" % (cdp.ri_labels[i], 
cdp.frq_labels[cdp.remap_table[i]])
+
+            # Not unique.
+            if ri_id in cdp.ri_ids:
+                # Loop until a unique ID is found.
+                for i in range(100):
+                    # New id.
+                    new_id = "%s_%s" % (ri_id, i)
+
+                    # Unique.
+                    if not new_id in cdp.ri_ids:
+                        ri_id = new_id
+                        break
+
+            # Add the ID.
+            cdp.ri_ids.append(ri_id)
+
+            # The relaxation data type.
+            cdp.ri_type[ri_id] = cdp.ri_labels[i]
+
+            # The frequency data.
+            frq[ri_id] = cdp.frq[cdp.remap_table[i]]
+
+        # Delete the old structures.
+        del cdp.frq
+        del cdp.frq_labels
+        del cdp.noe_r1_table
+        del cdp.num_frq
+        del cdp.num_ri
+        del cdp.remap_table
+        del cdp.ri_labels
+
+        # Set the frequencies.
+        cdp.frq = frq
+
+
+    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 dir:       The name of the directory containing the results 
file (needed for
-                            loading external files).
-        @type dir:          str
+        @param pipe_node:       The data pipe XML node.
+        @type pipe_node:        xml.dom.minidom.Element instance
+        @keyword file_version:  The relax version used to create the XML 
file.
+        @type file_version:     str
+        @keyword dir:           The name of the directory containing the 
results file (needed for loading external files).
+        @type dir:              str
         """
 
         # Test if empty.
@@ -117,6 +180,9 @@
         # 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)
+
+        # 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]




Related Messages


Powered by MHonArc, Updated Wed Mar 02 14:00:02 2011