mailr17081 - in /branches/interatomic: data/interatomic.py generic_fns/interatomic.py


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

Header


Content

Posted by edward on June 28, 2012 - 10:39:
Author: bugman
Date: Thu Jun 28 10:39:43 2012
New Revision: 17081

URL: http://svn.gna.org/viewcvs/relax?rev=17081&view=rev
Log:
Shifted the InteratomContainer.id_match() method into the 
generic_fns.interatomic module.

This is needed to allow the correct data pipes to be matched.


Modified:
    branches/interatomic/data/interatomic.py
    branches/interatomic/generic_fns/interatomic.py

Modified: branches/interatomic/data/interatomic.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/interatomic/data/interatomic.py?rev=17081&r1=17080&r2=17081&view=diff
==============================================================================
--- branches/interatomic/data/interatomic.py (original)
+++ branches/interatomic/data/interatomic.py Thu Jun 28 10:39:43 2012
@@ -72,7 +72,7 @@
         text = text + "Objects:\n"
         for name in dir(self):
             # Skip the SpinContainer methods.
-            if name in ['id_match', 'is_empty']:
+            if name in ['is_empty']:
                 continue
 
             # Skip special objects.
@@ -83,31 +83,6 @@
             text += "  %s: %s\n" % (name, repr(getattr(self, name)))
 
         return text
-
-
-    def id_match(self, spin_id):
-        """Test if the spin ID matches one of the two spins of the current 
container.
-
-        @param spin_id:     The spin ID string of the first atom.
-        @type spin_id:      str
-        @return:            True if the spin ID matches one of the two 
spins, False otherwise.
-        @rtype:             bool
-        """
-
-        # Get the spin containers.
-        spin1 = generic_fns.mol_res_spin.return_spin(self.spin_id1)
-        spin2 = generic_fns.mol_res_spin.return_spin(self.spin_id2)
-
-        # No spins.
-        if spin1 == None or spin2 == None:
-            return False
-
-        # Check if the ID is in the private metadata list.
-        if spin_id in spin1._spin_ids or spin_id in spin2._spin_ids:
-            return True
-
-        # Nothing found.
-        return False
 
 
     def is_empty(self):
@@ -124,7 +99,7 @@
                 continue
 
             # Skip the SpinContainer methods.
-            if name in ['id_match', 'is_empty']:
+            if name in ['is_empty']:
                 continue
 
             # Skip special objects.
@@ -169,11 +144,6 @@
         @return:            The new interatomic data container.
         @rtype:             InteratomContainer instance
         """
-
-        # Check if the two spin ID have already been added.
-        for i in range(len(self)):
-            if self[i].id_match(spin_id1) and self[i].id_match(spin_id2):
-                raise RelaxError("The spin pair %s and %s have already been 
added." % (spin_id1, spin_id2))
 
         # Append a new InteratomContainer.
         cont = InteratomContainer(spin_id1, spin_id2)

Modified: branches/interatomic/generic_fns/interatomic.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/interatomic/generic_fns/interatomic.py?rev=17081&r1=17080&r2=17081&view=diff
==============================================================================
--- branches/interatomic/generic_fns/interatomic.py (original)
+++ branches/interatomic/generic_fns/interatomic.py Thu Jun 28 10:39:43 2012
@@ -127,6 +127,11 @@
     if spin == None:
         raise RelaxNoSpinWarning(spin_id2)
 
+    # Check if the two spin IDs have already been added.
+    for i in range(len(dp.interatomic)):
+        if id_match(spin_id=spin_id1, interatom=dp.interatomic[i], 
pipe=pipe) and id_match(spin_id=spin_id2, interatom=dp.interatomic[i], 
pipe=pipe):
+            raise RelaxError("The spin pair %s and %s have already been 
added." % (spin_id1, spin_id2))
+
     # Add and return the data.
     return dp.interatomic.add_item(spin_id1=spin_id1, spin_id2=spin_id2)
 
@@ -156,6 +161,35 @@
 
     # Otherwise.
     return True
+
+
+def id_match(spin_id=None, interatom=None, pipe=None):
+    """Test if the spin ID matches one of the two spins of the given 
container.
+
+    @keyword spin_id:   The spin ID string of the first atom.
+    @type spin_id:      str
+    @keyword interatom: The interatomic data container.
+    @type interatom:    InteratomContainer instance
+    @keyword pipe:      The data pipe containing the interatomic data 
container.  Defaults to the current data pipe.
+    @type pipe:         str or None
+    @return:            True if the spin ID matches one of the two spins, 
False otherwise.
+    @rtype:             bool
+    """
+
+    # Get the spin containers.
+    spin1 = return_spin(interatom.spin_id1, pipe=pipe)
+    spin2 = return_spin(interatom.spin_id2, pipe=pipe)
+
+    # No spins.
+    if spin1 == None or spin2 == None:
+        return False
+
+    # Check if the ID is in the private metadata list.
+    if spin_id in spin1._spin_ids or spin_id in spin2._spin_ids:
+        return True
+
+    # Nothing found.
+    return False
 
 
 def interatomic_loop(selection1=None, selection2=None, pipe=None, 
selected=True):
@@ -247,7 +281,7 @@
 
     # Return the matching container.
     for i in range(len(dp.interatomic)):
-        if dp.interatomic[i].id_match(spin_id1) and 
dp.interatomic[i].id_match(spin_id2):
+        if id_match(spin_id=spin_id1, interatom=dp.interatomic[i], 
pipe=pipe) and id_match(spin_id=spin_id2, interatom=dp.interatomic[i], 
pipe=pipe):
             return dp.interatomic[i]
 
     # No matchs.




Related Messages


Powered by MHonArc, Updated Thu Jun 28 11:00:02 2012