Author: bugman Date: Fri Nov 10 07:48:15 2006 New Revision: 2798 URL: http://svn.gna.org/viewcvs/relax?rev=2798&view=rev Log: The intensity reading function now counts the number of header lines in the Sparky or XEasy file. The function 'self.number_of_header_lines()' has been added. This attempts to execute the intensity reading functions 'self.intensity_sparky()' or 'self.intensity_xeasy()' and if these fail with either a RelaxError or an IndexError, then the line is considered a header line. The function will then return the number of header lines. Modified: 1.3/generic_fns/intensity.py Modified: 1.3/generic_fns/intensity.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/intensity.py?rev=2798&r1=2797&r2=2798&view=diff ============================================================================== --- 1.3/generic_fns/intensity.py (original) +++ 1.3/generic_fns/intensity.py Fri Nov 10 07:48:15 2006 @@ -91,6 +91,41 @@ # Return the data. return res_num, x_name, h_name, intensity + + + def number_of_header_lines(self): + """Function for determining how many header lines are in the intensity file. + + @return: The number of header lines. + @rtype: int + """ + + # Sparky. + ######### + + # Assume the Sparky file has two header lines! + if self.format == 'sparky': + return 2 + + + # XEasy. + ######## + + # Loop over the lines of the file until a peak intensity value is reached. + header_lines = 0 + for i in xrange(len(self.file_data)): + # Try to see if the intensity can be extracted. + try: + self.intensity(self.file_data[i]) + except RelaxError: + header_lines = header_lines + 1 + except IndexError: + header_lines = header_lines + 1 + else: + break + + # Return the number of lines. + return header_lines def read(self, run=None, file=None, dir=None, format=None, heteronuc=None, proton=None, int_col=None, assign_func=None): @@ -128,22 +163,26 @@ raise RelaxNoSequenceError, self.run # Extract the data from the file. - file_data = self.relax.IO.extract_data(file, dir) + self.file_data = self.relax.IO.extract_data(file, dir) + + # Determine the number of header lines. + num = self.number_of_header_lines() + print "Number of header lines found: " + `num` # Remove the header. - file_data = file_data[2:] + self.file_data = self.file_data[num:] # Strip the data. - file_data = self.relax.IO.strip(file_data) + self.file_data = self.relax.IO.strip(self.file_data) # Loop over the peak intensity data. - for i in xrange(len(file_data)): + for i in xrange(len(self.file_data)): # Extract the data. - res_num, X_name, H_name, intensity = self.intensity(file_data[i]) + res_num, X_name, H_name, intensity = self.intensity(self.file_data[i]) # Skip data. if X_name != self.heteronuc or H_name != self.proton: - print "Skipping the data: " + `file_data[i]` + print "Skipping the data: " + `self.file_data[i]` continue # Find the index of self.relax.data.res[self.run] which corresponds to res_num. @@ -153,7 +192,7 @@ index = j break if index == None: - print "Skipping the data: " + `file_data[i]` + print "Skipping the data: " + `self.file_data[i]` continue # Remap the data structure 'self.relax.data.res[self.run][index]'.