Author: bugman Date: Tue Sep 30 18:01:09 2008 New Revision: 7464 URL: http://svn.gna.org/viewcvs/relax?rev=7464&view=rev Log: Converted the back_calc() function to the new relax design. Modified: branches/pipe_refs/generic_fns/relax_data.py Modified: branches/pipe_refs/generic_fns/relax_data.py URL: http://svn.gna.org/viewcvs/relax/branches/pipe_refs/generic_fns/relax_data.py?rev=7464&r1=7463&r2=7464&view=diff ============================================================================== --- branches/pipe_refs/generic_fns/relax_data.py (original) +++ branches/pipe_refs/generic_fns/relax_data.py Tue Sep 30 18:01:09 2008 @@ -33,6 +33,7 @@ from generic_fns import pipes from relax_errors import RelaxError, RelaxNoRiError, RelaxNoSequenceError, RelaxNoSpinError, RelaxRiError from relax_io import extract_data, strip +from specific_fns.setup import get_specific_fn def add_data_to_spin(spin=None, ri_labels=None, remap_table=None, frq_labels=None, frq=None, values=None, errors=None, sim=False): @@ -140,71 +141,67 @@ def back_calc(ri_label=None, frq_label=None, frq=None): - """Function for back calculating relaxation data.""" + """Back calculate the relaxation data. + + @param ri_label: The relaxation data type, ie 'R1', 'R2', or 'NOE'. + @type ri_label: str + @param frq_label: The field strength label. + @type frq_label: str + @param frq: The spectrometer proton frequency in Hz. + @type frq: float + """ # Test if the current pipe exists. pipes.test() + + # Get the current data pipe. + cdp = pipes.get_pipe() # Test if sequence data is loaded. if not exists_mol_res_spin_data(): raise RelaxNoSequenceError - # Test if relaxation data corresponding to 'self.ri_label' and 'self.frq_label' already exists. - if self.test_labels(): - raise RelaxRiError, (self.ri_label, self.frq_label) + # Test if relaxation data corresponding to 'ri_label' and 'frq_label' already exists. + if test_labels(): + raise RelaxRiError, (ri_label, frq_label) # Global (non-residue specific) data. ##################################### # Global data flag. - self.global_flag = 1 + global_flag = 1 # Initialise the global data if necessary. - self.data_init(ds) + data_init(cdp) # Update the global data. - self.update_data_structures_pipe(ri_label, frq_label, frq) + update_data_structures_pipe(ri_label, frq_label, frq) # Residue specific data. ######################## # Global data flag. - self.global_flag = 0 - - # Function type. - function_type = ds.run_types[ds.run_names.index(self.run)] + global_flag = 0 # Specific back-calculate function setup. - back_calculate = self.relax.specific_setup.setup('back_calc', function_type) - - # Loop over the sequence. - for i in xrange(len(ds.res[self.run])): - # Remap the data structure 'ds.res[self.run][i]'. - data = ds.res[self.run][i] - - # Skip deselected residues. - if not data.select: + back_calculate = get_specific_fn('back_calc', pipes.get_type()) + + # Loop over the spins. + for spin in spin_loop(): + # Skip deselected spins. + if not spin.select: continue - # Store a copy of all the data in 'ds.res[self.run][i]' for backing up if the back_calculation function fails. - back_up = deepcopy(data) - # Initialise all data structures. - self.update_data_structures_spin(data, ri_label, frq_label, frq) + update_data_structures_spin(spin, ri_label, frq_label, frq) # Back-calculate the relaxation value. - try: - value = back_calculate(run=self.run, index=i, ri_label=self.ri_label, frq_label=frq_label, frq=self.frq) - except: - # Restore the data. - ds.res[self.run][i] = deepcopy(back_up) - del back_up - raise + value = back_calculate(spin=spin, ri_label=ri_label, frq_label=frq_label, frq=frq) # Update all data structures. - self.update_data_structures_spin(data, ri_label, frq_label, frq, value) + update_data_structures_spin(spin, ri_label, frq_label, frq, value) def copy(pipe_from=None, pipe_to=None, ri_label=None, frq_label=None):