Package lib :: Package spectrum :: Module xeasy
[hide private]
[frames] | no frames]

Source Code for Module lib.spectrum.xeasy

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004-2013 Edward d'Auvergne                                   # 
  4  # Copyright (C) 2008 Sebastien Morin                                          # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Module containing functions for handling XEasy files.""" 
 25   
 26   
 27  # relax module imports. 
 28  from lib.errors import RelaxError 
 29  from lib.io import strip 
 30   
 31   
32 -def read_list(peak_list=None, file_data=None, int_col=None):
33 """Extract the peak intensity information from the XEasy file. 34 35 @keyword peak_list: The peak list object to place all data into. 36 @type peak_list: lib.spectrum.objects.Peak_list instance 37 @keyword file_data: The data extracted from the file converted into a list of lists. 38 @type file_data: list of lists of str 39 @keyword int_col: The column containing the peak intensity data (for a non-standard formatted file). 40 @type int_col: int 41 @raises RelaxError: When the expected peak intensity is not a float. 42 """ 43 44 # The hardcoded column positions (note that w1 and w2 are swapped!). 45 w1_col = 3 46 w2_col = 2 47 ass_w1_col = 7 48 ass_w2_col = 4 49 if int_col == None: 50 int_col = 10 51 52 # Determine the number of header lines. 53 num = 0 54 for line in file_data: 55 # Try to see if the intensity can be extracted. 56 try: 57 intensity = float(line[int_col]) 58 except ValueError: 59 num = num + 1 60 except IndexError: 61 num = num + 1 62 else: 63 break 64 print("Number of header lines found: " + repr(num)) 65 66 # Remove the header. 67 file_data = file_data[num:] 68 69 # Strip the data. 70 file_data = strip(file_data) 71 72 # Loop over the file data. 73 for line in file_data: 74 # Test for invalid assignment lines which have the column numbers changed and return empty data. 75 if line[ass_w1_col] == 'inv.' or line[ass_w2_col] == 'inv.': 76 continue 77 78 # The residue number. 79 try: 80 res_num = int(line[5]) 81 except: 82 raise RelaxError("Improperly formatted XEasy file, cannot read the line %s." % line) 83 84 # Nuclei names. 85 name1 = line[ass_w1_col] 86 name2 = line[ass_w2_col] 87 88 # Chemical shifts. 89 try: 90 w1 = float(line[w1_col]) 91 except ValueError: 92 raise RelaxError("The w1 chemical shift from the line %s is invalid." % line) 93 try: 94 w2 = float(line[w2_col]) 95 except ValueError: 96 raise RelaxError("The w2 chemical shift from the line %s is invalid." % line) 97 98 # Intensity. 99 try: 100 intensity = float(line[int_col]) 101 except ValueError: 102 raise RelaxError("The peak intensity value from the line %s is invalid." % line) 103 104 # Add the assignment to the peak list object. 105 peak_list.add(res_nums=[res_num, res_num], spin_names=[name1, name2], shifts=[w1, w2], intensity=intensity)
106