Author: bugman Date: Thu Jun 6 20:41:15 2013 New Revision: 19921 URL: http://svn.gna.org/viewcvs/relax?rev=19921&view=rev Log: Merged revisions 19920 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r19920 | bugman | 2013-06-06 20:41:01 +0200 (Thu, 06 Jun 2013) | 9 lines Fix for bug #20873 (http://gna.org/bugs/?20873). This was reported by Troels E. Linnet (http://gna.org/users/tlinnet). The ability to load multiple peak intensities from a single generic formatted file has been correctly implemented. This involves added checks to make sure that the user supplies reasonable arguments and to then loop over the intensity column argument. ........ Modified: branches/relax_disp/ (props changed) branches/relax_disp/pipe_control/spectrum.py Propchange: branches/relax_disp/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Thu Jun 6 20:41:15 2013 @@ -1,1 +1,1 @@ -/trunk:1-19918 +/trunk:1-19920 Modified: branches/relax_disp/pipe_control/spectrum.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/pipe_control/spectrum.py?rev=19921&r1=19920&r2=19921&view=diff ============================================================================== --- branches/relax_disp/pipe_control/spectrum.py (original) +++ branches/relax_disp/pipe_control/spectrum.py Thu Jun 6 20:41:15 2013 @@ -498,7 +498,7 @@ @keyword spin_num_col: The column containing the spin number information (used by the generic intensity file format). If supplied, spin_id_col must be None. @type spin_num_col: int or None @keyword data_col: The column containing the peak intensities. - @type data_col: int + @type data_col: int or list of int @keyword sep: The column separator which, if None, defaults to whitespace. @type sep: str or None @keyword spin_id: The spin ID string used to restrict data loading to a subset of all spins. @@ -515,21 +515,38 @@ # Strip the data. file_data = strip(file_data) - # Loop over the data. + # Convert the the data_col argument to a list if needed. + if not isinstance(data_col, list): + data_col = [data_col] + + # Loop over the data columns. data = [] - for values in read_spin_data(file_data=file_data, spin_id_col=spin_id_col, 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, data_col=data_col, sep=sep, spin_id=spin_id): - # Check the values. - if len(values) != 6: - raise RelaxError("The molecule name, residue number and name, spin number and name, and value columns could not be found in the data %s." % repr(values)) - - # Unpack. - mol_name, res_num, res_name, spin_num, spin_name, value = values - - # Create the unique spin ID. - id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name) - - # Store the necessary data. - data.append([None, None, id, value, id]) + for i in range(len(data_col)): + # Loop over the data. + row_index = 0 + for values in read_spin_data(file_data=file_data, spin_id_col=spin_id_col, 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, data_col=data_col[i], sep=sep, spin_id=spin_id): + # Check the values. + if len(values) != 6: + raise RelaxError("The molecule name, residue number and name, spin number and name, and value columns could not be found in the data %s." % repr(values)) + + # Unpack. + mol_name, res_num, res_name, spin_num, spin_name, value = values + + # Create the unique spin ID. + id = generate_spin_id_unique(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name) + + # Store the necessary data. + if i == 0: + # Convert the value to a list if multiple columns are present. + if len(data_col) > 1: + data.append([None, None, id, [value], id]) + else: + data.append([None, None, id, value, id]) + else: + data[row_index][3].append(value) + + # Go to the next row. + row_index += 1 # Return the data. return data @@ -607,6 +624,14 @@ # Print out. print("Generic formatted data file.\n") + # Checks. + if isinstance(spectrum_id, list) and not isinstance(int_col, list): + raise RelaxError("If a list of spectrum IDs is supplied, the intensity column argument must also be a list of equal length.") + if not isinstance(spectrum_id, list) and isinstance(int_col, list): + raise RelaxError("If a list of intensity columns is supplied, the spectrum ID argument must also be a list of equal length.") + if isinstance(spectrum_id, list) and len(spectrum_id) != len(int_col): + raise RelaxError("The spectrum ID list %s has a different number of elements to the intensity column list %s." % (spectrum_id, int_col)) + # Extract the data. intensity_data = intensity_generic(file_data=file_data, spin_id_col=spin_id_col, 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, data_col=int_col, sep=sep, spin_id=spin_id) @@ -675,41 +700,49 @@ # Extract the data. H_name, X_name, spin_id, intensity, line = intensity_data[i] - # Sanity check. - if intensity == 0.0: - warn(RelaxWarning("A peak intensity of zero has been encountered for the spin '%s' - this could be fatal later on." % spin_id)) - - # Skip data. - if (X_name and X_name != heteronuc) or (H_name and H_name != proton): - warn(RelaxWarning("Proton and heteronucleus names do not match, skipping the data %s." % line)) - continue - - # Get the spin container. - spin = return_spin(spin_id) - if not spin: - warn(RelaxNoSpinWarning(spin_id)) - continue - - # Skip deselected spins. - if not spin.select: - continue - - # Initialise. - if not hasattr(spin, 'intensities'): - spin.intensities = {} - - # Intensity scaling. - if ncproc != None: - intensity = intensity / float(2**ncproc) - - # Add the data. - spin.intensities[spectrum_id] = intensity - - # Switch the flag. - data_flag = True - - # Append the data for printing out. - data.append([spin_id, repr(intensity)]) + # Convert the intensity data and spectrum IDs to lists if needed. + if not isinstance(intensity, list): + intensity = [intensity] + if not isinstance(spectrum_id, list): + spectrum_id = [spectrum_id] + + # Loop over the data. + for i in range(len(intensity)): + # Sanity check. + if intensity[i] == 0.0: + warn(RelaxWarning("A peak intensity of zero has been encountered for the spin '%s' - this could be fatal later on." % spin_id)) + + # Skip data. + if (X_name and X_name != heteronuc) or (H_name and H_name != proton): + warn(RelaxWarning("Proton and heteronucleus names do not match, skipping the data %s." % line)) + continue + + # Get the spin container. + spin = return_spin(spin_id) + if not spin: + warn(RelaxNoSpinWarning(spin_id)) + continue + + # Skip deselected spins. + if not spin.select: + continue + + # Initialise. + if not hasattr(spin, 'intensities'): + spin.intensities = {} + + # Intensity scaling. + if ncproc != None: + intensity[i] = intensity[i] / float(2**ncproc) + + # Add the data. + spin.intensities[spectrum_id[i]] = intensity[i] + + # Switch the flag. + data_flag = True + + # Append the data for printing out. + data.append([spin_id, repr(intensity[i])]) # No data. if not data_flag: