1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for handling the frame order model parameters."""
24
25
26 from math import pi
27 from numpy import array, float64, zeros
28
29
30 from lib.errors import RelaxError
31 from lib.frame_order.variables import MODEL_DOUBLE_ROTOR, MODEL_FREE_ROTOR, MODEL_ISO_CONE, MODEL_ISO_CONE_FREE_ROTOR, MODEL_ISO_CONE_TORSIONLESS, MODEL_LIST_FREE_ROTORS, MODEL_LIST_ISO_CONE, MODEL_LIST_PSEUDO_ELLIPSE, MODEL_PSEUDO_ELLIPSE, MODEL_ROTOR
32 from lib.list import unique_elements
33 from specific_analyses.frame_order.data import pivot_fixed
34
35
37 """Assemble and return the parameter vector.
38
39 @keyword sim_index: The Monte Carlo simulation index.
40 @type sim_index: int
41 @keyword unset_fail: A flag which if True will cause a RelaxError to be raised if the parameter is not set yet.
42 @type unset_fail: bool
43 @return: The parameter vector.
44 @rtype: numpy rank-1 array
45 """
46
47
48 param_vect = []
49
50
51 ext = ''
52 if sim_index != None:
53 ext = '_sim'
54
55
56 for param_name in cdp.params:
57
58 param_name += ext
59
60
61 if not hasattr(cdp, param_name):
62 if unset_fail:
63 raise RelaxError("The parameter '%s' has not been set." % param_name)
64 else:
65 param_vect.append(None)
66 continue
67
68
69 obj = getattr(cdp, param_name)
70
71
72 if sim_index == None:
73 param_vect.append(obj)
74 else:
75 param_vect.append(obj[sim_index])
76
77
78 return array(param_vect, float64)
79
80
82 """Create the linear constraint matrices A and b.
83
84 Standard notation
85 =================
86
87 The parameter constraints for the motional amplitude parameters are::
88
89 0 <= theta <= pi,
90 0 <= theta_x <= theta_y <= pi,
91 -0.125 <= S <= 1,
92 0 <= sigma_max <= pi,
93
94 The pivot point and average domain position parameter constraints are::
95
96 -999 <= pivot_x <= 999
97 -999 <= pivot_y <= 999
98 -999 <= pivot_z <= 999
99 -500 <= ave_pos_x <= 500
100 -500 <= ave_pos_y <= 500
101 -500 <= ave_pos_y <= 500
102
103 These are necessary to allow for valid PDB representations to be created. The eigenframe parameters are unconstrained.
104
105
106 Matrix notation
107 ===============
108
109 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::
110
111 | 1 0 0 0 | | 0 |
112 | | | |
113 |-1 0 0 0 | | -pi |
114 | | | |
115 | 0 1 0 0 | | 0 |
116 | | | theta | | |
117 | 0 -1 0 0 | | | | -pi |
118 | | | theta_x | | |
119 | 0 -1 1 0 | . | | >= | 0 |
120 | | | theta_y | | |
121 | 0 0 1 0 | | | | 0 |
122 | | | sigma_max | | |
123 | 0 0 -1 0 | | -pi |
124 | | | |
125 | 0 0 0 1 | | 0 |
126 | | | |
127 | 0 0 0 -1 | | -pi |
128
129 The pivot and average position constraints in the A.x >= b notation are::
130
131 | 1 0 0 0 0 0 | | -999.0 |
132 | | | |
133 |-1 0 0 0 0 0 | | -999.0 |
134 | | | |
135 | 0 1 0 0 0 0 | | -999.0 |
136 | | | |
137 | 0 -1 0 0 0 0 | | pivot_x | | -999.0 |
138 | | | | | |
139 | 0 0 1 0 0 0 | | pivot_y | | -999.0 |
140 | | | | | |
141 | 0 0 -1 0 0 0 | | pivot_z | | -999.0 |
142 | | . | | >= | |
143 | 0 0 0 1 0 0 | | ave_pos_x | | -500.0 |
144 | | | | | |
145 | 0 0 0 -1 0 0 | | ave_pos_y | | -500.0 |
146 | | | | | |
147 | 0 0 0 0 1 0 | | ave_pos_z | | -500.0 |
148 | | | |
149 | 0 0 0 0 -1 0 | | -500.0 |
150 | | | |
151 | 0 0 0 0 0 1 | | -500.0 |
152 | | | |
153 | 0 0 0 0 0 -1 | | -500.0 |
154
155
156 @keyword scaling_matrix: The diagonal, square scaling matrix.
157 @type scaling_matrix: numpy rank-2 square matrix
158 @return: The matrices A and b.
159 @rtype: numpy rank-2 NxM array, numpy rank-1 N array
160 """
161
162
163 A = []
164 b = []
165 n = param_num()
166 zero_array = zeros(n, float64)
167 i = 0
168 j = 0
169
170
171 for i in range(n):
172
173 if cdp.params[i] in ['pivot_x', 'pivot_y', 'pivot_z']:
174
175 A.append(zero_array * 0.0)
176 A.append(zero_array * 0.0)
177 A[j][i] = 1.0
178 A[j+1][i] = -1.0
179 b.append(-999.0 / scaling_matrix[i, i])
180 b.append(-999.0 / scaling_matrix[i, i])
181 j = j + 2
182
183
184 if cdp.params[i] in ['ave_pos_x', 'ave_pos_y', 'ave_pos_z']:
185
186 A.append(zero_array * 0.0)
187 A.append(zero_array * 0.0)
188 A[j][i] = 1.0
189 A[j+1][i] = -1.0
190 b.append(-500.0 / scaling_matrix[i, i])
191 b.append(-500.0 / scaling_matrix[i, i])
192 j = j + 2
193
194
195 if cdp.params[i] in ['cone_theta', 'cone_theta_x', 'cone_theta_y', 'cone_sigma_max']:
196
197 A.append(zero_array * 0.0)
198 A.append(zero_array * 0.0)
199 A[j][i] = 1.0
200 A[j+1][i] = -1.0
201 b.append(0.0)
202 b.append(-pi / scaling_matrix[i, i])
203 j = j + 2
204
205
206 if cdp.params[i] == 'cone_theta_y':
207 for m in range(n):
208 if cdp.params[m] == 'cone_theta_x':
209 A.append(zero_array * 0.0)
210 A[j][i] = 1.0
211 A[j][m] = -1.0
212 b.append(0.0)
213 j = j + 1
214
215
216
217 A = array(A, float64)
218 b = array(b, float64)
219
220
221 if len(A) == 0:
222 A = None
223 b = None
224
225
226 return A, b
227
228
230 """Determine the number of parameters in the model.
231
232 @return: The number of model parameters.
233 @rtype: int
234 """
235
236
237 update_model(verbosity=0)
238
239
240 return len(cdp.params)
241
242
320