Author: bugman Date: Fri Jan 18 16:03:29 2008 New Revision: 4857 URL: http://svn.gna.org/viewcvs/relax?rev=4857&view=rev Log: Merged revisions 4854-4856 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3 ........ r4854 | bugman | 2008-01-18 15:42:02 +0100 (Fri, 18 Jan 2008) | 3 lines Big refactorisation of the partition_params() and set() functions. ........ r4855 | bugman | 2008-01-18 15:58:10 +0100 (Fri, 18 Jan 2008) | 3 lines Changed the way the model parameters are set in the set() function. ........ r4856 | bugman | 2008-01-18 16:01:28 +0100 (Fri, 18 Jan 2008) | 6 lines Reverted r4850 as generic_fns.value.partition_params() has returned to its previous behaviour. The command used was: svn merge -r4850:4849 . ........ Modified: branches/N_state_model/ (props changed) branches/N_state_model/generic_fns/value.py branches/N_state_model/test_suite/unit_tests/_generic_fns/test_value.py Propchange: branches/N_state_model/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: branches/N_state_model/generic_fns/value.py URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/generic_fns/value.py?rev=4857&r1=4856&r2=4857&view=diff ============================================================================== --- branches/N_state_model/generic_fns/value.py (original) +++ branches/N_state_model/generic_fns/value.py Fri Jan 18 16:03:29 2008 @@ -57,14 +57,42 @@ spin_values = [] other_params = [] other_values = [] - model_values = [] - - # The parameter has been specified. - if param: - # Single parameter. - if type(param) == str: + + # Single parameter. + if type(param) == str: + # Spin specific parameter. + if return_data_name(param): + params = spin_params + values = spin_values + + # Other parameters. + else: + params = other_params + values = other_values + + # List of values. + if type(val) == list or isinstance(val, ndarray): + # Parameter name. + for i in xrange(len(val)): + params.append(param) + + # Parameter value. + values = val + + # Single value. + else: + # Parameter name. + params.append(param) + + # Parameter value. + values.append(val) + + # Multiple parameters. + elif type(param) == list: + # Loop over all parameters. + for i in xrange(len(param)): # Spin specific parameter. - if return_data_name(param): + if return_data_name(param[i]): params = spin_params values = spin_values @@ -73,59 +101,18 @@ params = other_params values = other_values - # List of values. + # Parameter name. + params.append(param[i]) + + # Parameter value. if type(val) == list or isinstance(val, ndarray): - # Parameter name. - for i in xrange(len(val)): - params.append(param) - - # Parameter value. - values = val - - # Single value. + values.append(val[i]) else: - # Parameter name. - params.append(param) - - # Parameter value. values.append(val) - # Multiple parameters. - elif type(param) == list: - # Loop over all parameters. - for i in xrange(len(param)): - # Spin specific parameter. - if return_data_name(param[i]): - params = spin_params - values = spin_values - - # Other parameters. - else: - params = other_params - values = other_values - - # Parameter name. - params.append(param[i]) - - # Parameter value. - if type(val) == list or isinstance(val, ndarray): - values.append(val[i]) - else: - values.append(val) - - - # No parameter name supplied, so these must be the model parameter values. - else: - # List of values. - if type(val) == list or isinstance(val, ndarray): - model_values = val - - # Single value. - elif val: - model_values = [val] # Return the partitioned parameters and values. - return spin_params, spin_values, other_params, other_values, model_values + return spin_params, spin_values, other_params, other_values def set(val=None, param=None, spin_id=None, force=False): @@ -149,52 +136,70 @@ return_value = get_specific_fn('return_value', relax_data_store[relax_data_store.current_pipe].pipe_type) set_non_spin_params = get_specific_fn('set_non_spin_params', relax_data_store[relax_data_store.current_pipe].pipe_type) - # Partition the parameters into those which are spin specific and those which are not. - spin_params, spin_values, other_params, other_values, model_values = partition_params(val, param) - - - # Spin specific parameters. - ########################### - - if spin_params: - # Test if the sequence data is loaded. - if not exists_mol_res_spin_data(): - raise RelaxNoSequenceError - - # First test if parameter value already exists, prior to setting any params. - if not force: + # The parameters have been specified. + if param: + # Partition the parameters into those which are spin specific and those which are not. + spin_params, spin_values, other_params, other_values = partition_params(val, param) + + # Spin specific parameters. + if spin_params: + # Test if the sequence data is loaded. + if not exists_mol_res_spin_data(): + raise RelaxNoSequenceError + + # First test if parameter value already exists, prior to setting any params. + if not force: + # Loop over the spins. + for spin in spin_loop(spin_id): + # Skip unselected spins. + if not spin.select: + continue + + # Loop over the parameters. + for param in spin_params: + # Get the value and error. + temp_value, temp_error = return_value(spin, param) + + # Data exists. + if temp_value != None or temp_error != None: + raise RelaxValueError, (param) + + # Loop over the spins. + for spin in spin_loop(spin_id): + # Skip unselected residues. + if not spin.select: + continue + + # Set the individual parameter values. + for j in xrange(len(spin_params)): + set_spin_params(value=spin_values[j], error=None, spin=spin, param=spin_params[j]) + + + # All other parameters. + if other_params: + set_non_spin_params(value=other_values, param=other_params) + + + # All model parameters (i.e. no parameters have been supplied). + else: + # Convert val to a list if necessary. + if type(val) != list or not isinstance(val, ndarray): + val = [val] + + # Spin specific models. + if exists_mol_res_spin_data(): # Loop over the spins. for spin in spin_loop(spin_id): # Skip unselected spins. if not spin.select: continue - # Loop over the parameters. - for param in spin_params: - # Get the value and error. - temp_value, temp_error = return_value(spin, param) - - # Data exists. - if temp_value != None or temp_error != None: - raise RelaxValueError, (param) - - # Loop over the spins. - for spin in spin_loop(spin_id): - # Skip unselected residues. - if not spin.select: - continue - - # Go to the specific code. - for j in xrange(len(spin_params)): - set_spin_params(value=spin_values[j], error=None, spin=spin, param=spin_params[j]) - - - # All other parameters. - ####################### - - if other_params: - set_non_spin_params(value=other_values, param=other_params) - + # Set the individual parameter values. + for j in xrange(len(val)): + set_spin_params(value=val[j], error=None, spin=spin, param=None) + + # Set the non-spin specific parameters. + set_non_spin_params(value=val, param=param) # Reset all minimisation statistics. reset_min_stats() Modified: branches/N_state_model/test_suite/unit_tests/_generic_fns/test_value.py URL: http://svn.gna.org/viewcvs/relax/branches/N_state_model/test_suite/unit_tests/_generic_fns/test_value.py?rev=4857&r1=4856&r2=4857&view=diff ============================================================================== --- branches/N_state_model/test_suite/unit_tests/_generic_fns/test_value.py (original) +++ branches/N_state_model/test_suite/unit_tests/_generic_fns/test_value.py Fri Jan 18 16:03:29 2008 @@ -48,7 +48,7 @@ val = [0.8] # Partition. - spin_params, spin_values, other_params, other_values, model_values = value.partition_params(val, param) + spin_params, spin_values, other_params, other_values = value.partition_params(val, param) # Tests. self.assertEqual(spin_params, ['S2']) @@ -68,7 +68,7 @@ val = [1e7] # Partition. - spin_params, spin_values, other_params, other_values, model_values = value.partition_params(val, param) + spin_params, spin_values, other_params, other_values = value.partition_params(val, param) # Tests. self.assertEqual(spin_params, []) @@ -88,7 +88,7 @@ val = [1e7, 0.8] # Partition. - spin_params, spin_values, other_params, other_values, model_values = value.partition_params(val, param) + spin_params, spin_values, other_params, other_values = value.partition_params(val, param) # Tests. self.assertEqual(spin_params, ['S2']) @@ -108,7 +108,7 @@ val = [1e7, 0.8, -160e-6] # Partition. - spin_params, spin_values, other_params, other_values, model_values = value.partition_params(val, param) + spin_params, spin_values, other_params, other_values = value.partition_params(val, param) # Tests. self.assertEqual(spin_params, ['S2', 'CSA']) @@ -128,7 +128,7 @@ val = [1e7, 0.8, 2e7, -160e-6, 0.13] # Partition. - spin_params, spin_values, other_params, other_values, model_values = value.partition_params(val, param) + spin_params, spin_values, other_params, other_values = value.partition_params(val, param) # Tests. self.assertEqual(spin_params, ['S2', 'CSA']) @@ -148,7 +148,7 @@ val = [] # Partition. - spin_params, spin_values, other_params, other_values, model_values = value.partition_params(val, param) + spin_params, spin_values, other_params, other_values = value.partition_params(val, param) # Tests. self.assertEqual(spin_params, [])