Author: bugman Date: Tue Oct 6 20:22:15 2009 New Revision: 9608 URL: http://svn.gna.org/viewcvs/relax?rev=9608&view=rev Log: Converted the pcs.read() user fn to use the new relax_io.read_spin_data_file() function. Modified: 1.3/generic_fns/pcs.py 1.3/generic_fns/rdc.py 1.3/test_suite/shared_data/align_data/pcs.txt 1.3/test_suite/shared_data/align_data/pcs_err.txt Modified: 1.3/generic_fns/pcs.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/pcs.py?rev=9608&r1=9607&r2=9608&view=diff ============================================================================== --- 1.3/generic_fns/pcs.py (original) +++ 1.3/generic_fns/pcs.py Tue Oct 6 20:22:15 2009 @@ -31,7 +31,7 @@ from generic_fns.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_data_array, return_spin, spin_index_loop, spin_loop from generic_fns import pipes from relax_errors import RelaxError, RelaxNoPdbError, RelaxNoSequenceError, RelaxNoSpinError, RelaxPCSError -from relax_io import extract_data, strip +from relax_io import read_spin_data_file def add_data_to_spin(spin=None, ri_labels=None, remap_table=None, frq_labels=None, frq=None, values=None, errors=None, sim=False): @@ -437,10 +437,10 @@ return index -def read(id=None, file=None, dir=None, file_data=None, spin_id=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, data_col=None, error_col=None, sep=None): +def read(id=None, file=None, dir=None, file_data=None, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, data_col=None, error_col=None, sep=None, spin_id=None): """Read the PCS data from file. - @param id: The alignment identification string. + @param id: The alignment tensor ID string. @type id: str @param file: The name of the file to open. @type file: str @@ -453,18 +453,34 @@ @type file_data: list of lists @keyword spin_id: The spin identification string. @type spin_id: None or str - @param mol_name_col: The column containing the molecule name information. + @keyword spin_id_col: The column containing the spin ID strings. If supplied, the + mol_name_col, res_name_col, res_num_col, spin_name_col, and spin_num_col + arguments must be none. + @type spin_id_col: int or None + @keyword mol_name_col: The column containing the molecule name information. If supplied, + spin_id_col must be None. @type mol_name_col: int or None - @param res_name_col: The column containing the residue name information. + @keyword res_name_col: The column containing the residue name information. If supplied, + spin_id_col must be None. @type res_name_col: int or None - @param res_num_col: The column containing the residue number information. + @keyword res_num_col: The column containing the residue number information. If supplied, + spin_id_col must be None. @type res_num_col: int or None - @param spin_name_col: The column containing the spin name information. + @keyword spin_name_col: The column containing the spin name information. If supplied, + spin_id_col must be None. @type spin_name_col: int or None - @param spin_num_col: The column containing the spin number information. + @keyword spin_num_col: The column containing the spin number information. If supplied, + spin_id_col must be None. @type spin_num_col: int or None - @param sep: The column separator which, if None, defaults to whitespace. + @keyword data_col: The column containing the RDC data in Hz. + @type data_col: int or None + @keyword error_col: The column containing the RDC errors. + @type error_col: int or None + @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. + @type spin_id: None or str """ # Test if the current data pipe exists. @@ -478,97 +494,22 @@ if data_col == None and error_col == None: raise RelaxError("One of either the data or error column must be supplied.") - # Minimum number of columns. - min_col_num = max(mol_name_col, res_num_col, res_name_col, spin_num_col, spin_name_col, data_col, error_col) - - # Extract the data from the file. - if not file_data: - # Extract. - file_data = extract_data(file, dir) - - # Count the number of header lines. - header_lines = 0 - for i in xrange(len(file_data)): - try: - if data_col != None: - float(file_data[i][data_col]) - else: - float(file_data[i][error_col]) - except: - header_lines = header_lines + 1 - else: - break - - # Remove the header. - file_data = file_data[header_lines:] - - # Strip the data of all comments and empty lines. - file_data = strip(file_data) - - # Test the validity of the PCS data. - missing = True - for i in xrange(len(file_data)): - # Skip missing data. - if len(file_data[i]) <= min_col_num: - continue - elif data_col != None and file_data[i][data_col] == 'None': - continue - elif error_col != None and file_data[i][error_col] == 'None': - continue - - # Test that the data are numbers. - try: - if res_num_col != None: - int(file_data[i][res_num_col]) - if spin_num_col != None: - int(file_data[i][spin_num_col]) - if data_col != None: - float(file_data[i][data_col]) - if error_col != None: - float(file_data[i][error_col]) - except ValueError: - raise RelaxError("The PCS data in the line " + repr(file_data[i]) + " is invalid.") - - # Right, data is ok and exists. - missing = False - - # Hmmm, no data! - if missing: - raise RelaxError("No corresponding data could be found within the file.") - - - # Global (non-spin specific) data. - ################################## - - # Initialise. - if not hasattr(cdp, 'pcs_ids'): - cdp.pcs_ids = [] - - # Add the PCS id string. - if id not in cdp.pcs_ids: - cdp.pcs_ids.append(id) - # Spin specific data. ##################### # Loop over the PCS data. print(("\n%-50s %-15s %-15s" % ("spin_id", "value", "error"))) - for i in xrange(len(file_data)): - # Skip missing data. - if len(file_data[i]) <= min_col_num: - continue - - # Generate the spin identification string. - id = generate_spin_id_data_array(data=file_data[i], 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) - - # Convert the data. - value = None - if data_col != None: - value = eval(file_data[i][data_col]) - error = None - if error_col != None: - error = eval(file_data[i][error_col]) + for data in read_spin_data_file(file=file, dir=dir, 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, error_col=error_col, sep=sep, spin_id=spin_id): + # Unpack. + if data_col and error_col: + id, value, error = data + elif data_col: + id, value = data + error = None + else: + id, error = data + value = None # Test the error value (cannot be 0.0). if error == 0.0: @@ -580,7 +521,7 @@ raise RelaxNoSpinError(id) # Add the data. - if data_col != None: + if data_col: # Initialise. if not hasattr(spin, 'pcs'): spin.pcs = [] @@ -589,7 +530,7 @@ spin.pcs.append(value) # Add the error. - if error_col != None: + if error_col: # Initialise. if not hasattr(spin, 'pcs_err'): spin.pcs_err = [] @@ -599,6 +540,18 @@ # Print out. print(("%-50s %15s %15s" % (id, value, error))) + + + # Global (non-spin specific) data. + ################################## + + # Initialise. + if not hasattr(cdp, 'pcs_ids'): + cdp.pcs_ids = [] + + # Add the PCS id string. + if id not in cdp.pcs_ids: + cdp.pcs_ids.append(id) def return_data_desc(name): Modified: 1.3/generic_fns/rdc.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/rdc.py?rev=9608&r1=9607&r2=9608&view=diff ============================================================================== --- 1.3/generic_fns/rdc.py (original) +++ 1.3/generic_fns/rdc.py Tue Oct 6 20:22:15 2009 @@ -417,6 +417,7 @@ if data_col == None and error_col == None: raise RelaxError("One of either the data or error column must be supplied.") + # Spin specific data. ##################### @@ -428,8 +429,14 @@ id, value, error = data elif data_col: id, value = data + error = None else: id, error = data + value = None + + # Test the error value (cannot be 0.0). + if error == 0.0: + raise RelaxError("An invalid error value of zero has been encountered.") # Get the corresponding spin container. spin = return_spin([id, spin_id]) Modified: 1.3/test_suite/shared_data/align_data/pcs.txt URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/shared_data/align_data/pcs.txt?rev=9608&r1=9607&r2=9608&view=diff ============================================================================== --- 1.3/test_suite/shared_data/align_data/pcs.txt (original) +++ 1.3/test_suite/shared_data/align_data/pcs.txt Tue Oct 6 20:22:15 2009 @@ -1,4 +1,4 @@ -Name Dy Tb Tm E +#Name Dy Tb Tm E C1 0.004 0.040 0.100 0.037 C2 0.008 0.045 0.080 0.045 C3 0.021 0.050 0.090 0.018 Modified: 1.3/test_suite/shared_data/align_data/pcs_err.txt URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/shared_data/align_data/pcs_err.txt?rev=9608&r1=9607&r2=9608&view=diff ============================================================================== --- 1.3/test_suite/shared_data/align_data/pcs_err.txt (original) +++ 1.3/test_suite/shared_data/align_data/pcs_err.txt Tue Oct 6 20:22:15 2009 @@ -1,4 +1,4 @@ -Atom Dy Tb Tm Er +#Atom Dy Tb Tm Er H1 0.00017778978794241471 0.00020909584759850369 7.88347403825711e-05 0.00026363071804653775 H2 0.00015135068429266831 0.00010896251439994929 0.00010397661534864064 0.00037323554231773827 H3 0.00020797864504014244 0.00017137432686588103 0.00015997346046683463 0.00027037046207674463