Author: bugman Date: Wed Sep 24 18:46:03 2008 New Revision: 7259 URL: http://svn.gna.org/viewcvs/relax?rev=7259&view=rev Log: Wrote the count_molecules() and count_residues() functions. 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=7259&r1=7258&r2=7259&view=diff ============================================================================== --- 1.3/generic_fns/mol_res_spin.py (original) +++ 1.3/generic_fns/mol_res_spin.py Wed Sep 24 18:46:03 2008 @@ -723,6 +723,54 @@ # Return the number of spins. return spin_num + + +def count_molecules(selection=None): + """Count the number of molecules for which there is data. + + @param selection: The selection string. + @type selection: str + @return: The number of non-empty molecules. + @rtype: int + """ + + # No data, hence no molecules. + if not exists_mol_res_spin_data(): + return 0 + + # Init. + mol_num = 0 + + # Spin loop. + for mol in molecule_loop(selection): + mol_num = mol_num + 1 + + # Return the number of molecules. + return mol_num + + +def count_residues(selection=None): + """Count the number of residues for which there is data. + + @param selection: The selection string. + @type selection: str + @return: The number of non-empty residues. + @rtype: int + """ + + # No data, hence no residues. + if not exists_mol_res_spin_data(): + return 0 + + # Init. + res_num = 0 + + # Spin loop. + for res in residue_loop(selection): + res_num = res_num + 1 + + # Return the number of residues. + return res_num def count_spins(selection=None):