Author: bugman Date: Wed Mar 20 10:37:53 2013 New Revision: 18904 URL: http://svn.gna.org/viewcvs/relax?rev=18904&view=rev Log: Added the scaling argument to the value.display and value.write user functions. The idea comes from a suggestion by Angelo Figueiredo <am dott figueiredo att fct dott unl dott pt> and was discussed at http://thread.gmane.org/gmane.science.nmr.relax.user/1428/focus=1430. This allows the user to scale parameters to any value, for example scaling the Rex value to the field strength dependent value. Modified: trunk/generic_fns/value.py trunk/user_functions/value.py Modified: trunk/generic_fns/value.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/value.py?rev=18904&r1=18903&r2=18904&view=diff ============================================================================== --- trunk/generic_fns/value.py (original) +++ trunk/generic_fns/value.py Wed Mar 20 10:37:53 2013 @@ -92,11 +92,13 @@ minimise.reset_min_stats(pipe_to) -def display(param=None): +def display(param=None, scaling=1.0): """Display spin specific data values. - @param param: The name of the parameter to display. + @keyword param: The name of the parameter to display. @type param: str + @keyword scaling: The value to scale the parameter by. + @type scaling: float """ # Test if the current pipe exists. @@ -107,7 +109,7 @@ raise RelaxNoSequenceError # Print the data. - write_data(param, sys.stdout) + write_data(param=param, file=sys.stdout, scaling=scaling) def get_parameters(): @@ -426,7 +428,7 @@ pipes.switch(orig_pipe) -def write(param=None, file=None, dir=None, bc=False, force=False, return_value=None, return_data_desc=None): +def write(param=None, file=None, dir=None, scaling=1.0, return_value=None, return_data_desc=None, bc=False, force=False): """Write data to a file. @keyword param: The name of the parameter to write to file. @@ -435,14 +437,16 @@ @type file: str @keyword dir: The name of the directory to place the file into (defaults to the current directory). @type dir: str + @keyword scaling: The value to scale the parameter by. + @type scaling: float + @keyword return_value: An optional function which if supplied will override the default value returning function. + @type return_value: None or func + @keyword return_data_desc: An optional function which if supplied will override the default parameter description returning function. + @type return_data_desc: None or func @keyword bc: A flag which if True will cause the back calculated values to be written. @type bc: bool @keyword force: A flag which if True will cause any pre-existing file to be overwritten. @type force: bool - @keyword return_value: An optional function which if supplied will override the default value returning function. - @type return_value: None or func - @keyword return_data_desc: An optional function which if supplied will override the default parameter description returning function. - @type return_data_desc: None or func """ # Test if the current pipe exists. @@ -457,7 +461,7 @@ file = open_write_file(file, dir, force) # Write the data. - write_data(param=param, file=file, bc=bc, return_value=return_value, return_data_desc=return_data_desc) + write_data(param=param, file=file, scaling=scaling, return_value=return_value, return_data_desc=return_data_desc, bc=bc) # Close the file. file.close() @@ -466,13 +470,15 @@ add_result_file(type='text', label='Text', file=file_path) -def write_data(param=None, file=None, bc=False, return_value=None, return_data_desc=None): +def write_data(param=None, file=None, scaling=1.0, bc=False, return_value=None, return_data_desc=None): """The function which actually writes the data. @keyword param: The parameter to write. @type param: str @keyword file: The file to write the data to. @type file: str + @keyword scaling: The value to scale the parameter by. + @type scaling: float @keyword bc: A flag which if True will cause the back calculated values to be written. @type bc: bool @keyword return_value: An optional function which if supplied will override the default value returning function. @@ -510,12 +516,18 @@ # Get the value and error. value, error = return_value(spin, param, bc=bc) - # Append the data. + # Append the spin data (scaled). mol_names.append(mol_name) res_nums.append(res_num) res_names.append(res_name) spin_nums.append(spin.num) spin_names.append(spin.name) + + # Append the scaled values and errors. + if value != None: + value *= scaling + if error != None: + error *= scaling values.append(value) errors.append(error) Modified: trunk/user_functions/value.py URL: http://svn.gna.org/viewcvs/relax/trunk/user_functions/value.py?rev=18904&r1=18903&r2=18904&view=diff ============================================================================== --- trunk/user_functions/value.py (original) +++ trunk/user_functions/value.py Wed Mar 20 10:37:53 2013 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2003-2012 Edward d'Auvergne # +# Copyright (C) 2003-2013 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -125,6 +125,16 @@ wiz_combo_iter = value.get_parameters, wiz_read_only = True ) +uf.add_keyarg( + name = "scaling", + default = 1.0, + py_type = "float", + desc_short = "scaling", + desc = "The factor to scale parameters by." +) +# Description. +uf.desc.append(Desc_container()) +uf.desc[-1].add_paragraph("The values corresponding to the given parameter will be displayed. The scaling argument can be used to scale the parameter values. This can be useful for example in the case of the model-free Rex parameter to obtain the spectrometer dependent value from the omega_ex field strength independent internal value. Or to scale correlation times from seconds down to nanosecond or picosecond timescales.") uf.desc.append(regexp_doc) uf.desc.append(Model_free.return_data_name_doc) uf.desc.append(Model_free.write_doc) @@ -137,6 +147,9 @@ uf.desc.append(Desc_container("Prompt examples")) uf.desc[-1].add_paragraph("To show all CSA values, type:") uf.desc[-1].add_prompt("relax> value.display('csa')") +uf.desc[-1].add_paragraph("To display the model-free Rex values scaled to 600 MHz, type one of:") +uf.desc[-1].add_prompt("relax> value.display('rex', scaling=(2.0*pi*600e6)**2)") +uf.desc[-1].add_prompt("relax> value.display(param='rex', scaling=(2.0*pi*600e6)**2)") uf.backend = value.display uf.menu_text = "&display" uf.gui_icon = "oxygen.actions.document-preview" @@ -417,6 +430,13 @@ can_be_none = True ) uf.add_keyarg( + name = "scaling", + default = 1.0, + py_type = "float", + desc_short = "scaling", + desc = "The factor to scale parameters by." +) +uf.add_keyarg( name = "bc", default = False, py_type = "bool", @@ -432,7 +452,7 @@ ) # Description. uf.desc.append(Desc_container()) -uf.desc[-1].add_paragraph("The values corresponding to the given parameter will be written to file.") +uf.desc[-1].add_paragraph("The values corresponding to the given parameter will be written to file. The scaling argument can be used to scale the parameter values. This can be useful for example in the case of the model-free Rex parameter to obtain the spectrometer dependent value from the omega_ex field strength independent internal value. Or to scale correlation times from seconds down to nanosecond or picosecond timescales.") uf.desc.append(regexp_doc) uf.desc.append(Model_free.return_data_name_doc) uf.desc.append(Model_free.write_doc) @@ -451,6 +471,9 @@ uf.desc[-1].add_prompt("relax> value.write(param='noe', file='noe.out')") uf.desc[-1].add_prompt("relax> value.write(param='noe', file='noe.out')") uf.desc[-1].add_prompt("relax> value.write(param='noe', file='noe.out', force=True)") +uf.desc[-1].add_paragraph("To write the model-free Rex values scaled to 600 MHz to the file 'rex_600', type one of:") +uf.desc[-1].add_prompt("relax> value.write('rex', 'rex_600', scaling=(2.0*pi*600e6)**2)") +uf.desc[-1].add_prompt("relax> value.write(param='rex', file='rex_600', scaling=(2.0*pi*600e6)**2)") uf.backend = value.write uf.menu_text = "&write" uf.gui_icon = "oxygen.actions.document-save"