mailr20657 - in /trunk: pipe_control/ user_functions/


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

Header


Content

Posted by edward on August 21, 2013 - 11:43:
Author: bugman
Date: Wed Aug 21 11:43:00 2013
New Revision: 20657

URL: http://svn.gna.org/viewcvs/relax?rev=20657&view=rev
Log:
Created the chemical_shift.read user function.

This includes both the front and back end code.


Added:
    trunk/pipe_control/chemical_shift.py
    trunk/user_functions/chemical_shift.py
Modified:
    trunk/pipe_control/__init__.py
    trunk/user_functions/__init__.py

Modified: trunk/pipe_control/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/__init__.py?rev=20657&r1=20656&r2=20657&view=diff
==============================================================================
--- trunk/pipe_control/__init__.py (original)
+++ trunk/pipe_control/__init__.py Wed Aug 21 11:43:00 2013
@@ -27,6 +27,7 @@
             'angles',
             'bmrb',
             'bruker',
+            'chemical_shift',
             'dasha',
             'diffusion_tensor',
             'domain',

Added: trunk/pipe_control/chemical_shift.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/pipe_control/chemical_shift.py?rev=20657&view=auto
==============================================================================
--- trunk/pipe_control/chemical_shift.py (added)
+++ trunk/pipe_control/chemical_shift.py Wed Aug 21 11:43:00 2013
@@ -1,0 +1,116 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2013 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax (http://www.nmr-relax.com).         
 #
+#                                                                            
 #
+# This program is free software: you can redistribute it and/or modify       
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation, either version 3 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# This program is distributed in the hope that it will be useful,            
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.      
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""Module containing functions for the handling of chemical shifts."""
+
+
+# Python module imports.
+from warnings import warn
+
+# relax module imports.
+from lib.errors import RelaxError, RelaxNoSequenceError
+from lib.spectrum.peak_list import read_peak_list
+from lib.warnings import RelaxNoSpinWarning
+from pipe_control import pipes
+from pipe_control.mol_res_spin import exists_mol_res_spin_data, 
generate_spin_id_unique, return_spin
+
+
+def read(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, 
sep=None, spin_id=None, verbose=True):
+    """Read the peak intensity data.
+
+    @keyword file:          The name of the file containing the peak 
intensities.
+    @type file:             str
+    @keyword dir:           The directory where the file is located.
+    @type dir:              str
+    @keyword spin_id_col:   The column containing the spin ID strings (used 
by the generic intensity file format).  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 (used by the generic intensity file format).  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 (used by the generic intensity file format).  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 (used by the generic intensity file format).  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 
(used by the generic intensity file format).  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 (used by the generic intensity file format).  If supplied, 
spin_id_col must be None.
+    @type spin_num_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 used to restrict data loading 
to a subset of all spins.  If 'auto' is provided for a NMRPipe seriesTab 
formatted file, the ID's are auto generated in form of Z_Ai.
+    @type spin_id:          None or str
+    @keyword verbose:       A flag which if True will cause all chemical 
shift data loaded to be printed out.
+    @type verbose:          bool
+    """
+
+    # Test if the current data pipe exists.
+    pipes.test()
+
+    # Test if sequence data is loaded.
+    if not exists_mol_res_spin_data():
+        raise RelaxNoSequenceError
+
+    # Check the file name.
+    if file == None:
+        raise RelaxError("The file name must be supplied.")
+
+    # Read the peak list data.
+    peak_list = read_peak_list(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, sep=sep, spin_id=spin_id)
+
+    # Loop over the assignments.
+    data = []
+    data_flag = False
+    dim = peak_list._dim
+    for assign in peak_list:
+        # Loop over the dimensions of the peak list.
+        for i in range(dim):
+            # Generate the spin_id.
+            spin_id = generate_spin_id_unique(res_num=assign.res_nums[i], 
spin_name=assign.spin_names[i])
+
+            # Get the spin container.
+            spin = return_spin(spin_id)
+            if not spin:
+                warn(RelaxNoSpinWarning(spin_id))
+                continue
+
+            # Skip deselected spins.
+            if not spin.select:
+                continue
+
+            # Store the shift.
+            spin.chemical_shift = assign.shifts[i]
+
+            # Switch the flag.
+            data_flag = True
+
+            # Append the data for printing out.
+            data.append([spin_id, repr(spin.chemical_shift)])
+
+    # No data.
+    if not data_flag:
+        raise RelaxError("No chemical shifts could be loaded from the peak 
list")
+
+    # Print out.
+    if verbose:
+        print("\nThe following chemical shifts have been loaded into the 
relax data store:\n")
+        write_data(out=sys.stdout, headings=["Spin_ID", "Chemical shift"], 
data=data)
+
+

Modified: trunk/user_functions/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/user_functions/__init__.py?rev=20657&r1=20656&r2=20657&view=diff
==============================================================================
--- trunk/user_functions/__init__.py (original)
+++ trunk/user_functions/__init__.py Wed Aug 21 11:43:00 2013
@@ -37,6 +37,7 @@
     'angles',
     'bmrb',
     'bruker',
+    'chemical_shift',
     'consistency_tests',
     'dasha',
     'deselect',
@@ -91,6 +92,7 @@
     import user_functions.angles
     import user_functions.bmrb
     import user_functions.bruker
+    import user_functions.chemical_shift
     import user_functions.consistency_tests
     import user_functions.dasha
     import user_functions.deselect

Added: trunk/user_functions/chemical_shift.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/user_functions/chemical_shift.py?rev=20657&view=auto
==============================================================================
--- trunk/user_functions/chemical_shift.py (added)
+++ trunk/user_functions/chemical_shift.py Wed Aug 21 11:43:00 2013
@@ -1,0 +1,141 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2013 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax (http://www.nmr-relax.com).         
 #
+#                                                                            
 #
+# This program is free software: you can redistribute it and/or modify       
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation, either version 3 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# This program is distributed in the hope that it will be useful,            
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.      
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""The chemical_shift user function definitions."""
+
+# Python module imports.
+import dep_check
+if dep_check.wx_module:
+    from wx import FD_OPEN
+else:
+    FD_OPEN = -1
+from os import sep
+
+# relax module imports.
+from graphics import WIZARD_IMAGE_PATH
+from pipe_control import chemical_shift
+from user_functions.data import Uf_info; uf_info = Uf_info()
+from user_functions.objects import Desc_container
+
+
+# The user function class.
+uf_class = uf_info.add_class('chemical_shift')
+uf_class.title = "Class for handling chemical shifts."
+uf_class.menu_text = "&chemical_shift"
+uf_class.gui_icon = "relax.chemical_shift"
+
+
+# The chemical_shift.read user function.
+uf = uf_info.add_uf('chemical_shift.read')
+uf.title = "Read chemical shifts from a file."
+uf.title_short = "Chemical shift reading."
+uf.add_keyarg(
+    name = "file",
+    py_type = "str",
+    arg_type = "file sel",
+    desc_short = "file name",
+    desc = "The name of the peak list of generic formatted file containing 
the chemical shifts.",
+    wiz_filesel_style = FD_OPEN
+)
+uf.add_keyarg(
+    name = "dir",
+    py_type = "str",
+    arg_type = "dir",
+    desc_short = "directory name",
+    desc = "The directory where the file is located.",
+    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 = "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
+)
+uf.add_keyarg(
+    name = "spin_id",
+    py_type = "str",
+    desc_short = "spin ID string",
+    desc = "The spin ID string used to restrict the loading of data to 
certain spin subsets.",
+    can_be_none = True
+)
+# Description.
+uf.desc.append(Desc_container())
+uf.desc[-1].add_paragraph("This will read chemical shifts from a peak list 
or a generic column formatted file.")
+# Prompt examples.
+uf.desc.append(Desc_container("Prompt examples"))
+uf.desc[-1].add_paragraph("The following commands will read the chemical 
shifts out of the Sparky peak list '10ms.list':")
+uf.desc[-1].add_prompt("relax> chemical_shift.read('10ms.list')")
+uf.backend = chemical_shift.read
+uf.menu_text = "&read"
+uf.gui_icon = "oxygen.actions.document-open"
+uf.wizard_size = (800, 500)
+uf.wizard_image = WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png'




Related Messages


Powered by MHonArc, Updated Wed Aug 21 14:40:02 2013