Author: bugman Date: Tue Oct 18 08:51:59 2011 New Revision: 14876 URL: http://svn.gna.org/viewcvs/relax?rev=14876&view=rev Log: Bug fix for the relax_io.read_spin_data() function for spin IDs. Spin IDs can now be handled if they are the first column in the data file! Modified: 1.3/relax_io.py Modified: 1.3/relax_io.py URL: http://svn.gna.org/viewcvs/relax/1.3/relax_io.py?rev=14876&r1=14875&r2=14876&view=diff ============================================================================== --- 1.3/relax_io.py (original) +++ 1.3/relax_io.py Tue Oct 18 08:51:59 2011 @@ -524,7 +524,10 @@ file_data = extract_data(file, dir) # Strip the data of all comments and empty lines. - file_data = strip(file_data) + if spin_id_col != None: + file_data = strip(file_data, comments=False) + else: + file_data = strip(file_data) # No data! if not file_data: @@ -553,13 +556,44 @@ else: id = generate_spin_id_data_array(data=line, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col) + # Invalid spin ID. + if id == '#': + warn(RelaxWarning("Invalid spin ID, skipping the line %s" % line)) + continue + # Convert the data. value = None if data_col: - value = eval(line[data_col-1]) + try: + # None. + if line[data_col-1] == 'None': + value = None + + # A float. + else: + value = float(line[data_col-1]) + + # Bad data. + except ValueError: + warn(RelaxWarning("Invalid data, skipping the line %s" % line)) + continue + + # Convert the errors. error = None if error_col: - error = eval(line[error_col-1]) + try: + # None. + if line[error_col-1] == 'None': + error = None + + # A float. + else: + error = float(line[error_col-1]) + + # Bad data. + except ValueError: + warn(RelaxWarning("Invalid errors, skipping the line %s" % line)) + continue # Right, data is OK and exists. missing_data = False @@ -579,13 +613,16 @@ raise RelaxError("No corresponding data could be found within the file.") -def strip(data): - """Function to remove all comment and empty lines from the file data structure. - - @param data: The file data. - @type data: list of lists of str - @return: The file data with comment and empty lines removed. - @rtype: list of lists of str +def strip(data, comments=True): + """Remove all comment and empty lines from the file data structure. + + @param data: The file data to clean up. + @type data: list of lists of str + @keyword comments: A flag which if True will cause comments to be deleted. + @type comments: bool + @return: The input data with the empty and comment lines removed. + @return: The file data with comment and empty lines removed. + @rtype: list of lists of str """ # Initialise the new data array. @@ -598,12 +635,11 @@ continue # Comment lines. - elif match("#", data[i][0]): + if comments and search("^#", data[i][0]): continue # Data lines. - else: - new.append(data[i]) + new.append(data[i]) # Return the new data structure. return new