Author: bugman Date: Mon Dec 13 23:51:44 2010 New Revision: 11801 URL: http://svn.gna.org/viewcvs/relax?rev=11801&view=rev Log: The molecule_loop() and residue_loop() methods now accept the return_id flag. The molecule or residue ID strings are now returned when requested. Modified: 1.3/generic_fns/mol_res_spin.py Modified: 1.3/generic_fns/mol_res_spin.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/mol_res_spin.py?rev=11801&r1=11800&r2=11801&view=diff ============================================================================== --- 1.3/generic_fns/mol_res_spin.py (original) +++ 1.3/generic_fns/mol_res_spin.py Mon Dec 13 23:51:44 2010 @@ -1061,7 +1061,7 @@ residues = parse_token(res_token) # Molecule loop. - for mol in molecule_loop(mol_token): + for mol in molecule_loop(res_id): # List of indices to delete. indices = [] @@ -1395,13 +1395,15 @@ return mol.res[-1].num -def molecule_loop(selection=None, pipe=None): +def molecule_loop(selection=None, pipe=None, return_id=False): """Generator function for looping over all the molecules of the given selection. @param selection: The molecule selection identifier. @type selection: str @param pipe: The data pipe containing the molecule. Defaults to the current data pipe. @type pipe: str + @keyword return_id: A flag which if True will cause the molecule identification string of the molecule spin to be returned in addition to the spin container. + @type return_id: bool @return: The molecule specific data container. @rtype: instance of the MoleculeContainer class. """ @@ -1435,8 +1437,15 @@ if mol not in select_obj: continue + # Generate the spin id. + if return_id: + mol_id = generate_spin_id(mol.name) + # Yield the molecule data container. - yield mol + if return_id: + yield mol, mol_id + else: + yield mol def linear_ave(positions): @@ -1697,21 +1706,19 @@ return id_list -def residue_loop(selection=None, pipe=None, full_info=False): +def residue_loop(selection=None, pipe=None, full_info=False, return_id=False): """Generator function for looping over all the residues 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 - @param full_info: A flag specifying if the amount of information to be returned. If false, - only the data container is returned. If true, the molecule name, residue - number, and residue name is additionally returned. + @param full_info: A flag specifying if the amount of information to be returned. If false, only the data container is returned. If true, the molecule name, residue number, and residue name is additionally returned. @type full_info: boolean - @return: The residue specific data container and, if full_info=True, the molecule - name. - @rtype: instance of the ResidueContainer class. If full_info=True, the type is the - tuple (ResidueContainer, str). + @keyword return_id: A flag which if True will cause the molecule identification string of the molecule spin to be returned in addition to the spin container. + @type return_id: bool + @return: The residue specific data container and, if full_info=True, the molecule name. + @rtype: instance of the ResidueContainer class. If full_info=True, the type is the tuple (ResidueContainer, str). """ # The data pipe. @@ -1739,9 +1746,17 @@ if (mol, res) not in select_obj: continue + # Generate the spin id. + if return_id: + res_id = generate_spin_id(mol.name, res.num, res.name) + # Yield the residue data container. - if full_info: + if full_info and return_id: + yield res, mol.name, res_id + elif full_info: yield res, mol.name + elif return_id: + yield res, res_id else: yield res @@ -2285,22 +2300,12 @@ @type selection: str @keyword pipe: The data pipe containing the spin. Defaults to the current data pipe. @type pipe: str - @keyword full_info: A flag which if True will cause the the molecule name, residue number, and - residue name to be returned in addition to the spin container. + @keyword full_info: A flag which if True will cause the the molecule name, residue number, and residue name to be returned in addition to the spin container. @type full_info: bool - @keyword return_id: A flag which if True will cause the spin identification string of the - current spin to be returned in addition to the spin container. + @keyword return_id: A flag which if True will cause the spin identification string of the current spin to be returned in addition to the spin container. @type return_id: bool - @return: The spin system specific data container. If full_info is True, a tuple of - the spin container, the molecule name, residue number, and residue name. If - return_id is True, a tuple of the spin container and spin id. If both flags - are True, then a tuple of the spin container, the molecule name, residue - number, residue name, and spin id. - @rtype: If full_info and return_id are False, SpinContainer instance. If full_info - is True and return_id is false, a tuple of (SpinContainer instance, str, - int, str). If full_info is False and return_id is True, a tuple of - (SpinContainer instance, str). If full_info and return_id are False, a - tuple of (SpinContainer instance, str, int, str, str) + @return: The spin system specific data container. If full_info is True, a tuple of the spin container, the molecule name, residue number, and residue name. If return_id is True, a tuple of the spin container and spin id. If both flags are True, then a tuple of the spin container, the molecule name, residue number, residue name, and spin id. + @rtype: If full_info and return_id are False, SpinContainer instance. If full_info is True and return_id is false, a tuple of (SpinContainer instance, str, int, str). If full_info is False and return_id is True, a tuple of (SpinContainer instance, str). If full_info and return_id are False, a tuple of (SpinContainer instance, str, int, str, str) """ # The data pipe.