Package generic_fns :: Module intensity
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.intensity

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2004 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  from re import split 
 24   
25 -class Intensity:
26 - def __init__(self, relax):
27 """Class containing functions for handelling peak intensities.""" 28 29 self.relax = relax
30 31
32 - def extract_int_data(self, line):
33 """Function for returning relevant data from the peak intensity line. 34 35 The residue number, heteronucleus and proton names, and peak intensity will be returned. 36 """ 37 38 # Sparky formatted line. 39 if self.format == 'sparky': 40 # The Sparky assignment. 41 assignment = split('([A-Z]+)', line[0]) 42 assignment = assignment[1:-1] 43 44 # The residue number. 45 try: 46 res_num = int(assignment[1]) 47 except: 48 raise RelaxError, "Improperly formatted Sparky file." 49 50 # Nuclei names. 51 x_name = assignment[2] 52 h_name = assignment[4] 53 54 # Intensity. 55 intensity = line[self.int_col] 56 57 # XEasy formatted line. 58 elif self.format == 'xeasy': 59 # Test for invalid assignment lines which have the column numbers changed and return empty data. 60 if line[4] == 'inv.': 61 return None, None, None, 0.0 62 63 # The residue number. 64 try: 65 res_num = int(line[5]) 66 except: 67 raise RelaxError, "Improperly formatted XEasy file." 68 69 # Nuclei names. 70 x_name = line[7] 71 h_name = line[4] 72 73 # Intensity. 74 intensity = line[self.int_col] 75 76 # Test the validity of the peak intensity data. 77 try: 78 intensity = float(intensity) 79 except ValueError: 80 raise RelaxError, "The peak height value " + `intensity` + " from the line " + `line` + " is invalid." 81 82 return res_num, x_name, h_name, intensity
83 84
85 - def read(self, run=None, file=None, dir=None, format=None, heteronuc=None, proton=None, int_col=None, assign_func=None):
86 """Function for reading peak intensity data.""" 87 88 # Arguments. 89 self.run = run 90 self.format = format 91 self.heteronuc = heteronuc 92 self.proton = proton 93 self.int_col = int_col 94 self.assign_func = assign_func 95 96 # Format argument. 97 format_list = ['sparky', 'xeasy'] 98 if self.format not in format_list: 99 raise RelaxArgNotInListError, ('format', self.format, format_list) 100 if self.format == 'sparky': 101 print "Sparky formatted data file.\n" 102 elif self.format == 'xeasy': 103 print "XEasy formatted data file.\n" 104 105 # Test if the run exists. 106 if not self.run in self.relax.data.run_names: 107 raise RelaxNoRunError, self.run 108 109 # Test if sequence data is loaded. 110 if not self.relax.data.res.has_key(self.run): 111 raise RelaxNoSequenceError, self.run 112 113 # Extract the data from the file. 114 file_data = self.relax.IO.extract_data(file, dir) 115 116 # Remove the header. 117 file_data = file_data[2:] 118 119 # Strip the data. 120 file_data = self.relax.IO.strip(file_data) 121 122 # The peak intensity column. 123 if self.format == 'sparky': 124 if int_col: 125 self.int_col = int_col 126 else: 127 self.int_col = 3 128 elif self.format == 'xeasy': 129 self.int_col = 10 130 131 # Loop over the peak intensity data. 132 for i in xrange(len(file_data)): 133 # Extract the data. 134 res_num, X_name, H_name, intensity = self.extract_int_data(file_data[i]) 135 136 # Skip data. 137 if X_name != self.heteronuc or H_name != self.proton: 138 print "Skipping the data: " + `file_data[i]` 139 continue 140 141 # Find the index of self.relax.data.res[self.run] which corresponds to res_num. 142 index = None 143 for j in xrange(len(self.relax.data.res[self.run])): 144 if self.relax.data.res[self.run][j].num == res_num: 145 index = j 146 break 147 if index == None: 148 print "Skipping the data: " + `file_data[i]` 149 continue 150 151 # Remap the data structure 'self.relax.data.res[self.run][index]'. 152 data = self.relax.data.res[self.run][index] 153 154 # Skip unselected residues. 155 if not data.select: 156 continue 157 158 # Assign the data. 159 self.assign_func(run=self.run, i=index, intensity=intensity)
160