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

Source Code for Module user_functions.spin

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2002-2004,2007-2010,2012,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 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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["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      basic_types = ["str"], 
194      container_types = ["list"], 
195      dim = (None,), 
196      desc_short = "members", 
197      desc = "A list of the atoms (as spin ID strings) that the pseudo-atom is composed of.", 
198      wiz_element_type = "combo_list", 
199      wiz_combo_iter = get_spin_ids, 
200      wiz_combo_list_min = 2, 
201      wiz_read_only = False 
202  ) 
203  uf.add_keyarg( 
204      name = "averaging", 
205      default = "linear", 
206      basic_types = ["str"], 
207      desc_short = "positional averaging", 
208      desc = "The positional averaging technique.", 
209      wiz_element_type = "combo", 
210      wiz_combo_choices = ["linear"], 
211      wiz_read_only = True 
212  ) 
213  # Description. 
214  uf.desc.append(Desc_container()) 
215  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.") 
216  uf.desc.append(id_string_doc) 
217  # Prompt examples. 
218  uf.desc.append(Desc_container("Prompt examples")) 
219  uf.desc[-1].add_paragraph("The following will create the pseudo-atom named 'Q9' consisting of the protons '@H16', '@H17', '@H18':") 
220  uf.desc[-1].add_prompt("relax> spin.create_pseudo('Q9', members=['@H16', '@H17', '@H18'])") 
221  uf.backend = create_pseudo_spin 
222  uf.menu_text = "create_p&seudo" 
223  uf.gui_icon = "oxygen.actions.list-add-relax-blue" 
224  uf.wizard_height_desc = 350 
225  uf.wizard_size = (1000, 750) 
226  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
227   
228   
229  # The spin.delete user function. 
230  uf = uf_info.add_uf('spin.delete') 
231  uf.title = "Delete spins." 
232  uf.title_short = "Spin deletion." 
233  uf.add_keyarg( 
234      name = "spin_id", 
235      basic_types = ["str"], 
236      desc_short = "spin ID string", 
237      desc = "The spin identifier string.", 
238      wiz_element_type = 'combo', 
239      wiz_combo_iter = get_spin_ids 
240  ) 
241  # Description. 
242  uf.desc.append(Desc_container()) 
243  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.") 
244  uf.desc.append(id_string_doc) 
245  uf.backend = delete_spin 
246  uf.menu_text = "&delete" 
247  uf.gui_icon = "oxygen.actions.list-remove" 
248  uf.wizard_height_desc = 550 
249  uf.wizard_size = (900, 750) 
250  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
251   
252   
253  # The spin.display user function. 
254  uf = uf_info.add_uf('spin.display') 
255  uf.title = "Display information about the spin(s)." 
256  uf.title_short = "Spin information." 
257  uf.display = True 
258  uf.add_keyarg( 
259      name = "spin_id", 
260      basic_types = ["str"], 
261      desc_short = "spin ID string", 
262      desc = "The spin identification string.", 
263      wiz_element_type = 'combo', 
264      wiz_combo_iter = get_spin_ids, 
265      can_be_none = True 
266  ) 
267  # Description. 
268  uf.desc.append(Desc_container()) 
269  uf.desc[-1].add_paragraph("This will display the spin data loaded into the current data pipe.") 
270  uf.desc.append(id_string_doc) 
271  uf.backend = display_spin 
272  uf.menu_text = "dis&play" 
273  uf.gui_icon = "oxygen.actions.document-preview" 
274  uf.wizard_height_desc = 550 
275  uf.wizard_size = (1000, 750) 
276  uf.wizard_apply_button = False 
277  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
278   
279   
280  # The spin.element user function. 
281  uf = uf_info.add_uf('spin.element') 
282  uf.title = "Set the element type of the spin." 
283  uf.title_short = "Spin element setting." 
284  uf.add_keyarg( 
285      name = "element", 
286      basic_types = ["str"], 
287      desc_short = "IUPAC element name", 
288      desc = "The IUPAC element name.", 
289      wiz_element_type = "combo", 
290      wiz_combo_choices = ["N", "C", "H", "O", "P"] 
291  ) 
292  uf.add_keyarg( 
293      name = "spin_id", 
294      basic_types = ["str"], 
295      desc_short = "spin ID string", 
296      desc = "The spin identification string corresponding to one or more spins.", 
297      wiz_element_type = 'combo', 
298      wiz_combo_iter = get_spin_ids, 
299      can_be_none = True 
300  ) 
301  uf.add_keyarg( 
302      name = "force", 
303      default = False, 
304      arg_type = "force flag", 
305      desc_short = "force flag", 
306      desc = "A flag which if True will cause the element to be changed." 
307  ) 
308  # Description. 
309  uf.desc.append(Desc_container()) 
310  uf.desc[-1].add_paragraph("This allows the element type of the spins to be set.") 
311  uf.desc.append(id_string_doc) 
312  # Prompt examples. 
313  uf.desc.append(Desc_container("Prompt examples")) 
314  uf.desc[-1].add_paragraph("The set all spins of residue 1 to be carbons, type one of:") 
315  uf.desc[-1].add_prompt("relax> spin.element('@1', 'C', force=True)") 
316  uf.desc[-1].add_prompt("relax> spin.element(spin_id='@1', element='C', force=True)") 
317  uf.backend = set_spin_element 
318  uf.menu_text = "&element" 
319  uf.gui_icon = "oxygen.actions.edit-rename" 
320  uf.wizard_height_desc = 500 
321  uf.wizard_size = (1000, 750) 
322  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
323   
324   
325  # The spin.isotope user function. 
326  uf = uf_info.add_uf('spin.isotope') 
327  uf.title = "Set the spins' nuclear isotope type." 
328  uf.title_short = "Nuclear isotope type." 
329  uf.add_keyarg( 
330      name = "isotope", 
331      basic_types = ["str"], 
332      desc_short = "nuclear isotope name", 
333      desc = "The nuclear isotope name in the AE notation - the atomic mass number followed by the element symbol.", 
334      wiz_element_type = "combo", 
335      wiz_combo_choices = ["1H", "2H", "13C", "14N", "15N", "17O", "19F", "23Na", "31P", "113Cd"], 
336      wiz_read_only = False 
337  ) 
338  uf.add_keyarg( 
339      name = "spin_id", 
340      basic_types = ["str"], 
341      desc_short = "spin ID string", 
342      desc = "The spin identification string corresponding to one or more spins.", 
343      wiz_element_type = 'combo', 
344      wiz_combo_iter = get_spin_ids, 
345      can_be_none = True 
346  ) 
347  uf.add_keyarg( 
348      name = "force", 
349      default = False, 
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      basic_types = ["str"], 
378      desc_short = "new spin name", 
379      desc = "The new name." 
380  ) 
381  uf.add_keyarg( 
382      name = "spin_id", 
383      arg_type = "spin ID", 
384      desc_short = "spin ID string", 
385      desc = "The spin identification string corresponding to one or more spins.", 
386      wiz_combo_iter = get_spin_ids, 
387      can_be_none = True 
388  ) 
389  uf.add_keyarg( 
390      name = "force", 
391      default = False, 
392      arg_type = "force flag", 
393      desc_short = "force flag", 
394      desc = "A flag which if True will cause the spin to be renamed." 
395  ) 
396  # Description. 
397  uf.desc.append(Desc_container()) 
398  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.") 
399  uf.desc.append(id_string_doc) 
400  # Prompt examples. 
401  uf.desc.append(Desc_container("Prompt examples")) 
402  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}:") 
403  uf.desc[-1].add_prompt("relax> spin.name('@1', 'C11', force=True)") 
404  uf.desc[-1].add_prompt("relax> spin.name('@2', 'C12', force=True)") 
405  uf.desc[-1].add_prompt("relax> spin.name('@3', 'C13', force=True)") 
406  uf.backend = name_spin 
407  uf.menu_text = "&name" 
408  uf.gui_icon = "oxygen.actions.edit-rename" 
409  uf.wizard_height_desc = 500 
410  uf.wizard_size = (1000, 750) 
411  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
412   
413   
414  # The spin.number user function. 
415  uf = uf_info.add_uf('spin.number') 
416  uf.title = "Number the spins." 
417  uf.title_short = "Spin numbering." 
418  uf.add_keyarg( 
419      name = "spin_id", 
420      basic_types = ["str"], 
421      desc_short = "spin ID string", 
422      desc = "The spin identification string corresponding to a single spin.", 
423      wiz_element_type = 'combo', 
424      wiz_combo_iter = get_spin_ids, 
425      can_be_none = True 
426  ) 
427  uf.add_keyarg( 
428      name = "number", 
429      basic_types = ["int"], 
430      min = -10000, 
431      max = 10000, 
432      desc_short = "new spin number", 
433      desc = "The new spin number.", 
434      can_be_none = True 
435  ) 
436  uf.add_keyarg( 
437      name = "force", 
438      default = False, 
439      arg_type = "force flag", 
440      desc_short = "force flag", 
441      desc = "A flag which if True will cause the spin to be renumbered." 
442  ) 
443  # Description. 
444  uf.desc.append(Desc_container()) 
445  uf.desc[-1].add_paragraph("This simply allows spins to be numbered.  The new number cannot correspond to an existing spin number.") 
446  uf.desc.append(id_string_doc) 
447  # Prompt examples. 
448  uf.desc.append(Desc_container("Prompt examples")) 
449  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}:") 
450  uf.desc[-1].add_prompt("relax> spin.number('@1', -1, force=True)") 
451  uf.desc[-1].add_prompt("relax> spin.number('@2', -2, force=True)") 
452  uf.desc[-1].add_prompt("relax> spin.number('@3', -3, force=True)") 
453  uf.backend = number_spin 
454  uf.menu_text = "num&ber" 
455  uf.gui_icon = "oxygen.actions.edit-rename" 
456  uf.wizard_height_desc = 500 
457  uf.wizard_size = (1000, 750) 
458  uf.wizard_image = WIZARD_IMAGE_PATH + 'spin.png' 
459