Author: bugman Date: Tue Feb 1 20:03:23 2011 New Revision: 12491 URL: http://svn.gna.org/viewcvs/relax?rev=12491&view=rev Log: Shifted some of the code out of specific_fns/model_free/bmrb.py for use in generic_fns/relax_data.py. Modified: branches/bmrb/generic_fns/bmrb.py branches/bmrb/generic_fns/relax_data.py branches/bmrb/specific_fns/model_free/bmrb.py Modified: branches/bmrb/generic_fns/bmrb.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/generic_fns/bmrb.py?rev=12491&r1=12490&r2=12491&view=diff ============================================================================== --- branches/bmrb/generic_fns/bmrb.py (original) +++ branches/bmrb/generic_fns/bmrb.py Tue Feb 1 20:03:23 2011 @@ -115,6 +115,51 @@ create_spin(spin_num=spin_nums[i], spin_name=spin_names[i], res_num=res_nums[i], res_name=res_names[i], mol_name=mol_names[i]) +def molecule_names(data): + """Generate the molecule names list. + + @param data: An element of data from bmrblib. + @type data: dict + @return: The list of molecule names. + @rtype: list of str + """ + + # The molecule index and name. + mol_index = [] + for i in range(N): + if 'entity_ids' in keys and data['entity_ids'] != None and data['entity_ids'][i] != None: + mol_index.append(int(data['entity_ids'][i]) -1 ) + else: + mol_index = [0]*N + mol_names = [] + for i in range(N): + mol_names.append(cdp.mol[mol_index[i]].name) + + +def num_spins(data): + """Determine the number of spins in the given data. + + @param data: An element of data from bmrblib. + @type data: dict + @return: The number of spins. + @rtype: int + """ + + # The number of spins. + N = 0 + if data['data_ids']: + N = len(data['data_ids']) + elif data['entity_ids']: + N = len(data['entity_ids']) + elif data['res_nums']: + N = len(data['res_nums']) + elif data['s2']: + N = len(data['s2']) + + # Return the number. + return N + + def read(file=None, directory=None, version='3.1'): """Read the contents of a BMRB NMR-STAR formatted file.""" Modified: branches/bmrb/generic_fns/relax_data.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/generic_fns/relax_data.py?rev=12491&r1=12490&r2=12491&view=diff ============================================================================== --- branches/bmrb/generic_fns/relax_data.py (original) +++ branches/bmrb/generic_fns/relax_data.py Tue Feb 1 20:03:23 2011 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2003-2010 Edward d'Auvergne # +# Copyright (C) 2003-2011 Edward d'Auvergne # # # # This file is part of the program relax. # # # @@ -33,7 +33,7 @@ # relax module imports. from data import Relax_data_store; ds = Relax_data_store() from data.exp_info import ExpInfo -from generic_fns.bmrb import generate_sequence +from generic_fns import bmrb from generic_fns.mol_res_spin import create_spin, exists_mol_res_spin_data, find_index, generate_spin_id, get_molecule_names, return_spin, spin_index_loop, spin_loop from generic_fns import pipes from generic_fns import value @@ -242,6 +242,9 @@ # Get the relaxation data. for data in star.relaxation.loop(): + # Store the keys. + keys = data.keys() + # Create the labels. ri_label = data['data_type'] frq = float(data['frq']) * 1e6 @@ -249,8 +252,18 @@ # Round the label to the nearest factor of 10. frq_label = str(int(round(float(data['frq'])/10)*10)) + # 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) + # Pack the data. - pack_data(ri_label, frq_label, frq, data['data'], data['errors'], res_nums=data['res_nums'], res_names=data['res_names'], spin_nums=None, spin_names=data['atom_names'], gen_seq=True) + pack_data(ri_label, frq_label, frq, data['data'], data['errors'], mol_names=mol_names, res_nums=data['res_nums'], res_names=data['res_names'], spin_nums=None, spin_names=data['atom_names'], gen_seq=True) @@ -807,7 +820,7 @@ # Generate the sequence. if gen_seq: - generate_sequence(N, spin_ids=spin_ids, spin_nums=spin_nums, spin_names=spin_names, res_nums=res_nums, res_names=res_names, mol_names=mol_names) + bmrb.generate_sequence(N, spin_ids=spin_ids, spin_nums=spin_nums, spin_names=spin_names, res_nums=res_nums, res_names=res_names, mol_names=mol_names) # Loop over the spin data. for i in range(N): Modified: branches/bmrb/specific_fns/model_free/bmrb.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/specific_fns/model_free/bmrb.py?rev=12491&r1=12490&r2=12491&view=diff ============================================================================== --- branches/bmrb/specific_fns/model_free/bmrb.py (original) +++ branches/bmrb/specific_fns/model_free/bmrb.py Tue Feb 1 20:03:23 2011 @@ -139,16 +139,8 @@ if N == 0: continue - # The molecule index and name. - mol_index = [] - for i in range(N): - if 'entity_ids' in keys and data['entity_ids'] != None and data['entity_ids'][i] != None: - mol_index.append(int(data['entity_ids'][i]) -1 ) - else: - mol_index = [0]*N - mol_names = [] - for i in range(N): - mol_names.append(cdp.mol[mol_index[i]].name) + # The molecule names. + mol_names = bmrb.molecule_names(data) # Generate the spin IDs. spin_ids = []