Author: bugman Date: Thu Jun 14 15:40:44 2012 New Revision: 16910 URL: http://svn.gna.org/viewcvs/relax?rev=16910&view=rev Log: generic_fns.mol_res_spin.create_pseudo_spin() is now adding data to the spin ID look up table. To support this, the return_residue() method now takes the 'indices' argument and returns the molecule and residue indices. Modified: trunk/generic_fns/mol_res_spin.py Modified: trunk/generic_fns/mol_res_spin.py URL: http://svn.gna.org/viewcvs/relax/trunk/generic_fns/mol_res_spin.py?rev=16910&r1=16909&r2=16910&view=diff ============================================================================== --- trunk/generic_fns/mol_res_spin.py (original) +++ trunk/generic_fns/mol_res_spin.py Thu Jun 14 15:40:44 2012 @@ -1055,11 +1055,13 @@ # Get the residue container to add the spin to. if res_id: - res_to_cont = return_residue(res_id) + res_to_cont, mol_index, res_index = return_residue(res_id, indices=True) if res_to_cont == None: raise RelaxError("The residue in " + repr(res_id) + " does not exist in the current data pipe.") else: res_to_cont = cdp.mol[0].res[0] + mol_index = 0 + res_index = 0 # Check the averaging technique. if averaging not in ['linear']: @@ -1108,6 +1110,7 @@ # Add the spin. res_to_cont.spin.add_item(spin_num=spin_num, spin_name=spin_name) spin = res_to_cont.spin[-1] + spin_index = len(res_to_cont.spin) - 1 # Set the pseudo-atom spin container attributes. spin.averaging = averaging @@ -1121,6 +1124,10 @@ spin.pos = ave else: spin.pos = ave[0] + + # Add the spin ID and indices to the lookup table. + spin_id = generate_spin_id(mol_name=cdp.mol[mol_index].name, res_num=cdp.mol[mol_index].res[res_index].num, res_name=cdp.mol[mol_index].res[res_index].name, spin_num=spin.num, spin_name=spin.name) + cdp.mol.lookup_table[spin_id] = [mol_index, res_index, spin_index] # Release the lock. finally: @@ -2296,14 +2303,14 @@ return mol_container -def return_residue(selection=None, pipe=None): +def return_residue(selection=None, pipe=None, indices=False): """Function for returning the residue data container of the given selection. @param selection: The residue selection identifier. @type selection: str @param pipe: The data pipe containing the residue. Defaults to the current data pipe. @type pipe: str - @return: The residue specific data container. + @return: The residue specific data container, and the molecule and residue indices if asked. @rtype: instance of the ResidueContainer class. """ @@ -2324,19 +2331,23 @@ res = None res_num = 0 res_container = None - for mol in dp.mol: + for i in range(len(dp.mol)): # Skip the molecule if there is no match to the selection. - if mol not in select_obj: + if dp.mol[i] not in select_obj: continue + # Store the molecule index. + mol_index = i + # Loop over the residues. - for res in mol.res: + for j in range(len(cdp.mol[i].res)): # Skip the residue if there is no match to the selection. - if res not in select_obj: + if cdp.mol[i].res[j] not in select_obj: continue - # Store the residue container. - res_container = res + # Store the residue container and index. + res_container = cdp.mol[i].res[j] + res_index = j # Increment the residue number counter. res_num = res_num + 1 @@ -2346,7 +2357,10 @@ raise RelaxMultiResIDError(selection) # Return the residue container. - return res_container + if indices: + return res_container, mol_index, res_index + else: + return res_container def return_spin(selection=None, pipe=None, full_info=False):