Package specific_analyses :: Package relax_fit :: Module optimisation
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.relax_fit.optimisation

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2004-2014 Edward d'Auvergne                                   # 
 4  # Copyright (C) 2014 Troels E. Linnet                                         # 
 5  #                                                                             # 
 6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 7  #                                                                             # 
 8  # This program is free software: you can redistribute it and/or modify        # 
 9  # it under the terms of the GNU General Public License as published by        # 
10  # the Free Software Foundation, either version 3 of the License, or           # 
11  # (at your option) any later version.                                         # 
12  #                                                                             # 
13  # This program is distributed in the hope that it will be useful,             # 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
16  # GNU General Public License for more details.                                # 
17  #                                                                             # 
18  # You should have received a copy of the GNU General Public License           # 
19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  # Module docstring. 
24  """The R1 and R2 exponential relaxation curve fitting optimisation functions.""" 
25   
26  # relax module imports. 
27  from specific_analyses.relax_fit.parameters import assemble_param_vector 
28  from target_functions.relax_fit_wrapper import Relax_fit_opt 
29   
30   
31 -def back_calc(spin=None, relax_time_id=None):
32 """Back-calculation of peak intensity for the given relaxation time. 33 34 @keyword spin: The spin container. 35 @type spin: SpinContainer instance 36 @keyword relax_time_id: The ID string for the desired relaxation time. 37 @type relax_time_id: str 38 @return: The peak intensity for the desired relaxation time. 39 @rtype: float 40 """ 41 42 # Create the initial parameter vector. 43 param_vector = assemble_param_vector(spin=spin) 44 45 # The keys. 46 keys = list(spin.peak_intensity.keys()) 47 48 # The peak intensities and times. 49 values = [] 50 errors = [] 51 times = [] 52 for key in keys: 53 values.append(spin.peak_intensity[key]) 54 errors.append(spin.peak_intensity_err[key]) 55 times.append(cdp.relax_times[key]) 56 57 # A fake scaling matrix in a diagonalised list form. 58 scaling_list = [] 59 for i in range(len(param_vector)): 60 scaling_list.append(1.0) 61 62 # Initialise the relaxation fit functions. 63 model = Relax_fit_opt(model=spin.model, num_params=len(spin.params), values=values, errors=errors, relax_times=times, scaling_matrix=scaling_list) 64 65 # Make a single function call. This will cause back calculation and the data will be stored in the C module. 66 model.func(param_vector) 67 68 # Get the data back. 69 results = model.back_calc_data() 70 71 # Return the correct peak height. 72 return results[keys.index(relax_time_id)]
73