Author: bugman Date: Wed Sep 4 18:08:18 2013 New Revision: 20812 URL: http://svn.gna.org/viewcvs/relax?rev=20812&view=rev Log: Merged revisions 20809-20811 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r20809 | bugman | 2013-09-04 17:59:10 +0200 (Wed, 04 Sep 2013) | 5 lines Renamed pipe_control.spectrum.test_spectrum_id() to check_spectrum_id(). A bug in the function was also removed, and the other code in the module now uses this function. ........ r20810 | bugman | 2013-09-04 18:05:59 +0200 (Wed, 04 Sep 2013) | 6 lines Created the pipe_control.mol_res_spin.check_mol_res_spin_data() function. This will check for the existence of molecule, residue and spin data and raise a RelaxError if none exists. ........ r20811 | bugman | 2013-09-04 18:07:14 +0200 (Wed, 04 Sep 2013) | 5 lines Simplification of the data checks in the pipe_control.spectrum module. This is using the new pipe_control.*.check*() functions. ........ Modified: branches/relax_disp/ (props changed) branches/relax_disp/pipe_control/mol_res_spin.py branches/relax_disp/pipe_control/spectrum.py Propchange: branches/relax_disp/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Wed Sep 4 18:08:18 2013 @@ -1,1 +1,1 @@ -/trunk:1-20807 +/trunk:1-20811 Modified: branches/relax_disp/pipe_control/mol_res_spin.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/pipe_control/mol_res_spin.py?rev=20812&r1=20811&r2=20812&view=diff ============================================================================== --- branches/relax_disp/pipe_control/mol_res_spin.py (original) +++ branches/relax_disp/pipe_control/mol_res_spin.py Wed Sep 4 18:08:18 2013 @@ -39,7 +39,7 @@ # relax module imports. from lib.check_types import is_unicode -from lib.errors import RelaxError, RelaxNoSpinError, RelaxMultiMolIDError, RelaxMultiResIDError, RelaxMultiSpinIDError, RelaxResSelectDisallowError, RelaxSpinSelectDisallowError +from lib.errors import RelaxError, RelaxNoSequenceError, RelaxNoSpinError, RelaxMultiMolIDError, RelaxMultiResIDError, RelaxMultiSpinIDError, RelaxResSelectDisallowError, RelaxSpinSelectDisallowError from lib.selection import Selection, parse_token, tokenise from lib.warnings import RelaxWarning from pipe_control import exp_info, pipes @@ -180,6 +180,17 @@ # Add the entity. star.entity.add(mol_name=mol.name, mol_type=mol_type, polymer_type=polymer_type, polymer_seq_code=polymer_seq_code, thiol_state=cdp.exp_info.thiol_state, res_nums=res_nums, res_names=res_names) + + +def check_mol_res_spin_data(): + """Check for the presence of molecule, residue, and spin data. + + @raises: RelaxNoSequenceError if no data is present. + """ + + # Check that the spectrum ID structure exists. + if not exists_mol_res_spin_data(): + raise RelaxNoSequenceError def copy_molecule(pipe_from=None, mol_from=None, pipe_to=None, mol_to=None): Modified: branches/relax_disp/pipe_control/spectrum.py URL: http://svn.gna.org/viewcvs/relax/branches/relax_disp/pipe_control/spectrum.py?rev=20812&r1=20811&r2=20812&view=diff ============================================================================== --- branches/relax_disp/pipe_control/spectrum.py (original) +++ branches/relax_disp/pipe_control/spectrum.py Wed Sep 4 18:08:18 2013 @@ -31,12 +31,12 @@ from warnings import warn # relax module imports. -from lib.errors import RelaxError, RelaxImplementError, RelaxNoSequenceError, RelaxNoSpectraError +from lib.errors import RelaxError, RelaxImplementError, RelaxNoSpectraError from lib.io import write_data from lib.spectrum.peak_list import read_peak_list from lib.warnings import RelaxWarning, RelaxNoSpinWarning from pipe_control import pipes -from pipe_control.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_unique, return_spin, spin_loop +from pipe_control.mol_res_spin import check_mol_res_spin_data, generate_spin_id_unique, return_spin, spin_loop def __errors_height_no_repl(): @@ -264,16 +264,10 @@ @type spin_id: str """ - # Test if the current pipe exists + # Data checks. pipes.test() - - # Test if the sequence data is loaded. - if not exists_mol_res_spin_data(): - raise RelaxNoSequenceError - - # Test the spectrum id string. - if spectrum_id not in cdp.spectrum_ids: - raise RelaxError("The peak intensities corresponding to the spectrum id '%s' do not exist." % spectrum_id) + check_mol_res_spin_data() + check_spectrum_id(spectrum_id) # The scaling by NC_proc. if hasattr(cdp, 'ncproc') and spectrum_id in cdp.ncproc: @@ -295,6 +289,23 @@ spin.baseplane_rmsd[spectrum_id] = float(error) * scale +def check_spectrum_id(id): + """Check that the give spectrum ID exists. + + @param id: The spectrum ID to check for. + @type id: str + @raises: RelaxNoSpectraError if the ID does not exist. + """ + + # Check that the spectrum ID structure exists. + if not hasattr(cdp, 'spectrum_ids'): + raise RelaxNoSpectraError(id) + + # Test if the spectrum ID exists. + if id not in cdp.spectrum_ids: + raise RelaxNoSpectraError(id) + + def delete(spectrum_id=None): """Delete spectral data corresponding to the spectrum ID. @@ -302,16 +313,10 @@ @type spectrum_id: str """ - # Test if the current pipe exists. + # Data checks. pipes.test() - - # Test if the sequence data is loaded. - if not exists_mol_res_spin_data(): - raise RelaxNoSequenceError - - # Test if data exists. - if not hasattr(cdp, 'spectrum_ids') or spectrum_id not in cdp.spectrum_ids: - raise RelaxNoSpectraError(spectrum_id) + check_mol_res_spin_data() + check_spectrum_id(spectrum_id) # Remove the ID. cdp.spectrum_ids.pop(cdp.spectrum_ids.index(spectrum_id)) @@ -357,12 +362,9 @@ @type subset: list of str """ - # Test if the current pipe exists + # Tests. pipes.test() - - # Test if the sequence data is loaded. - if not exists_mol_res_spin_data(): - raise RelaxNoSequenceError + check_mol_res_spin_data() # Test if spectra have been loaded. if not hasattr(cdp, 'spectrum_ids'): @@ -488,12 +490,9 @@ @type verbose: bool """ - # Test if the current data pipe exists. + # Data checks. pipes.test() - - # Test if sequence data is loaded. - if not exists_mol_res_spin_data(): - raise RelaxNoSequenceError + check_mol_res_spin_data() # Check the file name. if file == None: @@ -612,22 +611,21 @@ @type spectrum_ids: list of str """ - # Test if the current pipe exists + # Test if the current pipe exists. pipes.test() - - # Test if spectra have been loaded. - if not hasattr(cdp, 'spectrum_ids'): - raise RelaxError("No spectra have been loaded therefore replicates cannot be specified.") - - # Test the spectrum id strings. - for spectrum_id in spectrum_ids: - if spectrum_id not in cdp.spectrum_ids: - raise RelaxError("The peak intensities corresponding to the spectrum id '%s' do not exist." % spectrum_id) # Test for None. if spectrum_ids == None: warn(RelaxWarning("The spectrum ID list cannot be None.")) return + + # Test if spectra have been loaded. + if not hasattr(cdp, 'spectrum_ids'): + raise RelaxError("No spectra have been loaded therefore replicates cannot be specified.") + + # Test the spectrum id strings. + for spectrum_id in spectrum_ids: + check_spectrum_id(spectrum_id) # Test for more than one element. if len(spectrum_ids) == 1: @@ -726,19 +724,3 @@ # Return the list. return repl - - -def test_spectrum_id(id): - """Test that the give spectrum ID exists. - - @param id: The spectrum ID to check for. - @type id: str - """ - - # Check that the spectrum ID structure exists. - if not hasattr(cdp, 'spectrum_ids'): - raise RelaxNoSpectraError(id) - - # Test if the spectrum ID exists. - if spectrum_id not in cdp.spectrum_ids: - raise RelaxNoSpectraError(id)