Author: bugman Date: Fri Jan 30 09:59:25 2015 New Revision: 27379 URL: http://svn.gna.org/viewcvs/relax?rev=27379&view=rev Log: Large speed up of the mol-res-spin selection object. The Selection.contains_mol(), Selection.contains_res() and Selection.contains_spin() methods of the lib.selection module have been redesigned for speed. Instead of setting a number of flags and performing bit operations at the end of the method to return the correct Boolean value, each of the multiple checks now simply returns a Boolean value, avoiding all subsequent checks. The check list order has also been rearranged so that the least expensive checks are to the top and the most time intensive checks are last. Modified: trunk/lib/selection.py Modified: trunk/lib/selection.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/selection.py?rev=27379&r1=27378&r2=27379&view=diff ============================================================================== --- trunk/lib/selection.py (original) +++ trunk/lib/selection.py Fri Jan 30 09:59:25 2015 @@ -1,7 +1,7 @@ from __future__ import absolute_import ############################################################################### # # -# Copyright (C) 2003-2013 Edward d'Auvergne # +# Copyright (C) 2003-2015 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -415,12 +415,12 @@ elif self._intersect: return self._intersect[0].contains_mol(mol) and self._intersect[1].contains_mol(mol) + # Nothingness. + if not self.molecules: + return True + # The check. if regex.search(self.molecules, mol): - return True - - # Nothingness. - if not self.molecules: return True # No match. @@ -449,21 +449,22 @@ return self._intersect[0].contains_res(res_num, res_name, mol) and self._intersect[1].contains_res(res_num, res_name, mol) # Does it contain the molecule. - select_mol = self.contains_mol(mol) + if not self.contains_mol(mol): + return False # Residue selection flag. select_res = False + # Nothingness. + if not self.residues: + return True + # The residue checks. if res_num in self.residues or regex.search(self.residues, res_name): - select_res = True - - # Nothingness. - if not self.residues: - select_res = True - - # Return the result. - return select_res and select_mol + return True + + # No match. + return False def contains_spin(self, spin_num=None, spin_name=None, res_num=None, res_name=None, mol=None): @@ -492,24 +493,23 @@ return self._intersect[0].contains_spin(spin_num, spin_name, res_num, res_name, mol) and self._intersect[1].contains_spin(spin_num, spin_name, res_num, res_name, mol) # Does it contain the molecule. - select_mol = self.contains_mol(mol) + if not self.contains_mol(mol): + return False # Does it contain the residue. - select_res = self.contains_res(res_num, res_name, mol) - - # Spin selection flag. - select_spin = False + if not self.contains_res(res_num, res_name, mol): + return False + + # Nothingness. + if not self.spins: + return True # The spin checks. if spin_num in self.spins or regex.search(self.spins, spin_name): - select_spin = True - - # Nothingness. - if not self.spins: - select_spin = True - - # Return the result. - return select_spin and select_res and select_mol + return True + + # No match. + return False def contains_spin_id(self, spin_id):