mailr5727 - in /1.3: ./ generic_fns/selection.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on April 14, 2008 - 23:42:
Author: bugman
Date: Mon Apr 14 23:42:15 2008
New Revision: 5727

URL: http://svn.gna.org/viewcvs/relax?rev=5727&view=rev
Log:
Merged revisions 5711,5713-5725 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/spin_loop_bool

........
  r5711 | bugman | 2008-04-14 21:20:26 +0200 (Mon, 14 Apr 2008) | 12 lines
  
  Ok, lets try this again!  Created a branch for some nasty breakages and 
testing new ideas.
  
  The command used was:
  svn cp svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/spin_loop_bool
  
  The spin_loop and its siblings cannot currently handle the branching tree 
formed by the Selection
  object (nested within Selection._union and Selection._intersect).  For 
example if there are two
  molecules loaded into the data store, 'Ap4Aase' and 'RNA', the spin_loop 
with the spin id string
  '#Ap4Aase:Glu | #RNA@C8' loops over all spins of both molecules!!!  
Therefore all the usages of the
  Selection object need to be redesigned, and possibly the Selection object 
itself.
........
  r5713 | bugman | 2008-04-14 21:26:08 +0200 (Mon, 14 Apr 2008) | 3 lines
  
  Modified the spin_loop to check the tuple of (mol, res, spin) against the 
selection object.
........
  r5714 | bugman | 2008-04-14 21:49:20 +0200 (Mon, 14 Apr 2008) | 5 lines
  
  Redesigned the selection object method Selection.__contains__().
  
  Now multiple MoleculeContainer, ResidueContainer, or SpinContainer 
instances can be compared.
........
  r5715 | bugman | 2008-04-14 21:54:34 +0200 (Mon, 14 Apr 2008) | 3 lines
  
  Some fixes for the Selection.__contains__() method.
........
  r5716 | bugman | 2008-04-14 21:59:10 +0200 (Mon, 14 Apr 2008) | 3 lines
  
  Changed the spin_index_loop() function to use the same form as spin_loop().
........
  r5717 | bugman | 2008-04-14 22:00:39 +0200 (Mon, 14 Apr 2008) | 3 lines
  
  Updated the residue_loop() function.
........
  r5718 | bugman | 2008-04-14 22:03:08 +0200 (Mon, 14 Apr 2008) | 3 lines
  
  Updated all the other comparisons to the selection object.
........
  r5719 | bugman | 2008-04-14 22:17:11 +0200 (Mon, 14 Apr 2008) | 3 lines
  
  The Selection.__contains__() method now is complete and all the relevant 
unit tests pass again.
........
  r5720 | bugman | 2008-04-14 22:22:08 +0200 (Mon, 14 Apr 2008) | 3 lines
  
  Small docstring updates.
........

Modified:
    1.3/   (props changed)
    1.3/generic_fns/selection.py

Propchange: 1.3/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Apr 14 23:42:15 2008
@@ -1,1 +1,1 @@
-/branches/spin_loop_bool:1-5710
+/branches/spin_loop_bool:1-5726

Modified: 1.3/generic_fns/selection.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/selection.py?rev=5727&r1=5726&r2=5727&view=diff
==============================================================================
--- 1.3/generic_fns/selection.py (original)
+++ 1.3/generic_fns/selection.py Mon Apr 14 23:42:15 2008
@@ -61,15 +61,16 @@
 class Selection(object):
     """An object containing mol-res-spin selections.
 
-    A Selection object represents either a set of selected
-    molecules, residues and spins, or the union or intersection
-    of two other Selection objects."""
+    A Selection object represents either a set of selected molecules, 
residues and spins, or the
+    union or intersection of two other Selection objects.
+    """
 
     def __init__(self, select_string):
         """Initialise a Selection object.
 
-        @type select_string: string
-        @param select_string: a mol-res-spin selection string"""
+        @param select_string:   A mol-res-spin selection string.
+        @type select_string:    string
+        """
 
         self._union = None
         self._intersect = None
@@ -106,10 +107,12 @@
     def __contains__(self, obj):
         """Replacement function for determining if an object matches the 
selection.
 
-        @param obj:     The data object.
-        @type obj:      MoleculeContainer, ResidueContainer, or 
SpinContainer object.
+        @param obj:     The data object.  This can be a MoleculeContainer, 
ResidueContainer, or
+                        SpinContainer instance or a type of these instances. 
 If a tuple, only one
+                        type of object can be in the tuple.
+        @type obj:      instance or type of instances.
         @return:        The answer of whether the object matches the 
selection.
-        @rtype:         Boolean
+        @rtype:         bool
         """
 
         # The selection object is a union.
@@ -120,29 +123,94 @@
         elif self._intersect:
             return (obj in self._intersect[0]) and (obj in 
self._intersect[1])
 
-        # The object is a molecule.
-        elif isinstance(obj, MoleculeContainer):
+        # Initialise the molecule, residue, and spin objects.
+        mol = None
+        res = None
+        spin = None
+
+        # The object is not a tuple, so lets turn it into one.
+        if type(obj) != tuple:
+            obj = (obj,)
+
+        # Max 3 objects (cannot match, so False).
+        if len(obj) > 3:
+            return False
+
+        # Loop over the objects.
+        for i in range(len(obj)):
+            # The object is a molecule.
+            if isinstance(obj[i], MoleculeContainer):
+                # Error.
+                if mol != None:
+                    raise RelaxError, "Comparing two molecular containers 
simultaneously with the selection object is not supported."
+
+                # Unpack.
+                mol = obj[i]
+
+            # The object is a residue.
+            elif isinstance(obj[i], ResidueContainer):
+                # Error.
+                if res != None:
+                    raise RelaxError, "Comparing two residue containers 
simultaneously with the selection object is not supported."
+
+                # Unpack.
+                res = obj[i]
+
+            # The object is a spin.
+            elif isinstance(obj[i], SpinContainer):
+                # Error.
+                if spin != None:
+                    raise RelaxError, "Comparing two spin containers 
simultaneously with the selection object is not supported."
+
+                # Unpack.
+                spin = obj[i]
+
+        # Selection flags.
+        select_mol = False
+        select_res = False
+        select_spin = False
+
+        # Molecule container.
+        if mol:
+            # No molecules in selection object, therefore default to a match.
             if not self.molecules:
-                return True
-            elif wildcard_match(obj.name, self.molecules):
-                return True
-
-        # The object is a residue.
-        elif isinstance(obj, ResidueContainer):
+                select_mol = True
+
+            # A true match.
+            elif wildcard_match(mol.name, self.molecules):
+                select_mol = True
+        else:
+            # No molecule container sent in, therefore the molecule is 
assumed to match.
+            select_mol = True
+
+        # Residue container.
+        if res:
+            # No residues in selection object, therefore default to a match.
             if not self.residues:
-                return True
-            elif wildcard_match(obj.name, self.residues) or obj.num in 
self.residues:
-                return True
-
-        # The object is a spin.
-        elif isinstance(obj, SpinContainer):
+                select_res = True
+
+            # A true match.
+            elif wildcard_match(res.name, self.residues) or res.num in 
self.residues:
+                select_res = True
+        else:
+            # No residue container sent in, therefore the residue is assumed 
to match.
+            select_res = True
+
+        # Spin container.
+        if spin:
+            # No spins in selection object, therefore default to a match.
             if not self.spins:
-                return True
-            elif wildcard_match(obj.name, self.spins) or obj.num in 
self.spins:
-                return True
-
-        # No match.
-        return False
+                select_spin = True
+
+            # A true match.
+            elif wildcard_match(spin.name, self.spins) or spin.num in 
self.spins:
+                select_spin = True
+        else:
+            # No spin container sent in, therefore the spin is assumed to 
match.
+            select_spin = True
+
+        # Return the selection status.
+        return select_mol and select_res and select_spin
 
 
     def intersection(self, select_obj0, select_obj1):
@@ -597,14 +665,10 @@
 
     # Loop over the molecules.
     for mol in relax_data_store[pipe].mol:
-        # Skip the molecule if there is no match to the selection.
-        if mol not in select_obj:
-            continue
-
         # Loop over the residues.
         for res in mol.res:
             # Skip the residue if there is no match to the selection.
-            if res not in select_obj:
+            if (mol, res) not in select_obj:
                 continue
 
             # Yield the residue data container.
@@ -687,14 +751,10 @@
     res_num = 0
     res_container = None
     for mol in relax_data_store[pipe].mol:
-        # Skip the molecule if there is no match to the selection.
-        if mol not in select_obj:
-            continue
-
         # Loop over the residues.
         for res in mol.res:
             # Skip the residue if there is no match to the selection.
-            if res not in select_obj:
+            if (mol, res) not in select_obj:
                 continue
 
             # Store the residue container.
@@ -737,20 +797,12 @@
     spin_num = 0
     spin_container = None
     for mol in relax_data_store[pipe].mol:
-        # Skip the molecule if there is no match to the selection.
-        if mol not in select_obj:
-            continue
-
         # Loop over the residues.
         for res in mol.res:
-            # Skip the residue if there is no match to the selection.
-            if res not in select_obj:
-                continue
-
             # Loop over the spins.
             for spin in res.spin:
                 # Skip the spin if there is no match to the selection.
-                if spin not in select_obj:
+                if (mol, res, spin) not in select_obj:
                     continue
 
                 # Store the spin container.
@@ -1196,20 +1248,21 @@
 
     # Loop over the molecules.
     for mol_index in xrange(len(relax_data_store[pipe].mol)):
-        # Skip the molecule if there is no match to the selection.
-        if relax_data_store[pipe].mol[mol_index] not in select_obj:
-            continue
+        # Alias the molecule container.
+        mol = relax_data_store[pipe].mol[mol_index]
 
         # Loop over the residues.
         for res_index in 
xrange(len(relax_data_store[pipe].mol[mol_index].res)):
-            # Skip the residue if there is no match to the selection.
-            if relax_data_store[pipe].mol[mol_index].res[res_index] not in 
select_obj:
-                continue
+            # Alias the residue container.
+            res = relax_data_store[pipe].mol[mol_index].res[res_index]
 
             # Loop over the spins.
             for spin_index in 
xrange(len(relax_data_store[pipe].mol[mol_index].res[res_index].spin)):
+                # Alias the spin container.
+                spin = 
relax_data_store[pipe].mol[mol_index].res[res_index].spin[spin_index]
+
                 # Skip the spin if there is no match to the selection.
-                if 
relax_data_store[pipe].mol[mol_index].res[res_index].spin[spin_index] not in 
select_obj:
+                if (mol, res, spin) not in select_obj:
                     continue
 
                 # Yield the spin system specific indecies.
@@ -1249,20 +1302,12 @@
 
     # Loop over the molecules.
     for mol in relax_data_store[pipe].mol:
-        # Skip the molecule if there is no match to the selection.
-        if mol not in select_obj:
-            continue
-
         # Loop over the residues.
         for res in mol.res:
-            # Skip the residue if there is no match to the selection.
-            if res not in select_obj:
-                continue
-
             # Loop over the spins.
             for spin in res.spin:
                 # Skip the spin if there is no match to the selection.
-                if spin not in select_obj:
+                if (mol, res, spin) not in select_obj:
                     continue
 
                 # Yield the spin system data container.




Related Messages


Powered by MHonArc, Updated Tue Apr 15 00:00:21 2008