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

Source Code for Module user_functions.select

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2014 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 select user function definitions.""" 
 24   
 25  # Python module imports. 
 26  import dep_check 
 27  if dep_check.wx_module: 
 28      from wx import FD_OPEN 
 29  else: 
 30      FD_OPEN = -1 
 31   
 32  # relax module imports. 
 33  from graphics import WIZARD_IMAGE_PATH 
 34  from pipe_control import domain, selection, spectrum 
 35  from user_functions.data import Uf_info; uf_info = Uf_info() 
 36  from user_functions.objects import Desc_container 
 37   
 38   
 39  # The user function class. 
 40  uf_class = uf_info.add_class("select") 
 41  uf_class.title = "Class for selecting spins." 
 42  uf_class.menu_text = "&select" 
 43  uf_class.gui_icon = "relax.spin" 
 44   
 45   
 46  # The select.all user function. 
 47  uf = uf_info.add_uf("select.all") 
 48  uf.title = "Select all spins in the current data pipe." 
 49  uf.title_short = "Selection of all spins." 
 50  uf.display = True 
 51  # Description. 
 52  uf.desc.append(Desc_container()) 
 53  uf.desc[-1].add_paragraph("This will select all spins, irregardless of their current state.") 
 54  # Prompt examples. 
 55  uf.desc.append(Desc_container("Prompt examples")) 
 56  uf.desc[-1].add_paragraph("To select all spins, simply type:") 
 57  uf.desc[-1].add_prompt("relax> select.all()") 
 58  uf.backend = selection.sel_all 
 59  uf.menu_text = "&all" 
 60  uf.wizard_size = (600, 550) 
 61  uf.wizard_apply_button = False 
 62  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
 63   
 64   
 65  # The select.display user function. 
 66  uf = uf_info.add_uf('select.display') 
 67  uf.title = "Display the current spin selection status." 
 68  uf.title_short = "Display spin selection status." 
 69  uf.display = True 
 70  # Description. 
 71  uf.desc.append(Desc_container()) 
 72  uf.desc[-1].add_paragraph("This simply prints out the current spin selections.") 
 73  # Prompt examples. 
 74  uf.desc.append(Desc_container("Prompt examples")) 
 75  uf.desc[-1].add_paragraph("To show the current selections, type:") 
 76  uf.desc[-1].add_prompt("relax> select.display()") 
 77  uf.backend = selection.display 
 78  uf.menu_text = "dis&play" 
 79  uf.gui_icon = "oxygen.actions.document-preview" 
 80  uf.wizard_size = (600, 550) 
 81  uf.wizard_apply_button = False 
 82  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
 83   
 84   
 85  # The select.domain user function. 
 86  uf = uf_info.add_uf("select.domain") 
 87  uf.title = "Select all spins and interatomic data containers of a domain." 
 88  uf.title_short = "Selection of whole domains." 
 89  uf.display = True 
 90  uf.add_keyarg( 
 91      name = "domain_id", 
 92      py_type = "str", 
 93      arg_type = "domain ID", 
 94      desc_short = "domain ID string", 
 95      desc = "The domain ID string of the domain to select.", 
 96      wiz_element_type = 'combo', 
 97      wiz_combo_iter = domain.get_domain_ids, 
 98      can_be_none = False 
 99  ) 
100  uf.add_keyarg( 
101      name = "boolean", 
102      default = "AND", 
103      py_type = "str", 
104      desc_short = "boolean operator", 
105      desc = "The boolean operator specifying how interatomic data containers should be selected.", 
106      wiz_element_type = "combo", 
107      wiz_combo_choices = [ 
108          "OR", 
109          "NOR", 
110          "AND", 
111          "NAND", 
112          "XOR", 
113          "XNOR" 
114      ], 
115      wiz_read_only = True 
116  ) 
117  uf.add_keyarg( 
118      name = "change_all", 
119      default = True, 
120      py_type = "bool", 
121      desc_short = "change all flag", 
122      desc = "A flag specifying if all non-matching spin and interatomic data containers should be deselected." 
123  ) 
124  # Description. 
125  uf.desc.append(Desc_container()) 
126  uf.desc[-1].add_paragraph("This will select all spins and interatomic data containers of a given domain.  This is defined by the domain ID string as specified by the previously executed domain-related user functions.") 
127  uf.desc.append(selection.boolean_doc) 
128  # Prompt examples. 
129  uf.desc.append(Desc_container("Prompt examples")) 
130  uf.desc[-1].add_paragraph("To select all spins of the domain 'N-dom', simply type one of:") 
131  uf.desc[-1].add_prompt("relax> select.domain('N-dom', change_all=True)") 
132  uf.desc[-1].add_prompt("relax> select.domain(domain_id='N-dom', change_all=True)") 
133  uf.desc[-1].add_paragraph("To select all spins of the domain 'N-dom', preserving the current selections, simply type one of:") 
134  uf.desc[-1].add_prompt("relax> select.domain('N-dom', 'AND', True)") 
135  uf.desc[-1].add_prompt("relax> select.domain(domain_id='N-dom', boolean='AND', change_all=True)") 
136  uf.backend = selection.sel_domain 
137  uf.menu_text = "&domain" 
138  uf.wizard_height_desc = 500 
139  uf.wizard_size = (1000, 750) 
140  uf.wizard_apply_button = True 
141  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
142   
143   
144  # The select.interatom user function. 
145  uf = uf_info.add_uf("select.interatom") 
146  uf.title = "Select specific interatomic data containers." 
147  uf.title_short = "Interatomic data container selection." 
148  uf.display = True 
149  uf.add_keyarg( 
150      name = "spin_id1", 
151      py_type = "str", 
152      arg_type = "spin ID", 
153      desc_short = "first spin ID string", 
154      desc = "The spin ID string of the first spin of the interatomic data container.", 
155      can_be_none = True 
156  ) 
157  uf.add_keyarg( 
158      name = "spin_id2", 
159      py_type = "str", 
160      arg_type = "spin ID", 
161      desc_short = "second spin ID string", 
162      desc = "The spin ID string of the second spin of the interatomic data container.", 
163      can_be_none = True 
164  ) 
165  uf.add_keyarg( 
166      name = "boolean", 
167      default = "OR", 
168      py_type = "str", 
169      desc_short = "boolean operator", 
170      desc = "The boolean operator specifying how interatomic data containers should be selected.", 
171      wiz_element_type = "combo", 
172      wiz_combo_choices = [ 
173          "OR", 
174          "NOR", 
175          "AND", 
176          "NAND", 
177          "XOR", 
178          "XNOR" 
179      ], 
180      wiz_read_only = True 
181  ) 
182  uf.add_keyarg( 
183      name = "change_all", 
184      default = False, 
185      py_type = "bool", 
186      desc_short = "change all", 
187      desc = "A flag specifying if all other interatomic data containers should be changed." 
188  ) 
189  # Description. 
190  uf.desc.append(Desc_container()) 
191  uf.desc[-1].add_paragraph("This is used to select specific interatomic data containers which store information about spin pairs such as RDCs, NOEs, dipole-dipole pairs involved in relaxation, etc.  The 'change all' flag default is False meaning that all interatomic data containers currently either selected or deselected will remain that way.  Setting this to True will cause all interatomic data containers not specified by the spin ID strings to be selected.") 
192  uf.desc.append(selection.boolean_doc) 
193  # Prompt examples. 
194  uf.desc.append(Desc_container("Prompt examples")) 
195  uf.desc[-1].add_paragraph("To select all N-H backbone bond vectors of a protein, assuming these interatomic data containers have been already set up, type one of:") 
196  uf.desc[-1].add_prompt("relax> select.interatom('@N', '@H')") 
197  uf.desc[-1].add_prompt("relax> select.interatom(spin_id1='@N', spin_id2='@H')") 
198  uf.desc[-1].add_paragraph("To select all H-H interatomic vectors of a small organic molecule, type one of:") 
199  uf.desc[-1].add_prompt("relax> select.interatom('@H*', '@H*')") 
200  uf.desc[-1].add_prompt("relax> select.interatom(spin_id1='@H*', spin_id2='@H*')") 
201  uf.backend = selection.sel_interatom 
202  uf.menu_text = "&interatom" 
203  uf.wizard_height_desc = 450 
204  uf.wizard_size = (1000, 750) 
205  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
206   
207   
208  # The select.read user function. 
209  uf = uf_info.add_uf("select.read") 
210  uf.title = "Select the spins contained in a file." 
211  uf.title_short = "Selecting spins from file." 
212  uf.display = True 
213  uf.add_keyarg( 
214      name = "file", 
215      py_type = "str_or_inst", 
216      arg_type = "file sel", 
217      desc_short = "file name", 
218      desc = "The name of the file containing the list of spins to select.", 
219      wiz_filesel_style = FD_OPEN 
220  ) 
221  uf.add_keyarg( 
222      name = "dir", 
223      py_type = "str", 
224      arg_type = "dir", 
225      desc_short = "directory name", 
226      desc = "The directory where the file is located.", 
227      can_be_none = True 
228  ) 
229  uf.add_keyarg( 
230      name = "spin_id_col", 
231      py_type = "int", 
232      arg_type = "free format", 
233      desc_short = "spin ID string column", 
234      desc = "The spin ID string column (an alternative to the mol, res, and spin name and number columns).", 
235      can_be_none = True 
236  ) 
237  uf.add_keyarg( 
238      name = "mol_name_col", 
239      py_type = "int", 
240      arg_type = "free format", 
241      desc_short = "molecule name column", 
242      desc = "The molecule name column (alternative to the spin_id_col).", 
243      can_be_none = True 
244  ) 
245  uf.add_keyarg( 
246      name = "res_num_col", 
247      py_type = "int", 
248      arg_type = "free format", 
249      desc_short = "residue number column", 
250      desc = "The residue number column (alternative to the spin_id_col).", 
251      can_be_none = True 
252  ) 
253  uf.add_keyarg( 
254      name = "res_name_col", 
255      py_type = "int", 
256      arg_type = "free format", 
257      desc_short = "residue name column", 
258      desc = "The residue name column (alternative to the spin_id_col).", 
259      can_be_none = True 
260  ) 
261  uf.add_keyarg( 
262      name = "spin_num_col", 
263      py_type = "int", 
264      arg_type = "free format", 
265      desc_short = "spin number column", 
266      desc = "The spin number column (alternative to the spin_id_col).", 
267      can_be_none = True 
268  ) 
269  uf.add_keyarg( 
270      name = "spin_name_col", 
271      py_type = "int", 
272      arg_type = "free format", 
273      desc_short = "spin name column", 
274      desc = "The spin name column (alternative to the spin_id_col).", 
275      can_be_none = True 
276  ) 
277  uf.add_keyarg( 
278      name = "sep", 
279      py_type = "str", 
280      arg_type = "free format", 
281      desc_short = "column separator", 
282      desc = "The column separator (the default is white space).", 
283      can_be_none = True 
284  ) 
285  uf.add_keyarg( 
286      name = "spin_id", 
287      py_type = "str", 
288      arg_type = "spin ID", 
289      desc_short = "spin ID string", 
290      desc = "The spin ID string to restrict the loading of data to certain spin subsets.", 
291      can_be_none = True 
292  ) 
293  uf.add_keyarg( 
294      name = "boolean", 
295      default = "OR", 
296      py_type = "str", 
297      desc_short = "boolean operator", 
298      desc = "The boolean operator specifying how spins should be selected.", 
299      wiz_element_type = "combo", 
300      wiz_combo_choices = [ 
301          "OR", 
302          "NOR", 
303          "AND", 
304          "NAND", 
305          "XOR", 
306          "XNOR" 
307      ], 
308      wiz_read_only = True 
309  ) 
310  uf.add_keyarg( 
311      name = "change_all", 
312      default = False, 
313      py_type = "bool", 
314      desc_short = "change all", 
315      desc = "A flag specifying if all other spins should be changed." 
316  ) 
317  # Description. 
318  uf.desc.append(Desc_container()) 
319  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, residue name, spin number and/or spin 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 string can be used to restrict the reading to certain spin types, for example only 15N spins when only residue information is in the file.") 
320  uf.desc[-1].add_paragraph("Empty lines and lines beginning with a hash are ignored.") 
321  uf.desc[-1].add_paragraph("The 'change all' flag default is False meaning that all spins currently either selected or deselected will remain that way.  Setting this to True will cause all spins not specified in the file to be deselected.") 
322  uf.desc.append(selection.boolean_doc) 
323  # Prompt examples. 
324  uf.desc.append(Desc_container("Prompt examples")) 
325  uf.desc[-1].add_paragraph("To select all residues listed with residue numbers in the first column of the file 'isolated_peaks', type one of:") 
326  uf.desc[-1].add_prompt("relax> select.read('isolated_peaks', res_num_col=1)") 
327  uf.desc[-1].add_prompt("relax> select.read(file='isolated_peaks', res_num_col=1)") 
328  uf.desc[-1].add_paragraph("To select the spins in the second column of the relaxation data file 'r1.600' while deselecting all other spins, for example type:") 
329  uf.desc[-1].add_prompt("relax> select.read('r1.600', spin_num_col=2, change_all=True)") 
330  uf.desc[-1].add_prompt("relax> select.read(file='r1.600', spin_num_col=2, change_all=True)") 
331  uf.backend = selection.sel_read 
332  uf.menu_text = "&read" 
333  uf.gui_icon = "oxygen.actions.document-open" 
334  uf.wizard_height_desc = 400 
335  uf.wizard_size = (1000, 750) 
336  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
337   
338   
339  # The select.reverse user function. 
340  uf = uf_info.add_uf("select.reverse") 
341  uf.title = "Reversal of the spin selection for the given spins." 
342  uf.title_short = "Spin selection reversal." 
343  uf.display = True 
344  uf.add_keyarg( 
345      name = "spin_id", 
346      py_type = "str", 
347      desc_short = "spin ID string", 
348      desc = "The spin ID string.", 
349      can_be_none = True 
350  ) 
351  # Description. 
352  uf.desc.append(Desc_container()) 
353  uf.desc[-1].add_paragraph("By supplying the spin ID string, a subset of spins can have their selection status reversed.") 
354  # Prompt examples. 
355  uf.desc.append(Desc_container("Prompt examples")) 
356  uf.desc[-1].add_paragraph("To select all currently deselected spins and deselect those which are selected type:") 
357  uf.desc[-1].add_prompt("relax> select.reverse()") 
358  uf.backend = selection.reverse 
359  uf.menu_text = "re&verse" 
360  uf.gui_icon = "oxygen.actions.system-switch-user" 
361  uf.wizard_size = (700, 550) 
362  uf.wizard_apply_button = False 
363  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
364   
365   
366  # The select.sn_ratio user function. 
367  uf = uf_info.add_uf("select.sn_ratio") 
368  uf.title = "Select spins with signal to noise ratio higher or lower than the given ratio." 
369  uf.title_short = "Spin signal to noise selection." 
370  uf.display = True 
371  uf.add_keyarg( 
372      name = "ratio", 
373      default = 10.0, 
374      py_type = "float", 
375      desc_short = "ratio", 
376      desc = "The signal to noise ratio to compare to." 
377  ) 
378  uf.add_keyarg( 
379      name = "operation", 
380      default = ">", 
381      py_type = "str", 
382      desc_short = "comparison operation", 
383      desc = "The comparison operation by which to select the spins.", 
384      wiz_element_type = "combo", 
385      wiz_combo_choices = [ 
386          "'<' : strictly less than", 
387          "'<=' : less than or equal", 
388          "'>' : strictly greater than", 
389          "'>=' : greater than or equal", 
390          "'==' : equal", 
391          "'!=' : not equal", 
392      ], 
393      wiz_combo_data = [ 
394          "<", 
395          "<=", 
396          ">", 
397          ">=", 
398          "==", 
399          "!=", 
400      ], 
401      wiz_read_only = True 
402  ) 
403  uf.add_keyarg( 
404      name = "all_sn", 
405      default = True, 
406      py_type = "bool", 
407      desc_short = "all S/N per spin flag", 
408      desc = "A flag specifying if all the signal to noise ratios per spin should match the comparison operator, of if just a single comparison match is enough." 
409  ) 
410  # Description. 
411  uf.desc.append(Desc_container()) 
412  uf.desc[-1].add_paragraph("The comparison operation is the method which to select spins according to: operation(sn_ratio, ratio).") 
413  uf.desc[-1].add_paragraph("The possible operations are: '<':strictly less than, '<=':less than or equal, '>':strictly greater than, '>=':greater than or equal, '==':equal, '!=':not equal.") 
414  uf.desc[-1].add_paragraph("The 'all_sn' flag default is True, meaning that if all of the spin's signal to noise levels evaluates to True in the comparison, the spin is selected.") 
415  # Prompt examples. 
416  uf.desc.append(Desc_container("Prompt examples")) 
417  uf.desc[-1].add_paragraph("To select all spins with a signal to noise ratio higher than 10.0:") 
418  uf.desc[-1].add_prompt("relax> select.sn_ratio(ratio=10.0, operation='>')") 
419  uf.desc[-1].add_prompt("relax> select.sn_ratio(ratio=10.0, operation='>', all_sn=False)") 
420  uf.backend = spectrum.sn_ratio_selection 
421  uf.menu_text = "&sn_ratio" 
422  uf.gui_icon = "relax.fid" 
423  uf.wizard_height_desc = 500 
424  uf.wizard_size = (1000, 750) 
425  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
426   
427   
428  # The select.spin user function. 
429  uf = uf_info.add_uf("select.spin") 
430  uf.title = "Select specific spins." 
431  uf.title_short = "Spin selection." 
432  uf.display = True 
433  uf.add_keyarg( 
434      name = "spin_id", 
435      py_type = "str", 
436      desc_short = "spin ID string", 
437      desc = "The spin ID string.", 
438      can_be_none = True 
439  ) 
440  uf.add_keyarg( 
441      name = "boolean", 
442      default = "OR", 
443      py_type = "str", 
444      desc_short = "boolean operator", 
445      desc = "The boolean operator specifying how spins should be selected.", 
446      wiz_element_type = "combo", 
447      wiz_combo_choices = [ 
448          "OR", 
449          "NOR", 
450          "AND", 
451          "NAND", 
452          "XOR", 
453          "XNOR" 
454      ], 
455      wiz_read_only = True 
456  ) 
457  uf.add_keyarg( 
458      name = "change_all", 
459      default = False, 
460      py_type = "bool", 
461      desc_short = "change all", 
462      desc = "A flag specifying if all other spins should be changed." 
463  ) 
464  # Description. 
465  uf.desc.append(Desc_container()) 
466  uf.desc[-1].add_paragraph("The 'change all' flag default is False meaning that all spins currently either selected or deselected will remain that way.  Setting this to True will cause all spins not specified by the spin ID string to be selected.") 
467  uf.desc.append(selection.boolean_doc) 
468  # Prompt examples. 
469  uf.desc.append(Desc_container("Prompt examples")) 
470  uf.desc[-1].add_paragraph("To select only glycines and alanines, assuming they have been loaded with the names GLY and ALA, type one of:") 
471  uf.desc[-1].add_prompt("relax> select.spin(spin_id=':GLY|:ALA')") 
472  uf.desc[-1].add_paragraph("To select residue 5 CYS in addition to the currently selected residues, type one of:") 
473  uf.desc[-1].add_prompt("relax> select.spin(':5')") 
474  uf.desc[-1].add_prompt("relax> select.spin(':5&:CYS')") 
475  uf.desc[-1].add_prompt("relax> select.spin(spin_id=':5&:CYS')") 
476  uf.backend = selection.sel_spin 
477  uf.menu_text = "&spin" 
478  uf.gui_icon = "relax.spin" 
479  uf.wizard_height_desc = 500 
480  uf.wizard_size = (1000, 750) 
481  uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' 
482