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

Source Code for Module user_functions.pcs'

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2012 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 pcs 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, pcs, pipes 
 35  from graphics import WIZARD_IMAGE_PATH 
 36  from user_functions.data import Uf_info; uf_info = Uf_info() 
 37  from user_functions.objects import Desc_container 
 38   
 39   
 40  # The user function class. 
 41  uf_class = uf_info.add_class('pcs') 
 42  uf_class.title = "Class for handling pseudo-contact shifts." 
 43  uf_class.menu_text = "&pcs" 
 44  uf_class.gui_icon = "relax.align_tensor" 
 45   
 46   
 47  # The pcs.back_calc user function. 
 48  uf = uf_info.add_uf('pcs.back_calc') 
 49  uf.title = "Back calculate the pseudo-contact shifts." 
 50  uf.title_short = "PCS back calculation." 
 51  uf.display = True 
 52  uf.add_keyarg( 
 53      name = "align_id", 
 54      py_type = "str", 
 55      desc_short = "alignment ID string", 
 56      desc = "The alignment ID string.", 
 57      wiz_element_type = 'combo', 
 58      wiz_combo_iter = align_tensor.get_ids, 
 59      wiz_read_only = True, 
 60      can_be_none = True 
 61  ) 
 62  # Description. 
 63  uf.desc.append(Desc_container()) 
 64  uf.desc[-1].add_paragraph("This will back calculate the pseudo-contact shifts if the paramagnetic centre, temperature and magnetic field strength has been specified, an alignment tensor is present, and atomic positions have been loaded into the relax data store.") 
 65  uf.backend = pcs.back_calc 
 66  uf.menu_text = "&back_calc" 
 67  uf.gui_icon = "oxygen.categories.applications-education" 
 68  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 69  uf.wizard_apply_button = False 
 70   
 71   
 72  # The pcs.calc_q_factors user function. 
 73  uf = uf_info.add_uf('pcs.calc_q_factors') 
 74  uf.title = "Calculate the PCS Q factor for the selected spins." 
 75  uf.title_short = "PCS Q factor calculation." 
 76  uf.display = True 
 77  uf.add_keyarg( 
 78      name = "spin_id", 
 79      py_type = "str", 
 80      desc_short = "spin ID string", 
 81      desc = "The spin ID string for restricting to subset of all selected spins.", 
 82      can_be_none = True 
 83  ) 
 84  # Description. 
 85  uf.desc.append(Desc_container()) 
 86  uf.desc[-1].add_paragraph("For this to work, the back-calculated PCS data must first be generated by the analysis specific code.  Otherwise a warning will be given.") 
 87  # Prompt examples. 
 88  uf.desc.append(Desc_container("Prompt examples")) 
 89  uf.desc[-1].add_paragraph("To calculate the PCS Q factor for only the spins '@H26', '@H27', and '@H28', type one of:") 
 90  uf.desc[-1].add_prompt("relax> pcs.calc_q_factors('@H26 & @H27 & @H28')") 
 91  uf.desc[-1].add_prompt("relax> pcs.calc_q_factors(spin_id='@H26 & @H27 & @H28')") 
 92  uf.backend = pcs.q_factors 
 93  uf.menu_text = "&calc_q_factors" 
 94  uf.gui_icon = "oxygen.categories.applications-education" 
 95  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
 96  uf.wizard_apply_button = False 
 97   
 98   
 99  # No backend! 
100  ## The pcs.copy user function. 
101  #uf = uf_info.add_uf('pcs.copy') 
102  #uf.title = "Copy PCS data from one data pipe to another." 
103  #uf.title_short = "PCS 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 PCS 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 PCS 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 PCS data from 'pipe_from' to 'pipe_to'.  If align_id is not given then all PCS 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 PCS data from pipe 'm1' to pipe 'm9', type one of:") 
138  #uf.desc[-1].add_prompt("relax> pcs.copy('m1', 'm9')") 
139  #uf.desc[-1].add_prompt("relax> pcs.copy(pipe_from='m1', pipe_to='m9')") 
140  #uf.desc[-1].add_prompt("relax> pcs.copy('m1', 'm9', None)") 
141  #uf.desc[-1].add_prompt("relax> pcs.copy(pipe_from='m1', pipe_to='m9', align_id=None)") 
142  #uf.desc[-1].add_paragraph("To copy only the 'Th' PCS data from 'm3' to 'm6', type one of:") 
143  #uf.desc[-1].add_prompt("relax> pcs.copy('m3', 'm6', 'Th')") 
144  #uf.desc[-1].add_prompt("relax> pcs.copy(pipe_from='m3', pipe_to='m6', align_id='Th')") 
145  #uf.backend = pcs.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 pcs.corr_plot user function. 
152  uf = uf_info.add_uf('pcs.corr_plot') 
153  uf.title = "Generate a correlation plot of the measured vs. the back-calculated PCSs." 
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 = "pcs_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> pcs.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> pcs.corr_plot(None)") 
200  uf.desc[-1].add_prompt("relax> pcs.corr_plot(format=None)") 
201  uf.backend = pcs.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 pcs.delete user function. 
209  uf = uf_info.add_uf('pcs.delete') 
210  uf.title = "Delete the PCS data corresponding to the alignment ID." 
211  uf.title_short = "PCS 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 PCS 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 PCS data corresponding to align_id='PH_gel', type:") 
228  uf.desc[-1].add_prompt("relax> pcs.delete('PH_gel')") 
229  uf.backend = pcs.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 pcs.display user function. 
236  uf = uf_info.add_uf('pcs.display') 
237  uf.title = "Display the PCS data corresponding to the alignment ID." 
238  uf.title_short = "PCS 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 PCS 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' PCS data, type:") 
262  uf.desc[-1].add_prompt("relax> pcs.display('phage')") 
263  uf.backend = pcs.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 pcs.read user function. 
270  uf = uf_info.add_uf('pcs.read') 
271  uf.title = "Read the PCS data from file." 
272  uf.title_short = "PCS 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 PCS 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 = "spin_id_col", 
299      py_type = "int", 
300      arg_type = "free format", 
301      desc_short = "spin ID column", 
302      desc = "The spin ID string column (an alternative to the mol, res, and spin name and number columns).", 
303      can_be_none = True 
304  ) 
305  uf.add_keyarg( 
306      name = "mol_name_col", 
307      py_type = "int", 
308      arg_type = "free format", 
309      desc_short = "molecule name column", 
310      desc = "The molecule name column (alternative to the spin_id_col).", 
311      can_be_none = True 
312  ) 
313  uf.add_keyarg( 
314      name = "res_num_col", 
315      py_type = "int", 
316      arg_type = "free format", 
317      desc_short = "residue number column", 
318      desc = "The residue number column (alternative to the spin_id_col).", 
319      can_be_none = True 
320  ) 
321  uf.add_keyarg( 
322      name = "res_name_col", 
323      py_type = "int", 
324      arg_type = "free format", 
325      desc_short = "residue name column", 
326      desc = "The residue name column (alternative to the spin_id_col).", 
327      can_be_none = True 
328  ) 
329  uf.add_keyarg( 
330      name = "spin_num_col", 
331      py_type = "int", 
332      arg_type = "free format", 
333      desc_short = "spin number column", 
334      desc = "The spin number column (alternative to the spin_id_col).", 
335      can_be_none = True 
336  ) 
337  uf.add_keyarg( 
338      name = "spin_name_col", 
339      py_type = "int", 
340      arg_type = "free format", 
341      desc_short = "spin name column", 
342      desc = "The spin name column (alternative to the spin_id_col).", 
343      can_be_none = True 
344  ) 
345  uf.add_keyarg( 
346      name = "data_col", 
347      py_type = "int", 
348      arg_type = "free format", 
349      desc_short = "data column", 
350      desc = "The PCS data column.", 
351      can_be_none = True 
352  ) 
353  uf.add_keyarg( 
354      name = "error_col", 
355      py_type = "int", 
356      arg_type = "free format", 
357      desc_short = "error column", 
358      desc = "The experimental error column.", 
359      can_be_none = True 
360  ) 
361  uf.add_keyarg( 
362      name = "sep", 
363      py_type = "str", 
364      arg_type = "free format", 
365      desc_short = "column separator", 
366      desc = "The column separator (the default is white space).", 
367      can_be_none = True 
368  ) 
369  uf.add_keyarg( 
370      name = "spin_id", 
371      py_type = "str", 
372      desc_short = "spin ID string", 
373      desc = "The spin ID string to restrict the loading of data to certain spin subsets.", 
374      can_be_none = True 
375  ) 
376  # Description. 
377  uf.desc.append(Desc_container()) 
378  uf.desc[-1].add_paragraph("This will read PCS data from a file and associate it with an alignment ID, either a new ID or a preexisting one with no PCS data.") 
379  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.") 
380  # Prompt examples. 
381  uf.desc.append(Desc_container("Prompt examples")) 
382  uf.desc[-1].add_paragraph("The following commands will read the PCS data out of the file 'Tb.txt' where the columns are separated by the symbol ',', and store the PCSs under the ID 'Tb'.") 
383  uf.desc[-1].add_prompt("relax> pcs.read('Tb', 'Tb.txt', sep=',')") 
384  uf.desc[-1].add_paragraph("To read the 15N and 1H PCSs from the file 'Eu.txt', where the 15N values are in the 4th column and the 1H in the 9th, type both the following:") 
385  uf.desc[-1].add_prompt("relax> pcs.read('Tb', 'Tb.txt', spin_id='@N', res_num_col=1, data_col=4)") 
386  uf.desc[-1].add_prompt("relax> pcs.read('Tb', 'Tb.txt', spin_id='@H', res_num_col=1, data_col=9)") 
387  uf.backend = pcs.read 
388  uf.menu_text = "&read" 
389  uf.gui_icon = "oxygen.actions.document-open" 
390  uf.wizard_height_desc = 250 
391  uf.wizard_size = (1000, 750) 
392  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
393   
394   
395  # The pcs.weight user function. 
396  uf = uf_info.add_uf('pcs.weight') 
397  uf.title = "Set optimisation weights on the PCS data." 
398  uf.title_short = "PCS weighting." 
399  uf.add_keyarg( 
400      name = "align_id", 
401      py_type = "str", 
402      desc_short = "alignment ID string", 
403      desc = "The alignment ID string.", 
404      wiz_element_type = 'combo', 
405      wiz_combo_iter = align_tensor.get_ids, 
406      wiz_read_only = True 
407  ) 
408  uf.add_keyarg( 
409      name = "spin_id", 
410      py_type = "str", 
411      desc_short = "spin ID string", 
412      desc = "The spin ID string." 
413  ) 
414  uf.add_keyarg( 
415      name = "weight", 
416      default = 1.0, 
417      py_type = "num", 
418      desc_short = "weight", 
419      desc = "The weighting value." 
420  ) 
421  # Description. 
422  uf.desc.append(Desc_container()) 
423  uf.desc[-1].add_paragraph("This can be used to force the PCS to contribute more or less to the chi-squared optimisation statistic.  The higher the value, the more importance the PCS will have.") 
424  uf.backend = pcs.weight 
425  uf.menu_text = "wei&ght" 
426  uf.wizard_size = (700, 500) 
427  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
428   
429   
430  # The pcs.write user function. 
431  uf = uf_info.add_uf('pcs.write') 
432  uf.title = "Write the PCS data to file." 
433  uf.title_short = "PCS data writing." 
434  uf.add_keyarg( 
435      name = "align_id", 
436      py_type = "str", 
437      desc_short = "alignment ID string", 
438      desc = "The alignment ID string.", 
439      wiz_element_type = 'combo', 
440      wiz_combo_iter = align_tensor.get_ids, 
441      wiz_read_only = True 
442  ) 
443  uf.add_keyarg( 
444      name = "file", 
445      py_type = "str", 
446      arg_type = "file sel", 
447      desc_short = "file name", 
448      desc = "The name of the file.", 
449      wiz_filesel_style = FD_SAVE 
450  ) 
451  uf.add_keyarg( 
452      name = "dir", 
453      py_type = "str", 
454      arg_type = "dir", 
455      desc_short = "directory name", 
456      desc = "The directory name.", 
457      can_be_none = True 
458  ) 
459  uf.add_keyarg( 
460      name = "bc", 
461      default = False, 
462      py_type = "bool", 
463      desc_short = "back-calculation flag", 
464      desc = "A flag which if set will write out the back-calculated rather than measured RDCs." 
465  ) 
466  uf.add_keyarg( 
467      name = "force", 
468      default = False, 
469      py_type = "bool", 
470      desc_short = "force flag", 
471      desc = "A flag which if True will cause the file to be overwritten." 
472  ) 
473  # Description. 
474  uf.desc.append(Desc_container()) 
475  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 PCS data set will be written to file.") 
476  uf.backend = pcs.write 
477  uf.menu_text = "&write" 
478  uf.gui_icon = "oxygen.actions.document-save" 
479  uf.wizard_size = (800, 600) 
480  uf.wizard_image = WIZARD_IMAGE_PATH + 'align_tensor.png' 
481