Author: bugman Date: Sun Apr 20 21:02:04 2008 New Revision: 5876 URL: http://svn.gna.org/viewcvs/relax?rev=5876&view=rev Log: Implemented the Selection.contains_res() method. 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=5876&r1=5875&r2=5876&view=diff ============================================================================== --- 1.3/generic_fns/selection.py (original) +++ 1.3/generic_fns/selection.py Sun Apr 20 21:02:04 2008 @@ -294,6 +294,44 @@ return False + def contains_res(self, res=None, mol=None): + """Determine if the residue name, in string form, is contained in this selection object. + + @keyword res: The name of the residue. + @type res: str or None + @keyword mol: The name of the molecule. + @type mol: str or None + @return: The answer of whether the molecule is contained withing the selection + object. + @rtype: bool + """ + + # The selection object is a union. + if self._union: + return self._union[0].contains_res(res, mol) or self._union[1].contains_res(res, mol) + + # The selection object is an intersection. + elif self._intersect: + return self._intersect[0].contains_res(res, mol) and self._intersect[1].contains_res(res, mol) + + # Does it contain the molecule. + select_mol = self.contains_mol(mol) + + # Residue selection flag. + select_res = False + + # The residue checks. + if res in self.residues: + select_res = True + + # Double nothingness. + if res == None and not self.residues: + select_res = True + + # Return the result. + return select_res or select_mol + + def intersection(self, select_obj0, select_obj1): """Make this Selection object the intersection of two other Selection objects.