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

Source Code for Module lib.spectrum.nmrview

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2004,2006-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 NMRView files.""" 
 25   
 26   
 27  # Python module imports. 
 28  from warnings import warn 
 29   
 30  # relax module imports. 
 31  from lib.errors import RelaxError 
 32  from lib.io import strip 
 33  from lib.warnings import RelaxWarning 
 34   
 35   
36 -def read_list(peak_list=None, file_data=None, int_col=None):
37 """Extract the peak intensity information from the NMRView peak intensity file. 38 39 @keyword peak_list: The peak list object to place all data into. 40 @type peak_list: lib.spectrum.objects.Peak_list instance 41 @keyword file_data: The data extracted from the file converted into a list of lists. 42 @type file_data: list of lists of str 43 @keyword int_col: The column containing the peak intensity data. The default is 16 for intensities. Setting the int_col argument to 15 will use the volumes (or evolumes). For a non-standard formatted file, use a different value. 44 @type int_col: int 45 @raises RelaxError: When the expected peak intensity is not a float. 46 """ 47 48 # Assume the NMRView file has six header lines! 49 num = 6 50 print("Number of header lines: %s" % num) 51 52 # Remove the header. 53 file_data = file_data[num:] 54 55 # Strip the data. 56 file_data = strip(file_data) 57 58 # The chemical shift columns. 59 w2_col = 2 60 w1_col = 9 61 62 # The peak intensity column. 63 if int_col == None: 64 int_col = 16 65 if int_col == 16: 66 print('Using peak heights.') 67 if int_col == 15: 68 print('Using peak volumes (or evolumes).') 69 70 # Loop over the file data. 71 for line in file_data: 72 # Unknown assignment. 73 if line[1] == '{}': 74 warn(RelaxWarning("The assignment '%s' is unknown, skipping this peak." % line[1])) 75 continue 76 77 # The residue number 78 res_num = '' 79 try: 80 res_num = line[1].strip('{') 81 res_num = res_num.strip('}') 82 res_num = res_num.split('.') 83 res_num = int(res_num[0]) 84 except ValueError: 85 raise RelaxError("Improperly formatted NMRView file, cannot process the assignment '%s'." % line[1]) 86 87 # Nuclei names. 88 name2 = '' 89 if line[1]!='{}': 90 name2 = line[1].strip('{') 91 name2 = name2.strip('}') 92 name2 = name2.split('.') 93 name2 = name2[1] 94 name1 = '' 95 if line[8]!='{}': 96 name1 = line[8].strip('{') 97 name1 = name1.strip('}') 98 name1 = name1.split('.') 99 name1 = name1[1] 100 101 # Chemical shifts. 102 w1 = None 103 w2 = None 104 if w1_col != None: 105 try: 106 w1 = float(line[w1_col]) 107 except ValueError: 108 raise RelaxError("The chemical shift from the line %s is invalid." % line) 109 if w2_col != None: 110 try: 111 w2 = float(line[w2_col]) 112 except ValueError: 113 raise RelaxError("The chemical shift from the line %s is invalid." % line) 114 115 # Intensity. 116 try: 117 intensity = float(line[int_col]) 118 except ValueError: 119 raise RelaxError("The peak intensity value " + repr(intensity) + " from the line " + repr(line) + " is invalid.") 120 121 # Add the assignment to the peak list object. 122 peak_list.add(res_nums=[res_num, res_num], spin_names=[name1, name2], shifts=[w1, w2], intensity=intensity)
123