Author: bugman Date: Thu Jan 23 15:37:00 2014 New Revision: 22043 URL: http://svn.gna.org/viewcvs/relax?rev=22043&view=rev Log: Added the has_molecule() method to the relax internal structural object. This is used to quickly check if a molecule name already exists in the structural object. Modified: trunk/lib/structure/internal/object.py Modified: trunk/lib/structure/internal/object.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=22043&r1=22042&r2=22043&view=diff ============================================================================== --- trunk/lib/structure/internal/object.py (original) +++ trunk/lib/structure/internal/object.py Thu Jan 23 15:37:00 2014 @@ -1,6 +1,6 @@ ############################################################################### # # -# Copyright (C) 2003-2013 Edward d'Auvergne # +# Copyright (C) 2003-2014 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -1676,6 +1676,31 @@ return mol + def has_molecule(self, name=None): + """Check if the molecule name exists. + + @param name: The molecule name. + @type name: str + @return: True if the molecule exists, False otherwise. + @rtype: bool + """ + + # No models. + if not len(self.structural_data): + return False + + # Loop over the models. + for model_cont in self.model_loop(): + # Loop over the molecules. + for mol in model_cont.mol: + # Matching molecule. + if mol.mol_name == name: + return True + + # No match. + return False + + def load_gaussian(self, file_path, set_mol_name=None, set_model_num=None, verbosity=False): """Method for loading structures from a Gaussian log file.