Author: bugman Date: Mon Jan 12 18:57:10 2009 New Revision: 8425 URL: http://svn.gna.org/viewcvs/relax?rev=8425&view=rev Log: Created a new private method, __compare_objects() to check if 2 objects are the same. Modified: branches/multi_structure/specific_fns/model_free/main.py Modified: branches/multi_structure/specific_fns/model_free/main.py URL: http://svn.gna.org/viewcvs/relax/branches/multi_structure/specific_fns/model_free/main.py?rev=8425&r1=8424&r2=8425&view=diff ============================================================================== --- branches/multi_structure/specific_fns/model_free/main.py (original) +++ branches/multi_structure/specific_fns/model_free/main.py Mon Jan 12 18:57:10 2009 @@ -43,6 +43,47 @@ class Model_free_main: """Class containing functions specific to model-free analysis.""" + + def __compare_objects(self, object_from, object_to, pipe_from, pipe_to): + """Compare the contents of the two objects and raise RelaxErrors if they are not the same. + + @param object_from: The first object. + @type object_from: any object + @param object_to: The second object. + @type object_to: any object + @param pipe_from: The name of the data pipe containing the first object. + @type pipe_from: str + @param pipe_to: The name of the data pipe containing the second object. + @type pipe_to: str + """ + + # Loop over the modifiable objects. + for data_name in dir(object_from): + # Skip special objects (starting with _, or in the original class and base class namespaces). + if search('^_', data_name) or data_name in object_from.__class__.__dict__.keys() or data_name in object_from.__class__.__bases__[0].__dict__.keys(): + continue + + # Skip some more special objects. + if data_name in ['structural_data']: + continue + + # Get the original object. + data_from = None + if hasattr(object_from, data_name): + data_from = getattr(object_from, data_name) + + # Get the target object. + if data_from and not hasattr(object_to, data_name): + raise RelaxError, "The structural object " + `data_name` + " of the " + `pipe_from` + " data pipe is not located in the " + `pipe_to` + " data pipe." + elif data_from: + data_to = getattr(object_to, data_name) + else: + continue + + # The data must match! + if data_from != data_to: + raise RelaxError, "The object " + `data_name` + " is not consistent between the pipes " + `pipe_from` + " and " + `pipe_to` + "." + def are_mf_params_set(self, spin): """Test if the model-free parameter values are set. @@ -1088,32 +1129,21 @@ # Otherwise compare the objects inside the container. else: - # Loop over the modifiable objects. - for data_name in dir(dp_from.structure): - # Skip special objects (starting with _, or in the original class and base class namespaces). - if search('^_', data_name) or data_name in dp_from.structure.__class__.__dict__.keys() or data_name in dp_from.structure.__class__.__bases__[0].__dict__.keys(): - continue - - # Skip some more special objects. - if data_name in ['structural_data']: - continue - - # Get the original object. - data_from = None - if hasattr(dp_from.structure, data_name): - data_from = getattr(dp_from.structure, data_name) - - # Get the target object. - if data_from and not hasattr(dp_to.structure, data_name): - raise RelaxError, "The structural object " + `data_name` + " of the " + `pipe_from` + " data pipe is not located in the " + `pipe_to` + " data pipe." - elif data_from: - data_to = getattr(dp_to.structure, data_name) - else: - continue - - # The data must match! - if data_from != data_to: - raise RelaxError, "The object " + `data_name` + " is not consistent between the pipes " + `pipe_from` + " and " + `pipe_to` + "." + # Modifiable object checks. + self.__compare_objects(dp_from.structure, dp_to.structure) + + # Tests for the model and molecule containers. + if len(dp_from.structure.structural_data) != len(dp_from.structure.structural_data): + raise RelaxError, "The number of structural models is not consistent between the pipes " + `pipe_from` + " and " + `pipe_to` + "." + + # Loop over the models. + for model_index in range(len(dp_from.structure.structural_data)): + # Molecule number. + if len(dp_from.structure.structural_data[model_index].mol) != len(dp_from.structure.structural_data[model_index].mol): + raise RelaxError, "The number of molecules is not consistent between the pipes " + `pipe_from` + " and " + `pipe_to` + "." + + # Modifiable object checks. + self.__compare_objects() # No sequence data, so skip the rest. if dp_from.mol.is_empty():