Author: bugman Date: Tue Nov 24 13:49:42 2009 New Revision: 9920 URL: http://svn.gna.org/viewcvs/relax?rev=9920&view=rev Log: Alphabetical ordering of methods, and separation of the private from the API methods. Modified: 1.3/specific_fns/noe.py Modified: 1.3/specific_fns/noe.py URL: http://svn.gna.org/viewcvs/relax/1.3/specific_fns/noe.py?rev=9920&r1=9919&r2=9920&view=diff ============================================================================== --- 1.3/specific_fns/noe.py (original) +++ 1.3/specific_fns/noe.py Tue Nov 24 13:49:42 2009 @@ -56,87 +56,6 @@ spin.sat = intensity else: raise RelaxError("The spectrum type '%s' is unknown." % spectrum_type) - - - def calculate(self, spin_id=None, verbosity=1, sim_index=None): - """Calculate the NOE and its error. - - The error for each peak is calculated using the formula:: - ___________________________________________ - \/ {sd(sat)*I(unsat)}^2 + {sd(unsat)*I(sat)}^2 - sd(NOE) = ----------------------------------------------- - I(unsat)^2 - - @keyword spin_id: The spin identification string. - @type spin_id: None or str - @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. - @type verbosity: int - @keyword sim_index: The MC simulation index (unused). - @type sim_index: None - """ - - # Test if the current pipe exists. - pipes.test() - - # The spectrum types have not been set. - if not hasattr(cdp, 'spectrum_type'): - raise RelaxError("The spectrum types have not been set.") - - # Test if the 2 spectra types 'ref' and 'sat' exist. - if not 'ref' in cdp.spectrum_type or not 'sat' in cdp.spectrum_type: - raise RelaxError("The reference and saturated NOE spectra have not been loaded.") - - # Loop over the spins. - for spin in spin_loop(): - # Skip deselected spins. - if not spin.select: - continue - - # Average intensities (if required). - sat = 0.0 - sat_err = 0.0 - ref = 0.0 - ref_err = 0.0 - for i in xrange(len(cdp.spectrum_type)): - # Sat spectra. - if cdp.spectrum_type[i] == 'sat': - sat = sat + spin.intensities[i] - sat_err = sat_err + spin.intensity_err[i] - - # Ref spectra. - if cdp.spectrum_type[i] == 'ref': - ref = ref + spin.intensities[i] - ref_err = ref_err + spin.intensity_err[i] - - # Calculate the NOE. - spin.noe = sat / ref - - # Calculate the error. - spin.noe_err = sqrt((sat_err * ref)**2 + (ref_err * sat)**2) / ref**2 - - - def overfit_deselect(self): - """Deselect spins which have insufficient data to support calculation""" - - # Test the sequence data exists. - if not exists_mol_res_spin_data(): - raise RelaxNoSequenceError - - # Loop over spin data. - for spin, spin_id in spin_loop(return_id=True): - # Skip deselected spins. - if not spin.select: - continue - - # Check for sufficient data. - if not hasattr(spin, 'intensities') or not len(spin.intensities) == 2: - warn(RelaxDeselectWarning(spin_id, 'insufficient data')) - spin.select = False - - # Check for sufficient errors. - elif not hasattr(spin, 'intensity_err') or not len(spin.intensity_err) == 2: - warn(RelaxDeselectWarning(spin_id, 'missing errors')) - spin.select = False def _read(self, file=None, dir=None, spectrum_type=None, format=None, heteronuc=None, proton=None, int_col=None): @@ -175,6 +94,116 @@ intensity.read(file=file, dir=dir, format=format, heteronuc=heteronuc, proton=proton, int_col=int_col, assign_func=self._assign_function, spectrum_type=spectrum_type) + def _spectrum_type(self, spectrum_type=None, spectrum_id=None): + """Set the spectrum type corresponding to the spectrum_id. + + @keyword spectrum_type: The type of NOE spectrum, one of 'ref' or 'sat'. + @type spectrum_type: str + @keyword spectrum_id: The spectrum id string. + @type spectrum_id: str + """ + + # Test if the current pipe exists + pipes.test() + + # Test the spectrum id string. + if spectrum_id not in cdp.spectrum_ids: + raise RelaxError("The peak intensities corresponding to the spectrum id '%s' does not exist." % spectrum_id) + + # The spectrum id index. + spect_index = cdp.spectrum_ids.index(spectrum_id) + + # Initialise or update the spectrum_type data structure as necessary. + if not hasattr(cdp, 'spectrum_type'): + cdp.spectrum_type = [None] * len(cdp.spectrum_ids) + elif len(cdp.spectrum_type) < len(cdp.spectrum_ids): + cdp.spectrum_type.append([None] * (len(cdp.spectrum_ids) - len(cdp.spectrum_type))) + + # Set the error. + cdp.spectrum_type[spect_index] = spectrum_type + + + def calculate(self, spin_id=None, verbosity=1, sim_index=None): + """Calculate the NOE and its error. + + The error for each peak is calculated using the formula:: + ___________________________________________ + \/ {sd(sat)*I(unsat)}^2 + {sd(unsat)*I(sat)}^2 + sd(NOE) = ----------------------------------------------- + I(unsat)^2 + + @keyword spin_id: The spin identification string. + @type spin_id: None or str + @keyword verbosity: The amount of information to print. The higher the value, the greater the verbosity. + @type verbosity: int + @keyword sim_index: The MC simulation index (unused). + @type sim_index: None + """ + + # Test if the current pipe exists. + pipes.test() + + # The spectrum types have not been set. + if not hasattr(cdp, 'spectrum_type'): + raise RelaxError("The spectrum types have not been set.") + + # Test if the 2 spectra types 'ref' and 'sat' exist. + if not 'ref' in cdp.spectrum_type or not 'sat' in cdp.spectrum_type: + raise RelaxError("The reference and saturated NOE spectra have not been loaded.") + + # Loop over the spins. + for spin in spin_loop(): + # Skip deselected spins. + if not spin.select: + continue + + # Average intensities (if required). + sat = 0.0 + sat_err = 0.0 + ref = 0.0 + ref_err = 0.0 + for i in xrange(len(cdp.spectrum_type)): + # Sat spectra. + if cdp.spectrum_type[i] == 'sat': + sat = sat + spin.intensities[i] + sat_err = sat_err + spin.intensity_err[i] + + # Ref spectra. + if cdp.spectrum_type[i] == 'ref': + ref = ref + spin.intensities[i] + ref_err = ref_err + spin.intensity_err[i] + + # Calculate the NOE. + spin.noe = sat / ref + + # Calculate the error. + spin.noe_err = sqrt((sat_err * ref)**2 + (ref_err * sat)**2) / ref**2 + + + def overfit_deselect(self): + """Deselect spins which have insufficient data to support calculation""" + + # Test the sequence data exists. + if not exists_mol_res_spin_data(): + raise RelaxNoSequenceError + + # Loop over spin data. + for spin, spin_id in spin_loop(return_id=True): + # Skip deselected spins. + if not spin.select: + continue + + # Check for sufficient data. + if not hasattr(spin, 'intensities') or not len(spin.intensities) == 2: + warn(RelaxDeselectWarning(spin_id, 'insufficient data')) + spin.select = False + + # Check for sufficient errors. + elif not hasattr(spin, 'intensity_err') or not len(spin.intensity_err) == 2: + warn(RelaxDeselectWarning(spin_id, 'missing errors')) + spin.select = False + + return_data_name_doc = """ NOE calculation data type string matching patterns ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -259,32 +288,3 @@ """ return None - - - def _spectrum_type(self, spectrum_type=None, spectrum_id=None): - """Set the spectrum type corresponding to the spectrum_id. - - @keyword spectrum_type: The type of NOE spectrum, one of 'ref' or 'sat'. - @type spectrum_type: str - @keyword spectrum_id: The spectrum id string. - @type spectrum_id: str - """ - - # Test if the current pipe exists - pipes.test() - - # Test the spectrum id string. - if spectrum_id not in cdp.spectrum_ids: - raise RelaxError("The peak intensities corresponding to the spectrum id '%s' does not exist." % spectrum_id) - - # The spectrum id index. - spect_index = cdp.spectrum_ids.index(spectrum_id) - - # Initialise or update the spectrum_type data structure as necessary. - if not hasattr(cdp, 'spectrum_type'): - cdp.spectrum_type = [None] * len(cdp.spectrum_ids) - elif len(cdp.spectrum_type) < len(cdp.spectrum_ids): - cdp.spectrum_type.append([None] * (len(cdp.spectrum_ids) - len(cdp.spectrum_type))) - - # Set the error. - cdp.spectrum_type[spect_index] = spectrum_type