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

Source Code for Module user_functions.rdc

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2002-2004,2007-2015,2019 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  # relax module imports. 
 26  from graphics import WIZARD_IMAGE_PATH 
 27  from pipe_control import align_tensor, pipes, rdc 
 28  from pipe_control.mol_res_spin import get_spin_ids 
 29  from user_functions.data import Uf_info; uf_info = Uf_info() 
 30  from user_functions.objects import Desc_container 
 31  from user_functions.wildcards import WILDCARD_GRACE_ALL 
 32   
 33   
 34  # The user function class. 
 35  uf_class = uf_info.add_class('rdc') 
 36  uf_class.title = "Class for handling residual dipolar couplings." 
 37  uf_class.menu_text = "&rdc" 
 38  uf_class.gui_icon = "relax.align_tensor" 
 39   
 40   
 41  # The rdc.back_calc user function. 
 42  uf = uf_info.add_uf('rdc.back_calc') 
 43  uf.title = "Back calculate the residual dipolar couplings." 
 44  uf.title_short = "RDC back calculation." 
 45  uf.display = True 
 46  uf.add_keyarg( 
 47      name = "align_id", 
 48      basic_types = ["str"], 
 49      desc_short = "alignment ID string", 
 50      desc = "The alignment ID string.", 
 51      wiz_element_type = 'combo', 
 52      wiz_combo_iter = align_tensor.get_align_ids, 
 53      wiz_read_only = True, 
 54      can_be_none = True 
 55  ) 
 56  # Description. 
 57  uf.desc.append(Desc_container()) 
 58  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.") 
 59  uf.backend = rdc.back_calc 
 60  uf.menu_text = "&back_calc" 
 61  uf.gui_icon = "oxygen.categories.applications-education" 
 62  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 63  uf.wizard_apply_button = False 
 64   
 65   
 66  # The rdc.calc_q_factors user function. 
 67  uf = uf_info.add_uf('rdc.calc_q_factors') 
 68  uf.title = "Calculate the RDC Q factor for the selected spins." 
 69  uf.title_short = "RDC Q factor calculation." 
 70  uf.display = True 
 71  uf.add_keyarg( 
 72      name = "spin_id", 
 73      basic_types = ["str"], 
 74      desc_short = "spin ID string", 
 75      desc = "The spin ID string for restricting to subset of all selected spins.", 
 76      can_be_none = True 
 77  ) 
 78  uf.add_keyarg( 
 79      name = "verbosity", 
 80      default = 1, 
 81      basic_types = ["int"], 
 82      desc_short = "verbosity level", 
 83      desc = "The amount of information to print out.  Set to zero to silence the user function, or one to see all messages." 
 84  ) 
 85  # Description. 
 86  uf.desc.append(Desc_container()) 
 87  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.") 
 88  # Prompt examples. 
 89  uf.desc.append(Desc_container("Prompt examples")) 
 90  uf.desc[-1].add_paragraph("To calculate the RDC Q factor for only the spins '@H26', '@H27', and '@H28', type one of:") 
 91  uf.desc[-1].add_prompt("relax> rdc.calc_q_factors('@H26 & @H27 & @H28')") 
 92  uf.desc[-1].add_prompt("relax> rdc.calc_q_factors(spin_id='@H26 & @H27 & @H28')") 
 93  uf.backend = rdc.q_factors 
 94  uf.menu_text = "&calc_q_factors" 
 95  uf.gui_icon = "oxygen.categories.applications-education" 
 96  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 97  uf.wizard_apply_button = False 
 98   
 99   
100  # The rdc.copy user function. 
101  uf = uf_info.add_uf('rdc.copy') 
102  uf.title = "Copy RDC data from one data pipe to another." 
103  uf.title_short = "RDC copying." 
104  uf.add_keyarg( 
105      name = "pipe_from", 
106      basic_types = ["str"], 
107      desc_short = "source pipe", 
108      desc = "The name of the pipe to copy the RDC data from.", 
109      wiz_element_type = 'combo', 
110      wiz_combo_iter = pipes.pipe_names, 
111      can_be_none = True 
112  ) 
113  uf.add_keyarg( 
114      name = "pipe_to", 
115      basic_types = ["str"], 
116      desc_short = "destination pipe", 
117      desc = "The name of the pipe to copy the RDC data to.", 
118      wiz_element_type = 'combo', 
119      wiz_combo_iter = pipes.pipe_names, 
120      can_be_none = True 
121  ) 
122  uf.add_keyarg( 
123      name = "align_id", 
124      basic_types = ["str"], 
125      desc_short = "alignment ID string", 
126      desc = "The alignment ID string.", 
127      wiz_element_type = 'combo', 
128      wiz_combo_iter = align_tensor.get_align_ids, 
129      wiz_read_only = True, 
130      can_be_none = True 
131  ) 
132  uf.add_keyarg( 
133      name = "back_calc", 
134      default = True, 
135      basic_types = ["bool"], 
136      desc_short = "back-calculated data flag", 
137      desc = "A flag which if True will cause any back-calculated RDCs present to also be copied with the real values and errors." 
138  ) 
139  # Description. 
140  uf.desc.append(Desc_container()) 
141  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.") 
142  # Prompt examples. 
143  uf.desc.append(Desc_container("Prompt examples")) 
144  uf.desc[-1].add_paragraph("To copy all RDC data from pipe 'm1' to pipe 'm9', type one of:") 
145  uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9')") 
146  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9')") 
147  uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9', None)") 
148  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9', align_id=None)") 
149  uf.desc[-1].add_paragraph("To copy only the 'Th' RDC data from 'm3' to 'm6', type one of:") 
150  uf.desc[-1].add_prompt("relax> rdc.copy('m3', 'm6', 'Th')") 
151  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m3', pipe_to='m6', align_id='Th')") 
152  uf.backend = rdc.copy 
153  uf.menu_text = "cop&y" 
154  uf.gui_icon = "oxygen.actions.list-add" 
155  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
156   
157   
158  # The rdc.corr_plot user function. 
159  uf = uf_info.add_uf('rdc.corr_plot') 
160  uf.title = "Generate a correlation plot of the measured vs. the back-calculated RDCs." 
161  uf.title_short = "Correlation plot generation." 
162  uf.add_keyarg( 
163      name = "format", 
164      default = "grace", 
165      basic_types = ["str"], 
166      desc_short = "format", 
167      desc = "The format of the plot data.", 
168      wiz_element_type = "combo", 
169      wiz_combo_choices = ["grace"], 
170      wiz_read_only = True, 
171      can_be_none = True 
172  ) 
173  uf.add_keyarg( 
174      name = "title", 
175      basic_types = ["str"], 
176      desc_short = "alternative plot title", 
177      desc = "The title for the plot, overriding the default.", 
178      can_be_none = True 
179  ) 
180  uf.add_keyarg( 
181      name = "subtitle", 
182      basic_types = ["str"], 
183      desc_short = "alternative plot subtitle", 
184      desc = "The subtitle for the plot, overriding the default.", 
185      can_be_none = True 
186  ) 
187  uf.add_keyarg( 
188      name = "file", 
189      default = "rdc_corr_plot.agr", 
190      arg_type = "file sel write", 
191      desc_short = "Grace file name", 
192      desc = "The name of the Grace file to create.", 
193      wiz_filesel_wildcard = WILDCARD_GRACE_ALL, 
194  ) 
195  uf.add_keyarg( 
196      name = "dir", 
197      arg_type = "dir", 
198      desc_short = "directory name", 
199      desc = "The directory name.", 
200      can_be_none = True 
201  ) 
202  uf.add_keyarg( 
203      name = "force", 
204      default = False, 
205      basic_types = ["bool"], 
206      desc_short = "force flag", 
207      desc = "A flag which if True will cause the file to be overwritten." 
208  ) 
209  # Description. 
210  uf.desc.append(Desc_container()) 
211  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.") 
212  # Prompt examples. 
213  uf.desc.append(Desc_container("Prompt examples")) 
214  uf.desc[-1].add_paragraph("To create a Grace plot of the data, type:") 
215  uf.desc[-1].add_prompt("relax> rdc.corr_plot()") 
216  uf.desc[-1].add_paragraph("To create a plain text list of the measured and back-calculated data, type one of:") 
217  uf.desc[-1].add_prompt("relax> rdc.corr_plot(None)") 
218  uf.desc[-1].add_prompt("relax> rdc.corr_plot(format=None)") 
219  uf.backend = rdc.corr_plot 
220  uf.menu_text = "corr_&plot" 
221  uf.gui_icon = "relax.grace_icon" 
222  uf.wizard_size = (900, 600) 
223  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
224  uf.wizard_apply_button = False 
225   
226   
227  # The rdc.delete user function. 
228  uf = uf_info.add_uf('rdc.delete') 
229  uf.title = "Delete the RDC data corresponding to the alignment ID." 
230  uf.title_short = "RDC deletion." 
231  uf.add_keyarg( 
232      name = "align_id", 
233      basic_types = ["str"], 
234      desc_short = "alignment ID string", 
235      desc = "The alignment ID string of the data to delete.", 
236      wiz_element_type = 'combo', 
237      wiz_combo_iter = align_tensor.get_align_ids, 
238      wiz_read_only = True, 
239      can_be_none = True 
240  ) 
241  # Description. 
242  uf.desc.append(Desc_container()) 
243  uf.desc[-1].add_paragraph("This will delete all RDC data associated with the alignment ID in the current data pipe.") 
244  # Prompt examples. 
245  uf.desc.append(Desc_container("Prompt examples")) 
246  uf.desc[-1].add_paragraph("To delete the RDC data corresponding to align_id='PH_gel', type:") 
247  uf.desc[-1].add_prompt("relax> rdc.delete('PH_gel')") 
248  uf.backend = rdc.delete 
249  uf.menu_text = "&delete" 
250  uf.gui_icon = "oxygen.actions.list-remove" 
251  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
252   
253   
254  # The rdc.display user function. 
255  uf = uf_info.add_uf('rdc.display') 
256  uf.title = "Display the RDC data corresponding to the alignment ID." 
257  uf.title_short = "RDC data display." 
258  uf.display = True 
259  uf.add_keyarg( 
260      name = "align_id", 
261      basic_types = ["str"], 
262      desc_short = "alignment ID string", 
263      desc = "The alignment ID string.", 
264      wiz_element_type = 'combo', 
265      wiz_combo_iter = align_tensor.get_align_ids, 
266      wiz_read_only = True 
267  ) 
268  uf.add_keyarg( 
269      name = "bc", 
270      default = False, 
271      basic_types = ["bool"], 
272      desc_short = "back-calculation flag", 
273      desc = "A flag which if set will display the back-calculated rather than measured RDCs." 
274  ) 
275  # Description. 
276  uf.desc.append(Desc_container()) 
277  uf.desc[-1].add_paragraph("This will display all of the RDC data associated with the alignment ID in the current data pipe.") 
278  # Prompt examples. 
279  uf.desc.append(Desc_container("Prompt examples")) 
280  uf.desc[-1].add_paragraph("To display the 'phage' RDC data, type:") 
281  uf.desc[-1].add_prompt("relax> rdc.display('phage')") 
282  uf.backend = rdc.display 
283  uf.menu_text = "di&splay" 
284  uf.gui_icon = "oxygen.actions.document-preview" 
285  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
286   
287   
288  # The rdc.read user function. 
289  uf = uf_info.add_uf('rdc.read') 
290  uf.title = "Read the RDC data from file." 
291  uf.title_short = "RDC data reading." 
292  uf.add_keyarg( 
293      name = "align_id", 
294      basic_types = ["str"], 
295      desc_short = "alignment ID string", 
296      desc = "The alignment ID string.", 
297      wiz_element_type = 'combo', 
298      wiz_combo_iter = align_tensor.get_align_ids 
299  ) 
300  uf.add_keyarg( 
301      name = "file", 
302      arg_type = "file sel read", 
303      desc_short = "file name", 
304      desc = "The name of the file containing the RDC data.", 
305  ) 
306  uf.add_keyarg( 
307      name = "dir", 
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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      arg_type = "spin ID", 
420      desc_short = "first spin ID string", 
421      desc = "The optional spin ID string of the first spin.", 
422      wiz_combo_iter = get_spin_ids, 
423      can_be_none = True 
424  ) 
425  uf.add_keyarg( 
426      name = "spin_id2", 
427      arg_type = "spin ID", 
428      desc_short = "second spin ID string", 
429      desc = "The optional spin ID string of the second spin.", 
430      wiz_combo_iter = get_spin_ids, 
431      can_be_none = True 
432  ) 
433  uf.add_keyarg( 
434      name = "sd", 
435      default = 1.0, 
436      basic_types = ["number"], 
437      desc_short = "RDC error (Hz)", 
438      desc = "The RDC standard deviation value in Hertz." 
439  ) 
440  # Description. 
441  uf.desc.append(Desc_container()) 
442  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.") 
443  uf.backend = rdc.set_errors 
444  uf.menu_text = "&set_errors" 
445  uf.gui_icon = "oxygen.actions.edit-rename" 
446  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
447   
448   
449  # The rdc.weight user function. 
450  uf = uf_info.add_uf('rdc.weight') 
451  uf.title = "Set optimisation weights on the RDC data." 
452  uf.title_short = "RDC weighting." 
453  uf.add_keyarg( 
454      name = "align_id", 
455      basic_types = ["str"], 
456      desc_short = "alignment ID string", 
457      desc = "The alignment ID string.", 
458      wiz_element_type = 'combo', 
459      wiz_combo_iter = align_tensor.get_align_ids, 
460      wiz_read_only = True 
461  ) 
462  uf.add_keyarg( 
463      name = "spin_id", 
464      basic_types = ["str"], 
465      desc_short = "spin ID string", 
466      desc = "The spin ID string.", 
467      can_be_none = True 
468  ) 
469  uf.add_keyarg( 
470      name = "weight", 
471      default = 1.0, 
472      basic_types = ["number"], 
473      desc_short = "weight", 
474      desc = "The weighting value." 
475  ) 
476  # Description. 
477  uf.desc.append(Desc_container()) 
478  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.") 
479  uf.backend = rdc.weight 
480  uf.menu_text = "wei&ght" 
481  uf.wizard_size = (700, 500) 
482  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
483   
484   
485  # The rdc.write user function. 
486  uf = uf_info.add_uf('rdc.write') 
487  uf.title = "Write the RDC data to file." 
488  uf.title_short = "RDC data writing." 
489  uf.add_keyarg( 
490      name = "align_id", 
491      basic_types = ["str"], 
492      desc_short = "alignment ID string", 
493      desc = "The alignment ID string.", 
494      wiz_element_type = 'combo', 
495      wiz_combo_iter = align_tensor.get_align_ids, 
496      wiz_read_only = True 
497  ) 
498  uf.add_keyarg( 
499      name = "file", 
500      arg_type = "file sel write", 
501      desc_short = "file name", 
502      desc = "The name of the file.", 
503  ) 
504  uf.add_keyarg( 
505      name = "dir", 
506      arg_type = "dir", 
507      desc_short = "directory name", 
508      desc = "The directory name.", 
509      can_be_none = True 
510  ) 
511  uf.add_keyarg( 
512      name = "bc", 
513      default = False, 
514      basic_types = ["bool"], 
515      desc_short = "back-calculation flag", 
516      desc = "A flag which if set will write out the back-calculated rather than measured RDCs." 
517  ) 
518  uf.add_keyarg( 
519      name = "force", 
520      default = False, 
521      basic_types = ["bool"], 
522      desc_short = "force flag", 
523      desc = "A flag which if True will cause the file to be overwritten." 
524  ) 
525  # Description. 
526  uf.desc.append(Desc_container()) 
527  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.") 
528  uf.backend = rdc.write 
529  uf.menu_text = "&write" 
530  uf.gui_icon = "oxygen.actions.document-save" 
531  uf.wizard_size = (800, 600) 
532  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
533