Author: bugman Date: Wed Apr 27 11:13:48 2016 New Revision: 28204 URL: http://svn.gna.org/viewcvs/relax?rev=28204&view=rev Log: Fix for bug #24601.
This is the failure of the optimisation of the 'R2eff' dispersion model when peaks are missing from one spectrum, as reported by Petr Padrta at https://gna.org/bugs/?24601. To handle the missing data, the peak intensity keys are now checked for in the spin container peak_intensities data structure. This is both for the R2eff model optimisation as well as the data back-calculation. A warning is given when the key is missing. The relaxation dispersion base_data_loop() method has been modified to now yield the spin ID string, as this is used in the warnings. In addition, the Grace plotting code in the relax library was also modified. When peak intensity keys are missing, some of the Grace plots will have no data. The code will now generate a plot for that data set, but detect the missing data and allow an empty plot to be created. Modified: trunk/lib/plotting/grace.py trunk/specific_analyses/relax_disp/api.py trunk/specific_analyses/relax_disp/optimisation.py Modified: trunk/lib/plotting/grace.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/plotting/grace.py?rev=28204&r1=28203&r2=28204&view=diff ============================================================================== --- trunk/lib/plotting/grace.py (original) +++ trunk/lib/plotting/grace.py Wed Apr 27 11:13:48 2016 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2003-2015 Edward d'Auvergne # +# Copyright (C) 2003-2016 Edward d'Auvergne # # Copyright (C) 2013-2014 Troels E. Linnet # # # # This file is part of the program relax (http://www.nmr-relax.com). # @@ -167,10 +167,16 @@ file.write("@target G%s.S%s\n" % (gi, si)) file.write("@type %s\n" % graph_type) + # Catch missing data sets. + if len(data[gi][si]) == 0: + file.write("&\n") + continue + # Normalisation (to the first data point y value!). norm_fact = 1.0 if norm[gi]: if norm_type == 'first': + print `data[gi][si]` norm_fact = data[gi][si][0][1] elif norm_type == 'last': norm_fact = data[gi][si][-1][1] Modified: trunk/specific_analyses/relax_disp/api.py URL: http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_disp/api.py?rev=28204&r1=28203&r2=28204&view=diff ============================================================================== --- trunk/specific_analyses/relax_disp/api.py (original) +++ trunk/specific_analyses/relax_disp/api.py Wed Apr 27 11:13:48 2016 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2004-2014 Edward d'Auvergne # +# Copyright (C) 2004-2016 Edward d'Auvergne # # Copyright (C) 2009 Sebastien Morin # # Copyright (C) 2013-2014 Troels E. Linnet # # # @@ -86,7 +86,7 @@ # The R2eff model data (the base data is peak intensities). if cdp.model_type == MODEL_R2EFF: # Loop over the sequence. - for spin in spin_loop(): + for spin, spin_id in spin_loop(return_id=True): # Skip deselected spins. if not spin.select: continue @@ -97,7 +97,7 @@ # Loop over each spectrometer frequency and dispersion point. for exp_type, frq, offset, point in loop_exp_frq_offset_point(): - yield spin, exp_type, frq, offset, point + yield spin, spin_id, exp_type, frq, offset, point # All other models (the base data is the R2eff/R1rho values). else: @@ -318,10 +318,10 @@ # The R2eff model (with peak intensity base data). if cdp.model_type == MODEL_R2EFF: # Unpack the data. - spin, exp_type, frq, offset, point = data_id + spin, spin_id, exp_type, frq, offset, point = data_id # Back calculate the peak intensities. - values = back_calc_peak_intensities(spin=spin, exp_type=exp_type, frq=frq, offset=offset, point=point) + values = back_calc_peak_intensities(spin=spin, spin_id=spin_id, exp_type=exp_type, frq=frq, offset=offset, point=point) # All other models (with R2eff/R1rho base data). else: @@ -982,7 +982,7 @@ # The R2eff model. if cdp.model_type == MODEL_R2EFF: # Unpack the data. - spin, exp_type, frq, offset, point = data_id + spin, spin_id, exp_type, frq, offset, point = data_id # Return the data. return spin.peak_intensity @@ -1004,7 +1004,7 @@ # The R2eff model. if cdp.model_type == MODEL_R2EFF: # Unpack the data. - spin, exp_type, frq, offset, point = data_id + spin, spin_id, exp_type, frq, offset, point = data_id # Generate the data structure to return. errors = [] @@ -1440,7 +1440,7 @@ # The R2eff model (with peak intensity base data). if cdp.model_type == MODEL_R2EFF: # Unpack the data. - spin, exp_type, frq, offset, point = data_id + spin, spin_id, exp_type, frq, offset, point = data_id # Initialise the data structure if needed. if not hasattr(spin, 'peak_intensity_sim'): Modified: trunk/specific_analyses/relax_disp/optimisation.py URL: http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_disp/optimisation.py?rev=28204&r1=28203&r2=28204&view=diff ============================================================================== --- trunk/specific_analyses/relax_disp/optimisation.py (original) +++ trunk/specific_analyses/relax_disp/optimisation.py Wed Apr 27 11:13:48 2016 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2013-2015 Edward d'Auvergne # +# Copyright (C) 2013-2016 Edward d'Auvergne # # Copyright (C) 2014 Troels E. Linnet # # # # This file is part of the program relax (http://www.nmr-relax.com). # @@ -49,11 +49,13 @@ from target_functions.relax_fit_wrapper import Relax_fit_opt -def back_calc_peak_intensities(spin=None, exp_type=None, frq=None, offset=None, point=None): +def back_calc_peak_intensities(spin=None, spin_id=None, exp_type=None, frq=None, offset=None, point=None): """Back-calculation of peak intensity for the given relaxation time. @keyword spin: The specific spin data container. @type spin: SpinContainer instance + @keyword spin_id: The optional spin ID string for use in warning messages. + @type spin_id: str or None @keyword exp_type: The experiment type. @type exp_type: str @keyword frq: The spectrometer frequency. @@ -81,6 +83,16 @@ errors = [] times = [] for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): + # Check the peak intensity keys. + int_keys = find_intensity_keys(exp_type=exp_type, frq=frq, offset=offset, point=point, time=time) + for i in range(len(int_keys)): + if int_keys[i] not in spin.peak_intensity: + if spin_id: + warn(RelaxWarning("The spin %s peak intensity key '%s' is not present, skipping the back-calculation." % (spin_id, int_keys[i]))) + else: + warn(RelaxWarning("The peak intensity key '%s' is not present, skipping the back-calculation." % int_keys[i])) + return + # The data. values.append(average_intensity(spin=spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) errors.append(average_intensity(spin=spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) @@ -381,16 +393,31 @@ values = [] errors = [] times = [] + data_flag = True for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): - values.append(average_intensity(spin=spins[si], exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=sim_index)) - errors.append(average_intensity(spin=spins[si], exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) - times.append(time) + # Check the peak intensity keys. + int_keys = find_intensity_keys(exp_type=exp_type, frq=frq, offset=offset, point=point, time=time) + peak_intensities = spins[si].peak_intensity + if sim_index != None: + peak_intensities = spins[si].peak_intensity_sim + for i in range(len(int_keys)): + if int_keys[i] not in peak_intensities: + if verbosity: + warn(RelaxWarning("The spin %s peak intensity key '%s' is not present, skipping the optimisation." % (spin_ids[si], int_keys[i]))) + data_flag = False + break + + if data_flag: + values.append(average_intensity(spin=spins[si], exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=sim_index)) + errors.append(average_intensity(spin=spins[si], exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) + times.append(time) + if not data_flag: + continue # Raise errors if number of time points is less than 2. if len(times) < 3: subsection(file=sys.stdout, text="Exponential curve fitting error for point:", prespace=2) point_info = "%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, with %i time points." % (exp_type, frq/1E6, offset, point, len(times)) - print(point_info) raise RelaxError("The data setup points to exponential curve fitting, but only %i time points was found, where 3 time points is minimum. If calculating R2eff values for fixed relaxation time period data, check that a reference intensity has been specified for each offset value."%(len(times))) # The scaling matrix in a diagonalised list form. _______________________________________________ relax (http://www.nmr-relax.com) This is the relax-commits mailing list relax-commits@gna.org To unsubscribe from this list, get a password reminder, or change your subscription options, visit the list information page at https://mail.gna.org/listinfo/relax-commits