mailr19163 - in /trunk: lib/software/__init__.py lib/software/bruker_dc.py pipe_control/bruker.py


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

Header


Content

Posted by edward on March 26, 2013 - 15:56:
Author: bugman
Date: Tue Mar 26 15:56:04 2013
New Revision: 19163

URL: http://svn.gna.org/viewcvs/relax?rev=19163&view=rev
Log:
Shifted the Bruker Dynamics Centre parsing code into the new 
lib.software.bruker_dc module.


Added:
    trunk/lib/software/bruker_dc.py
      - copied, changed from r19158, trunk/pipe_control/bruker.py
Modified:
    trunk/lib/software/__init__.py
    trunk/pipe_control/bruker.py

Modified: trunk/lib/software/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/software/__init__.py?rev=19163&r1=19162&r2=19163&view=diff
==============================================================================
--- trunk/lib/software/__init__.py (original)
+++ trunk/lib/software/__init__.py Tue Mar 26 15:56:04 2013
@@ -23,6 +23,7 @@
 """The relax-lib NMR package - a library of functions for creating input, 
reading output and control of external software."""
 
 __all__ = [
+    'bruker_dc',
     'grace',
     'opendx',
     'xplor'

Copied: trunk/lib/software/bruker_dc.py (from r19158, 
trunk/pipe_control/bruker.py)
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/software/bruker_dc.py?p2=trunk/lib/software/bruker_dc.py&p1=trunk/pipe_control/bruker.py&r1=19158&r2=19163&rev=19163&view=diff
==============================================================================
--- trunk/pipe_control/bruker.py (original)
+++ trunk/lib/software/bruker_dc.py Tue Mar 26 15:56:04 2013
@@ -26,11 +26,6 @@
 from re import search, split
 
 # relax module imports.
-from pipe_control import pipes
-from pipe_control import value
-from pipe_control.exp_info import software_select
-from pipe_control.mol_res_spin import exists_mol_res_spin_data, name_spin, 
set_spin_isotope, spin_loop
-from pipe_control.relax_data import pack_data, peak_intensity_type
 from lib.errors import RelaxError, RelaxNoSequenceError
 from lib.io import open_read_file
 from lib.physical_constants import element_from_isotope
@@ -80,23 +75,16 @@
     return ":%s" % res_num
 
 
-def read(ri_id=None, file=None, dir=None):
-    """Read the DC data file and place all the data into the relax data 
store.
+def parse_file(file=None, dir=None):
+    """Parse the DC data file and return the extracted data.
 
-    @keyword ri_id: The relaxation data ID string.
-    @type ri_id:    str
     @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
+    @return:        The data from the Bruker Dynamics Centre file.  This 
includes the values, the errors, the residue numbers, the integration type, 
the field strength frequency, the relaxation data type, the isotope, the spin 
name, and the BDC version number.
+    @rtype:         list of float, list of float, list of int, str, float, 
str, str, str, str
     """
-
-    # Test if the current pipe exists.
-    pipes.test()
-
-    # Test if sequence data is loaded.
-    if not exists_mol_res_spin_data():
-        raise RelaxNoSequenceError
 
     # Extract the data from the file.
     file_handle = open_read_file(file, dir)
@@ -108,6 +96,8 @@
     errors = []
     res_nums = []
     int_type = None
+    isotope = None
+    spin_name = None
 
     # Loop over the data.
     in_ri_data = False
@@ -192,12 +182,8 @@
             # Store the isotope for later use.
             isotope = row[1]
 
-            # Set the isotope value.
-            set_spin_isotope(isotope=isotope, force=None)
-
             # Name the spins.
-            name = split('([A-Z]+)', row[1])[1]
-            name_spin(name=name, force=None)
+            spin_name = split('([A-Z]+)', row[1])[1]
 
         # The integration method.
         elif row[0] == 'Used integrals:':
@@ -209,16 +195,5 @@
             if row[1] == 'area integral':
                 int_type = 'volume'
 
-    # Modify the residue numbers by adding the heteronucleus name.
-    atom_name = element_from_isotope(isotope)
-    for i in range(len(res_nums)):
-        res_nums[i] += '@' + atom_name
-
-    # Pack the data.
-    pack_data(ri_id, ri_type, frq, values, errors, spin_ids=res_nums)
-
-    # Set the integration method.
-    peak_intensity_type(ri_id=ri_id, type=int_type)
-
-    # Set the DC as used software.
-    software_select('Bruker DC', version=version)
+    # Return the data.
+    return values, errors, res_nums, int_type, frq, ri_type, spin_name, 
isotope, version

Modified: trunk/pipe_control/bruker.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/bruker.py?rev=19163&r1=19162&r2=19163&view=diff
==============================================================================
--- trunk/pipe_control/bruker.py (original)
+++ trunk/pipe_control/bruker.py Tue Mar 26 15:56:04 2013
@@ -34,50 +34,7 @@
 from lib.errors import RelaxError, RelaxNoSequenceError
 from lib.io import open_read_file
 from lib.physical_constants import element_from_isotope
-
-
-def convert_relax_data(data):
-    """Determine the relaxation data from the given DC data.
-
-    @param data:    The list of Tx, Tx error, and scaling factor for a given 
residue from the DC file.
-    @type data:     list of str
-    """
-
-    # Convert the value from Tx to Rx.
-    rx = 1.0 / float(data[0])
-
-    # Remove the scaling.
-    rx_err = float(data[1]) / float(data[2])
-
-    # Convert the Tx error to an Rx error.
-    rx_err = rx**2 * rx_err
-
-    # Return the value and error.
-    return rx, rx_err
-
-
-def get_res_num(data):
-    """Determine the residue number from the given DC data.
-
-    @param data:    The list of residue info, split by whitespace, from the 
DC file.
-    @type data:     list of str
-    """
-
-    # Init.
-    res_num = None
-
-    # Split the data.
-    row = split('([0-9]+)', data)
-
-    # Loop over the new list.
-    for j in range(len(row)):
-        try:
-            res_num = int(row[j])
-        except ValueError:
-            pass
-
-    # Return the value.
-    return ":%s" % res_num
+from lib.software.bruker_dc import convert_relax_data, get_res_num, 
parse_file
 
 
 def read(ri_id=None, file=None, dir=None):
@@ -99,120 +56,17 @@
         raise RelaxNoSequenceError
 
     # Extract the data from the file.
-    file_handle = open_read_file(file, dir)
-    lines = file_handle.readlines()
-    file_handle.close()
+    values, errors, res_nums, int_type, frq, ri_type, spin_name, isotope, 
version = parse_file(file=file, dir=dir)
 
-    # Init.
-    values = []
-    errors = []
-    res_nums = []
-    int_type = None
-
-    # Loop over the data.
-    in_ri_data = False
-    for line in lines:
-        # Split the line.
-        row = split("\t", line)
-
-        # Strip the rubbish.
-        for j in range(len(row)):
-            row[j] = row[j].strip()
-
-        # Empty line.
-        if len(row) == 0:
-            continue
-
-        # The DC version.
-        if row[0] == 'generated by:':
-            version = row[1]
-
-        # Check for bad errors.
-        if row[0] == 'Systematic error estimation of data:':
-            # Badness.
-            if row[1] == 'worst case per peak scenario':
-                raise RelaxError("The errors estimation method \"worst case 
per peak scenario\" is not suitable for model-free analysis.  Please go back 
to the DC and switch to \"average variance calculation\".")
-
-        # The data type.
-        if row[0] == 'Project:':
-            if search('T1', row[1]):
-                ri_type = 'R1'
-            elif search('T2', row[1]):
-                ri_type = 'R2'
-            elif search('NOE', row[1]):
-                ri_type = 'NOE'
-
-        # Get the frequency, converting to Hz.
-        elif row[0] == 'Proton frequency[MHz]:':
-            frq = float(row[1]) * 1e6
-
-        # Inside the relaxation data section.
-        elif row[0] == 'SECTION:' and row[1] == 'results':
-            in_ri_data = True
-
-        # The relaxation data.
-        elif in_ri_data:
-            # Skip the header.
-            if row[0] == 'Peak name':
-                # Catch old PDC files (to fix https://gna.org/bugs/?20152).
-                pdc_file = False
-                if ri_type == 'R1' and not search('R1', line):
-                    pdc_file = True
-                elif ri_type == 'R2' and not search('R2', line):
-                    pdc_file = True
-                if pdc_file:
-                    raise RelaxError("The old Protein Dynamics Center (PDC) 
files are not supported")
-
-                # Skip.
-                continue
-
-            # The residue info.
-            res_nums.append(get_res_num(row[0]))
-
-            # Get the relaxation data.
-            if ri_type != 'NOE':
-                #rx, rx_err = convert_relax_data(row[3:])
-                rx = float(row[-2])
-                rx_err = float(row[-1])
-            else:
-                rx = float(row[-3])
-                rx_err = float(row[-2])
-
-            # Append the data.
-            values.append(rx)
-            errors.append(rx_err)
-
-        # The temperature.
-        elif row[0] == 'Temperature (K):':
-            # Set the value (not implemented yet).
-            pass
-
-        # The labelling.
-        elif row[0] == 'Labelling:':
-            # Store the isotope for later use.
-            isotope = row[1]
-
-            # Set the isotope value.
-            set_spin_isotope(isotope=isotope, force=None)
-
-            # Name the spins.
-            name = split('([A-Z]+)', row[1])[1]
-            name_spin(name=name, force=None)
-
-        # The integration method.
-        elif row[0] == 'Used integrals:':
-            # Peak heights.
-            if row[1] == 'peak intensities':
-                int_type = 'height'
-
-            # Peak volumes:
-            if row[1] == 'area integral':
-                int_type = 'volume'
+    # Name the spins if needed.
+    print "name spin " + `spin_name`
+    name_spin(name=spin_name, force=False)
 
     # Modify the residue numbers by adding the heteronucleus name.
-    atom_name = element_from_isotope(isotope)
-    for i in range(len(res_nums)):
-        res_nums[i] += '@' + atom_name
+    if isotope:
+        atom_name = element_from_isotope(isotope)
+        for i in range(len(res_nums)):
+            res_nums[i] += '@' + atom_name
 
     # Pack the data.
     pack_data(ri_id, ri_type, frq, values, errors, spin_ids=res_nums)




Related Messages


Powered by MHonArc, Updated Tue Mar 26 18:40:02 2013