mailr9578 - in /1.3: generic_fns/dasha.py generic_fns/value.py prompt/value.py


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

Header


Content

Posted by edward on October 06, 2009 - 13:01:
Author: bugman
Date: Tue Oct  6 13:01:06 2009
New Revision: 9578

URL: http://svn.gna.org/viewcvs/relax?rev=9578&view=rev
Log:
Converted value.read() to use the new relax_io.read_spin_data_file() function.

This converts the user function to the 1.3 line design as well.


Modified:
    1.3/generic_fns/dasha.py
    1.3/generic_fns/value.py
    1.3/prompt/value.py

Modified: 1.3/generic_fns/dasha.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/dasha.py?rev=9578&r1=9577&r2=9578&view=diff
==============================================================================
--- 1.3/generic_fns/dasha.py (original)
+++ 1.3/generic_fns/dasha.py Tue Oct  6 13:01:06 2009
@@ -492,7 +492,7 @@
             scaling = 1.0
 
         # Set the values.
-        value.read(param=param, scaling=scaling, file=file_name, 
res_num_col=0, res_name_col=None, data_col=1, error_col=2)
+        value.read(param=param, scaling=scaling, file=file_name, 
res_num_col=1, res_name_col=None, data_col=2, error_col=3)
 
         # Clean up of non-existant parameters (set the parameter to None!).
         for spin in spin_loop():
@@ -515,4 +515,4 @@
         raise RelaxFileError('Dasha', file_name)
 
     # Set the values.
-    value.read(param='chi2', file=file_name, res_num_col=0, 
res_name_col=None, data_col=1, error_col=2)
+    value.read(param='chi2', file=file_name, res_num_col=1, 
res_name_col=None, data_col=2, error_col=3)

Modified: 1.3/generic_fns/value.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/value.py?rev=9578&r1=9577&r2=9578&view=diff
==============================================================================
--- 1.3/generic_fns/value.py (original)
+++ 1.3/generic_fns/value.py Tue Oct  6 13:01:06 2009
@@ -31,7 +31,7 @@
 from generic_fns import minimise, pipes
 from generic_fns.mol_res_spin import exists_mol_res_spin_data, 
generate_spin_id_data_array, return_spin, spin_loop
 from generic_fns.sequence import write_header, write_line
-from relax_errors import RelaxError, RelaxFileEmptyError, 
RelaxNoSequenceError, RelaxNoSpinError, RelaxParamSetError, RelaxValueError
+from relax_errors import RelaxError, RelaxNoSequenceError, RelaxNoSpinError, 
RelaxParamSetError, RelaxValueError
 from relax_io import extract_data, open_write_file, strip
 import specific_fns
 
@@ -191,7 +191,7 @@
     return spin_params, spin_values, other_params, other_values
 
 
-def read(param=None, scaling=1.0, file=None, dir=None, mol_name_col=None, 
res_num_col=0, res_name_col=1, spin_num_col=None, spin_name_col=None, 
data_col=2, error_col=3, sep=None):
+def read(param=None, scaling=1.0, file=None, dir=None, file_data=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, spin_id=None):
     """Read spin specific data values from a file.
 
     @keyword param:         The name of the parameter to read.
@@ -203,22 +203,37 @@
     @keyword dir:           The directory containing the file (defaults to 
the current directory if
                             None).
     @type dir:              str or None
-    @keyword mol_name_col:  The column containing the molecule name 
information.
+    @keyword file_data:     An alternative to opening a file, if the data 
already exists in the
+                            correct format.  The format is a list of lists 
where the first index
+                            corresponds to the row and the second the column.
+    @type file_data:        list of lists
+    @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.
+    @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.
+    @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.
+    @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.
+    @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 values.
-    @type data_col:         int
-    @keyword error_col:     The column containing the errors.
+    @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
+    @keyword spin_id:       The spin ID string.
+    @type spin_id:          None or str
     """
 
     # Test if the current pipe exists.
@@ -263,77 +278,18 @@
         if value != None or error != None:
             raise RelaxValueError(param)
 
-    # Extract the data from the file.
-    file_data = extract_data(file, dir=dir, sep=sep)
-
-    # Count the number of header lines.
-    header_lines = 0
-    num_col = max(res_num_col, spin_num_col)
-    for i in xrange(len(file_data)):
-        try:
-            int(file_data[i][num_col])
-        except:
-            header_lines = header_lines + 1
+    # Loop over the data.
+    for data in read_spin_data_file(file=file, dir=dir, file_data=file_data, 
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, 
spin_id=spin_id):
+        # Unpack.
+        if data_col and error_col:
+            id, value, error = data
+        elif data_col:
+            id, value = data
         else:
-            break
-
-    # Remove the header.
-    file_data = file_data[header_lines:]
-
-    # Strip the data.
-    file_data = strip(file_data)
-
-    # Do nothing if the file does not exist.
-    if not file_data:
-        raise RelaxFileEmptyError
-
-    # Minimum number of columns.
-    min_col_num = max(mol_name_col, res_num_col, res_name_col, spin_num_col, 
spin_name_col, data_col, error_col)
-
-    # Test the validity of the data.
-    for i in xrange(len(file_data)):
-        # Skip missing data.
-        if len(file_data[i]) <= min_col_num:
-            continue
-
-        try:
-            # Value column.
-            if file_data[i][data_col] != 'None':
-                float(file_data[i][data_col])
-
-            # Error column.
-            if error_col != None and file_data[i][error_col] != 'None':
-                float(file_data[i][error_col])
-
-        except ValueError:
-            if error_col != None:
-                raise RelaxError("The data is invalid (data=" + 
file_data[i][data_col] + ", error=" + file_data[i][error_col] + ").")
-            else:
-                raise RelaxError("The data is invalid (data=" + 
file_data[i][data_col] + ").")
-
-    # Loop over the data.
-    for i in xrange(len(file_data)):
-        # Skip missing data.
-        if len(file_data[i]) <= min_col_num:
-            continue
-
-        # Generate the spin identification string.
-        id = generate_spin_id_data_array(data=file_data[i], 
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)
-
-        # Value.
-        if file_data[i][data_col] != 'None':
-            value = float(file_data[i][data_col])
-        else:
-            value = None
-
-        # Error.
-        if error_col != None and file_data[i][error_col] != 'None':
-            error = float(file_data[i][error_col])
-        else:
-            error = None
+            id, error = data
 
         # Get the corresponding spin container.
-        spin = return_spin(id)
+        spin = return_spin([id, spin_id])
         if spin == None:
             raise RelaxNoSpinError(id)
 

Modified: 1.3/prompt/value.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/value.py?rev=9578&r1=9577&r2=9578&view=diff
==============================================================================
--- 1.3/prompt/value.py (original)
+++ 1.3/prompt/value.py Tue Oct  6 13:01:06 2009
@@ -128,7 +128,7 @@
         self.__relax__.generic.value.display(param=param)
 
 
-    def read(self, param=None, scaling=1.0, file=None, num_col=0, 
name_col=1, data_col=2, error_col=3, sep=None):
+    def read(self, param=None, scaling=1.0, file=None, dir=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, spin_id=None):
         """Read spin specific data values from a file.
 
         Keyword Arguments
@@ -138,40 +138,60 @@
 
         scaling:  The factor to scale parameters by.
 
-        file:  The name of the file containing the relaxation data.
-
-        num_col:  The residue number column (the default is 0, ie the first 
column).
-
-        name_col:  The residue name column (the default is 1).
-
-        data_col:  The relaxation data column (the default is 2).
-
-        error_col:  The experimental error column (the default is 3).
+        file:  The name of the file containing the values.
+
+        dir:  The directory where the file is located.
+
+        spin_id_col:  The spin ID string column (an alternative to the mol, 
res, and spin name and
+            number columns).
+
+        mol_name_col:  The molecule name column (alternative to the 
spid_id_col).
+
+        res_num_col:  The residue number column (alternative to the 
spid_id_col).
+
+        res_name_col:  The residue name column (alternative to the 
spid_id_col).
+
+        spin_num_col:  The spin number column (alternative to the 
spid_id_col).
+
+        spin_name_col:  The spin name column (alternative to the 
spid_id_col).
+
+        data_col:  The RDC data column.
+
+        error_col:  The experimental error column.
 
         sep:  The column separator (the default is white space).
+
+        spin_id:  The spin ID string to restrict the loading of data to 
certain spin subsets.
 
 
         Description
         ~~~~~~~~~~~
 
-        Only one parameter may be selected, therefore the 'param' argument 
should be a string.  If
-        the file only contains values and no errors, set the error column 
argument to None.
+        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 mol_name_col, 
res_num_col, res_name_col,
+        spin_num_col, and/or spin_name_col arguments can be supplied 
allowing this information to be
+        in separate columns.  Note that the numbering of columns starts at 
one.  The spin_id
+        argument can be used to restrict the reading to certain spin types, 
for example only 15N
+        spins when only residue information is in the file.
+
+        Only one parameter may be selected, therefore the 'param' argument 
should be a string.
 
         If this function 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 to None.
+        and Hessian count) will be reset.
 
 
         Examples
         ~~~~~~~~
 
-        To load CSA values from the file 'csa_values' in the directory 
'data', type one of the
-        following:
-
-        relax> value.read('CSA', 'data/csa_value')
-        relax> value.read('CSA', 'data/csa_value', 0, 1, 2, 3, None, 1)
-        relax> value.read(param='CSA', file='data/csa_value', num_col=0, 
name_col=1,
-                          data_col=2, error_col=3, sep=None)
+        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:
+
+        relax> value.read('CSA', 'data/csa_value', spin_id='@N')
+        relax> value.read('CSA', 'csa_value', dir='data', spin_id='@N')
+        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')
         """
 
         # Function intro text.
@@ -180,25 +200,37 @@
             text = text + "param=" + repr(param)
             text = text + ", scaling=" + repr(scaling)
             text = text + ", file=" + repr(file)
-            text = text + ", num_col=" + repr(num_col)
-            text = text + ", name_col=" + repr(name_col)
+            text = text + ", dir=" + repr(dir)
+            text = text + ", spin_id_col=" + repr(spin_id_col)
+            text = text + ", mol_name_col=" + repr(mol_name_col)
+            text = text + ", res_num_col=" + repr(res_num_col)
+            text = text + ", res_name_col=" + repr(res_name_col)
+            text = text + ", spin_num_col=" + repr(spin_num_col)
+            text = text + ", spin_name_col=" + repr(spin_name_col)
             text = text + ", data_col=" + repr(data_col)
             text = text + ", error_col=" + repr(error_col)
-            text = text + ", sep=" + repr(sep) + ")"
+            text = text + ", sep=" + repr(sep)
+            text = text + ", spin_id=" + repr(spin_id) + ")"
             print(text)
 
         # The argument checks.
         check.is_str(param, 'parameter')
         check.is_float(scaling, 'scaling')
         check.is_str(file, 'file name')
-        check.is_int(num_col, 'residue number column')
-        check.is_int(name_col, 'residue name column')
-        check.is_int(data_col, 'data column')
-        check.is_int(error_col, 'residue name column', can_be_none=True)
+        check.is_str(dir, 'directory name', can_be_none=True)
+        check.is_int(spin_id_col, 'spin ID string column', can_be_none=True)
+        check.is_int(mol_name_col, 'molecule name column', can_be_none=True)
+        check.is_int(res_num_col, 'residue number column', can_be_none=True)
+        check.is_int(res_name_col, 'residue name column', can_be_none=True)
+        check.is_int(spin_num_col, 'spin number column', can_be_none=True)
+        check.is_int(spin_name_col, 'spin name column', can_be_none=True)
+        check.is_int(data_col, 'data column', can_be_none=True)
+        check.is_int(error_col, 'error column', can_be_none=True)
         check.is_str(sep, 'column separator', can_be_none=True)
+        check.is_str(spin_id, 'spin ID string', can_be_none=True)
 
         # Execute the functional code.
-        self.__relax__.generic.value.read(param=param, scaling=scaling, 
file=file, num_col=num_col, name_col=name_col, data_col=data_col, 
error_col=error_col, sep=sep)
+        self.__relax__.generic.value.read(param=param, scaling=scaling, 
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, spin_id=spin_id)
 
 
     def set(self, val=None, param=None, spin_id=None):




Related Messages


Powered by MHonArc, Updated Tue Oct 06 14:00:02 2009