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

Source Code for Module user_functions.rdc'

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """The rdc user function definitions.""" 
 25   
 26  # Python module imports. 
 27  import wx 
 28   
 29  # relax module imports. 
 30  from generic_fns import align_tensor, pipes, rdc 
 31  from graphics import WIZARD_IMAGE_PATH 
 32  from user_functions.data import Uf_info; uf_info = Uf_info() 
 33  from user_functions.objects import Desc_container 
 34   
 35   
 36  # The user function class. 
 37  uf_class = uf_info.add_class('rdc') 
 38  uf_class.title = "Class for handling residual dipolar couplings." 
 39  uf_class.menu_text = "&rdc" 
 40  uf_class.gui_icon = "relax.align_tensor" 
 41   
 42   
 43  # The rdc.back_calc user function. 
 44  uf = uf_info.add_uf('rdc.back_calc') 
 45  uf.title = "Back calculate the residual dipolar couplings." 
 46  uf.title_short = "RDC back calculation." 
 47  uf.display = True 
 48  uf.add_keyarg( 
 49      name = "align_id", 
 50      py_type = "str", 
 51      desc_short = "alignment ID string", 
 52      desc = "The alignment ID string.", 
 53      wiz_element_type = 'combo', 
 54      wiz_combo_iter = align_tensor.get_ids, 
 55      wiz_read_only = True, 
 56      can_be_none = True 
 57  ) 
 58  # Description. 
 59  uf.desc.append(Desc_container()) 
 60  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.") 
 61  uf.backend = rdc.back_calc 
 62  uf.menu_text = "&back_calc" 
 63  uf.gui_icon = "oxygen.categories.applications-education" 
 64  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 65  uf.wizard_apply_button = False 
 66   
 67   
 68  # The rdc.calc_q_factors user function. 
 69  uf = uf_info.add_uf('rdc.calc_q_factors') 
 70  uf.title = "Calculate the RDC Q factor for the selected spins." 
 71  uf.title_short = "RDC Q factor calculation." 
 72  uf.display = True 
 73  uf.add_keyarg( 
 74      name = "spin_id", 
 75      py_type = "str", 
 76      desc_short = "spin ID string", 
 77      desc = "The spin ID string for restricting to subset of all selected spins.", 
 78      can_be_none = True 
 79  ) 
 80  # Description. 
 81  uf.desc.append(Desc_container()) 
 82  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.") 
 83  # Prompt examples. 
 84  uf.desc.append(Desc_container("Prompt examples")) 
 85  uf.desc[-1].add_paragraph("To calculate the RDC Q factor for only the spins '@H26', '@H27', and '@H28', type one of:") 
 86  uf.desc[-1].add_prompt("relax> rdc.calc_q_factors('@H26 & @H27 & @H28')") 
 87  uf.desc[-1].add_prompt("relax> rdc.calc_q_factors(spin_id='@H26 & @H27 & @H28')") 
 88  uf.backend = rdc.q_factors 
 89  uf.menu_text = "&calc_q_factors" 
 90  uf.gui_icon = "oxygen.categories.applications-education" 
 91  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 92  uf.wizard_apply_button = False 
 93   
 94   
 95  # No backend! 
 96  ## The rdc.copy user function. 
 97  #uf = uf_info.add_uf('rdc.copy') 
 98  #uf.title = "Copy RDC data from one data pipe to another." 
 99  #uf.title_short = "RDC copying." 
100  #uf.add_keyarg( 
101  #    name = "pipe_from", 
102  #    py_type = "str", 
103  #    desc_short = "source pipe", 
104  #    desc = "The name of the pipe to copy the RDC data from.", 
105  #    wiz_element_type = 'combo', 
106  #    wiz_combo_iter = pipes.pipe_names, 
107  #    can_be_none = True 
108  #) 
109  #uf.add_keyarg( 
110  #    name = "pipe_to", 
111  #    py_type = "str", 
112  #    desc_short = "destination pipe", 
113  #    desc = "The name of the pipe to copy the RDC data to.", 
114  #    wiz_element_type = 'combo', 
115  #    wiz_combo_iter = pipes.pipe_names, 
116  #    can_be_none = True 
117  #) 
118  #uf.add_keyarg( 
119  #    name = "align_id", 
120  #    py_type = "str", 
121  #    desc_short = "alignment ID string", 
122  #    desc = "The alignment ID string.", 
123  #    wiz_element_type = 'combo', 
124  #    wiz_combo_iter = align_tensor.get_ids, 
125  #    wiz_read_only = True, 
126  #    can_be_none = True 
127  #) 
128  ## Description. 
129  #uf.desc.append(Desc_container()) 
130  #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.") 
131  ## Prompt examples. 
132  #uf.desc.append(Desc_container("Prompt examples")) 
133  #uf.desc[-1].add_paragraph("To copy all RDC data from pipe 'm1' to pipe 'm9', type one of:") 
134  #uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9')") 
135  #uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9')") 
136  #uf.desc[-1].add_prompt("relax> rdc.copy('m1', 'm9', None)") 
137  #uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m1', pipe_to='m9', align_id=None)") 
138  #uf.desc[-1].add_paragraph("To copy only the 'Th' RDC data from 'm3' to 'm6', type one of:") 
139  #uf.desc[-1].add_prompt("relax> rdc.copy('m3', 'm6', 'Th')") 
140  #uf.desc[-1].add_prompt("relax> rdc.copy(pipe_from='m3', pipe_to='m6', align_id='Th')") 
141  #uf.backend = rdc.copy 
142  #uf.menu_text = "cop&y" 
143  #uf.gui_icon = "oxygen.actions.list-add" 
144  #uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
145   
146   
147  # The rdc.corr_plot user function. 
148  uf = uf_info.add_uf('rdc.corr_plot') 
149  uf.title = "Generate a correlation plot of the measured vs. the back-calculated RDCs." 
150  uf.title_short = "Correlation plot generation." 
151  uf.add_keyarg( 
152      name = "format", 
153      default = "grace", 
154      py_type = "str", 
155      desc_short = "format", 
156      desc = "The format of the plot data.", 
157      wiz_element_type = "combo", 
158      wiz_combo_choices = ["grace"], 
159      wiz_read_only = True, 
160      can_be_none = True 
161  ) 
162  uf.add_keyarg( 
163      name = "file", 
164      default = "rdc_corr_plot.agr", 
165      py_type = "str", 
166      arg_type = "file sel", 
167      desc_short = "Grace file name", 
168      desc = "The name of the Grace file to create.", 
169      wiz_filesel_wildcard = "Grace files (*.agr)|*.agr;*.AGR", 
170      wiz_filesel_style = wx.FD_SAVE 
171  ) 
172  uf.add_keyarg( 
173      name = "dir", 
174      py_type = "str", 
175      arg_type = "dir", 
176      desc_short = "directory name", 
177      desc = "The directory name.", 
178      can_be_none = True 
179  ) 
180  uf.add_keyarg( 
181      name = "force", 
182      default = False, 
183      py_type = "bool", 
184      desc_short = "force flag", 
185      desc = "A flag which if True will cause the file to be overwritten." 
186  ) 
187  # Description. 
188  uf.desc.append(Desc_container()) 
189  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.") 
190  # Prompt examples. 
191  uf.desc.append(Desc_container("Prompt examples")) 
192  uf.desc[-1].add_paragraph("To create a Grace plot of the data, type:") 
193  uf.desc[-1].add_prompt("relax> rdc.corr_plot()") 
194  uf.desc[-1].add_paragraph("To create a plain text list of the measured and back-calculated data, type one of:") 
195  uf.desc[-1].add_prompt("relax> rdc.corr_plot(None)") 
196  uf.desc[-1].add_prompt("relax> rdc.corr_plot(format=None)") 
197  uf.backend = rdc.corr_plot 
198  uf.menu_text = "corr_&plot" 
199  uf.wizard_size = (800, 500) 
200  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
201  uf.wizard_apply_button = False 
202   
203   
204  # The rdc.delete user function. 
205  uf = uf_info.add_uf('rdc.delete') 
206  uf.title = "Delete the RDC data corresponding to the alignment ID." 
207  uf.title_short = "RDC deletion." 
208  uf.add_keyarg( 
209      name = "align_id", 
210      py_type = "str", 
211      desc_short = "alignment ID string", 
212      desc = "The alignment ID string of the data to delete.", 
213      wiz_element_type = 'combo', 
214      wiz_combo_iter = align_tensor.get_ids, 
215      wiz_read_only = True, 
216      can_be_none = True 
217  ) 
218  # Description. 
219  uf.desc.append(Desc_container()) 
220  uf.desc[-1].add_paragraph("This will delete all RDC data associated with the alignment ID in the current data pipe.") 
221  # Prompt examples. 
222  uf.desc.append(Desc_container("Prompt examples")) 
223  uf.desc[-1].add_paragraph("To delete the RDC data corresponding to align_id='PH_gel', type:") 
224  uf.desc[-1].add_prompt("relax> rdc.delete('PH_gel')") 
225  uf.backend = rdc.delete 
226  uf.menu_text = "&delete" 
227  uf.gui_icon = "oxygen.actions.list-remove" 
228  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
229   
230   
231  # The rdc.display user function. 
232  uf = uf_info.add_uf('rdc.display') 
233  uf.title = "Display the RDC data corresponding to the alignment ID." 
234  uf.title_short = "RDC data display." 
235  uf.display = True 
236  uf.add_keyarg( 
237      name = "align_id", 
238      py_type = "str", 
239      desc_short = "alignment ID string", 
240      desc = "The alignment ID string.", 
241      wiz_element_type = 'combo', 
242      wiz_combo_iter = align_tensor.get_ids, 
243      wiz_read_only = True 
244  ) 
245  uf.add_keyarg( 
246      name = "bc", 
247      default = False, 
248      py_type = "bool", 
249      desc_short = "back-calculation flag", 
250      desc = "A flag which if set will display the back-calculated rather than measured RDCs." 
251  ) 
252  # Description. 
253  uf.desc.append(Desc_container()) 
254  uf.desc[-1].add_paragraph("This will display all of the RDC data associated with the alignment ID in the current data pipe.") 
255  # Prompt examples. 
256  uf.desc.append(Desc_container("Prompt examples")) 
257  uf.desc[-1].add_paragraph("To display the 'phage' RDC data, type:") 
258  uf.desc[-1].add_prompt("relax> rdc.display('phage')") 
259  uf.backend = rdc.display 
260  uf.menu_text = "di&splay" 
261  uf.gui_icon = "oxygen.actions.document-preview" 
262  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
263   
264   
265  # The rdc.read user function. 
266  uf = uf_info.add_uf('rdc.read') 
267  uf.title = "Read the RDC data from file." 
268  uf.title_short = "RDC data reading." 
269  uf.add_keyarg( 
270      name = "align_id", 
271      py_type = "str", 
272      desc_short = "alignment ID string", 
273      desc = "The alignment ID string.", 
274      wiz_element_type = 'combo', 
275      wiz_combo_iter = align_tensor.get_ids 
276  ) 
277  uf.add_keyarg( 
278      name = "file", 
279      py_type = "str", 
280      arg_type = "file sel", 
281      desc_short = "file name", 
282      desc = "The name of the file containing the RDC data.", 
283      wiz_filesel_style = wx.FD_OPEN 
284  ) 
285  uf.add_keyarg( 
286      name = "dir", 
287      py_type = "str", 
288      arg_type = "dir", 
289      desc_short = "directory name", 
290      desc = "The directory where the file is located.", 
291      can_be_none = True 
292  ) 
293  uf.add_keyarg( 
294      name = "data_type", 
295      default = "D", 
296      py_type = "str", 
297      desc_short = "data type", 
298      desc = "Whether the RDC data is in the D or 2D format.", 
299      wiz_element_type = "combo", 
300      wiz_combo_choices = ["D", "2D"], 
301      wiz_read_only = True 
302  ) 
303  uf.add_keyarg( 
304      name = "spin_id_col", 
305      py_type = "int", 
306      arg_type = "free format", 
307      desc_short = "spin ID column", 
308      desc = "The spin ID string column (an alternative to the mol, res, and spin name and number columns).", 
309      can_be_none = True 
310  ) 
311  uf.add_keyarg( 
312      name = "mol_name_col", 
313      py_type = "int", 
314      arg_type = "free format", 
315      desc_short = "molecule name column", 
316      desc = "The molecule name column (alternative to the spin_id_col).", 
317      can_be_none = True 
318  ) 
319  uf.add_keyarg( 
320      name = "res_num_col", 
321      py_type = "int", 
322      arg_type = "free format", 
323      desc_short = "residue number column", 
324      desc = "The residue number column (alternative to the spin_id_col).", 
325      can_be_none = True 
326  ) 
327  uf.add_keyarg( 
328      name = "res_name_col", 
329      py_type = "int", 
330      arg_type = "free format", 
331      desc_short = "residue name column", 
332      desc = "The residue name column (alternative to the spin_id_col).", 
333      can_be_none = True 
334  ) 
335  uf.add_keyarg( 
336      name = "spin_num_col", 
337      py_type = "int", 
338      arg_type = "free format", 
339      desc_short = "spin number column", 
340      desc = "The spin number column (alternative to the spin_id_col).", 
341      can_be_none = True 
342  ) 
343  uf.add_keyarg( 
344      name = "spin_name_col", 
345      py_type = "int", 
346      arg_type = "free format", 
347      desc_short = "spin name column", 
348      desc = "The spin name column (alternative to the spin_id_col).", 
349      can_be_none = True 
350  ) 
351  uf.add_keyarg( 
352      name = "data_col", 
353      py_type = "int", 
354      arg_type = "free format", 
355      desc_short = "data column", 
356      desc = "The RDC data column.", 
357      can_be_none = True 
358  ) 
359  uf.add_keyarg( 
360      name = "error_col", 
361      py_type = "int", 
362      arg_type = "free format", 
363      desc_short = "error column", 
364      desc = "The experimental error column.", 
365      can_be_none = True 
366  ) 
367  uf.add_keyarg( 
368      name = "sep", 
369      py_type = "str", 
370      arg_type = "free format", 
371      desc_short = "column separator", 
372      desc = "The column separator (the default is white space).", 
373      can_be_none = True 
374  ) 
375  uf.add_keyarg( 
376      name = "spin_id", 
377      py_type = "str", 
378      desc_short = "spin ID string", 
379      desc = "The spin ID string to restrict the loading of data to certain spin subsets.", 
380      can_be_none = True 
381  ) 
382  uf.add_keyarg( 
383      name = "neg_g_corr", 
384      default = False, 
385      py_type = "bool", 
386      desc_short = "negative gyromagnetic ratio correction", 
387      desc = "A flag which is used to correct for the negative gyromagnetic ratio of 15N." 
388  ) 
389  # Description. 
390  uf.desc.append(Desc_container()) 
391  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.") 
392  uf.desc[-1].add_paragraph("The data type is used to specify how the RDC is defined.  It can be set to two values:") 
393  uf.desc[-1].add_list_element("'D' means that the splitting in the aligned sample was taken as J + D.") 
394  uf.desc[-1].add_list_element("'2D' means that the splitting in the aligned sample was assumed to be J + 2D.") 
395  uf.desc[-1].add_paragraph("Internally, relax uses the D notation.  Therefore if set to '2D', the values will be doubled when read in.") 
396  uf.desc[-1].add_paragraph("If neg_g_corr is set to True, 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.") 
397  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.") 
398  # Prompt examples. 
399  uf.desc.append(Desc_container("Prompt examples")) 
400  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':") 
401  uf.desc[-1].add_prompt("relax> rdc.read('Tb', 'Tb.txt', sep=',')") 
402  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:") 
403  uf.desc[-1].add_prompt("relax> rdc.read('phage', 'rdc_err.txt', data_type='D', error_col=5)") 
404  uf.desc[-1].add_prompt("relax> rdc.read(align_id='phage', file='rdc_err.txt', data_type='D', error_col=5)") 
405  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:") 
406  uf.desc[-1].add_prompt("relax> rdc.read('Tb', 'Tb.txt', spin_id='@N')") 
407  uf.backend = rdc.read 
408  uf.menu_text = "&read" 
409  uf.gui_icon = "oxygen.actions.document-open" 
410  uf.wizard_height_desc = 180 
411  uf.wizard_size = (1000, 750) 
412  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
413   
414   
415  # The rdc.weight user function. 
416  uf = uf_info.add_uf('rdc.weight') 
417  uf.title = "Set optimisation weights on the RDC data." 
418  uf.title_short = "RDC weighting." 
419  uf.add_keyarg( 
420      name = "align_id", 
421      py_type = "str", 
422      desc_short = "alignment ID string", 
423      desc = "The alignment ID string.", 
424      wiz_element_type = 'combo', 
425      wiz_combo_iter = align_tensor.get_ids, 
426      wiz_read_only = True 
427  ) 
428  uf.add_keyarg( 
429      name = "spin_id", 
430      py_type = "str", 
431      desc_short = "spin ID string", 
432      desc = "The spin ID string." 
433  ) 
434  uf.add_keyarg( 
435      name = "weight", 
436      default = 1.0, 
437      py_type = "num", 
438      desc_short = "weight", 
439      desc = "The weighting value." 
440  ) 
441  # Description. 
442  uf.desc.append(Desc_container()) 
443  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.") 
444  uf.backend = rdc.weight 
445  uf.menu_text = "wei&ght" 
446  uf.wizard_size = (700, 500) 
447  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
448   
449   
450  # The rdc.write user function. 
451  uf = uf_info.add_uf('rdc.write') 
452  uf.title = "Write the RDC data to file." 
453  uf.title_short = "RDC data writing." 
454  uf.add_keyarg( 
455      name = "align_id", 
456      py_type = "str", 
457      desc_short = "alignment ID string", 
458      desc = "The alignment ID string.", 
459      wiz_element_type = 'combo', 
460      wiz_combo_iter = align_tensor.get_ids, 
461      wiz_read_only = True 
462  ) 
463  uf.add_keyarg( 
464      name = "file", 
465      py_type = "str", 
466      arg_type = "file sel", 
467      desc_short = "file name", 
468      desc = "The name of the file.", 
469      wiz_filesel_style = wx.FD_SAVE 
470  ) 
471  uf.add_keyarg( 
472      name = "dir", 
473      py_type = "str", 
474      arg_type = "dir", 
475      desc_short = "directory name", 
476      desc = "The directory name.", 
477      can_be_none = True 
478  ) 
479  uf.add_keyarg( 
480      name = "bc", 
481      default = False, 
482      py_type = "bool", 
483      desc_short = "back-calculation flag", 
484      desc = "A flag which if set will write out the back-calculated rather than measured RDCs." 
485  ) 
486  uf.add_keyarg( 
487      name = "force", 
488      default = False, 
489      py_type = "bool", 
490      desc_short = "force flag", 
491      desc = "A flag which if True will cause the file to be overwritten." 
492  ) 
493  # Description. 
494  uf.desc.append(Desc_container()) 
495  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.") 
496  uf.backend = rdc.write 
497  uf.menu_text = "&write" 
498  uf.gui_icon = "oxygen.actions.document-save" 
499  uf.wizard_size = (800, 600) 
500  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
501