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

Source Code for Module specific_analyses.relax_fit.parameters

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004-2014 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """The R1 and R2 exponential relaxation curve fitting parameter functions.""" 
 24   
 25  # Python module imports. 
 26  from numpy import array, float64, zeros 
 27  from re import search 
 28   
 29   
30 -def assemble_param_vector(spin=None, sim_index=None):
31 """Assemble the exponential curve parameter vector (as a numpy array). 32 33 @keyword spin: The spin data container. 34 @type spin: SpinContainer instance 35 @keyword sim_index: The optional MC simulation index. 36 @type sim_index: int 37 @return: An array of the parameter values of the exponential model. 38 @rtype: numpy array 39 """ 40 41 # Initialise. 42 param_vector = [] 43 44 # Loop over the model parameters. 45 for i in range(len(spin.params)): 46 # Relaxation rate. 47 if spin.params[i] == 'rx': 48 if sim_index != None: 49 param_vector.append(spin.rx_sim[sim_index]) 50 elif spin.rx == None: 51 param_vector.append(None) 52 else: 53 param_vector.append(spin.rx) 54 55 # Initial intensity. 56 elif spin.params[i] == 'i0': 57 if sim_index != None: 58 param_vector.append(spin.i0_sim[sim_index]) 59 elif spin.i0 == None: 60 param_vector.append(None) 61 else: 62 param_vector.append(spin.i0) 63 64 # Intensity at infinity. 65 elif spin.params[i] == 'iinf': 66 if sim_index != None: 67 param_vector.append(spin.iinf_sim[sim_index]) 68 elif spin.iinf == None: 69 param_vector.append(None) 70 else: 71 param_vector.append(spin.iinf) 72 73 # Return a numpy array. 74 return array(param_vector, float64)
75 76
77 -def disassemble_param_vector(param_vector=None, spin=None, sim_index=None):
78 """Disassemble the parameter vector. 79 80 @keyword param_vector: The parameter vector. 81 @type param_vector: numpy array 82 @keyword spin: The spin data container. 83 @type spin: SpinContainer instance 84 @keyword sim_index: The optional MC simulation index. 85 @type sim_index: int 86 """ 87 88 # Monte Carlo simulations. 89 if sim_index != None: 90 # Two parameter exponential. 91 if spin.model == 'exp': 92 spin.rx_sim[sim_index] = param_vector[0] 93 spin.i0_sim[sim_index] = param_vector[1] 94 95 # Two parameter exponential. 96 elif spin.model == 'inv': 97 spin.rx_sim[sim_index] = param_vector[0] 98 spin.i0_sim[sim_index] = param_vector[1] 99 spin.iinf_sim[sim_index] = param_vector[2] 100 101 # Saturation recovery. 102 elif spin.model == 'sat': 103 spin.rx_sim[sim_index] = param_vector[0] 104 spin.iinf_sim[sim_index] = param_vector[1] 105 106 # Parameter values. 107 else: 108 # Two parameter exponential. 109 if spin.model == 'exp': 110 spin.rx = param_vector[0] 111 spin.i0 = param_vector[1] 112 113 # Two parameter exponential. 114 elif spin.model == 'inv': 115 spin.rx = param_vector[0] 116 spin.i0 = param_vector[1] 117 spin.iinf = param_vector[2] 118 119 # Saturation recovery. 120 elif spin.model == 'sat': 121 spin.rx = param_vector[0] 122 spin.iinf = param_vector[1]
123 124
125 -def linear_constraints(spin=None, scaling_matrix=None):
126 """Set up the relaxation curve fitting linear constraint matrices A and b. 127 128 Standard notation 129 ================= 130 131 The relaxation rate constraints are:: 132 133 Rx >= 0 134 135 The intensity constraints are:: 136 137 I0 >= 0 138 Iinf >= 0 139 140 141 Matrix notation 142 =============== 143 144 In the notation A.x >= b, where A is an matrix of coefficients, x is an array of parameter values, and b is a vector of scalars, these inequality constraints are:: 145 146 | 1 0 0 | | Rx | | 0 | 147 | | | | | | 148 | 1 0 0 | . | I0 | >= | 0 | 149 | | | | | | 150 | 1 0 0 | | Iinf | | 0 | 151 152 153 @keyword spin: The spin data container. 154 @type spin: SpinContainer instance 155 @keyword scaling_matrix: The diagonal, square scaling matrix. 156 @type scaling_matrix: numpy diagonal matrix 157 """ 158 159 # Initialisation (0..j..m). 160 A = [] 161 b = [] 162 n = len(spin.params) 163 zero_array = zeros(n, float64) 164 i = 0 165 j = 0 166 167 # Loop over the parameters. 168 for k in range(len(spin.params)): 169 # Relaxation rate. 170 if spin.params[k] == 'rx': 171 # Rx >= 0. 172 A.append(zero_array * 0.0) 173 A[j][i] = 1.0 174 b.append(0.0) 175 j = j + 1 176 177 # Intensity parameter. 178 elif search('^i', spin.params[k]): 179 # I0, Iinf >= 0. 180 A.append(zero_array * 0.0) 181 A[j][i] = 1.0 182 b.append(0.0) 183 j = j + 1 184 185 # Increment i. 186 i = i + 1 187 188 # Convert to numpy data structures. 189 A = array(A, float64) 190 b = array(b, float64) 191 192 return A, b
193