Author: bugman Date: Wed Sep 29 15:27:23 2010 New Revision: 11619 URL: http://svn.gna.org/viewcvs/relax?rev=11619&view=rev Log: Merged revisions 11609,11618 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3 ........ r11609 | bugman | 2010-09-17 18:02:20 +0200 (Fri, 17 Sep 2010) | 5 lines Shifted the NOE specific analysis code into its own package. This is in preparation for splitting up the module and adding new modules. ........ r11618 | bugman | 2010-09-29 15:26:50 +0200 (Wed, 29 Sep 2010) | 3 lines Added a catch for no data in the error analysis by replicated spectra. ........ Added: branches/bieri_gui/specific_fns/noe/ - copied from r11618, 1.3/specific_fns/noe/ Removed: branches/bieri_gui/specific_fns/noe.py Modified: branches/bieri_gui/ (props changed) branches/bieri_gui/generic_fns/spectrum.py Propchange: branches/bieri_gui/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Wed Sep 29 15:27:23 2010 @@ -1,1 +1,1 @@ -/1.3:1-11607 +/1.3:1-11618 Modified: branches/bieri_gui/generic_fns/spectrum.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/generic_fns/spectrum.py?rev=11619&r1=11618&r2=11619&view=diff ============================================================================== --- branches/bieri_gui/generic_fns/spectrum.py (original) +++ branches/bieri_gui/generic_fns/spectrum.py Wed Sep 29 15:27:23 2010 @@ -210,6 +210,10 @@ cdp.var_I[indices[0]] = cdp.var_I[indices[0]] + var_I count = count + 1 + # No data catch. + if not count: + raise RelaxError("No data is present, unable to calculate errors from replicated spectra.") + # Average variance. cdp.var_I[indices[0]] = cdp.var_I[indices[0]] / float(count) Removed: branches/bieri_gui/specific_fns/noe.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/specific_fns/noe.py?rev=11618&view=auto ============================================================================== --- branches/bieri_gui/specific_fns/noe.py (original) +++ branches/bieri_gui/specific_fns/noe.py (removed) @@ -1,266 +1,0 @@ -############################################################################### -# # -# Copyright (C) 2004-2005,2007-2009 Edward d'Auvergne # -# # -# This file is part of the program relax. # -# # -# relax is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# relax is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with relax; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -############################################################################### - -# Python module imports. -from math import sqrt -from re import match -from warnings import warn - -# relax module imports. -from api_base import API_base -from api_common import API_common -from generic_fns import pipes -from generic_fns.mol_res_spin import exists_mol_res_spin_data, spin_loop -from relax_errors import RelaxArgNotInListError, RelaxError, RelaxNoSequenceError -from relax_warnings import RelaxDeselectWarning - - -class Noe(API_base, API_common): - """Class containing functions for relaxation data.""" - - def __init__(self): - """Initialise the class by placing API_common methods into the API.""" - - # Place methods into the API. - self.return_conversion_factor = self._return_no_conversion_factor - self.return_value = self._return_value_general - - - def _assign_function(self, spin=None, intensity=None, spectrum_type=None): - """Place the peak intensity data into the spin container. - - The intensity data can be either that of the reference or saturated spectrum. - - @keyword spin: The spin container. - @type spin: SpinContainer instance - @keyword intensity: The intensity value. - @type intensity: float - @keyword spectrum_type: The type of spectrum, one of 'ref' or 'sat'. - @type spectrum_type: str - """ - - # Add the data. - if spectrum_type == 'ref': - spin.ref = intensity - elif spectrum_type == 'sat': - spin.sat = intensity - else: - raise RelaxError("The spectrum type '%s' is unknown." % 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.""" - - # Print out. - print("\n\nOver-fit spin deselection.\n") - - # 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 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - ____________________________________________________________________________________________ - | | | | - | Data type | Object name | Patterns | - |________________________|______________|__________________________________________________| - | | | | - | Reference intensity | 'ref' | '^[Rr]ef$' or '[Rr]ef[ -_][Ii]nt' | - | | | | - | Saturated intensity | 'sat' | '^[Ss]at$' or '[Ss]at[ -_][Ii]nt' | - | | | | - | NOE | 'noe' | '^[Nn][Oo][Ee]$' | - |________________________|______________|__________________________________________________| - - """ - - def return_data_name(self, param): - """Return a unique identifying string for the steady-state NOE parameter. - - @param param: The steady-state NOE parameter. - @type param: str - @return: The unique parameter identifying string. - @rtype: str - """ - - # Reference intensity. - if match('^[Rr]ef$', param) or match('[Rr]ef[ -_][Ii]nt', param): - return 'ref' - - # Saturated intensity. - if match('^[Ss]at$', param) or match('[Ss]at[ -_][Ii]nt', param): - return 'sat' - - # NOE. - if match('^[Nn][Oo][Ee]$', param): - return 'noe' - - - def return_grace_string(self, param): - """Return the Grace string representation of the parameter. - - This is used for axis labelling. - - @param param: The specific analysis parameter. - @type param: str - @return: The Grace string representation of the parameter. - @rtype: str - """ - - # Get the object name. - object_name = self.return_data_name(param) - - # Reference intensity. - if object_name == 'ref': - return 'Reference intensity' - - # Saturated intensity. - if object_name == 'sat': - return 'Saturated intensity' - - # NOE. - if object_name == 'noe': - return '\\qNOE\\Q' - - # Return the parameter as the Grace string. - return param - - - def return_units(self, param, spin=None, spin_id=None): - """Dummy function which returns None as the stats have no units. - - @param param: The name of the parameter to return the units string for. - @type param: str - @param spin: The spin container. - @type spin: SpinContainer instance - @param spin_id: The spin identification string (ignored if the spin container is supplied). - @type spin_id: str - @return: Nothing. - @rtype: None - """ - - return None