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