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, identity, zeros 
 27  from re import search 
 28   
 29  # relax module imports. 
 30  from lib.mathematics import round_to_next_order 
 31   
 32   
33 -def assemble_param_vector(spin=None, sim_index=None):
34 """Assemble the exponential curve parameter vector (as a numpy array). 35 36 @keyword spin: The spin data container. 37 @type spin: SpinContainer instance 38 @keyword sim_index: The optional MC simulation index. 39 @type sim_index: int 40 @return: An array of the parameter values of the exponential model. 41 @rtype: numpy array 42 """ 43 44 # Initialise. 45 param_vector = [] 46 47 # Loop over the model parameters. 48 for i in range(len(spin.params)): 49 # Relaxation rate. 50 if spin.params[i] == 'rx': 51 if sim_index != None: 52 param_vector.append(spin.rx_sim[sim_index]) 53 elif spin.rx == None: 54 param_vector.append(0.0) 55 else: 56 param_vector.append(spin.rx) 57 58 # Initial intensity. 59 elif spin.params[i] == 'i0': 60 if sim_index != None: 61 param_vector.append(spin.i0_sim[sim_index]) 62 elif spin.i0 == None: 63 param_vector.append(0.0) 64 else: 65 param_vector.append(spin.i0) 66 67 # Intensity at infinity. 68 elif spin.params[i] == 'iinf': 69 if sim_index != None: 70 param_vector.append(spin.iinf_sim[sim_index]) 71 elif spin.iinf == None: 72 param_vector.append(0.0) 73 else: 74 param_vector.append(spin.iinf) 75 76 # Return a numpy array. 77 return array(param_vector, float64)
78 79
80 -def assemble_scaling_matrix(spin=None, scaling=True):
81 """Create and return the scaling matrix. 82 83 @keyword spin: The spin data container. 84 @type spin: SpinContainer instance 85 @keyword scaling: A flag which if false will cause the identity matrix to be returned. 86 @type scaling: bool 87 @return: The diagonal and square scaling matrix. 88 @rtype: numpy diagonal matrix 89 """ 90 91 # Initialise. 92 scaling_matrix = identity(len(spin.params), float64) 93 i = 0 94 95 # No diagonal scaling. 96 if not scaling: 97 return scaling_matrix 98 99 # Loop over the parameters. 100 for i in range(len(spin.params)): 101 # Relaxation rate. 102 if spin.params[i] == 'rx': 103 pass 104 105 # Intensity scaling. 106 elif search('^i', spin.params[i]): 107 scaling_matrix[i, i] = round_to_next_order(max(spin.peak_intensity.values())) 108 109 # Return the scaling matrix. 110 return scaling_matrix
111 112
113 -def disassemble_param_vector(param_vector=None, spin=None, sim_index=None):
114 """Disassemble the parameter vector. 115 116 @keyword param_vector: The parameter vector. 117 @type param_vector: numpy array 118 @keyword spin: The spin data container. 119 @type spin: SpinContainer instance 120 @keyword sim_index: The optional MC simulation index. 121 @type sim_index: int 122 """ 123 124 # Monte Carlo simulations. 125 if sim_index != None: 126 # The relaxation rate. 127 spin.rx_sim[sim_index] = param_vector[0] 128 129 # Initial intensity. 130 spin.i0_sim[sim_index] = param_vector[1] 131 132 # Intensity at infinity. 133 if cdp.curve_type == 'inv': 134 spin.iinf_sim[sim_index] = param_vector[2] 135 136 # Parameter values. 137 else: 138 # The relaxation rate. 139 spin.rx = param_vector[0] 140 141 # Initial intensity. 142 spin.i0 = param_vector[1] 143 144 # Intensity at infinity. 145 if cdp.curve_type == 'inv': 146 spin.iinf = param_vector[2]
147 148
149 -def linear_constraints(spin=None, scaling_matrix=None):
150 """Set up the relaxation curve fitting linear constraint matrices A and b. 151 152 Standard notation 153 ================= 154 155 The relaxation rate constraints are:: 156 157 Rx >= 0 158 159 The intensity constraints are:: 160 161 I0 >= 0 162 Iinf >= 0 163 164 165 Matrix notation 166 =============== 167 168 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:: 169 170 | 1 0 0 | | Rx | | 0 | 171 | | | | | | 172 | 1 0 0 | . | I0 | >= | 0 | 173 | | | | | | 174 | 1 0 0 | | Iinf | | 0 | 175 176 177 @keyword spin: The spin data container. 178 @type spin: SpinContainer instance 179 @keyword scaling_matrix: The diagonal, square scaling matrix. 180 @type scaling_matrix: numpy diagonal matrix 181 """ 182 183 # Initialisation (0..j..m). 184 A = [] 185 b = [] 186 n = len(spin.params) 187 zero_array = zeros(n, float64) 188 i = 0 189 j = 0 190 191 # Loop over the parameters. 192 for k in range(len(spin.params)): 193 # Relaxation rate. 194 if spin.params[k] == 'rx': 195 # Rx >= 0. 196 A.append(zero_array * 0.0) 197 A[j][i] = 1.0 198 b.append(0.0) 199 j = j + 1 200 201 # Intensity parameter. 202 elif search('^i', spin.params[k]): 203 # I0, Iinf >= 0. 204 A.append(zero_array * 0.0) 205 A[j][i] = 1.0 206 b.append(0.0) 207 j = j + 1 208 209 # Increment i. 210 i = i + 1 211 212 # Convert to numpy data structures. 213 A = array(A, float64) 214 b = array(b, float64) 215 216 return A, b
217