mailr14810 - in /1.3: generic_fns/rdc.py prompt/rdc.py


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

Header


Content

Posted by edward on October 08, 2011 - 17:28:
Author: bugman
Date: Sat Oct  8 17:28:22 2011
New Revision: 14810

URL: http://svn.gna.org/viewcvs/relax?rev=14810&view=rev
Log:
Added the ability to specify J+D verses J+2D measured RDCs.

This is to make it easier for the user so that data conversion by dividing by 
2 is not needed prior
to loading into relax.


Modified:
    1.3/generic_fns/rdc.py
    1.3/prompt/rdc.py

Modified: 1.3/generic_fns/rdc.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/rdc.py?rev=14810&r1=14809&r2=14810&view=diff
==============================================================================
--- 1.3/generic_fns/rdc.py (original)
+++ 1.3/generic_fns/rdc.py Sat Oct  8 17:28:22 2011
@@ -115,6 +115,38 @@
             spin.rdc_bc[id] = ave_rdc_tensor(dj, unit_vect, cdp.N, 
cdp.align_tensors[get_tensor_index(id)].A, weights=weights)
 
 
+def convert(value, align_id, to_intern=False):
+    """Convert the RDC based on the 'D' or '2D' data type.
+
+    @param value:           The value or error to convert.
+    @type value:            float or None
+    @param align_id:        The alignment tensor ID string.
+    @type align_id:         str
+    @keyword to_intern:     A flag which if True will convert to the 
internal 2D notation if needed, or if False will convert from the internal 2D 
notation to the external D or 2D format.
+    @type to_intern:        bool
+    @return:                The converted value.
+    @rtype:                 float or None
+    """
+
+    # Handle values of None.
+    if value == None:
+        return None
+
+    # The conversion factor.
+    factor = 1.0
+    if hasattr(cdp, 'rdc_data_types') and 
cdp.rdc_data_types.has_key(align_id) and cdp.rdc_data_types[align_id] == 'D':
+        # Convert from D to 2D.
+        if to_intern:
+            factor = 0.5
+
+        # Convert from 2D to D.
+        else:
+            factor = 2.0
+
+    # Return the converted value.
+    return value * factor
+
+
 def corr_plot(format=None, file=None, dir=None, force=False):
     """Generate a correlation plot of the measured vs. back-calculated RDCs.
 
@@ -177,12 +209,12 @@
                 continue
 
             # Append the data.
-            data[-1].append([spin.rdc_bc[align_id], spin.rdc[align_id]])
+            data[-1].append([convert(spin.rdc_bc[align_id], align_id), 
convert(spin.rdc[align_id], align_id)])
 
             # Errors.
             if err_flag:
                 if hasattr(spin, 'rdc_err') and align_id in 
spin.rdc_err.keys():
-                    data[-1][-1].append(spin.rdc_err[align_id])
+                    data[-1][-1].append(convert(spin.rdc_err[align_id], 
align_id))
                 else:
                     data[-1][-1].append(None)
 
@@ -326,7 +358,7 @@
     cdp.q_rdc_norm2 = sqrt(cdp.q_rdc_norm2 / len(cdp.q_factors_rdc_norm2))
 
 
-def read(align_id=None, 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, neg_g_corr=False):
+def read(align_id=None, file=None, dir=None, file_data=None, data_type='2D', 
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, neg_g_corr=False):
     """Read the RDC data from file.
 
     @keyword align_id:      The alignment tensor ID string.
@@ -337,6 +369,7 @@
     @type dir:              str or None
     @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 data_type:     A string which is set to '2D' means that the 
splitting in the aligned sample was assumed to be J + 2D, or if set to 'D' 
then the splitting was taken as J + D.
     @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.
@@ -372,6 +405,11 @@
     if data_col == None and error_col == None:
         raise RelaxError("One of either the data or error column must be 
supplied.")
 
+    # Store the data type as global data (need for the conversion of spin 
data).
+    if not hasattr(cdp, 'rdc_data_types'):
+        cdp.rdc_data_types = {}
+    if not cdp.rdc_data_types.has_key(align_id):
+        cdp.rdc_data_types[align_id] = data_type
 
     # Spin specific data.
     #####################
@@ -407,6 +445,9 @@
             if not hasattr(spin, 'rdc'):
                 spin.rdc = {}
 
+            # Data conversion.
+            value = convert(value, align_id, to_intern=True)
+
             # Correction for the negative gyromagnetic ratio of 15N.
             if neg_g_corr and value != None:
                 value = -value
@@ -419,6 +460,9 @@
             # Initialise.
             if not hasattr(spin, 'rdc_err'):
                 spin.rdc_err = {}
+
+            # Data conversion.
+            value = convert(value, align_id, to_intern=True)
 
             # Append the error.
             spin.rdc_err[align_id] = error
@@ -520,11 +564,15 @@
         if not hasattr(spin, 'rdc') or align_id not in spin.rdc.keys():
             continue
 
-        # Store the data.
+        # Store the spin ID.
         spin_ids.append(spin_id)
-        values.append(spin.rdc[align_id])
+
+        # The value.
+        values.append(convert(spin.rdc[align_id], align_id))
+
+        # The error.
         if hasattr(spin, 'rdc_err') and align_id in spin.rdc_err.keys():
-            errors.append(spin.rdc_err[align_id])
+            errors.append(convert(spin.rdc_err[align_id], align_id))
         else:
             errors.append(None)
 

Modified: 1.3/prompt/rdc.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/rdc.py?rev=14810&r1=14809&r2=14810&view=diff
==============================================================================
--- 1.3/prompt/rdc.py (original)
+++ 1.3/prompt/rdc.py Sat Oct  8 17:28:22 2011
@@ -267,7 +267,7 @@
         rdc.display(align_id=align_id)
 
 
-    def read(self, align_id=None, 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, 
neg_g_corr=False):
+    def read(self, align_id=None, file=None, dir=None, data_type='2D', 
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, neg_g_corr=False):
         """Read the RDC data from file.
 
         Keyword Arguments
@@ -278,6 +278,8 @@
         file:  The name of the file containing the RDC data.
 
         dir:  The directory where the file is located.
+
+        data_type:  Whether the RDC data is in the 2D or D format.
 
         spin_id_col:  The spin ID string column (an alternative to the mol, 
res, and spin name and
             number columns).
@@ -305,6 +307,19 @@
         
         Description
         ~~~~~~~~~~~
+
+        The data_type argument is used to specify how the RDC is defined.  
It is a string which can
+        be set to two values:
+        
+            - '2D' means that the splitting in the aligned sample was 
assumed to be J + 2D.
+            - 'D' means that the splitting in the aligned sample was taken 
as J + D.
+
+        Internally, relax uses the 2D notation.  Therefore if set to 'D', 
the values will be halved
+        when read in.
+
+        If neg_g_corr is set to True, a sign inversion will be applied to 
all RDC values to be
+        loaded.  This is sometimes needed for 15N if the data is not 
compensated for the negative
+        gyromagnetic ratio.
 
         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
@@ -314,24 +329,21 @@
         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.
 
-        If neg_g_corr is set to True, a sign inversion will be applied to 
all RDC values to be
-        loaded.
-
 
         Examples
         ~~~~~~~~
 
         The following commands will read the RDC data out of the file 
'Tb.txt' where the columns are
-        separated by the symbol ',', and store the RDCs under the ID 'Tb'.
+        separated by the symbol ',', and store the RDCs under the ID 'Tb':
 
         relax> rdc.read('Tb', 'Tb.txt', sep=',')
 
 
         If the individual spin RDC errors are located in the file 
'rdc_err.txt' in column number 5,
-        then to read these values into relax, type one of:
-
-        relax> rdc.read('phage', 'rdc_err.txt', error_col=5)
-        relax> rdc.read(align_id='phage', file='rdc_err.txt', error_col=5)
+        then to read these values into relax, assuming J + D was measured, 
type one of:
+
+        relax> rdc.read('phage', 'rdc_err.txt', data_type='D', error_col=5)
+        relax> rdc.read(align_id='phage', file='rdc_err.txt', data_type='D', 
error_col=5)
 
 
         If the RDCs correspond to the 'N' spin and other spin types such as 
1H, 13C, etc. are loaded
@@ -346,6 +358,7 @@
             text = text + "align_id=" + repr(align_id)
             text = text + ", file=" + repr(file)
             text = text + ", dir=" + repr(dir)
+            text = text + ", data_type=" + repr(data_type)
             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)
@@ -363,6 +376,7 @@
         arg_check.is_str(align_id, 'alignment ID string')
         arg_check.is_str(file, 'file name')
         arg_check.is_str(dir, 'directory name', can_be_none=True)
+        arg_check.is_str(data_type, 'data type')
         arg_check.is_int(spin_id_col, 'spin ID string column', 
can_be_none=True)
         arg_check.is_int(mol_name_col, 'molecule name column', 
can_be_none=True)
         arg_check.is_int(res_num_col, 'residue number column', 
can_be_none=True)
@@ -376,7 +390,7 @@
         arg_check.is_bool(neg_g_corr, 'negative gyromagnetic ratio 
correction')
 
         # Execute the functional code.
-        rdc.read(align_id=align_id, 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, neg_g_corr=neg_g_corr)
+        rdc.read(align_id=align_id, file=file, dir=dir, data_type=data_type, 
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, neg_g_corr=neg_g_corr)
 
 
     def weight(self, align_id=None, spin_id=None, weight=1.0):




Related Messages


Powered by MHonArc, Updated Sat Oct 08 19:00:02 2011