Author: bugman Date: Thu Mar 17 13:31:59 2011 New Revision: 12812 URL: http://svn.gna.org/viewcvs/relax?rev=12812&view=rev Log: Alphabetical arrangement of the methods. Modified: 1.3/specific_fns/model_free/bmrb.py Modified: 1.3/specific_fns/model_free/bmrb.py URL: http://svn.gna.org/viewcvs/relax/1.3/specific_fns/model_free/bmrb.py?rev=12812&r1=12811&r2=12812&view=diff ============================================================================== --- 1.3/specific_fns/model_free/bmrb.py (original) +++ 1.3/specific_fns/model_free/bmrb.py Thu Mar 17 13:31:59 2011 @@ -93,6 +93,199 @@ raise RelaxError("The BMRB model-free model '%s' is unknown." % name) + def _sf_model_free_read(self, star, sample_conditions=None): + """Fill the spin containers with the model-free data from the saveframe records. + + @param star: The NMR-STAR dictionary object. + @type star: NMR_STAR instance + @keyword sample_conditions: The sample condition label to read. Only one sample condition can be read per data pipe. + @type sample_conditions: None or str + """ + + # The list of model-free parameters (both bmrblib names and relax names). + mf_bmrb_key = ['bond_length', 'local_tm', 's2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex', 'chi2'] + mf_params = ['r', 'local_tm', 's2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex', 'chi2'] + + # Get the entities. + for data in star.model_free.loop(): + # Store the keys. + keys = data.keys() + + # Sample conditions do not match (remove the $ sign). + if 'sample_cond_list_label' in keys and sample_conditions and string.replace(data['sample_cond_list_label'], '$', '') != sample_conditions: + continue + + # Global data. + if 'global_chi2' in keys: + setattr(cdp, 'chi2', data['global_chi2']) + + # The number of spins. + N = bmrb.num_spins(data) + + # No data in the saveframe. + if N == 0: + continue + + # The molecule names. + mol_names = bmrb.molecule_names(data, N) + + # Missing atom names. + if 'atom_names' not in keys or data['atom_names'] == None: + data['atom_names'] = [None] * N + + # Generate the sequence if needed. + bmrb.generate_sequence(N, spin_names=data['atom_names'], res_nums=data['res_nums'], res_names=data['res_names'], mol_names=mol_names) + + # Correlation time scaling. + table = {'s': 1.0, + 'ns': 1e-9, + 'ps': 1e-12} + te_scale = 1.0 + if data['te_units']: + te_scale = table[data['te_units']] + + # Fast correlation time scaling. + if data['tf_units']: + tf_scale = table[data['tf_units']] + else: + tf_scale = te_scale + + # Slow correlation time scaling. + if data['ts_units']: + ts_scale = table[data['ts_units']] + else: + ts_scale = te_scale + + # Rex scaling. + rex_scale = 1.0 + if hasattr(cdp, 'frq') and len(cdp.frq): + rex_scale = 1.0 / (2.0*pi*cdp.frq[cdp.ri_ids[0]])**2 + + # Loop over the spins. + for i in range(N): + # Generate a spin ID. + spin_id = mol_res_spin.generate_spin_id(mol_name=mol_names[i], res_name=data['res_names'][i], res_num=data['res_nums'][i], spin_name=data['atom_names'][i]) + + # Obtain the spin. + spin = mol_res_spin.return_spin(spin_id) + + # No spin?!? + if spin == None: + raise(RelaxError("The spin '%s' does not exist." % spin_id)) + + # Loop over and set the model-free parameters. + for j in range(len(mf_params)): + # The parameter. + param = mf_params[j] + + # No parameter. + if not mf_bmrb_key[j] in keys: + continue + + # The parameter and its value. + if data[mf_bmrb_key[j]] != None: + # The value. + value = data[mf_bmrb_key[j]][i] + + # A te value which should be ts! + if param == 'te' and not hasattr(spin, 'te'): + if (data['s2s'] and data['s2s'][i] != None) or (data['s2f'] and data['s2f'][i] != None): + # Change the parameter name of te to ts. + param = 'ts' + + # Set the te and te_err values to None. + spin.te = None + spin.te_err = None + + # Parameter scaling. + if value != None: + if param == 'te': + value = value * te_scale + elif param == 'tf': + value = value * tf_scale + elif param == 'ts': + value = value * ts_scale + elif param == 'rex': + value = value * rex_scale + + # No parameter value. + else: + value = None + + # Set the parameter. + setattr(spin, param, value) + + # The error. + mf_bmrb_key_err = mf_bmrb_key[j] + '_err' + error = None + if mf_bmrb_key_err in keys and data[mf_bmrb_key_err] != None: + error = data[mf_bmrb_key_err][i] + + # Error scaling. + if error != None: + if param == 'te': + error = error * te_scale + elif param == 'tf': + error = error * tf_scale + elif param == 'ts': + error = error * ts_scale + elif param == 'rex': + error = error * rex_scale + + # Set the error. + mf_param_err = param + '_err' + if mf_bmrb_key_err in keys and data[mf_bmrb_key_err] != None: + setattr(spin, mf_param_err, error) + + # The model. + if data['model_fit'] != None and data['model_fit'][i] != None: + model = self._from_bmrb_model(data['model_fit'][i]) + setattr(spin, 'model', model) + + # The equation and parameters. + equation, params = self._model_map(model) + setattr(spin, 'equation', equation) + setattr(spin, 'params', params) + + # The element. + if'atom_types' in keys and data['atom_types'] != None: + setattr(spin, 'element', data['atom_types'][i]) + + # Heteronucleus type. + if'atom_types' in keys and data['atom_types'] != None and data['atom_types'][i] != None and 'isotope' in keys and data['isotope'] != None: + # The isotope number. + iso_num = data['isotope'][i] + + # No isotope number. + iso_table = {'C': 13, 'N': 15} + if not data['isotope'][i]: + iso_num = iso_table[data['atom_types'][i]] + + # Set the type. + setattr(spin, 'heteronuc_type', str(iso_num) + data['atom_types'][i]) + + + def _sf_csa_read(self, star): + """Place the CSA data from the saveframe records into the spin container. + + @param star: The NMR-STAR dictionary object. + @type star: NMR_STAR instance + """ + + # Get the entities. + for data in star.chem_shift_anisotropy.loop(): + # Loop over the spins. + for i in range(len(data['data_ids'])): + # Generate a spin ID. + spin_id = mol_res_spin.generate_spin_id(res_num=data['res_nums'][i], spin_name=data['atom_names'][i]) + + # Obtain the spin. + spin = mol_res_spin.return_spin(spin_id) + + # The CSA value (converted from ppm). + setattr(spin, 'csa', data['csa'][i] * 1e-6) + + def _to_bmrb_model(self, name=None): """Convert the model-free model name to the BMRB name. @@ -133,199 +326,6 @@ return map[name] - def _sf_model_free_read(self, star, sample_conditions=None): - """Fill the spin containers with the model-free data from the saveframe records. - - @param star: The NMR-STAR dictionary object. - @type star: NMR_STAR instance - @keyword sample_conditions: The sample condition label to read. Only one sample condition can be read per data pipe. - @type sample_conditions: None or str - """ - - # The list of model-free parameters (both bmrblib names and relax names). - mf_bmrb_key = ['bond_length', 'local_tm', 's2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex', 'chi2'] - mf_params = ['r', 'local_tm', 's2', 's2f', 's2s', 'te', 'tf', 'ts', 'rex', 'chi2'] - - # Get the entities. - for data in star.model_free.loop(): - # Store the keys. - keys = data.keys() - - # Sample conditions do not match (remove the $ sign). - if 'sample_cond_list_label' in keys and sample_conditions and string.replace(data['sample_cond_list_label'], '$', '') != sample_conditions: - continue - - # Global data. - if 'global_chi2' in keys: - setattr(cdp, 'chi2', data['global_chi2']) - - # The number of spins. - N = bmrb.num_spins(data) - - # No data in the saveframe. - if N == 0: - continue - - # The molecule names. - mol_names = bmrb.molecule_names(data, N) - - # Missing atom names. - if 'atom_names' not in keys or data['atom_names'] == None: - data['atom_names'] = [None] * N - - # Generate the sequence if needed. - bmrb.generate_sequence(N, spin_names=data['atom_names'], res_nums=data['res_nums'], res_names=data['res_names'], mol_names=mol_names) - - # Correlation time scaling. - table = {'s': 1.0, - 'ns': 1e-9, - 'ps': 1e-12} - te_scale = 1.0 - if data['te_units']: - te_scale = table[data['te_units']] - - # Fast correlation time scaling. - if data['tf_units']: - tf_scale = table[data['tf_units']] - else: - tf_scale = te_scale - - # Slow correlation time scaling. - if data['ts_units']: - ts_scale = table[data['ts_units']] - else: - ts_scale = te_scale - - # Rex scaling. - rex_scale = 1.0 - if hasattr(cdp, 'frq') and len(cdp.frq): - rex_scale = 1.0 / (2.0*pi*cdp.frq[cdp.ri_ids[0]])**2 - - # Loop over the spins. - for i in range(N): - # Generate a spin ID. - spin_id = mol_res_spin.generate_spin_id(mol_name=mol_names[i], res_name=data['res_names'][i], res_num=data['res_nums'][i], spin_name=data['atom_names'][i]) - - # Obtain the spin. - spin = mol_res_spin.return_spin(spin_id) - - # No spin?!? - if spin == None: - raise(RelaxError("The spin '%s' does not exist." % spin_id)) - - # Loop over and set the model-free parameters. - for j in range(len(mf_params)): - # The parameter. - param = mf_params[j] - - # No parameter. - if not mf_bmrb_key[j] in keys: - continue - - # The parameter and its value. - if data[mf_bmrb_key[j]] != None: - # The value. - value = data[mf_bmrb_key[j]][i] - - # A te value which should be ts! - if param == 'te' and not hasattr(spin, 'te'): - if (data['s2s'] and data['s2s'][i] != None) or (data['s2f'] and data['s2f'][i] != None): - # Change the parameter name of te to ts. - param = 'ts' - - # Set the te and te_err values to None. - spin.te = None - spin.te_err = None - - # Parameter scaling. - if value != None: - if param == 'te': - value = value * te_scale - elif param == 'tf': - value = value * tf_scale - elif param == 'ts': - value = value * ts_scale - elif param == 'rex': - value = value * rex_scale - - # No parameter value. - else: - value = None - - # Set the parameter. - setattr(spin, param, value) - - # The error. - mf_bmrb_key_err = mf_bmrb_key[j] + '_err' - error = None - if mf_bmrb_key_err in keys and data[mf_bmrb_key_err] != None: - error = data[mf_bmrb_key_err][i] - - # Error scaling. - if error != None: - if param == 'te': - error = error * te_scale - elif param == 'tf': - error = error * tf_scale - elif param == 'ts': - error = error * ts_scale - elif param == 'rex': - error = error * rex_scale - - # Set the error. - mf_param_err = param + '_err' - if mf_bmrb_key_err in keys and data[mf_bmrb_key_err] != None: - setattr(spin, mf_param_err, error) - - # The model. - if data['model_fit'] != None and data['model_fit'][i] != None: - model = self._from_bmrb_model(data['model_fit'][i]) - setattr(spin, 'model', model) - - # The equation and parameters. - equation, params = self._model_map(model) - setattr(spin, 'equation', equation) - setattr(spin, 'params', params) - - # The element. - if'atom_types' in keys and data['atom_types'] != None: - setattr(spin, 'element', data['atom_types'][i]) - - # Heteronucleus type. - if'atom_types' in keys and data['atom_types'] != None and data['atom_types'][i] != None and 'isotope' in keys and data['isotope'] != None: - # The isotope number. - iso_num = data['isotope'][i] - - # No isotope number. - iso_table = {'C': 13, 'N': 15} - if not data['isotope'][i]: - iso_num = iso_table[data['atom_types'][i]] - - # Set the type. - setattr(spin, 'heteronuc_type', str(iso_num) + data['atom_types'][i]) - - - def _sf_csa_read(self, star): - """Place the CSA data from the saveframe records into the spin container. - - @param star: The NMR-STAR dictionary object. - @type star: NMR_STAR instance - """ - - # Get the entities. - for data in star.chem_shift_anisotropy.loop(): - # Loop over the spins. - for i in range(len(data['data_ids'])): - # Generate a spin ID. - spin_id = mol_res_spin.generate_spin_id(res_num=data['res_nums'][i], spin_name=data['atom_names'][i]) - - # Obtain the spin. - spin = mol_res_spin.return_spin(spin_id) - - # The CSA value (converted from ppm). - setattr(spin, 'csa', data['csa'][i] * 1e-6) - - def bmrb_read(self, file_path, version=None, sample_conditions=None): """Read the model-free results from a BMRB NMR-STAR v3.1 formatted file.