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

Source Code for Module lib.spectrum.nmrview

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