mailr21304 - in /branches/relax_disp: specific_analyses/relax_disp/disp_data.py user_functions/relax_disp.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 29, 2013 - 12:13:
Author: bugman
Date: Tue Oct 29 12:13:02 2013
New Revision: 21304

URL: http://svn.gna.org/viewcvs/relax?rev=21304&view=rev
Log:
Implemented the relax_disp.r2eff_read user function.

Bot the frontend and backend have been implemented and are functional.


Modified:
    branches/relax_disp/specific_analyses/relax_disp/disp_data.py
    branches/relax_disp/user_functions/relax_disp.py

Modified: branches/relax_disp/specific_analyses/relax_disp/disp_data.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/disp_data.py?rev=21304&r1=21303&r2=21304&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/disp_data.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/disp_data.py Tue Oct 29 
12:13:02 2013
@@ -39,14 +39,15 @@
 
 # relax module imports.
 from lib.errors import RelaxError, RelaxNoSpectraError, RelaxSpinTypeError
-from lib.io import get_file_path, open_write_file
+from lib.io import get_file_path, open_write_file, read_spin_data
 from lib.physical_constants import g1H, return_gyromagnetic_ratio
 from lib.software.grace import write_xy_data, write_xy_header, 
script_grace2images
 from pipe_control import pipes
-from pipe_control.mol_res_spin import exists_mol_res_spin_data, return_spin, 
spin_loop
+from pipe_control.mol_res_spin import check_mol_res_spin_data, 
exists_mol_res_spin_data, generate_spin_id_unique, return_spin, spin_loop
 from pipe_control.result_files import add_result_file
 from pipe_control.selection import desel_spin
-from pipe_control.spectrum import check_spectrum_id
+from pipe_control.spectrum import add_spectrum_id, check_spectrum_id
+from pipe_control.spectrometer import set_frequency
 from specific_analyses.relax_disp.checks import check_exp_type, 
check_mixed_curve_types
 from specific_analyses.relax_disp.variables import EXP_TYPE_CPMG, 
EXP_TYPE_DESC_CPMG, EXP_TYPE_DESC_DQ_CPMG, EXP_TYPE_DESC_R1RHO, 
EXP_TYPE_DESC_MQ_CPMG, EXP_TYPE_DESC_MQ_R1RHO, EXP_TYPE_DESC_ZQ_CPMG, 
EXP_TYPE_DQ_CPMG, EXP_TYPE_LIST, EXP_TYPE_LIST_CPMG, EXP_TYPE_LIST_R1RHO, 
EXP_TYPE_MQ_CPMG, EXP_TYPE_MQ_R1RHO, EXP_TYPE_R1RHO, EXP_TYPE_ZQ_CPMG
 from stat import S_IRWXU, S_IRGRP, S_IROTH
@@ -1042,6 +1043,113 @@
     add_result_file(type='grace', label='Grace', file=file_path)
 
 
+def r2eff_read(file=None, dir=None, exp_type=None, frq=None, disp_frq=None, 
spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, 
spin_num_col=None, spin_name_col=None, data_col=None, error_col=None, 
sep=None):
+    """Read R2eff/R1rho values directly from a file whereby each row 
corresponds to a different spin.
+
+    @keyword file:          The name of the file to open.
+    @type file:             str
+    @keyword dir:           The directory containing the file (defaults to 
the current directory if None).
+    @type dir:              str or None
+    @keyword exp_type:      The relaxation dispersion experiment type.
+    @type exp_type:         str
+    @keyword frq:           The spectrometer frequency in Hertz.
+    @type frq:              float
+    @keyword disp_frq:      For CPMG-type data, the frequency of the CPMG 
pulse train.  For R1rho-type data, the spin-lock field strength (nu1).  The 
units must be Hertz.
+    @type disp_frq:         float
+    @keyword spin_id_col:   The column containing the spin ID strings.  If 
supplied, the mol_name_col, res_name_col, res_num_col, spin_name_col, and 
spin_num_col arguments must be none.
+    @type spin_id_col:      int or None
+    @keyword mol_name_col:  The column containing the molecule name 
information.  If supplied, spin_id_col must be None.
+    @type mol_name_col:     int or None
+    @keyword res_name_col:  The column containing the residue name 
information.  If supplied, spin_id_col must be None.
+    @type res_name_col:     int or None
+    @keyword res_num_col:   The column containing the residue number 
information.  If supplied, spin_id_col must be None.
+    @type res_num_col:      int or None
+    @keyword spin_name_col: The column containing the spin name information. 
 If supplied, spin_id_col must be None.
+    @type spin_name_col:    int or None
+    @keyword spin_num_col:  The column containing the spin number 
information.  If supplied, spin_id_col must be None.
+    @type spin_num_col:     int or None
+    @keyword data_col:      The column containing the RDC data in Hz.
+    @type data_col:         int or None
+    @keyword error_col:     The column containing the RDC errors.
+    @type error_col:        int or None
+    @keyword sep:           The column separator which, if None, defaults to 
whitespace.
+    @type sep:              str or None
+    """
+
+    # Data checks.
+    pipes.test()
+    check_mol_res_spin_data()
+
+    # Create a key for the global data (the pseudo-spectrum ID).
+    spectrum_id = "%s_%s" % (frq, disp_frq)
+    print("Using the pseudo-spectrum ID of '%s'." % spectrum_id)
+
+    # Loop over the data.
+    data_flag = False
+    for data in read_spin_data(file=file, dir=dir, spin_id_col=spin_id_col, 
mol_name_col=mol_name_col, res_num_col=res_num_col, 
res_name_col=res_name_col, spin_num_col=spin_num_col, 
spin_name_col=spin_name_col, data_col=data_col, error_col=error_col, sep=sep):
+        # Unpack.
+        if data_col and error_col:
+            mol_name, res_num, res_name, spin_num, spin_name, value, error = 
data
+        elif data_col:
+            mol_name, res_num, res_name, spin_num, spin_name, value = data
+            error = None
+        else:
+            mol_name, res_num, res_name, spin_num, spin_name, error = data
+            value = None
+
+        # Test the error value (cannot be 0.0).
+        if error == 0.0:
+            raise RelaxError("An invalid error value of zero has been 
encountered.")
+
+        # Get the corresponding spin container.
+        id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, 
res_name=res_name, spin_num=spin_num, spin_name=spin_name)
+        spin = return_spin(id)
+        if spin == None:
+            warn(RelaxNoSpinWarning(id))
+            continue
+
+        # The dispersion point key.
+        point_key = return_param_key_from_data(frq=frq, point=disp_frq)
+
+        # Store the R2eff data.
+        if data_col:
+            # Initialise if necessary.
+            if not hasattr(spin, 'r2eff'):
+                spin.r2eff = {}
+
+            # Store.
+            spin.r2eff[point_key] = value
+
+        # Store the R2eff error.
+        if error_col:
+            # Initialise if necessary.
+            if not hasattr(spin, 'r2eff_err'):
+                spin.r2eff_err = {}
+
+            # Store.
+            spin.r2eff_err[point_key] = error
+
+        # Data added.
+        data_flag = True
+
+    # Update the global structures.
+    if data_flag:
+        # Store the spectrum ID.
+        add_spectrum_id(spectrum_id)
+
+        # Set the spectrometer frequency information.
+        set_frequency(id=spectrum_id, frq=frq)
+
+        # Set the experiment type.
+        set_exp_type(spectrum_id=spectrum_id, exp_type=exp_type)
+
+        # Set the dispersion point frequency.
+        if exp_type in EXP_TYPE_LIST_CPMG:
+            cpmg_frq(spectrum_id=spectrum_id, cpmg_frq=disp_frq)
+        else:
+            spin_lock_field(spectrum_id=spectrum_id, field=disp_frq)
+
+
 def randomise_R1(spin=None, ri_id=None, N=None):
     """Randomise the R1 data for the given spin for use in the Monte Carlo 
simulations.
 

Modified: branches/relax_disp/user_functions/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/user_functions/relax_disp.py?rev=21304&r1=21303&r2=21304&view=diff
==============================================================================
--- branches/relax_disp/user_functions/relax_disp.py (original)
+++ branches/relax_disp/user_functions/relax_disp.py Tue Oct 29 12:13:02 2013
@@ -38,7 +38,7 @@
 from pipe_control.mol_res_spin import get_spin_ids
 from specific_analyses.relax_disp.catia import catia_execute, catia_input
 from specific_analyses.relax_disp.cpmgfit import cpmgfit_execute, 
cpmgfit_input
-from specific_analyses.relax_disp.disp_data import cpmg_frq, insignificance, 
plot_disp_curves, plot_exp_curves, relax_time, set_exp_type, spin_lock_field, 
spin_lock_offset
+from specific_analyses.relax_disp.disp_data import cpmg_frq, insignificance, 
plot_disp_curves, plot_exp_curves, r2eff_read, relax_time, set_exp_type, 
spin_lock_field, spin_lock_offset
 from specific_analyses.relax_disp.nessy import nessy_input
 from specific_analyses.relax_disp.parameters import copy
 from specific_analyses.relax_disp.sherekhan import sherekhan_input
@@ -516,6 +516,144 @@
 uf.gui_icon = "oxygen.actions.document-save"
 uf.wizard_size = (800, 600)
 uf.wizard_image = WIZARD_IMAGE_PATH + 'grace.png'
+
+
+# The relax_disp.r2eff_read user function.
+uf = uf_info.add_uf('relax_disp.r2eff_read')
+uf.title = "Read R2eff/R1rho values and errors from a file."
+uf.title_short = "R2eff/R1rho value reading."
+uf.add_keyarg(
+    name = "file",
+    py_type = "str",
+    arg_type = "file sel",
+    desc_short = "file name",
+    desc = "The name of the file.",
+    wiz_filesel_style = FD_SAVE
+)
+uf.add_keyarg(
+    name = "dir",
+    py_type = "str",
+    arg_type = "dir",
+    desc_short = "directory name",
+    desc = "The directory name.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "exp_type",
+    default = "CPMG",
+    py_type = "str",
+    desc_short = "experiment type",
+    desc = "The type of relaxation dispersion experiment performed.",
+    wiz_element_type = "combo",
+    wiz_combo_choices = [
+        "Single quantum (SQ) CPMG-type data",
+        "Zero quantum (ZQ) CPMG-type data",
+        "Double quantum (DQ) CPMG-type data",
+        "Multiple quantum (MQ) CPMG-type data",
+        "%s-type data" % r1rho
+    ],
+    wiz_combo_data = [
+        EXP_TYPE_CPMG,
+        EXP_TYPE_ZQ_CPMG,
+        EXP_TYPE_DQ_CPMG,
+        EXP_TYPE_MQ_CPMG,
+        EXP_TYPE_R1RHO
+    ],
+    wiz_read_only = True
+)
+uf.add_keyarg(
+    name = "frq",
+    py_type = "num",
+    desc_short = "spectrometer frequency",
+    desc = "The spectrometer frequency in Hertz.  See the 'sfrq' parameter 
in the Varian procpar file or the 'SFO1' parameter in the Bruker acqus file."
+)
+uf.add_keyarg(
+    name = "disp_frq",
+    py_type = "num",
+    desc_short = "CPMG frequency or spin-lock field strength (Hz)",
+    desc = "For CPMG-type data, the frequency of the CPMG pulse train.  For 
R1rho-type data, the spin-lock field strength nu1.  The units must be Hertz",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "spin_id_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "spin ID string column",
+    desc = "The spin ID string column used by the generic file format (an 
alternative to the mol, res, and spin name and number columns).",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "mol_name_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "molecule name column",
+    desc = "The molecule name column used by the generic file format 
(alternative to the spin ID column).",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "res_num_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "residue number column",
+    desc = "The residue number column used by the generic file format 
(alternative to the spin ID column).",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "res_name_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "residue name column",
+    desc = "The residue name column used by the generic file format 
(alternative to the spin ID column).",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "spin_num_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "spin number column",
+    desc = "The spin number column used by the generic file format 
(alternative to the spin ID column).",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "spin_name_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "spin name column",
+    desc = "The spin name column used by the generic file format 
(alternative to the spin ID column).",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "data_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "data column",
+    desc = "The RDC data column.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "error_col",
+    py_type = "int",
+    arg_type = "free format",
+    desc_short = "error column",
+    desc = "The experimental error column.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "sep",
+    py_type = "str",
+    arg_type = "free format",
+    desc_short = "column separator",
+    desc = "The column separator used by the generic format (the default is 
white space).",
+    can_be_none = True
+)
+# Description.
+uf.desc.append(Desc_container())
+uf.desc[-1].add_paragraph("This will read R2eff/R1rho data directly from a 
file.  The format of this text file must be that each row corresponds to a 
unique spin system and that there is one file per dispersion point (i.e. per 
CPMG frequency nu_CPMG or per spin-lock field strength n1).  The file must be 
in columnar format and information to identify the spin must be in columns of 
the file.")
+uf.backend = r2eff_read
+uf.menu_text = "&r2eff_read"
+uf.gui_icon = "oxygen.actions.document-open"
+uf.wizard_size = (900, 600)
+uf.wizard_image = ANALYSIS_IMAGE_PATH + 'relax_disp_200x200.png'
 
 
 # The relax_disp.relax_time user function.




Related Messages


Powered by MHonArc, Updated Tue Oct 29 12:40:01 2013