mailr11653 - /branches/bmrb/test_suite/system_tests/bmrb.py


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

Header


Content

Posted by edward on October 22, 2010 - 19:21:
Author: bugman
Date: Fri Oct 22 19:21:54 2010
New Revision: 11653

URL: http://svn.gna.org/viewcvs/relax?rev=11653&view=rev
Log:
The restoration of the data from BMRB files into data pipes is now fully 
tested in the system tests.


Modified:
    branches/bmrb/test_suite/system_tests/bmrb.py

Modified: branches/bmrb/test_suite/system_tests/bmrb.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/bmrb/test_suite/system_tests/bmrb.py?rev=11653&r1=11652&r2=11653&view=diff
==============================================================================
--- branches/bmrb/test_suite/system_tests/bmrb.py (original)
+++ branches/bmrb/test_suite/system_tests/bmrb.py Fri Oct 22 19:21:54 2010
@@ -22,6 +22,8 @@
 
 # Python module imports.
 import __main__
+import inspect
+from numpy import ndarray
 from os import remove, sep
 from re import search
 import sys
@@ -59,24 +61,16 @@
         """Check that all data has been successfully restored from the BMRB 
files."""
 
         # Print out.
-        print "\n\nComparing data pipe contents:\n"
+        print("\n\nComparing data pipe contents:")
+
+        # Blacklists (data that is not restored, and relaxation data which 
has been reordered).
+        blacklist_spin = ['name'] + ['attached_proton', 'element', 
'equation', 'fixed', 'heteronuc_type', 'nucleus', 'proton_type', 
'relax_sim_data', 'select', 'xh_vect'] + ['local_tm', 'local_tm_err', 
'model', 'params', 'rex', 'rex_err', 's2', 's2_err', 's2f', 's2f_err', 's2s', 
's2s_err', 'te', 'te_err', 'tf', 'tf_err', 'ts', 'ts_err'] + ['r', 'r_err', 
'csa', 'csa_err'] + ['chi2', 'chi2_sim', 'f_count', 'g_count', 'h_count', 
'iter', 'warning'] + ['frq', 'frq_labels', 'noe_r1_table', 'remap_table', 
'ri_labels', 'relax_data', 'relax_error']
+        blacklist_diff = []
+        blacklist_global = ['diff_tensor', 'exp_info', 'hybrid_pipes', 
'mol', 'sim_number', 'sim_state'] + ['frq', 'frq_labels', 'noe_r1_table', 
'remap_table', 'ri_labels']
 
         # The data pipes.
         old_pipe = ds[old_pipe_name]
         new_pipe = ds[new_pipe_name]
-
-        # The global data structures.
-        names = dir(old_pipe)
-        for name in names:
-            # Skip special names.
-            if search('^__', name):
-                continue
-
-            # Print out.
-            print "Object: %s" % name
-
-            # Check.
-            self.assert_(hasattr(new_pipe, name))
 
         # The molecule data structure.
         self.assertEqual(len(old_pipe.mol), len(new_pipe.mol))
@@ -95,27 +89,128 @@
                 # The spin data structure.
                 self.assertEqual(len(old_pipe.mol[i].res[j].spin), 
len(new_pipe.mol[i].res[j].spin))
                 for k in range(len(old_pipe.mol[i].res[j].spin)):
-                    # Check the attributes.
-                    names = dir(old_pipe.mol[i].res[j].spin[k])
-                    for name in names:
-                        # Skip special names.
-                        if search('^__', name):
-                            continue
-
-                        # Print out.
-                        print "Spin object: %s" % name
-
-                        # Does it exist?
-                        self.assert_(hasattr(new_pipe.mol[i].res[j].spin[k], 
name))
-
-                        # Get the objects.
-                        obj_old = getattr(old_pipe.mol[i].res[j].spin[k], 
name)
-                        obj_new = getattr(new_pipe.mol[i].res[j].spin[k], 
name)
-
-                        # Compare values.
-                        self.assertEqual(obj_old, obj_new)
-
-
+                    # Skip deselected spins.
+                    if not old_pipe.mol[i].res[j].spin[k].select:
+                        continue
+
+                    # Check the containers.
+                    self.data_cont_comp(label='Spin', 
cont_old=old_pipe.mol[i].res[j].spin[k], 
cont_new=new_pipe.mol[i].res[j].spin[k], blacklist=blacklist_spin)
+                    if hasattr(old_pipe.mol[i].res[j].spin[k], 'ri_labels'):
+                        self.data_ri_comp(label='Global', 
cont_old=old_pipe.mol[i].res[j].spin[k], 
cont_new=new_pipe.mol[i].res[j].spin[k])
+
+        # The diffusion tensor.
+        self.assert_(hasattr(new_pipe, 'diff_tensor'))
+        self.data_cont_comp(label='Diff tensor', 
cont_old=old_pipe.diff_tensor, cont_new=new_pipe.diff_tensor, prec=4, 
blacklist=blacklist_diff)
+
+        # The global data structures.
+        self.data_cont_comp(label='Global', cont_old=old_pipe, 
cont_new=new_pipe, blacklist=blacklist_global)
+        if hasattr(old_pipe, 'ri_labels'):
+            self.data_ri_comp(label='Global', cont_old=old_pipe, 
cont_new=new_pipe)
+
+
+    def data_cont_comp(self, label=None, cont_old=None, cont_new=None, 
prec=7, blacklist=[]):
+        """Compare the contents of the two data containers."""
+
+        # Print a new line.
+        print('')
+
+        # Check the attributes.
+        names = dir(cont_old)
+        for name in names:
+            # Skip special names.
+            if search('^__', name):
+                continue
+
+            # Skip the data store methods.
+            if name in list(cont_old.__class__.__dict__.keys()):
+                continue
+
+            # Simulation data.
+            if search('_sim$', name):
+                continue
+
+            # Blacklisting.
+            if name in blacklist:
+                continue
+
+            # Print out.
+            print("%s object: '%s'" % (label, name))
+
+            # Get the objects.
+            obj_old = getattr(cont_old, name)
+            obj_new = getattr(cont_new, name)
+
+            # Functions and methods.
+            if inspect.isfunction(obj_old) or inspect.ismethod(obj_old):
+                continue
+
+            # Does it exist?
+            self.assert_(hasattr(cont_new, name))
+
+            # Compare lists.
+            if (isinstance(obj_old, list) or isinstance(obj_old, ndarray)):
+                self.assertEqual(len(obj_old), len(obj_new))
+
+                # List of lists (or rank-2 array).
+                if (isinstance(obj_old[0], list) or isinstance(obj_old[0], 
ndarray)):
+                    for i in range(len(obj_old)):
+                        for j in range(len(obj_old[i])):
+                            if isinstance(obj_old[i][j], float):
+                                self.assertAlmostEqual(obj_old[i][j], 
obj_new[i][j], prec)
+                            else:
+                                self.assertEqual(obj_old[i][j], 
obj_new[i][j])
+
+                # Standard list.
+                else:
+                    for i in range(len(obj_old)):
+                        if isinstance(obj_old[i], float):
+                            self.assertAlmostEqual(obj_old[i], obj_new[i], 
prec)
+                        else:
+                            self.assertEqual(obj_old[i], obj_new[i])
+
+            # Compare floats.
+            elif isinstance(obj_old, float):
+                self.assertAlmostEqual(obj_old, obj_new, prec)
+
+            # Compare ints and strings.
+            else:
+                self.assertEqual(obj_old, obj_new)
+
+
+    def data_ri_comp(self, label=None, cont_old=None, cont_new=None, prec=7):
+        """Compare the contents of the two data containers."""
+
+        # Check that the new container has relaxation data.
+        for name in ['frq', 'frq_labels', 'noe_r1_table', 'remap_table', 
'ri_labels']:
+            self.assert_(hasattr(cont_new, name))
+
+        # Loop over the original relaxation data.
+        for i in range(cont_old.num_ri):
+            # A flag to make sure the data matches.
+            match = False
+
+            # Loop over the new relaxation data.
+            for j in range(cont_old.num_ri):
+                # Matching relaxation data.
+                if cont_old.ri_labels[i] == cont_new.ri_labels[j] and 
cont_old.frq_labels[cont_old.remap_table[i]] == 
cont_new.frq_labels[cont_new.remap_table[j]]:
+                    # NOE to R1 checks.
+                    if cont_old.noe_r1_table[i] == None:
+                        self.assertEqual(cont_new.noe_r1_table[j], None)
+                    else:
+                        
self.assertEqual(cont_old.ri_labels[cont_old.noe_r1_table[i]], 
cont_new.ri_labels[cont_new.noe_r1_table[j]])
+                        
self.assertEqual(cont_old.remap_table[cont_old.noe_r1_table[i]], 
cont_new.remap_table[cont_new.noe_r1_table[j]])
+                        
self.assertEqual(cont_old.frq_labels[cont_old.remap_table[cont_old.noe_r1_table[i]]],
 cont_new.frq_labels[cont_new.remap_table[cont_new.noe_r1_table[j]]])
+
+                    # Relaxation data checks.
+                    if hasattr(cont_old, 'relax_data'):
+                        self.assertAlmostEqual(cont_old.relax_data[i],   
cont_new.relax_data[j])
+                        self.assertAlmostEqual(cont_old.relax_error[i], 
cont_new.relax_error[j])
+
+                    # Flag.
+                    match = True
+
+            # No match.
+            self.assert_(match)
 
 
     def test_rw_bmrb_3_0_model_free(self):




Related Messages


Powered by MHonArc, Updated Fri Oct 22 20:00:02 2010