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 data in the relax data store."""
24
25
26 from numpy import array, float64, zeros
27 from warnings import warn
28
29
30 from lib.errors import RelaxError
31 from lib.frame_order.variables import MODEL_DOUBLE_ROTOR, MODEL_RIGID
32 from lib.warnings import RelaxWarning
33 from lib.geometry.rotations import euler_to_R_zyz
34 from pipe_control import pipes
35 from pipe_control.interatomic import interatomic_loop
36 from pipe_control.mol_res_spin import spin_loop
37 from pipe_control.pipes import check_pipe
38 from specific_analyses.frame_order.checks import check_model, check_pivot
39
40
73
74
76 """Return the spin ID string corresponding to the moving domain.
77
78 @return: The spin ID string defining the moving domain.
79 @rtype: str
80 """
81
82
83 if not hasattr(cdp, 'domain'):
84 raise RelaxError("No domains have been defined. Please use the domain user function.")
85
86
87 if len(cdp.domain) > 2:
88 raise RelaxError("Only two domains are supported in the frame order analysis.")
89
90
91 if not hasattr(cdp, 'ref_domain'):
92 raise RelaxError("The reference non-moving domain has not been specified.")
93
94
95 for id in cdp.domain:
96
97 if id == cdp.ref_domain:
98 continue
99
100
101 return cdp.domain[id]
102
103
104 -def generate_pivot(order=1, sim_index=None, pipe_name=None, pdb_limit=False):
105 """Create and return the given pivot.
106
107 @keyword order: The pivot number with 1 corresponding to the first pivot, 2 to the second, etc.
108 @type order: int
109 @keyword sim_index: The optional Monte Carlo simulation index. If provided, the pivot for the given simulation will be returned instead.
110 @type sim_index: None or int
111 @keyword pipe_name: The data pipe
112 @type pipe_name: str
113 @keyword pdb_limit: A flag which if True will cause the coordinate to be between -1000 and 1000.
114 @type pdb_limit: bool
115 @return: The give pivot point.
116 @rtype: numpy 3D rank-1 float64 array
117 """
118
119
120 check_pipe(pipe_name)
121 check_pivot(pipe_name=pipe_name)
122 check_model(pipe_name=pipe_name)
123
124
125 if pipe_name == None:
126 pipe_name = pipes.cdp_name()
127
128
129 dp = pipes.get_pipe(pipe_name)
130
131
132 pivot = None
133
134
135 if dp.model in [MODEL_DOUBLE_ROTOR]:
136
137 if sim_index != None and hasattr(dp, 'pivot_x_sim'):
138 pivot_2nd = array([dp.pivot_x_sim[sim_index], dp.pivot_y_sim[sim_index], dp.pivot_z_sim[sim_index]], float64)
139 else:
140 pivot_2nd = array([dp.pivot_x, dp.pivot_y, dp.pivot_z], float64)
141
142
143 if order == 1:
144
145 frame = zeros((3, 3), float64)
146 if sim_index != None and hasattr(dp, 'pivot_disp_sim'):
147 euler_to_R_zyz(dp.eigen_alpha_sim[sim_index], dp.eigen_beta_sim[sim_index], dp.eigen_gamma_sim[sim_index], frame)
148 pivot_disp = dp.pivot_disp_sim[sim_index]
149 else:
150 euler_to_R_zyz(dp.eigen_alpha, dp.eigen_beta, dp.eigen_gamma, frame)
151 pivot_disp = dp.pivot_disp
152
153
154 pivot = pivot_2nd + frame[:, 2] * pivot_disp
155
156
157 elif order == 2:
158 pivot = pivot_2nd
159
160
161 elif order == 1:
162 if sim_index != None and hasattr(dp, 'pivot_x_sim'):
163 pivot = array([dp.pivot_x_sim[sim_index], dp.pivot_y_sim[sim_index], dp.pivot_z_sim[sim_index]], float64)
164 else:
165 pivot = array([dp.pivot_x, dp.pivot_y, dp.pivot_z], float64)
166
167
168 if pivot is not None and pdb_limit:
169
170 orig_pivot = "[%.3f, %.3f, %.3f]" % (pivot[0], pivot[1], pivot[2])
171
172
173 out = False
174 for i in range(3):
175 if pivot[i] <= -900.0:
176 pivot[i] = -900.0
177 out = True
178 elif pivot[i] > 9900.0:
179 pivot[i] = 9900.0
180 out = True
181
182
183 if out:
184 new_pivot = "[%.3f, %.3f, %.3f]" % (pivot[0], pivot[1], pivot[2])
185 warn(RelaxWarning("The pivot point %s is outside of the PDB coordinate limits of [-999.999, 9999.999], less a 100 Angstrom buffer, shifting to %s." % (orig_pivot, new_pivot)))
186
187
188 return pivot
189
190
192 """Determine if the pivot is fixed or not.
193
194 @return: The answer to the question.
195 @rtype: bool
196 """
197
198
199 if cdp.model in [MODEL_RIGID]:
200 return True
201
202
203 if not hasattr(cdp, 'pcs_ids') or len(cdp.pcs_ids) == 0:
204 return True
205
206
207 if hasattr(cdp, 'pivot_fixed') and not cdp.pivot_fixed:
208 return False
209
210
211 return True
212
213
215 """Generator method for looping over the full or reduced tensors.
216
217 @keyword red: A flag which if True causes the reduced tensors to be returned, and if False
218 the full tensors are returned.
219 @type red: bool
220 @return: The tensor index and the tensor.
221 @rtype: (int, AlignTensorData instance)
222 """
223
224
225 n = len(cdp.align_tensors.reduction)
226
227
228 data = cdp.align_tensors
229 list = data.reduction
230
231
232 if red:
233 index = 1
234 else:
235 index = 0
236
237
238 for i in range(n):
239 yield i, data[list[i][index]]
240