Author: bugman Date: Tue Jun 19 11:38:32 2012 New Revision: 16950 URL: http://svn.gna.org/viewcvs/relax?rev=16950&view=rev Log: Expanded the return_interatom() function to handle a single spin ID. This function now returns a list of matching interatomic data containers. Modified: branches/interatomic/generic_fns/interatomic.py Modified: branches/interatomic/generic_fns/interatomic.py URL: http://svn.gna.org/viewcvs/relax/branches/interatomic/generic_fns/interatomic.py?rev=16950&r1=16949&r2=16950&view=diff ============================================================================== --- branches/interatomic/generic_fns/interatomic.py (original) +++ branches/interatomic/generic_fns/interatomic.py Tue Jun 19 11:38:32 2012 @@ -26,6 +26,7 @@ # relax module imports. from generic_fns import pipes from generic_fns.mol_res_spin import return_spin +from relax_errors import RelaxError from relax_warnings import RelaxNoSpinWarning @@ -76,13 +77,17 @@ @keyword spin_id1: The spin ID string of the first atom. @type spin_id1: str - @keyword spin_id2: The spin ID string of the first atom. - @type spin_id2: str + @keyword spin_id2: The spin ID string of the optional second atom. + @type spin_id2: str or None @keyword pipe: The data pipe holding the container. Defaults to the current data pipe. @type pipe: str or None - @return: The interatomic data container, if it exists. - @rtype: data.interatomic.InteratomContainer instance or None + @return: The list of matching interatomic data containers, if any exist. + @rtype: list of data.interatomic.InteratomContainer instances """ + + # Check. + if spin_id1 == None: + raise RelaxError("The first spin ID must be supplied.") # The data pipe. if pipe == None: @@ -91,10 +96,20 @@ # Get the data pipe. dp = pipes.get_pipe(pipe) - # Loop over the data. - for i in range(len(dp.interatomic)): - if dp.interatomic[i].id_match(spin_id1, spin_id2): - return dp.interatomic[i] + # Initialise. + interatoms = [] - # No container found. - return None + # Precise match. + if spin_id1 != None and spin_id2 != None: + for i in range(len(dp.interatomic)): + if dp.interatomic[i].id_match(spin_id1, spin_id2): + interatoms.append(dp.interatomic[i]) + + # Single spin. + else: + for i in range(len(dp.interatomic)): + if dp.interatomic[i].spin_id1 == spin_id1 or dp.interatomic[i].spin_id2 == spin_id1: + interatoms.append(dp.interatomic[i]) + + # Return the list of containers. + return interatoms