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

Source Code for Module user_functions.spin

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-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 spin user function definitions.""" 
 24   
 25  # relax module imports. 
 26  from graphics import WIZARD_IMAGE_PATH 
 27  from pipe_control import pipes 
 28  from pipe_control.mol_res_spin import copy_spin, create_pseudo_spin, create_spin, delete_spin, display_spin, get_molecule_names, get_residue_ids, get_residue_names, get_residue_nums, get_spin_ids, id_string_doc, name_spin, number_spin, set_spin_element, set_spin_isotope 
 29  from user_functions.data import Uf_info; uf_info = Uf_info() 
 30  from user_functions.objects import Desc_container 
 31   
 32   
 33  # The user function class. 
 34  uf_class = uf_info.add_class('spin') 
 35  uf_class.title = "Class for manipulating the spin data." 
 36  uf_class.menu_text = "&spin" 
 37  uf_class.gui_icon = "relax.spin" 
 38   
 39   
 40  # The spin.copy user function. 
 41  uf = uf_info.add_uf('spin.copy') 
 42  uf.title = "Copy all data associated with a spin." 
 43  uf.title_short = "Spin copying." 
 44  uf.display = True 
 45  uf.add_keyarg( 
 46      name = "pipe_from", 
 47      py_type = "str", 
 48      desc_short = "source data pipe", 
 49      desc = "The data pipe containing the spin from which the data will be copied.  This defaults to the current data pipe.", 
 50      wiz_element_type = 'combo', 
 51      wiz_combo_iter = pipes.pipe_names, 
 52      wiz_read_only = True, 
 53      can_be_none = True 
 54  ) 
 55  uf.add_keyarg( 
 56      name = "spin_from", 
 57      py_type = "str", 
 58      desc_short = "source spin ID", 
 59      desc = "The spin identifier string of the spin to copy the data from.", 
 60      wiz_element_type = 'combo', 
 61      wiz_combo_iter = get_spin_ids 
 62  ) 
 63  uf.add_keyarg( 
 64      name = "pipe_to", 
 65      py_type = "str", 
 66      desc_short = "destination data pipe", 
 67      desc = "The data pipe to copy the data to.  This defaults to the current data pipe.", 
 68      wiz_element_type = 'combo', 
 69      wiz_combo_iter = pipes.pipe_names, 
 70      wiz_read_only = True, 
 71      can_be_none = True 
 72  ) 
 73  uf.add_keyarg( 
 74      name = "spin_to", 
 75      py_type = "str", 
 76      desc_short = "destination spin ID", 
 77      desc = "The spin identifier string of the spin to copy the data to.  If left blank, the new spin will have the same name as the old.", 
 78      can_be_none = True 
 79  ) 
 80  # Description. 
 81  uf.desc.append(Desc_container()) 
 82  uf.desc[-1].add_paragraph("This will copy all the data associated with the identified spin to the new, non-existent spin.  The new spin must not already exist.") 
 83  # Prompt examples. 
 84  uf.desc.append(Desc_container("Prompt examples")) 
 85  uf.desc[-1].add_paragraph("To copy the spin data from spin 1 to the new spin 2, type:") 
 86  uf.desc[-1].add_prompt("relax> spin.copy(spin_from='@1', spin_to='@2')") 
 87  uf.desc[-1].add_paragraph("To copy spin 1 of the molecule 'Old mol' to spin 5 of the molecule 'New mol', type:") 
 88  uf.desc[-1].add_prompt("relax> spin.copy(spin_from='#Old mol@1', spin_to='#New mol@5')") 
 89  uf.desc[-1].add_paragraph("To copy the spin data of spin 1 from the data pipe 'm1' to 'm2', assuming the current data pipe is 'm1', type:") 
 90  uf.desc[-1].add_prompt("relax> spin.copy(spin_from='@1', pipe_to='m2')") 
 91  uf.desc[-1].add_prompt("relax> spin.copy(pipe_from='m1', spin_from='@1', pipe_to='m2', spin_to='@1')") 
 92  uf.backend = copy_spin 
 93  uf.menu_text = "&copy" 
 94  uf.gui_icon = "oxygen.actions.list-add" 
 95  uf.wizard_size = (700, 600) 
 96  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
 97   
 98   
 99  # The spin.create user function. 
100  uf = uf_info.add_uf('spin.create') 
101  uf.title = "Create a new spin." 
102  uf.title_short = "Spin creation." 
103  uf.display = True 
104  uf.add_keyarg( 
105      name = "spin_name", 
106      py_type = "str", 
107      desc_short = "spin name", 
108      desc = "The name of the spin.", 
109      can_be_none = True 
110  ) 
111  uf.add_keyarg( 
112      name = "spin_num", 
113      py_type = "int", 
114      min = -10000, 
115      max = 10000, 
116      desc_short = "spin number", 
117      desc = "The spin number.", 
118      can_be_none = True 
119  ) 
120  uf.add_keyarg( 
121      name = "res_name", 
122      py_type = "str", 
123      desc_short = "residue name", 
124      desc = "The name of the residue to add the spin to.", 
125      wiz_element_type = 'combo', 
126      wiz_combo_iter = get_residue_names, 
127      can_be_none = True 
128  ) 
129  uf.add_keyarg( 
130      name = "res_num", 
131      py_type = "int", 
132      desc_short = "residue number", 
133      desc = "The number of the residue to add the spin to.", 
134      wiz_element_type = 'combo', 
135      wiz_combo_iter = get_residue_nums, 
136      can_be_none = True 
137  ) 
138  uf.add_keyarg( 
139      name = "mol_name", 
140      py_type = "str", 
141      desc_short = "molecule name", 
142      desc = "The name of the molecule to add the spin to.", 
143      wiz_element_type = 'combo', 
144      wiz_combo_iter = get_molecule_names, 
145      can_be_none = True 
146  ) 
147  # Description. 
148  uf.desc.append(Desc_container()) 
149  uf.desc[-1].add_paragraph("This will add a new spin data container to the relax data storage object.  The same spin number cannot be used more than once.") 
150  # Prompt examples. 
151  uf.desc.append(Desc_container("Prompt examples")) 
152  uf.desc[-1].add_paragraph("The following sequence of commands will add the spins 1 C4, 2 C9, 3 C15 to residue number 10:") 
153  uf.desc[-1].add_prompt("relax> spin.create('C4',  1, res_num=10)") 
154  uf.desc[-1].add_prompt("relax> spin.create('C9',  2, res_num=10)") 
155  uf.desc[-1].add_prompt("relax> spin.create('C15', 3, res_num=10)") 
156  uf.backend = create_spin 
157  uf.menu_text = "c&reate" 
158  uf.gui_icon = "oxygen.actions.list-add-relax-blue" 
159  uf.wizard_size = (700, 500) 
160  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
161   
162   
163  # The spin.create_pseudo user function. 
164  uf = uf_info.add_uf('spin.create_pseudo') 
165  uf.title = "Create a spin system representing a pseudo-atom." 
166  uf.title_short = "Pseudo-atom creation." 
167  uf.add_keyarg( 
168      name = "spin_name", 
169      py_type = "str", 
170      desc_short = "spin name", 
171      desc = "The name of the pseudo-atom spin." 
172  ) 
173  uf.add_keyarg( 
174      name = "spin_num", 
175      py_type = "int", 
176      min = -10000, 
177      max = 10000, 
178      desc_short = "spin number", 
179      desc = "The spin number.", 
180      can_be_none = True 
181  ) 
182  uf.add_keyarg( 
183      name = "res_id", 
184      py_type = "str", 
185      desc_short = "residue ID string", 
186      desc = "The molecule and residue ID string identifying the position to add the pseudo-spin to.", 
187      wiz_element_type = 'combo', 
188      wiz_combo_iter = get_residue_ids, 
189      can_be_none = True 
190  ) 
191  uf.add_keyarg( 
192      name = "members", 
193      py_type = "str_list", 
194      desc_short = "members", 
195      desc = "A list of the atoms (as spin ID strings) that the pseudo-atom is composed of.", 
196      wiz_element_type = "combo_list", 
197      wiz_combo_iter = get_spin_ids, 
198      wiz_combo_list_min = 2, 
199      wiz_read_only = False 
200  ) 
201  uf.add_keyarg( 
202      name = "averaging", 
203      default = "linear", 
204      py_type = "str", 
205      desc_short = "positional averaging", 
206      desc = "The positional averaging technique.", 
207      wiz_element_type = "combo", 
208      wiz_combo_choices = ["linear"], 
209      wiz_read_only = True 
210  ) 
211  # Description. 
212  uf.desc.append(Desc_container()) 
213  uf.desc[-1].add_paragraph("This will create a spin data container representing a number of pre-existing spin containers as a pseudo-atom.  The optional spin number must not already exist.") 
214  uf.desc.append(id_string_doc) 
215  # Prompt examples. 
216  uf.desc.append(Desc_container("Prompt examples")) 
217  uf.desc[-1].add_paragraph("The following will create the pseudo-atom named 'Q9' consisting of the protons '@H16', '@H17', '@H18':") 
218  uf.desc[-1].add_prompt("relax> spin.create_pseudo('Q9', members=['@H16', '@H17', '@H18'])") 
219  uf.backend = create_pseudo_spin 
220  uf.menu_text = "create_p&seudo" 
221  uf.gui_icon = "oxygen.actions.list-add-relax-blue" 
222  uf.wizard_height_desc = 350 
223  uf.wizard_size = (1000, 750) 
224  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
225   
226   
227  # The spin.delete user function. 
228  uf = uf_info.add_uf('spin.delete') 
229  uf.title = "Delete spins." 
230  uf.title_short = "Spin deletion." 
231  uf.add_keyarg( 
232      name = "spin_id", 
233      py_type = "str", 
234      desc_short = "spin ID string", 
235      desc = "The spin identifier string.", 
236      wiz_element_type = 'combo', 
237      wiz_combo_iter = get_spin_ids 
238  ) 
239  # Description. 
240  uf.desc.append(Desc_container()) 
241  uf.desc[-1].add_paragraph("This can be used to delete a single or sets of spins.  See the identification string documentation below for more information.") 
242  uf.desc.append(id_string_doc) 
243  uf.backend = delete_spin 
244  uf.menu_text = "&delete" 
245  uf.gui_icon = "oxygen.actions.list-remove" 
246  uf.wizard_height_desc = 550 
247  uf.wizard_size = (900, 750) 
248  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
249   
250   
251  # The spin.display user function. 
252  uf = uf_info.add_uf('spin.display') 
253  uf.title = "Display information about the spin(s)." 
254  uf.title_short = "Spin information." 
255  uf.display = True 
256  uf.add_keyarg( 
257      name = "spin_id", 
258      py_type = "str", 
259      desc_short = "spin ID string", 
260      desc = "The spin identification string.", 
261      wiz_element_type = 'combo', 
262      wiz_combo_iter = get_spin_ids, 
263      can_be_none = True 
264  ) 
265  # Description. 
266  uf.desc.append(Desc_container()) 
267  uf.desc[-1].add_paragraph("This will display the spin data loaded into the current data pipe.") 
268  uf.desc.append(id_string_doc) 
269  uf.backend = display_spin 
270  uf.menu_text = "dis&play" 
271  uf.gui_icon = "oxygen.actions.document-preview" 
272  uf.wizard_height_desc = 550 
273  uf.wizard_size = (1000, 750) 
274  uf.wizard_apply_button = False 
275  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
276   
277   
278  # The spin.element user function. 
279  uf = uf_info.add_uf('spin.element') 
280  uf.title = "Set the element type of the spin." 
281  uf.title_short = "Spin element setting." 
282  uf.add_keyarg( 
283      name = "element", 
284      py_type = "str", 
285      desc_short = "IUPAC element name", 
286      desc = "The IUPAC element name.", 
287      wiz_element_type = "combo", 
288      wiz_combo_choices = ["N", "C", "H", "O", "P"] 
289  ) 
290  uf.add_keyarg( 
291      name = "spin_id", 
292      py_type = "str", 
293      desc_short = "spin ID string", 
294      desc = "The spin identification string corresponding to one or more spins.", 
295      wiz_element_type = 'combo', 
296      wiz_combo_iter = get_spin_ids, 
297      can_be_none = True 
298  ) 
299  uf.add_keyarg( 
300      name = "force", 
301      default = False, 
302      py_type = "bool", 
303      arg_type = "force flag", 
304      desc_short = "force flag", 
305      desc = "A flag which if True will cause the element to be changed." 
306  ) 
307  # Description. 
308  uf.desc.append(Desc_container()) 
309  uf.desc[-1].add_paragraph("This allows the element type of the spins to be set.") 
310  uf.desc.append(id_string_doc) 
311  # Prompt examples. 
312  uf.desc.append(Desc_container("Prompt examples")) 
313  uf.desc[-1].add_paragraph("The set all spins of residue 1 to be carbons, type one of:") 
314  uf.desc[-1].add_prompt("relax> spin.element('@1', 'C', force=True)") 
315  uf.desc[-1].add_prompt("relax> spin.element(spin_id='@1', element='C', force=True)") 
316  uf.backend = set_spin_element 
317  uf.menu_text = "&element" 
318  uf.gui_icon = "oxygen.actions.edit-rename" 
319  uf.wizard_height_desc = 500 
320  uf.wizard_size = (1000, 750) 
321  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
322   
323   
324  # The spin.isotope user function. 
325  uf = uf_info.add_uf('spin.isotope') 
326  uf.title = "Set the spins' nuclear isotope type." 
327  uf.title_short = "Nuclear isotope type." 
328  uf.add_keyarg( 
329      name = "isotope", 
330      py_type = "str", 
331      desc_short = "nuclear isotope name", 
332      desc = "The nuclear isotope name in the AE notation - the atomic mass number followed by the element symbol.", 
333      wiz_element_type = "combo", 
334      wiz_combo_choices = ["1H", "2H", "13C", "14N", "15N", "17O", "19F", "23Na", "31P", "113Cd"], 
335      wiz_read_only = False 
336  ) 
337  uf.add_keyarg( 
338      name = "spin_id", 
339      py_type = "str", 
340      desc_short = "spin ID string", 
341      desc = "The spin identification string corresponding to one or more spins.", 
342      wiz_element_type = 'combo', 
343      wiz_combo_iter = get_spin_ids, 
344      can_be_none = True 
345  ) 
346  uf.add_keyarg( 
347      name = "force", 
348      default = False, 
349      py_type = "bool", 
350      arg_type = "force flag", 
351      desc_short = "force flag", 
352      desc = "A flag which if True will cause the nuclear isotope to be changed." 
353  ) 
354  # Description. 
355  uf.desc.append(Desc_container()) 
356  uf.desc[-1].add_paragraph("This allows the nuclear isotope type of the spins to be set.") 
357  uf.desc.append(id_string_doc) 
358  # Prompt examples. 
359  uf.desc.append(Desc_container("Prompt examples")) 
360  uf.desc[-1].add_paragraph("The set all spins of residue 1 to the '13C' nuclear isotope, type one of:") 
361  uf.desc[-1].add_prompt("relax> spin.isotope('@1', '13C', force=True)") 
362  uf.desc[-1].add_prompt("relax> spin.isotope(spin_id='@1', isotope='13C', force=True)") 
363  uf.backend = set_spin_isotope 
364  uf.menu_text = "&isotope" 
365  uf.gui_icon = "relax.nuclear_symbol" 
366  uf.wizard_height_desc = 500 
367  uf.wizard_size = (1000, 750) 
368  uf.wizard_image = WIZARD_IMAGE_PATH + 'nuclear_symbol.png' 
369   
370   
371  # The spin.name user function. 
372  uf = uf_info.add_uf('spin.name') 
373  uf.title = "Name the spins." 
374  uf.title_short = "Spin naming." 
375  uf.add_keyarg( 
376      name = "name", 
377      py_type = "str", 
378      desc_short = "new spin name", 
379      desc = "The new name." 
380  ) 
381  uf.add_keyarg( 
382      name = "spin_id", 
383      py_type = "str", 
384      arg_type = "spin ID", 
385      desc_short = "spin ID string", 
386      desc = "The spin identification string corresponding to one or more spins.", 
387      wiz_combo_iter = get_spin_ids, 
388      can_be_none = True 
389  ) 
390  uf.add_keyarg( 
391      name = "force", 
392      default = False, 
393      py_type = "bool", 
394      arg_type = "force flag", 
395      desc_short = "force flag", 
396      desc = "A flag which if True will cause the spin to be renamed." 
397  ) 
398  # Description. 
399  uf.desc.append(Desc_container()) 
400  uf.desc[-1].add_paragraph("This simply allows spins to be named (or renamed).  Spin naming often essential.  For example when reading Sparky peak list files, then the spin name must match that in the file.") 
401  uf.desc.append(id_string_doc) 
402  # Prompt examples. 
403  uf.desc.append(Desc_container("Prompt examples")) 
404  uf.desc[-1].add_paragraph("The following sequence of commands will rename the sequence {1 C1, 2 C2, 3 C3} to {1 C11, 2 C12, 3 C13}:") 
405  uf.desc[-1].add_prompt("relax> spin.name('@1', 'C11', force=True)") 
406  uf.desc[-1].add_prompt("relax> spin.name('@2', 'C12', force=True)") 
407  uf.desc[-1].add_prompt("relax> spin.name('@3', 'C13', force=True)") 
408  uf.backend = name_spin 
409  uf.menu_text = "&name" 
410  uf.gui_icon = "oxygen.actions.edit-rename" 
411  uf.wizard_height_desc = 500 
412  uf.wizard_size = (1000, 750) 
413  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
414   
415   
416  # The spin.number user function. 
417  uf = uf_info.add_uf('spin.number') 
418  uf.title = "Number the spins." 
419  uf.title_short = "Spin numbering." 
420  uf.add_keyarg( 
421      name = "spin_id", 
422      py_type = "str", 
423      desc_short = "spin ID string", 
424      desc = "The spin identification string corresponding to a single spin.", 
425      wiz_element_type = 'combo', 
426      wiz_combo_iter = get_spin_ids, 
427      can_be_none = True 
428  ) 
429  uf.add_keyarg( 
430      name = "number", 
431      py_type = "int", 
432      min = -10000, 
433      max = 10000, 
434      desc_short = "new spin number", 
435      desc = "The new spin number.", 
436      can_be_none = True 
437  ) 
438  uf.add_keyarg( 
439      name = "force", 
440      default = False, 
441      py_type = "bool", 
442      arg_type = "force flag", 
443      desc_short = "force flag", 
444      desc = "A flag which if True will cause the spin to be renumbered." 
445  ) 
446  # Description. 
447  uf.desc.append(Desc_container()) 
448  uf.desc[-1].add_paragraph("This simply allows spins to be numbered.  The new number cannot correspond to an existing spin number.") 
449  uf.desc.append(id_string_doc) 
450  # Prompt examples. 
451  uf.desc.append(Desc_container("Prompt examples")) 
452  uf.desc[-1].add_paragraph("The following sequence of commands will renumber the sequence {1 C1, 2 C2, 3 C3} to {-1 C1, -2 C2, -3 C3}:") 
453  uf.desc[-1].add_prompt("relax> spin.number('@1', -1, force=True)") 
454  uf.desc[-1].add_prompt("relax> spin.number('@2', -2, force=True)") 
455  uf.desc[-1].add_prompt("relax> spin.number('@3', -3, force=True)") 
456  uf.backend = number_spin 
457  uf.menu_text = "num&ber" 
458  uf.gui_icon = "oxygen.actions.edit-rename" 
459  uf.wizard_height_desc = 500 
460  uf.wizard_size = (1000, 750) 
461  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
462