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

Source Code for Module user_functions.value

  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 value user function definitions.""" 
 25   
 26  # Python module imports. 
 27  from os import sep 
 28  import wx 
 29   
 30  # relax module imports. 
 31  from prompt.doc_string import regexp_doc 
 32  from generic_fns import diffusion_tensor, pipes, value 
 33  from graphics import WIZARD_IMAGE_PATH 
 34  from relax_errors import RelaxError 
 35  from specific_fns.jw_mapping import Jw_mapping 
 36  from specific_fns.model_free import Model_free 
 37  from specific_fns.relax_fit import Relax_fit 
 38  from specific_fns.n_state_model import N_state_model 
 39  from specific_fns.noe import Noe 
 40  from user_functions.data import Uf_info; uf_info = Uf_info() 
 41  from user_functions.data import Uf_tables; uf_tables = Uf_tables() 
 42  from user_functions.objects import Desc_container 
 43   
 44   
 45  # The user function class. 
 46  uf_class = uf_info.add_class('value') 
 47  uf_class.title = "Class for setting data values." 
 48  uf_class.menu_text = "&value" 
 49  uf_class.gui_icon = "relax.value" 
 50   
 51   
 52  # The value.copy user function. 
 53  uf = uf_info.add_uf('value.copy') 
 54  uf.title = "Copy spin specific data values from one data pipe to another." 
 55  uf.title_short = "Value copying." 
 56  uf.add_keyarg( 
 57      name = "pipe_from", 
 58      py_type = "str", 
 59      desc_short = "source data pipe", 
 60      desc = "The name of the pipe to copy from.", 
 61      wiz_element_type = 'combo', 
 62      wiz_combo_iter = pipes.pipe_names, 
 63      wiz_read_only = True 
 64  ) 
 65  uf.add_keyarg( 
 66      name = "pipe_to", 
 67      py_type = "str", 
 68      desc_short = "destination data pipe", 
 69      desc = "The name of the pipe to copy to.", 
 70      wiz_element_type = 'combo', 
 71      wiz_combo_iter = pipes.pipe_names, 
 72      wiz_read_only = True 
 73  ) 
 74  uf.add_keyarg( 
 75      name = "param", 
 76      py_type = "str", 
 77      desc_short = "parameter", 
 78      desc = "The parameter to copy.  Only one parameter may be selected.", 
 79      wiz_element_type = 'combo', 
 80      wiz_combo_iter = value.get_parameters, 
 81      wiz_read_only = True 
 82  ) 
 83  # Description. 
 84  uf.desc.append(Desc_container()) 
 85  uf.desc[-1].add_paragraph("If this is used to change values of previously minimised parameters, then the minimisation statistics (chi-squared value, iteration count, function count, gradient count, and Hessian count) will be reset.") 
 86  # Prompt examples. 
 87  uf.desc.append(regexp_doc) 
 88  uf.desc.append(Model_free.set_doc) 
 89  uf.desc.append(Model_free.return_data_name_doc) 
 90  uf.desc.append(Jw_mapping.set_doc) 
 91  uf.desc.append(Jw_mapping.return_data_name_doc) 
 92  uf.desc.append(Relax_fit.set_doc) 
 93  uf.desc.append(Relax_fit.return_data_name_doc) 
 94  uf.desc.append(N_state_model.set_doc) 
 95  uf.desc.append(N_state_model.return_data_name_doc) 
 96  uf.desc.append(Desc_container("Prompt examples")) 
 97  uf.desc[-1].add_paragraph("To copy the CSA values from the data pipe 'm1' to 'm2', type:") 
 98  uf.desc[-1].add_prompt("relax> value.copy('m1', 'm2', 'csa')") 
 99  uf.backend = value.copy 
100  uf.menu_text = "&copy" 
101  uf.gui_icon = "oxygen.actions.list-add" 
102  uf.wizard_height_desc = 500 
103  uf.wizard_size = (1000, 750) 
104  uf.wizard_image = WIZARD_IMAGE_PATH + 'value' + sep + 'value.png' 
105   
106   
107  # The value.display user function. 
108  uf = uf_info.add_uf('value.display') 
109  uf.title = "Display spin specific data values." 
110  uf.title_short = "Display values." 
111  uf.display = True 
112  uf.add_keyarg( 
113      name = "param", 
114      py_type = "str", 
115      desc_short = "parameter", 
116      desc = "The parameter to display.  Only one parameter may be selected.", 
117      wiz_element_type = 'combo', 
118      wiz_combo_iter = value.get_parameters, 
119      wiz_read_only = True 
120  ) 
121  uf.desc.append(regexp_doc) 
122  uf.desc.append(Model_free.return_data_name_doc) 
123  uf.desc.append(Jw_mapping.return_data_name_doc) 
124  uf.desc.append(Noe.return_data_name_doc) 
125  uf.desc.append(Relax_fit.return_data_name_doc) 
126  uf.desc.append(N_state_model.return_data_name_doc) 
127  # Prompt examples. 
128  uf.desc.append(Desc_container("Prompt examples")) 
129  uf.desc[-1].add_paragraph("To show all CSA values, type:") 
130  uf.desc[-1].add_prompt("relax> value.display('csa')") 
131  uf.backend = value.display 
132  uf.menu_text = "&display" 
133  uf.gui_icon = "oxygen.actions.document-preview" 
134  uf.wizard_height_desc = 550 
135  uf.wizard_size = (1000, 750) 
136  uf.wizard_apply_button = False 
137  uf.wizard_image = WIZARD_IMAGE_PATH + 'value' + sep + 'value.png' 
138   
139   
140  # The value.read user function. 
141  uf = uf_info.add_uf('value.read') 
142  uf.title = "Read spin specific data values from a file." 
143  uf.title_short = "Reading values from file." 
144  uf.add_keyarg( 
145      name = "param", 
146      py_type = "str", 
147      desc_short = "parameter", 
148      desc = "The parameter.  Only one parameter may be selected.", 
149      wiz_element_type = 'combo', 
150      wiz_combo_iter = value.get_parameters, 
151      wiz_read_only = True 
152  ) 
153  uf.add_keyarg( 
154      name = "scaling", 
155      default = 1.0, 
156      py_type = "float", 
157      desc_short = "scaling", 
158      desc = "The factor to scale parameters by." 
159  ) 
160  uf.add_keyarg( 
161      name = "file", 
162      py_type = "str", 
163      arg_type = "file sel", 
164      desc_short = "file name", 
165      desc = "The name of the file containing the values.", 
166      wiz_filesel_style = wx.FD_OPEN 
167  ) 
168  uf.add_keyarg( 
169      name = "dir", 
170      py_type = "str", 
171      arg_type = "dir", 
172      desc_short = "directory name", 
173      desc = "The directory where the file is located.", 
174      can_be_none = True 
175  ) 
176  uf.add_keyarg( 
177      name = "spin_id_col", 
178      py_type = "int", 
179      arg_type = "free format", 
180      desc_short = "spin ID string column", 
181      desc = "The spin ID string column (an alternative to the mol, res, and spin name and number columns).", 
182      can_be_none = True 
183  ) 
184  uf.add_keyarg( 
185      name = "mol_name_col", 
186      py_type = "int", 
187      arg_type = "free format", 
188      desc_short = "molecule name column", 
189      desc = "The molecule name column (alternative to the spin_id_col).", 
190      can_be_none = True 
191  ) 
192  uf.add_keyarg( 
193      name = "res_num_col", 
194      py_type = "int", 
195      arg_type = "free format", 
196      desc_short = "residue number column", 
197      desc = "The residue number column (alternative to the spin_id_col).", 
198      can_be_none = True 
199  ) 
200  uf.add_keyarg( 
201      name = "res_name_col", 
202      py_type = "int", 
203      arg_type = "free format", 
204      desc_short = "residue name column", 
205      desc = "The residue name column (alternative to the spin_id_col).", 
206      can_be_none = True 
207  ) 
208  uf.add_keyarg( 
209      name = "spin_num_col", 
210      py_type = "int", 
211      arg_type = "free format", 
212      desc_short = "spin number column", 
213      desc = "The spin number column (alternative to the spin_id_col).", 
214      can_be_none = True 
215  ) 
216  uf.add_keyarg( 
217      name = "spin_name_col", 
218      py_type = "int", 
219      arg_type = "free format", 
220      desc_short = "spin name column", 
221      desc = "The spin name column (alternative to the spin_id_col).", 
222      can_be_none = True 
223  ) 
224  uf.add_keyarg( 
225      name = "data_col", 
226      py_type = "int", 
227      arg_type = "free format", 
228      desc_short = "data column", 
229      desc = "The RDC data column.", 
230      can_be_none = True 
231  ) 
232  uf.add_keyarg( 
233      name = "error_col", 
234      py_type = "int", 
235      arg_type = "free format", 
236      desc_short = "error column", 
237      desc = "The experimental error column.", 
238      can_be_none = True 
239  ) 
240  uf.add_keyarg( 
241      name = "sep", 
242      py_type = "str", 
243      arg_type = "free format", 
244      desc_short = "column separator", 
245      desc = "The column separator (the default is white space).", 
246      can_be_none = True 
247  ) 
248  uf.add_keyarg( 
249      name = "spin_id", 
250      py_type = "str", 
251      desc_short = "spin ID string", 
252      desc = "The spin ID string to restrict the loading of data to certain spin subsets." 
253  ) 
254  # Description. 
255  uf.desc.append(Desc_container()) 
256  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.") 
257  uf.desc[-1].add_paragraph("If this is used to change values of previously minimised parameters, then the minimisation statistics (chi-squared value, iteration count, function count, gradient count, and Hessian count) will be reset.") 
258  uf.desc.append(regexp_doc) 
259  uf.desc.append(Model_free.set_doc) 
260  uf.desc.append(Model_free.return_data_name_doc) 
261  uf.desc.append(Jw_mapping.set_doc) 
262  uf.desc.append(Jw_mapping.return_data_name_doc) 
263  uf.desc.append(Relax_fit.set_doc) 
264  uf.desc.append(Relax_fit.return_data_name_doc) 
265  uf.desc.append(N_state_model.set_doc) 
266  uf.desc.append(N_state_model.return_data_name_doc) 
267  # Prompt examples. 
268  uf.desc.append(Desc_container("Prompt examples")) 
269  uf.desc[-1].add_paragraph("To load 15N CSA values from the file 'csa_values' in the directory 'data', where spins are only identified by residue name and number, type one of the following:") 
270  uf.desc[-1].add_prompt("relax> value.read('csa', 'data/csa_value', spin_id='@N')") 
271  uf.desc[-1].add_prompt("relax> value.read('csa', 'csa_value', dir='data', spin_id='@N')") 
272  uf.desc[-1].add_prompt("relax> value.read(param='csa', file='csa_value', dir='data', res_num_col=1, res_name_col=2, data_col=3, error_col=4, spin_id='@N')") 
273  uf.backend = value.read 
274  uf.menu_text = "&read" 
275  uf.gui_icon = "oxygen.actions.document-open" 
276  uf.wizard_height_desc = 200 
277  uf.wizard_size = (1000, 750) 
278  uf.wizard_image = WIZARD_IMAGE_PATH + 'value' + sep + 'value.png' 
279   
280   
281  # The value.set user function. 
282  uf = uf_info.add_uf('value.set') 
283  uf.title = "Set spin specific data values." 
284  uf.title_short = "Value setting." 
285  uf.add_keyarg( 
286      name = "val", 
287      py_type = "val_or_list", 
288      desc_short = "value", 
289      desc = "The value(s).", 
290      can_be_none = True 
291  ) 
292  uf.add_keyarg( 
293      name = "param", 
294      py_type = "str_or_str_list", 
295      desc_short = "parameter", 
296      desc = "The parameter(s).", 
297      wiz_element_type = 'combo_list', 
298      wiz_combo_iter = value.get_parameters, 
299      wiz_read_only = False, 
300      can_be_none = True 
301  ) 
302  uf.add_keyarg( 
303      name = "spin_id", 
304      py_type = "str", 
305      arg_type = "spin ID", 
306      desc_short = "spin ID to restrict value setting to", 
307      desc = "The spin ID string to restrict value setting to.", 
308      can_be_none = True 
309  ) 
310  # Description. 
311  uf.desc.append(Desc_container()) 
312  uf.desc[-1].add_paragraph("If this function is used to change values of previously minimised results, then the minimisation statistics (chi-squared value, iteration count, function count, gradient count, and Hessian count) will be reset to None.") 
313  uf.desc[-1].add_paragraph("The value can be None, a single value, or an array of values while the parameter can be None, a string, or array of strings.  The choice of which combination determines the behaviour of this function.  The following table describes what occurs in each instance.  In these columns, 'None' corresponds to None, '1' corresponds to either a single value or single string, and 'n' corresponds to either an array of values or an array of strings.") 
314  table = uf_tables.add_table(label="table: value.set combinations", caption="The value and parameter combination options for the value.set user function.", caption_short="The value and parameter combinations for the value.set user function.") 
315  table.add_headings(["Value", "Param", "Description"]) 
316  table.add_row(["None", "None", "This case is used to set the model parameters prior to minimisation or calculation.  The model parameters are set to the default values."]) 
317  table.add_row(["1", "None", "Invalid combination."]) 
318  table.add_row(["n", "None", "This case is used to set the model parameters prior to minimisation or calculation.  The length of the val array must be equal to the number of model parameters.  The parameters will be set to the corresponding number."]) 
319  table.add_row(["None", "1", "The parameter matching the string will be set to the default value."]) 
320  table.add_row(["1", "1", "The parameter matching the string will be set to the supplied number."]) 
321  table.add_row(["n", "1", "Invalid combination."]) 
322  table.add_row(["None", "n", "Each parameter matching the strings will be set to the default values."]) 
323  table.add_row(["1", "n", "Each parameter matching the strings will be set to the supplied number."]) 
324  table.add_row(["n", "n", "Each parameter matching the strings will be set to the corresponding number.  Both arrays must be of equal length."]) 
325  uf.desc[-1].add_table(table.label) 
326  # Spin identification. 
327  uf.desc.append(Desc_container("Spin identification")) 
328  uf.desc[-1].add_paragraph("If the spin ID is left unset, then this will be applied to all spins.  If the data is global non-spin specific data, such as diffusion tensor parameters, supplying the spin identifier will terminate the program with an error.") 
329  uf.desc.append(regexp_doc) 
330  uf.desc.append(Model_free.set_doc) 
331  uf.desc.append(Model_free.return_data_name_doc) 
332  uf.desc.append(Model_free.default_value_doc) 
333  uf.desc.append(Jw_mapping.set_doc) 
334  uf.desc.append(Jw_mapping.return_data_name_doc) 
335  uf.desc.append(Jw_mapping.default_value_doc) 
336  uf.desc.append(diffusion_tensor.__set_doc__) 
337  uf.desc.append(diffusion_tensor.__return_data_name_doc__) 
338  uf.desc.append(diffusion_tensor.__default_value_doc__) 
339  uf.desc.append(Relax_fit.set_doc) 
340  uf.desc.append(Relax_fit.return_data_name_doc) 
341  uf.desc.append(Relax_fit.default_value_doc) 
342  uf.desc.append(N_state_model.set_doc) 
343  uf.desc.append(N_state_model.return_data_name_doc) 
344  uf.desc.append(N_state_model.default_value_doc) 
345  # Prompt examples. 
346  uf.desc.append(Desc_container("Prompt examples")) 
347  uf.desc[-1].add_paragraph("To set the parameter values for the current data pipe to the default values, for all spins, type:") 
348  uf.desc[-1].add_prompt("relax> value.set()") 
349  uf.desc[-1].add_paragraph("To set the parameter values of residue 10, which is in the current model-free data pipe 'm4' and has the parameters {S2, te, Rex}, the following can be used.  Rex term is the value for the first given field strength.") 
350  uf.desc[-1].add_prompt("relax> value.set([0.97, 2.048*1e-9, 0.149], spin_id=':10')") 
351  uf.desc[-1].add_prompt("relax> value.set(val=[0.97, 2.048*1e-9, 0.149], spin_id=':10')") 
352  uf.desc[-1].add_paragraph("To set the CSA value of all spins to the default value, type:") 
353  uf.desc[-1].add_prompt("relax> value.set(param='csa')") 
354  uf.desc[-1].add_paragraph("To set the CSA value of all spins to -172 ppm, type:") 
355  uf.desc[-1].add_prompt("relax> value.set(-172 * 1e-6, 'csa')") 
356  uf.desc[-1].add_prompt("relax> value.set(val=-172 * 1e-6, param='csa')") 
357  uf.desc[-1].add_paragraph("To set the NH bond length of all spins to 1.02 Angstroms, type:") 
358  uf.desc[-1].add_prompt("relax> value.set(1.02 * 1e-10, 'r')") 
359  uf.desc[-1].add_prompt("relax> value.set(val=1.02 * 1e-10, param='r')") 
360  uf.desc[-1].add_paragraph("To set both the bond length and the CSA value to the default values, type:") 
361  uf.desc[-1].add_prompt("relax> value.set(param=['r', 'csa'])") 
362  uf.desc[-1].add_paragraph("To set both tf and ts to 100 ps, type:") 
363  uf.desc[-1].add_prompt("relax> value.set(100e-12, ['tf', 'ts'])") 
364  uf.desc[-1].add_prompt("relax> value.set(val=100e-12, param=['tf', 'ts'])") 
365  uf.desc[-1].add_paragraph("To set the S2 and te parameter values of residue 126, Ca spins to 0.56 and 13 ps, type:") 
366  uf.desc[-1].add_prompt("relax> value.set([0.56, 13e-12], ['s2', 'te'], ':126@Ca')") 
367  uf.desc[-1].add_prompt("relax> value.set(val=[0.56, 13e-12], param=['s2', 'te'], spin_id=':126@Ca')") 
368  uf.desc[-1].add_prompt("relax> value.set(val=[0.56, 13e-12], param=['s2', 'te'], spin_id=':126@Ca')") 
369  uf.backend = value.set 
370  uf.menu_text = "&set" 
371  uf.wizard_height_desc = 480 
372  uf.wizard_size = (1000, 750) 
373  uf.wizard_image = WIZARD_IMAGE_PATH + 'value' + sep + 'value.png' 
374   
375   
376  # The value.write user function. 
377  uf = uf_info.add_uf('value.write') 
378  uf.title = "Write spin specific data values to a file." 
379  uf.title_short = "Value writing." 
380  uf.add_keyarg( 
381      name = "param", 
382      py_type = "str", 
383      desc_short = "parameter", 
384      desc = "The parameter.", 
385      wiz_element_type = 'combo', 
386      wiz_combo_iter = value.get_parameters, 
387      wiz_read_only = True 
388  ) 
389  uf.add_keyarg( 
390      name = "file", 
391      py_type = "str", 
392      arg_type = "file sel", 
393      desc_short = "file name", 
394      desc = "The name of the file.", 
395      wiz_filesel_style = wx.FD_SAVE 
396  ) 
397  uf.add_keyarg( 
398      name = "dir", 
399      py_type = "str", 
400      arg_type = "dir", 
401      desc_short = "directory name", 
402      desc = "The directory name.", 
403      can_be_none = True 
404  ) 
405  uf.add_keyarg( 
406      name = "bc", 
407      default = False, 
408      py_type = "bool", 
409      desc_short = "back calculated value flag", 
410      desc = "A flag which if True will cause the back calculated values to be written to file rather than the actual data." 
411  ) 
412  uf.add_keyarg( 
413      name = "force", 
414      default = False, 
415      py_type = "bool", 
416      desc_short = "force flag", 
417      desc = "A flag which, if set to True, will cause the file to be overwritten." 
418  ) 
419  # Description. 
420  uf.desc.append(Desc_container()) 
421  uf.desc[-1].add_paragraph("The values corresponding to the given parameter will be written to file.") 
422  uf.desc.append(regexp_doc) 
423  uf.desc.append(Model_free.return_data_name_doc) 
424  uf.desc.append(Jw_mapping.return_data_name_doc) 
425  uf.desc.append(Noe.return_data_name_doc) 
426  uf.desc.append(Relax_fit.return_data_name_doc) 
427  uf.desc.append(N_state_model.return_data_name_doc) 
428  # Prompt examples. 
429  uf.desc.append(Desc_container("Prompt examples")) 
430  uf.desc[-1].add_paragraph("To write the CSA values to the file 'csa.txt', type one of:") 
431  uf.desc[-1].add_prompt("relax> value.write('csa', 'csa.txt')") 
432  uf.desc[-1].add_prompt("relax> value.write(param='csa', file='csa.txt')") 
433  uf.desc[-1].add_paragraph("To write the NOE values to the file 'noe', type one of:") 
434  uf.desc[-1].add_prompt("relax> value.write('noe', 'noe.out')") 
435  uf.desc[-1].add_prompt("relax> value.write(param='noe', file='noe.out')") 
436  uf.desc[-1].add_prompt("relax> value.write(param='noe', file='noe.out')") 
437  uf.desc[-1].add_prompt("relax> value.write(param='noe', file='noe.out', force=True)") 
438  uf.backend = value.write 
439  uf.menu_text = "&write" 
440  uf.gui_icon = "oxygen.actions.document-save" 
441  uf.wizard_height_desc = 400 
442  uf.wizard_size = (1000, 750) 
443  uf.wizard_image = WIZARD_IMAGE_PATH + 'value' + sep + 'value.png' 
444