Author: bugman Date: Thu Feb 18 13:24:04 2010 New Revision: 10711 URL: http://svn.gna.org/viewcvs/relax?rev=10711&view=rev Log: The Q-factor calculation functions can now accept a spin_id arg. As there can now be data problems, the functions check if there is any selected spins looped over, that the is RDC/PCS data, and that there is back-calculated RDC/PCS data. Modified: 1.3/generic_fns/pcs.py 1.3/generic_fns/rdc.py Modified: 1.3/generic_fns/pcs.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/pcs.py?rev=10711&r1=10710&r2=10711&view=diff ============================================================================== --- 1.3/generic_fns/pcs.py (original) +++ 1.3/generic_fns/pcs.py Thu Feb 18 13:24:04 2010 @@ -27,12 +27,14 @@ from copy import deepcopy from math import sqrt from numpy import array, float64, zeros +from warnings import warn # relax module imports. 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 read_spin_data +from relax_warnings import RelaxWarning def add_data_to_spin(spin=None, ri_labels=None, remap_table=None, frq_labels=None, frq=None, values=None, errors=None, sim=False): @@ -453,8 +455,12 @@ return index -def q_factors(): - """Calculate the Q-factors for the PCS data.""" +def q_factors(spin_id=None): + """Calculate the Q-factors for the PCS data. + + @keyword spin_id: The spin ID string used to restrict the Q-factor calculation to a subset of all spins. + @type spin_id: None or str + """ # Q-factor list. cdp.q_factors_pcs = [] @@ -466,11 +472,23 @@ sse = 0.0 # Spin loop. - for spin in spin_loop(): + spin_count = 0 + pcs_data = False + pcs_bc_data = False + for spin in spin_loop(spin_id): # Skip deselected spins. if not spin.select: continue + # Increment the spin counter. + spin_count += 1 + + # Data checks. + if hasattr(spin, 'pcs'): + pcs_data = True + if hasattr(spin, 'pcs_bc'): + pcs_bc_data = True + # Skip spins without PCS data. if not hasattr(spin, 'pcs') or not hasattr(spin, 'pcs_bc') or spin.pcs[i] == None: continue @@ -484,6 +502,17 @@ # The Q-factor for the alignment. Q = sqrt(sse / pcs2_sum) cdp.q_factors_pcs.append(Q) + + # Warnings (and then exit). + if not spin_count: + warn(RelaxWarning("No spins have been used in the calculation.")) + return + if not pcs_data: + warn(RelaxWarning("No PCS data can be found.")) + return + if not pcs_bc_data: + warn(RelaxWarning("No back-calculated PCS data can be found.")) + return # The total Q-factor. cdp.q_pcs = 0.0 Modified: 1.3/generic_fns/rdc.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/rdc.py?rev=10711&r1=10710&r2=10711&view=diff ============================================================================== --- 1.3/generic_fns/rdc.py (original) +++ 1.3/generic_fns/rdc.py Thu Feb 18 13:24:04 2010 @@ -29,6 +29,7 @@ from numpy import float64, ones, zeros from numpy.linalg import norm import sys +from warnings import warn # relax module imports. from generic_fns.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_data_array, return_spin, spin_index_loop, spin_loop @@ -37,6 +38,7 @@ from physical_constants import dipolar_constant, g1H, pcs_constant, return_gyromagnetic_ratio from relax_errors import RelaxError, RelaxNoSequenceError, RelaxNoSpinError, RelaxRDCError from relax_io import read_spin_data, write_spin_data +from relax_warnings import RelaxWarning def add_data_to_spin(spin=None, ri_labels=None, remap_table=None, frq_labels=None, frq=None, values=None, errors=None, sim=False): @@ -410,8 +412,12 @@ return index -def q_factors(): - """Calculate the Q-factors for the RDC data.""" +def q_factors(spin_id=None): + """Calculate the Q-factors for the RDC data. + + @keyword spin_id: The spin ID string used to restrict the Q-factor calculation to a subset of all spins. + @type spin_id: None or str + """ # Q-factor list. cdp.q_factors_rdc = [] @@ -426,10 +432,22 @@ # Spin loop. dj = None N = 0 - for spin in spin_loop(): + spin_count = 0 + rdc_data = False + rdc_bc_data = False + for spin in spin_loop(spin_id): # Skip deselected spins. if not spin.select: continue + + # Increment the spin counter. + spin_count += 1 + + # Data checks. + if hasattr(spin, 'rdc'): + rdc_data = True + if hasattr(spin, 'rdc_bc'): + rdc_bc_data = True # Skip spins without RDC data. if not hasattr(spin, 'rdc') or not hasattr(spin, 'rdc_bc') or spin.rdc[i] == None: @@ -454,6 +472,17 @@ # Increment the number of data sets. N = N + 1 + + # Warnings (and then exit). + if not spin_count: + warn(RelaxWarning("No spins have been used in the calculation.")) + return + if not rdc_data: + warn(RelaxWarning("No RDC data can be found.")) + return + if not rdc_bc_data: + warn(RelaxWarning("No back-calculated RDC data can be found.")) + return # Normalisation factor of 2Da^2(4 + 3R)/5. D = dj * cdp.align_tensors[i].A_diag