Author: bugman Date: Mon Mar 19 06:20:13 2007 New Revision: 3222 URL: http://svn.gna.org/viewcvs/relax?rev=3222&view=rev Log: Wrote the spin_loop() generator function for looping over and returning spin containers. For more info, see my post at https://mail.gna.org/public/relax-devel/2006-10/msg00057.html (Message-id: <1160557041.9523.74.camel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>). The idea of the generator function, using the yield statement, to return the spin data containers was given by Gary Thompson at https://mail.gna.org/public/relax-devel/2007-01/msg00014.html (Message-id: <f001463a0701071417w6bd7927cp8fdd052e698575ec@xxxxxxxxxxxxxx>). More details are given by Chris MacRaild at https://mail.gna.org/public/relax-devel/2007-01/msg00036.html (Message-ID: <1168883717.7569.511.camel@mrspell>). The full generator function is generic_fns.selection.spin_loop(). Modified: 1.3/generic_fns/selection.py Modified: 1.3/generic_fns/selection.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/selection.py?rev=3222&r1=3221&r2=3222&view=diff ============================================================================== --- 1.3/generic_fns/selection.py (original) +++ 1.3/generic_fns/selection.py Mon Mar 19 06:20:13 2007 @@ -408,5 +408,44 @@ print "No residues match." +def spin_loop(selection): + """Generator function for looping over all the spin systems of the given selection. + + @param selection: The spin system selection identifier. + @type selection: str + @return: The spin system specific data container. + @rtype: instance of the SpinContainer class. + """ + + # Split up the selection string. + mol_token, res_token, spin_token = tokenise(selection) + + # Parse the tokens. + molecules = parse_token(mol_token) + residues = parse_token(res_token) + spins = parse_token(spin_token) + + # Loop over the molecules. + for mol in relax_data_store[relax_data_store.current_pipe].mol: + # Skip the molecule if there is no match to the selection. + if mol_token and mol.name not in molecules: + continue + + # Loop over the residues. + for res in mol.res: + # Skip the residue if there is no match to the selection. + if res_token and res.name not in residues: + continue + + # Loop over the spins. + for spin in res.spin: + # Skip the spin if there is no match to the selection. + if spin_token and spin.name not in spins: + continue + + # Yield the spin system data container. + yield spin + + def tokenise(selection): return None, None, None