Package user_functions :: Module rdc
[hide private]
[frames] | no frames]

Source Code for Module user_functions.rdc

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-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 rdc user function definitions.""" 
 24   
 25  # Python module imports. 
 26  import dep_check 
 27  if dep_check.wx_module: 
 28      from wx import FD_OPEN, FD_SAVE 
 29  else: 
 30      FD_OPEN = -1 
 31      FD_SAVE = -1 
 32   
 33  # relax module imports. 
 34  from graphics import WIZARD_IMAGE_PATH 
 35  from pipe_control import align_tensor, pipes, rdc 
 36  from pipe_control.mol_res_spin import get_spin_ids 
 37  from user_functions.data import Uf_info; uf_info = Uf_info() 
 38  from user_functions.objects import Desc_container 
 39  from user_functions.wildcards import WILDCARD_GRACE_ALL 
 40   
 41   
 42  # The user function class. 
 43  uf_class = uf_info.add_class('rdc') 
 44  uf_class.title = "Class for handling residual dipolar couplings." 
 45  uf_class.menu_text = "&rdc" 
 46  uf_class.gui_icon = "relax.align_tensor" 
 47   
 48   
 49  # The rdc.back_calc user function. 
 50  uf = uf_info.add_uf('rdc.back_calc') 
 51  uf.title = "Back calculate the residual dipolar couplings." 
 52  uf.title_short = "RDC back calculation." 
 53  uf.display = True 
 54  uf.add_keyarg( 
 55      name = "align_id", 
 56      py_type = "str", 
 57      desc_short = "alignment ID string", 
 58      desc = "The alignment ID string.", 
 59      wiz_element_type = 'combo', 
 60      wiz_combo_iter = align_tensor.get_align_ids, 
 61      wiz_read_only = True, 
 62      can_be_none = True 
 63  ) 
 64  # Description. 
 65  uf.desc.append(Desc_container()) 
 66  uf.desc[-1].add_paragraph("This will back calculate the residual dipolar couplings (RDCs) if an alignment tensor is present and inter-dipole vectors have been loaded into the relax data store.") 
 67  uf.backend = rdc.back_calc 
 68  uf.menu_text = "&back_calc" 
 69  uf.gui_icon = "oxygen.categories.applications-education" 
 70  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 71  uf.wizard_apply_button = False 
 72   
 73   
 74  # The rdc.calc_q_factors user function. 
 75  uf = uf_info.add_uf('rdc.calc_q_factors') 
 76  uf.title = "Calculate the RDC Q factor for the selected spins." 
 77  uf.title_short = "RDC Q factor calculation." 
 78  uf.display = True 
 79  uf.add_keyarg( 
 80      name = "spin_id", 
 81      py_type = "str", 
 82      desc_short = "spin ID string", 
 83      desc = "The spin ID string for restricting to subset of all selected spins.", 
 84      can_be_none = True 
 85  ) 
 86  # Description. 
 87  uf.desc.append(Desc_container()) 
 88  uf.desc[-1].add_paragraph("For this to work, the back-calculated RDC data must first be generated by the analysis specific code.  Otherwise a warning will be given.") 
 89  # Prompt examples. 
 90  uf.desc.append(Desc_container("Prompt examples")) 
 91  uf.desc[-1].add_paragraph("To calculate the RDC Q factor for only the spins '@H26', '@H27', and '@H28', type one of:") 
 92  uf.desc[-1].add_prompt("relax> rdc.calc_q_factors('@H26 & @H27 & @H28')") 
 93  uf.desc[-1].add_prompt("relax> rdc.calc_q_factors(spin_id='@H26 & @H27 & @H28')") 
 94  uf.backend = rdc.q_factors 
 95  uf.menu_text = "&calc_q_factors" 
 96  uf.gui_icon = "oxygen.categories.applications-education" 
 97  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 98  uf.wizard_apply_button = False 
 99   
100   
101  # The rdc.copy user function. 
102  uf = uf_info.add_uf('rdc.copy') 
103  uf.title = "Copy RDC data from one data pipe to another." 
104  uf.title_short = "RDC copying." 
105  uf.add_keyarg( 
106      name = "pipe_from", 
107      py_type = "str", 
108      desc_short = "source pipe", 
109      desc = "The name of the pipe to copy the RDC data from.", 
110      wiz_element_type = 'combo', 
111      wiz_combo_iter = pipes.pipe_names, 
112      can_be_none = True 
113  ) 
114  uf.add_keyarg( 
115      name = "pipe_to", 
116      py_type = "str", 
117      desc_short = "destination pipe", 
118      desc = "The name of the pipe to copy the RDC data to.", 
119      wiz_element_type = 'combo', 
120      wiz_combo_iter = pipes.pipe_names, 
121      can_be_none = True 
122  ) 
123  uf.add_keyarg( 
124      name = "align_id", 
125      py_type = "str", 
126      desc_short = "alignment ID string", 
127      desc = "The alignment ID string.", 
128      wiz_element_type = 'combo', 
129      wiz_combo_iter = align_tensor.get_align_ids, 
130      wiz_read_only = True, 
131      can_be_none = True 
132  ) 
133  # Description. 
134  uf.desc.append(Desc_container()) 
135  uf.desc[-1].add_paragraph("This function will copy RDC data from 'pipe_from' to 'pipe_to'.  If align_id is not given then all RDC data will be copied, otherwise only a specific data set will be.") 
136  # Prompt examples. 
137  uf.desc.append(Desc_container("Prompt examples")) 
138  uf.desc[-1].add_paragraph("To copy all RDC data from pipe 'm1' to pipe 'm9', type one of:") 
139  uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9')") 
140  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9')") 
141  uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9', None)") 
142  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9', align_id=None)") 
143  uf.desc[-1].add_paragraph("To copy only the 'Th' RDC data from 'm3' to 'm6', type one of:") 
144  uf.desc[-1].add_prompt("relax> rdc.copy('m3', 'm6', 'Th')") 
145  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m3', pipe_to='m6', align_id='Th')") 
146  uf.backend = rdc.copy 
147  uf.menu_text = "cop&y" 
148  uf.gui_icon = "oxygen.actions.list-add" 
149  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
150   
151   
152  # The rdc.corr_plot user function. 
153  uf = uf_info.add_uf('rdc.corr_plot') 
154  uf.title = "Generate a correlation plot of the measured vs. the back-calculated RDCs." 
155  uf.title_short = "Correlation plot generation." 
156  uf.add_keyarg( 
157      name = "format", 
158      default = "grace", 
159      py_type = "str", 
160      desc_short = "format", 
161      desc = "The format of the plot data.", 
162      wiz_element_type = "combo", 
163      wiz_combo_choices = ["grace"], 
164      wiz_read_only = True, 
165      can_be_none = True 
166  ) 
167  uf.add_keyarg( 
168      name = "title", 
169      py_type = "str", 
170      desc_short = "alternative plot title", 
171      desc = "The title for the plot, overriding the default.", 
172      can_be_none = True 
173  ) 
174  uf.add_keyarg( 
175      name = "subtitle", 
176      py_type = "str", 
177      desc_short = "alternative plot subtitle", 
178      desc = "The subtitle for the plot, overriding the default.", 
179      can_be_none = True 
180  ) 
181  uf.add_keyarg( 
182      name = "file", 
183      default = "rdc_corr_plot.agr", 
184      py_type = "str", 
185      arg_type = "file sel", 
186      desc_short = "Grace file name", 
187      desc = "The name of the Grace file to create.", 
188      wiz_filesel_wildcard = WILDCARD_GRACE_ALL, 
189      wiz_filesel_style = FD_SAVE 
190  ) 
191  uf.add_keyarg( 
192      name = "dir", 
193      py_type = "str", 
194      arg_type = "dir", 
195      desc_short = "directory name", 
196      desc = "The directory name.", 
197      can_be_none = True 
198  ) 
199  uf.add_keyarg( 
200      name = "force", 
201      default = False, 
202      py_type = "bool", 
203      desc_short = "force flag", 
204      desc = "A flag which if True will cause the file to be overwritten." 
205  ) 
206  # Description. 
207  uf.desc.append(Desc_container()) 
208  uf.desc[-1].add_paragraph("Two formats are currently supported.  If format is set to 'grace', then a Grace plot file will be created.  If the format is not set then a plain text list of the measured and back-calculated data will be created.") 
209  # Prompt examples. 
210  uf.desc.append(Desc_container("Prompt examples")) 
211  uf.desc[-1].add_paragraph("To create a Grace plot of the data, type:") 
212  uf.desc[-1].add_prompt("relax> rdc.corr_plot()") 
213  uf.desc[-1].add_paragraph("To create a plain text list of the measured and back-calculated data, type one of:") 
214  uf.desc[-1].add_prompt("relax> rdc.corr_plot(None)") 
215  uf.desc[-1].add_prompt("relax> rdc.corr_plot(format=None)") 
216  uf.backend = rdc.corr_plot 
217  uf.menu_text = "corr_&plot" 
218  uf.gui_icon = "relax.grace_icon" 
219  uf.wizard_size = (900, 600) 
220  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
221  uf.wizard_apply_button = False 
222   
223   
224  # The rdc.delete user function. 
225  uf = uf_info.add_uf('rdc.delete') 
226  uf.title = "Delete the RDC data corresponding to the alignment ID." 
227  uf.title_short = "RDC deletion." 
228  uf.add_keyarg( 
229      name = "align_id", 
230      py_type = "str", 
231      desc_short = "alignment ID string", 
232      desc = "The alignment ID string of the data to delete.", 
233      wiz_element_type = 'combo', 
234      wiz_combo_iter = align_tensor.get_align_ids, 
235      wiz_read_only = True, 
236      can_be_none = True 
237  ) 
238  # Description. 
239  uf.desc.append(Desc_container()) 
240  uf.desc[-1].add_paragraph("This will delete all RDC data associated with the alignment ID in the current data pipe.") 
241  # Prompt examples. 
242  uf.desc.append(Desc_container("Prompt examples")) 
243  uf.desc[-1].add_paragraph("To delete the RDC data corresponding to align_id='PH_gel', type:") 
244  uf.desc[-1].add_prompt("relax> rdc.delete('PH_gel')") 
245  uf.backend = rdc.delete 
246  uf.menu_text = "&delete" 
247  uf.gui_icon = "oxygen.actions.list-remove" 
248  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
249   
250   
251  # The rdc.display user function. 
252  uf = uf_info.add_uf('rdc.display') 
253  uf.title = "Display the RDC data corresponding to the alignment ID." 
254  uf.title_short = "RDC data display." 
255  uf.display = True 
256  uf.add_keyarg( 
257      name = "align_id", 
258      py_type = "str", 
259      desc_short = "alignment ID string", 
260      desc = "The alignment ID string.", 
261      wiz_element_type = 'combo', 
262      wiz_combo_iter = align_tensor.get_align_ids, 
263      wiz_read_only = True 
264  ) 
265  uf.add_keyarg( 
266      name = "bc", 
267      default = False, 
268      py_type = "bool", 
269      desc_short = "back-calculation flag", 
270      desc = "A flag which if set will display the back-calculated rather than measured RDCs." 
271  ) 
272  # Description. 
273  uf.desc.append(Desc_container()) 
274  uf.desc[-1].add_paragraph("This will display all of the RDC data associated with the alignment ID in the current data pipe.") 
275  # Prompt examples. 
276  uf.desc.append(Desc_container("Prompt examples")) 
277  uf.desc[-1].add_paragraph("To display the 'phage' RDC data, type:") 
278  uf.desc[-1].add_prompt("relax> rdc.display('phage')") 
279  uf.backend = rdc.display 
280  uf.menu_text = "di&splay" 
281  uf.gui_icon = "oxygen.actions.document-preview" 
282  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
283   
284   
285  # The rdc.read user function. 
286  uf = uf_info.add_uf('rdc.read') 
287  uf.title = "Read the RDC data from file." 
288  uf.title_short = "RDC data reading." 
289  uf.add_keyarg( 
290      name = "align_id", 
291      py_type = "str", 
292      desc_short = "alignment ID string", 
293      desc = "The alignment ID string.", 
294      wiz_element_type = 'combo', 
295      wiz_combo_iter = align_tensor.get_align_ids 
296  ) 
297  uf.add_keyarg( 
298      name = "file", 
299      py_type = "str", 
300      arg_type = "file sel", 
301      desc_short = "file name", 
302      desc = "The name of the file containing the RDC data.", 
303      wiz_filesel_style = FD_OPEN 
304  ) 
305  uf.add_keyarg( 
306      name = "dir", 
307      py_type = "str", 
308      arg_type = "dir", 
309      desc_short = "directory name", 
310      desc = "The directory where the file is located.", 
311      can_be_none = True 
312  ) 
313  uf.add_keyarg( 
314      name = "data_type", 
315      default = "D", 
316      py_type = "str", 
317      desc_short = "data type", 
318      desc = "Specify if the RDC data is in the D or 2D format, or the T = J + D format.", 
319      wiz_element_type = "combo", 
320      wiz_combo_choices = ["D", "2D", "T"], 
321      wiz_read_only = True 
322  ) 
323  uf.add_keyarg( 
324      name = "spin_id1_col", 
325      default = 1, 
326      py_type = "int", 
327      min = 1, 
328      desc_short = "first spin ID column", 
329      desc = "The spin ID string column for the first spin." 
330  ) 
331  uf.add_keyarg( 
332      name = "spin_id2_col", 
333      default = 2, 
334      py_type = "int", 
335      min = 1, 
336      desc_short = "second spin ID column", 
337      desc = "The spin ID string column for the second spin." 
338  ) 
339  uf.add_keyarg( 
340      name = "data_col", 
341      py_type = "int", 
342      desc_short = "data column", 
343      desc = "The RDC data column.", 
344      can_be_none = True 
345  ) 
346  uf.add_keyarg( 
347      name = "error_col", 
348      py_type = "int", 
349      desc_short = "error column", 
350      desc = "The experimental error column.", 
351      can_be_none = True 
352  ) 
353  uf.add_keyarg( 
354      name = "sep", 
355      py_type = "str", 
356      desc_short = "column separator", 
357      desc = "The column separator (the default is white space).", 
358      wiz_element_type = "combo", 
359      wiz_combo_choices = ["white space", ",", ";", ":"], 
360      wiz_combo_data = [None, ",", ";", ":"], 
361      wiz_read_only = False, 
362      can_be_none = True 
363  ) 
364  uf.add_keyarg( 
365      name = "neg_g_corr", 
366      default = False, 
367      py_type = "bool", 
368      desc_short = "negative gyromagnetic ratio correction", 
369      desc = "A flag which is used to correct for the negative gyromagnetic ratio of 15N.  If set to True, all RDC values will be inverted prior to being stored in the relax data store." 
370  ) 
371  uf.add_keyarg( 
372      name = "absolute", 
373      default = False, 
374      py_type = "bool", 
375      desc_short = "absolute RDCs", 
376      desc = "A flag which indicates that the loaded RDCs are are signless." 
377  ) 
378  # Description. 
379  uf.desc.append(Desc_container()) 
380  uf.desc[-1].add_paragraph("This will read RDC data from a file and associate it with an alignment ID, either a new ID or a preexisting one with no RDC data.") 
381  uf.desc[-1].add_paragraph("The data type is used to specify how the RDC is defined.  It can be set to a number of values:") 
382  uf.desc[-1].add_list_element("'D' means that the splitting in the aligned sample was taken as J + D.") 
383  uf.desc[-1].add_list_element("'2D' means that the splitting in the aligned sample was assumed to be J + 2D.") 
384  uf.desc[-1].add_list_element("'T' means that the file contains T = J + D values.") 
385  uf.desc[-1].add_paragraph("Internally, relax uses the D notation.  Therefore if set to '2D', the values will be doubled when read in.  If the 'T' data type is specified, then J couplings must be present for this data to be of any use.") 
386  uf.desc[-1].add_paragraph("If the negative gyromagnetic ratio correction flag is set, a sign inversion will be applied to all RDC values to be loaded.  This is sometimes needed for 15N if the data is not compensated for the negative gyromagnetic ratio.") 
387  uf.desc[-1].add_paragraph("The absolute RDCs flag is used for RDCs in which the sign is unknown.  All absolute RDCs loaded will be converted to positive values.") 
388  # Prompt examples. 
389  uf.desc.append(Desc_container("Prompt examples")) 
390  uf.desc[-1].add_paragraph("The following commands will read the RDC data out of the file 'Tb.txt' where the columns are separated by the symbol ',', and store the RDCs under the ID 'Tb':") 
391  uf.desc[-1].add_prompt("relax> rdc.read('Tb', 'Tb.txt', sep=',')") 
392  uf.desc[-1].add_paragraph("If the individual spin RDC errors are located in the file 'rdc_err.txt' in column number 5, then to read these values into relax, assuming J + D was measured, type one of:") 
393  uf.desc[-1].add_prompt("relax> rdc.read('phage', 'rdc_err.txt', data_type='D', error_col=5)") 
394  uf.desc[-1].add_prompt("relax> rdc.read(align_id='phage', file='rdc_err.txt', data_type='D', error_col=5)") 
395  uf.backend = rdc.read 
396  uf.menu_text = "&read" 
397  uf.gui_icon = "oxygen.actions.document-open" 
398  uf.wizard_height_desc = 300 
399  uf.wizard_size = (1000, 750) 
400  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
401   
402   
403  # The rdc.set_errors user function. 
404  uf = uf_info.add_uf('rdc.set_errors') 
405  uf.title = "Set the errors for the RDCs." 
406  uf.title_short = "RDC error setting." 
407  uf.add_keyarg( 
408      name = "align_id", 
409      py_type = "str", 
410      desc_short = "alignment ID string", 
411      desc = "The optional alignment ID string.", 
412      wiz_element_type = 'combo', 
413      wiz_combo_iter = align_tensor.get_align_ids, 
414      wiz_read_only = True, 
415      can_be_none = True 
416  ) 
417  uf.add_keyarg( 
418      name = "spin_id1", 
419      py_type = "str", 
420      arg_type = "spin ID", 
421      desc_short = "first spin ID string", 
422      desc = "The optional spin ID string of the first spin.", 
423      wiz_combo_iter = get_spin_ids, 
424      can_be_none = True 
425  ) 
426  uf.add_keyarg( 
427      name = "spin_id2", 
428      py_type = "str", 
429      arg_type = "spin ID", 
430      desc_short = "second spin ID string", 
431      desc = "The optional spin ID string of the second spin.", 
432      wiz_combo_iter = get_spin_ids, 
433      can_be_none = True 
434  ) 
435  uf.add_keyarg( 
436      name = "sd", 
437      default = 1.0, 
438      py_type = "num", 
439      desc_short = "RDC error (Hz)", 
440      desc = "The RDC standard deviation value in Hertz." 
441  ) 
442  # Description. 
443  uf.desc.append(Desc_container()) 
444  uf.desc[-1].add_paragraph("If the RDC errors have not already been read from a RDC data file or if they need to be changed, then the errors can be set via this user function.") 
445  uf.backend = rdc.set_errors 
446  uf.menu_text = "&set_errors" 
447  uf.gui_icon = "oxygen.actions.edit-rename" 
448  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
449   
450   
451  # The rdc.weight user function. 
452  uf = uf_info.add_uf('rdc.weight') 
453  uf.title = "Set optimisation weights on the RDC data." 
454  uf.title_short = "RDC weighting." 
455  uf.add_keyarg( 
456      name = "align_id", 
457      py_type = "str", 
458      desc_short = "alignment ID string", 
459      desc = "The alignment ID string.", 
460      wiz_element_type = 'combo', 
461      wiz_combo_iter = align_tensor.get_align_ids, 
462      wiz_read_only = True 
463  ) 
464  uf.add_keyarg( 
465      name = "spin_id", 
466      py_type = "str", 
467      desc_short = "spin ID string", 
468      desc = "The spin ID string." 
469  ) 
470  uf.add_keyarg( 
471      name = "weight", 
472      default = 1.0, 
473      py_type = "num", 
474      desc_short = "weight", 
475      desc = "The weighting value." 
476  ) 
477  # Description. 
478  uf.desc.append(Desc_container()) 
479  uf.desc[-1].add_paragraph("This can be used to force the RDC to contribute more or less to the chi-squared optimisation statistic.  The higher the value, the more importance the RDC will have.") 
480  uf.backend = rdc.weight 
481  uf.menu_text = "wei&ght" 
482  uf.wizard_size = (700, 500) 
483  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
484   
485   
486  # The rdc.write user function. 
487  uf = uf_info.add_uf('rdc.write') 
488  uf.title = "Write the RDC data to file." 
489  uf.title_short = "RDC data writing." 
490  uf.add_keyarg( 
491      name = "align_id", 
492      py_type = "str", 
493      desc_short = "alignment ID string", 
494      desc = "The alignment ID string.", 
495      wiz_element_type = 'combo', 
496      wiz_combo_iter = align_tensor.get_align_ids, 
497      wiz_read_only = True 
498  ) 
499  uf.add_keyarg( 
500      name = "file", 
501      py_type = "str", 
502      arg_type = "file sel", 
503      desc_short = "file name", 
504      desc = "The name of the file.", 
505      wiz_filesel_style = FD_SAVE 
506  ) 
507  uf.add_keyarg( 
508      name = "dir", 
509      py_type = "str", 
510      arg_type = "dir", 
511      desc_short = "directory name", 
512      desc = "The directory name.", 
513      can_be_none = True 
514  ) 
515  uf.add_keyarg( 
516      name = "bc", 
517      default = False, 
518      py_type = "bool", 
519      desc_short = "back-calculation flag", 
520      desc = "A flag which if set will write out the back-calculated rather than measured RDCs." 
521  ) 
522  uf.add_keyarg( 
523      name = "force", 
524      default = False, 
525      py_type = "bool", 
526      desc_short = "force flag", 
527      desc = "A flag which if True will cause the file to be overwritten." 
528  ) 
529  # Description. 
530  uf.desc.append(Desc_container()) 
531  uf.desc[-1].add_paragraph("If no directory name is given, the file will be placed in the current working directory.  The alignment ID is required for selecting which RDC data set will be written to file.") 
532  uf.backend = rdc.write 
533  uf.menu_text = "&write" 
534  uf.gui_icon = "oxygen.actions.document-save" 
535  uf.wizard_size = (800, 600) 
536  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
537