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

Source Code for Module user_functions.rdc

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2013 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 generic_fns import align_tensor, pipes, rdc 
 35  from generic_fns.mol_res_spin import get_spin_ids 
 36  from graphics import WIZARD_IMAGE_PATH 
 37  from user_functions.data import Uf_info; uf_info = Uf_info() 
 38  from user_functions.objects import Desc_container 
 39   
 40   
 41  # The user function class. 
 42  uf_class = uf_info.add_class('rdc') 
 43  uf_class.title = "Class for handling residual dipolar couplings." 
 44  uf_class.menu_text = "&rdc" 
 45  uf_class.gui_icon = "relax.align_tensor" 
 46   
 47   
 48  # The rdc.back_calc user function. 
 49  uf = uf_info.add_uf('rdc.back_calc') 
 50  uf.title = "Back calculate the residual dipolar couplings." 
 51  uf.title_short = "RDC back calculation." 
 52  uf.display = True 
 53  uf.add_keyarg( 
 54      name = "align_id", 
 55      py_type = "str", 
 56      desc_short = "alignment ID string", 
 57      desc = "The alignment ID string.", 
 58      wiz_element_type = 'combo', 
 59      wiz_combo_iter = align_tensor.get_ids, 
 60      wiz_read_only = True, 
 61      can_be_none = True 
 62  ) 
 63  # Description. 
 64  uf.desc.append(Desc_container()) 
 65  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.") 
 66  uf.backend = rdc.back_calc 
 67  uf.menu_text = "&back_calc" 
 68  uf.gui_icon = "oxygen.categories.applications-education" 
 69  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 70  uf.wizard_apply_button = False 
 71   
 72   
 73  # The rdc.calc_q_factors user function. 
 74  uf = uf_info.add_uf('rdc.calc_q_factors') 
 75  uf.title = "Calculate the RDC Q factor for the selected spins." 
 76  uf.title_short = "RDC Q factor calculation." 
 77  uf.display = True 
 78  uf.add_keyarg( 
 79      name = "spin_id", 
 80      py_type = "str", 
 81      desc_short = "spin ID string", 
 82      desc = "The spin ID string for restricting to subset of all selected spins.", 
 83      can_be_none = True 
 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      py_type = "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      py_type = "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      py_type = "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_ids, 
129      wiz_read_only = True, 
130      can_be_none = True 
131  ) 
132  # Description. 
133  uf.desc.append(Desc_container()) 
134  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.") 
135  # Prompt examples. 
136  uf.desc.append(Desc_container("Prompt examples")) 
137  uf.desc[-1].add_paragraph("To copy all RDC data from pipe 'm1' to pipe 'm9', type one of:") 
138  uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9')") 
139  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9')") 
140  uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9', None)") 
141  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9', align_id=None)") 
142  uf.desc[-1].add_paragraph("To copy only the 'Th' RDC data from 'm3' to 'm6', type one of:") 
143  uf.desc[-1].add_prompt("relax> rdc.copy('m3', 'm6', 'Th')") 
144  uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m3', pipe_to='m6', align_id='Th')") 
145  uf.backend = rdc.copy 
146  uf.menu_text = "cop&y" 
147  uf.gui_icon = "oxygen.actions.list-add" 
148  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
149   
150   
151  # The rdc.corr_plot user function. 
152  uf = uf_info.add_uf('rdc.corr_plot') 
153  uf.title = "Generate a correlation plot of the measured vs. the back-calculated RDCs." 
154  uf.title_short = "Correlation plot generation." 
155  uf.add_keyarg( 
156      name = "format", 
157      default = "grace", 
158      py_type = "str", 
159      desc_short = "format", 
160      desc = "The format of the plot data.", 
161      wiz_element_type = "combo", 
162      wiz_combo_choices = ["grace"], 
163      wiz_read_only = True, 
164      can_be_none = True 
165  ) 
166  uf.add_keyarg( 
167      name = "file", 
168      default = "rdc_corr_plot.agr", 
169      py_type = "str", 
170      arg_type = "file sel", 
171      desc_short = "Grace file name", 
172      desc = "The name of the Grace file to create.", 
173      wiz_filesel_wildcard = "Grace files (*.agr)|*.agr;*.AGR", 
174      wiz_filesel_style = FD_SAVE 
175  ) 
176  uf.add_keyarg( 
177      name = "dir", 
178      py_type = "str", 
179      arg_type = "dir", 
180      desc_short = "directory name", 
181      desc = "The directory name.", 
182      can_be_none = True 
183  ) 
184  uf.add_keyarg( 
185      name = "force", 
186      default = False, 
187      py_type = "bool", 
188      desc_short = "force flag", 
189      desc = "A flag which if True will cause the file to be overwritten." 
190  ) 
191  # Description. 
192  uf.desc.append(Desc_container()) 
193  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.") 
194  # Prompt examples. 
195  uf.desc.append(Desc_container("Prompt examples")) 
196  uf.desc[-1].add_paragraph("To create a Grace plot of the data, type:") 
197  uf.desc[-1].add_prompt("relax> rdc.corr_plot()") 
198  uf.desc[-1].add_paragraph("To create a plain text list of the measured and back-calculated data, type one of:") 
199  uf.desc[-1].add_prompt("relax> rdc.corr_plot(None)") 
200  uf.desc[-1].add_prompt("relax> rdc.corr_plot(format=None)") 
201  uf.backend = rdc.corr_plot 
202  uf.menu_text = "corr_&plot" 
203  uf.wizard_size = (800, 500) 
204  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
205  uf.wizard_apply_button = False 
206   
207   
208  # The rdc.delete user function. 
209  uf = uf_info.add_uf('rdc.delete') 
210  uf.title = "Delete the RDC data corresponding to the alignment ID." 
211  uf.title_short = "RDC deletion." 
212  uf.add_keyarg( 
213      name = "align_id", 
214      py_type = "str", 
215      desc_short = "alignment ID string", 
216      desc = "The alignment ID string of the data to delete.", 
217      wiz_element_type = 'combo', 
218      wiz_combo_iter = align_tensor.get_ids, 
219      wiz_read_only = True, 
220      can_be_none = True 
221  ) 
222  # Description. 
223  uf.desc.append(Desc_container()) 
224  uf.desc[-1].add_paragraph("This will delete all RDC data associated with the alignment ID in the current data pipe.") 
225  # Prompt examples. 
226  uf.desc.append(Desc_container("Prompt examples")) 
227  uf.desc[-1].add_paragraph("To delete the RDC data corresponding to align_id='PH_gel', type:") 
228  uf.desc[-1].add_prompt("relax> rdc.delete('PH_gel')") 
229  uf.backend = rdc.delete 
230  uf.menu_text = "&delete" 
231  uf.gui_icon = "oxygen.actions.list-remove" 
232  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
233   
234   
235  # The rdc.display user function. 
236  uf = uf_info.add_uf('rdc.display') 
237  uf.title = "Display the RDC data corresponding to the alignment ID." 
238  uf.title_short = "RDC data display." 
239  uf.display = True 
240  uf.add_keyarg( 
241      name = "align_id", 
242      py_type = "str", 
243      desc_short = "alignment ID string", 
244      desc = "The alignment ID string.", 
245      wiz_element_type = 'combo', 
246      wiz_combo_iter = align_tensor.get_ids, 
247      wiz_read_only = True 
248  ) 
249  uf.add_keyarg( 
250      name = "bc", 
251      default = False, 
252      py_type = "bool", 
253      desc_short = "back-calculation flag", 
254      desc = "A flag which if set will display the back-calculated rather than measured RDCs." 
255  ) 
256  # Description. 
257  uf.desc.append(Desc_container()) 
258  uf.desc[-1].add_paragraph("This will display all of the RDC data associated with the alignment ID in the current data pipe.") 
259  # Prompt examples. 
260  uf.desc.append(Desc_container("Prompt examples")) 
261  uf.desc[-1].add_paragraph("To display the 'phage' RDC data, type:") 
262  uf.desc[-1].add_prompt("relax> rdc.display('phage')") 
263  uf.backend = rdc.display 
264  uf.menu_text = "di&splay" 
265  uf.gui_icon = "oxygen.actions.document-preview" 
266  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
267   
268   
269  # The rdc.read user function. 
270  uf = uf_info.add_uf('rdc.read') 
271  uf.title = "Read the RDC data from file." 
272  uf.title_short = "RDC data reading." 
273  uf.add_keyarg( 
274      name = "align_id", 
275      py_type = "str", 
276      desc_short = "alignment ID string", 
277      desc = "The alignment ID string.", 
278      wiz_element_type = 'combo', 
279      wiz_combo_iter = align_tensor.get_ids 
280  ) 
281  uf.add_keyarg( 
282      name = "file", 
283      py_type = "str", 
284      arg_type = "file sel", 
285      desc_short = "file name", 
286      desc = "The name of the file containing the RDC data.", 
287      wiz_filesel_style = FD_OPEN 
288  ) 
289  uf.add_keyarg( 
290      name = "dir", 
291      py_type = "str", 
292      arg_type = "dir", 
293      desc_short = "directory name", 
294      desc = "The directory where the file is located.", 
295      can_be_none = True 
296  ) 
297  uf.add_keyarg( 
298      name = "data_type", 
299      default = "D", 
300      py_type = "str", 
301      desc_short = "data type", 
302      desc = "Specify if the RDC data is in the D or 2D format.", 
303      wiz_element_type = "combo", 
304      wiz_combo_choices = ["D", "2D"], 
305      wiz_read_only = True 
306  ) 
307  uf.add_keyarg( 
308      name = "spin_id1_col", 
309      default = 1, 
310      py_type = "int", 
311      min = 1, 
312      desc_short = "first spin ID column", 
313      desc = "The spin ID string column for the first spin." 
314  ) 
315  uf.add_keyarg( 
316      name = "spin_id2_col", 
317      default = 2, 
318      py_type = "int", 
319      min = 1, 
320      desc_short = "second spin ID column", 
321      desc = "The spin ID string column for the second spin." 
322  ) 
323  uf.add_keyarg( 
324      name = "data_col", 
325      py_type = "int", 
326      desc_short = "data column", 
327      desc = "The RDC data column.", 
328      can_be_none = True 
329  ) 
330  uf.add_keyarg( 
331      name = "error_col", 
332      py_type = "int", 
333      desc_short = "error column", 
334      desc = "The experimental error column.", 
335      can_be_none = True 
336  ) 
337  uf.add_keyarg( 
338      name = "sep", 
339      py_type = "str", 
340      desc_short = "column separator", 
341      desc = "The column separator (the default is white space).", 
342      wiz_element_type = "combo", 
343      wiz_combo_choices = ["white space", ",", ";", ":"], 
344      wiz_combo_data = [None, ",", ";", ":"], 
345      wiz_read_only = False, 
346      can_be_none = True 
347  ) 
348  uf.add_keyarg( 
349      name = "neg_g_corr", 
350      default = False, 
351      py_type = "bool", 
352      desc_short = "negative gyromagnetic ratio correction", 
353      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." 
354  ) 
355  uf.add_keyarg( 
356      name = "absolute", 
357      default = False, 
358      py_type = "bool", 
359      desc_short = "absolute RDCs", 
360      desc = "A flag which indicates that the loaded RDCs are are signless." 
361  ) 
362  # Description. 
363  uf.desc.append(Desc_container()) 
364  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.") 
365  uf.desc[-1].add_paragraph("The data type is used to specify how the RDC is defined.  It can be set to two values:") 
366  uf.desc[-1].add_list_element("'D' means that the splitting in the aligned sample was taken as J + D.") 
367  uf.desc[-1].add_list_element("'2D' means that the splitting in the aligned sample was assumed to be J + 2D.") 
368  uf.desc[-1].add_paragraph("Internally, relax uses the D notation.  Therefore if set to '2D', the values will be doubled when read in.") 
369  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.") 
370  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.") 
371  uf.desc[-1].add_paragraph("The spin system can be identified in the file using two different formats.  The first is the spin ID string column which can include the molecule name, the residue name and number, and the spin name and number.  Alternatively the molecule name, residue number and name, and spin number and name columns can be supplied allowing this information to be in separate columns.  Note that the numbering of columns starts at one.  The spin ID can be used to restrict the reading to certain spin types, for example only 15N spins when only residue information is in the file.") 
372  # Prompt examples. 
373  uf.desc.append(Desc_container("Prompt examples")) 
374  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':") 
375  uf.desc[-1].add_prompt("relax> rdc.read('Tb', 'Tb.txt', sep=',')") 
376  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:") 
377  uf.desc[-1].add_prompt("relax> rdc.read('phage', 'rdc_err.txt', data_type='D', error_col=5)") 
378  uf.desc[-1].add_prompt("relax> rdc.read(align_id='phage', file='rdc_err.txt', data_type='D', error_col=5)") 
379  uf.desc[-1].add_paragraph("If the RDCs correspond to the 'N' spin and other spin types such as 1H, 13C, etc. are loaded into relax, then type:") 
380  uf.desc[-1].add_prompt("relax> rdc.read('Tb', 'Tb.txt', spin_id='@N')") 
381  uf.backend = rdc.read 
382  uf.menu_text = "&read" 
383  uf.gui_icon = "oxygen.actions.document-open" 
384  uf.wizard_height_desc = 300 
385  uf.wizard_size = (1000, 750) 
386  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
387   
388   
389  # The rdc.set_errors user function. 
390  uf = uf_info.add_uf('rdc.set_errors') 
391  uf.title = "Set the errors for the RDCs." 
392  uf.title_short = "RDC error setting." 
393  uf.add_keyarg( 
394      name = "align_id", 
395      py_type = "str", 
396      desc_short = "alignment ID string", 
397      desc = "The optional alignment ID string.", 
398      wiz_element_type = 'combo', 
399      wiz_combo_iter = align_tensor.get_ids, 
400      wiz_read_only = True, 
401      can_be_none = True 
402  ) 
403  uf.add_keyarg( 
404      name = "spin_id1", 
405      py_type = "str", 
406      arg_type = "spin ID", 
407      desc_short = "first spin ID string", 
408      desc = "The optional spin ID string of the first spin.", 
409      wiz_combo_iter = get_spin_ids, 
410      can_be_none = True 
411  ) 
412  uf.add_keyarg( 
413      name = "spin_id2", 
414      py_type = "str", 
415      arg_type = "spin ID", 
416      desc_short = "second spin ID string", 
417      desc = "The optional spin ID string of the second spin.", 
418      wiz_combo_iter = get_spin_ids, 
419      can_be_none = True 
420  ) 
421  uf.add_keyarg( 
422      name = "sd", 
423      default = 1.0, 
424      py_type = "num", 
425      desc_short = "RDC error (Hz)", 
426      desc = "The RDC standard deviation value in Hertz." 
427  ) 
428  # Description. 
429  uf.desc.append(Desc_container()) 
430  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.") 
431  uf.backend = rdc.set_errors 
432  uf.menu_text = "&set_errors" 
433  uf.gui_icon = "oxygen.actions.edit-rename" 
434  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
435   
436   
437  # The rdc.weight user function. 
438  uf = uf_info.add_uf('rdc.weight') 
439  uf.title = "Set optimisation weights on the RDC data." 
440  uf.title_short = "RDC weighting." 
441  uf.add_keyarg( 
442      name = "align_id", 
443      py_type = "str", 
444      desc_short = "alignment ID string", 
445      desc = "The alignment ID string.", 
446      wiz_element_type = 'combo', 
447      wiz_combo_iter = align_tensor.get_ids, 
448      wiz_read_only = True 
449  ) 
450  uf.add_keyarg( 
451      name = "spin_id", 
452      py_type = "str", 
453      desc_short = "spin ID string", 
454      desc = "The spin ID string." 
455  ) 
456  uf.add_keyarg( 
457      name = "weight", 
458      default = 1.0, 
459      py_type = "num", 
460      desc_short = "weight", 
461      desc = "The weighting value." 
462  ) 
463  # Description. 
464  uf.desc.append(Desc_container()) 
465  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.") 
466  uf.backend = rdc.weight 
467  uf.menu_text = "wei&ght" 
468  uf.wizard_size = (700, 500) 
469  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
470   
471   
472  # The rdc.write user function. 
473  uf = uf_info.add_uf('rdc.write') 
474  uf.title = "Write the RDC data to file." 
475  uf.title_short = "RDC data writing." 
476  uf.add_keyarg( 
477      name = "align_id", 
478      py_type = "str", 
479      desc_short = "alignment ID string", 
480      desc = "The alignment ID string.", 
481      wiz_element_type = 'combo', 
482      wiz_combo_iter = align_tensor.get_ids, 
483      wiz_read_only = True 
484  ) 
485  uf.add_keyarg( 
486      name = "file", 
487      py_type = "str", 
488      arg_type = "file sel", 
489      desc_short = "file name", 
490      desc = "The name of the file.", 
491      wiz_filesel_style = FD_SAVE 
492  ) 
493  uf.add_keyarg( 
494      name = "dir", 
495      py_type = "str", 
496      arg_type = "dir", 
497      desc_short = "directory name", 
498      desc = "The directory name.", 
499      can_be_none = True 
500  ) 
501  uf.add_keyarg( 
502      name = "bc", 
503      default = False, 
504      py_type = "bool", 
505      desc_short = "back-calculation flag", 
506      desc = "A flag which if set will write out the back-calculated rather than measured RDCs." 
507  ) 
508  uf.add_keyarg( 
509      name = "force", 
510      default = False, 
511      py_type = "bool", 
512      desc_short = "force flag", 
513      desc = "A flag which if True will cause the file to be overwritten." 
514  ) 
515  # Description. 
516  uf.desc.append(Desc_container()) 
517  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.") 
518  uf.backend = rdc.write 
519  uf.menu_text = "&write" 
520  uf.gui_icon = "oxygen.actions.document-save" 
521  uf.wizard_size = (800, 600) 
522  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
523