mailr2389 - in /1.2: data.py generic_fns/selection.py generic_fns/sequence.py


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

Header


Content

Posted by c . a . macraild on March 15, 2006 - 15:46:
Author: macraild
Date: Wed Mar 15 15:46:24 2006
New Revision: 2389

URL: http://svn.gna.org/viewcvs/relax?rev=2389&view=rev
Log:
bugfix for bug#5501

Modified:
    1.2/data.py
    1.2/generic_fns/selection.py
    1.2/generic_fns/sequence.py

Modified: 1.2/data.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/data.py?rev=2389&r1=2388&r2=2389&view=diff
==============================================================================
--- 1.2/data.py (original)
+++ 1.2/data.py Wed Mar 15 15:46:24 2006
@@ -182,4 +182,71 @@
     def add_item(self):
         """Function for appending an empty container to the list."""
 
-        self.append(Element())
+        self.append(ResidueElement())
+
+
+class ResidueElement(object):
+    def __init__(self):
+        """Empty container for residue specific data for a single residue."""
+
+        self.userSelect = 1
+
+
+    def autoSelect(self):
+        """Function to automatically deselect residues lacking relax_data"""
+
+        if not hasattr(self, 'relax_data'):
+            return 0
+
+        if hasattr(self, 'params'):
+            if len(self.params) < len(self.relax_data):
+                return 0
+
+        return 1
+
+
+    def __getattr__(self, name):
+        """Force on-the-fly evaluation of select every time it is 
referenced"""
+
+        # The list of data maps.
+        if name == 'select':
+            return (self.autoSelect() and self.userSelect)
+        raise AttributeError, name
+
+
+    def __repr__(self):
+        # Header.
+        text = "%-25s%-100s\n\n" % ("Data structure", "Value")
+
+        # Data structures.
+        for name in dir(self):
+            if match("^__", name):
+                continue
+            if name == 'autoSelect' or name == 'userSelect':
+                continue
+            text = text + "%-25s%-100s\n" % (name, `getattr(self, name)`)
+
+        text = text + "%-25s%-100s\n" % ('select', `getattr(self, 'select')`)
+
+        # Return the lot.
+        return text
+
+
+    def __setattr__(self, name, value):
+        """Prevent accidental rebinding of select."""
+
+        # The list of prescribed attributes.
+        dontRebind = ['select', 'autoSelect']
+        if name in dontRebind:
+
+            # Allow initial binding of the attribute.
+            if not hasattr(self, name):
+                self.__dict__[name] = value
+
+            # But prevent rebinding.
+            else:
+                raise AttributeError, """Can't rebind automated residue 
selection. Use userSelect instead (do select.res())"""
+
+        # Normal behaviour for attributes not in list.
+        self.__dict__[name] = value
+

Modified: 1.2/generic_fns/selection.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/generic_fns/selection.py?rev=2389&r1=2388&r2=2389&view=diff
==============================================================================
--- 1.2/generic_fns/selection.py (original)
+++ 1.2/generic_fns/selection.py Wed Mar 15 15:46:24 2006
@@ -53,10 +53,10 @@
                 data = self.relax.data.res[self.run][i]
 
                 # Reverse the selection.
-                if data.select:
-                    data.select = 0
+                if data.userSelect:
+                    data.userSelect = 0
                 else:
-                    data.select = 1
+                    data.userSelect = 1
 
 
     def sel_all(self, run=None):
@@ -77,7 +77,7 @@
 
             # Loop over the sequence and set the selection flag to 1.
             for i in xrange(len(self.relax.data.res[self.run])):
-                self.relax.data.res[self.run][i].select = 1
+                self.relax.data.res[self.run][i].userSelect = 1
 
 
     def sel_read(self, run=None, file=None, dir=None, change_all=None):
@@ -118,11 +118,11 @@
 
                 # Unselect all residues.
                 if change_all:
-                    data.select = 0
+                    data.userSelect = 0
 
                 # Select the residue if it is in the list select.
                 if data.num in select:
-                    data.select = 1
+                    data.userSelect = 1
 
                 # Match flag.
                 no_match = 0
@@ -170,7 +170,7 @@
 
                 # Unselect all residues.
                 if change_all:
-                    data.select = 0
+                    data.userSelect = 0
 
                 # Skip the residue if there is no match to 'num'.
                 if type(num) == int:
@@ -186,7 +186,7 @@
                         continue
 
                 # Select the residue.
-                data.select = 1
+                data.userSelect = 1
 
                 # Match flag.
                 no_match = 0
@@ -214,7 +214,7 @@
 
             # Loop over the sequence and set the selection flag to 0.
             for i in xrange(len(self.relax.data.res[self.run])):
-                self.relax.data.res[self.run][i].select = 0
+                self.relax.data.res[self.run][i].userSelect = 0
 
 
     def unsel_read(self, run=None, file=None, dir=None, change_all=None):
@@ -255,11 +255,11 @@
 
                 # Select all residues.
                 if change_all:
-                    data.select = 1
+                    data.userSelect = 1
 
                 # Unselect the residue if it is in the list unselect.
                 if data.num in unselect:
-                    data.select = 0
+                    data.userSelect = 0
 
                 # Match flag.
                 no_match = 0
@@ -307,7 +307,7 @@
 
                 # Select all residues.
                 if change_all:
-                    data.select = 1
+                    data.userSelect = 1
 
                 # Skip the residue if there is no match to 'num'.
                 if type(num) == int:
@@ -323,7 +323,7 @@
                         continue
 
                 # Unselect the residue.
-                data.select = 0
+                data.userSelect = 0
 
                 # Match flag.
                 no_match = 0

Modified: 1.2/generic_fns/sequence.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/generic_fns/sequence.py?rev=2389&r1=2388&r2=2389&view=diff
==============================================================================
--- 1.2/generic_fns/sequence.py (original)
+++ 1.2/generic_fns/sequence.py Wed Mar 15 15:46:24 2006
@@ -54,7 +54,7 @@
         # Insert the data.
         self.relax.data.res[run][index].num = res_num
         self.relax.data.res[run][index].name = res_name
-        self.relax.data.res[run][index].select = select
+        self.relax.data.res[run][index].userSelect = select
 
 
     def copy(self, run1=None, run2=None):
@@ -87,7 +87,7 @@
             # Insert the data.
             self.relax.data.res[run2][i].num = 
self.relax.data.res[run1][i].num
             self.relax.data.res[run2][i].name = 
self.relax.data.res[run1][i].name
-            self.relax.data.res[run2][i].select = 
self.relax.data.res[run1][i].select
+            self.relax.data.res[run2][i].userSelect = 
self.relax.data.res[run1][i].userSelect
 
 
     def data_names(self):
@@ -156,7 +156,7 @@
             # Insert the data.
             self.relax.data.res[run][i].num = res[i].number
             self.relax.data.res[run][i].name = res[i].name
-            self.relax.data.res[run][i].select = 1
+            #self.relax.data.res[run][i].select = 1
 
 
     def read(self, run=None, file=None, dir=None, num_col=0, name_col=1, 
sep=None):
@@ -211,7 +211,7 @@
             # Insert the data.
             self.relax.data.res[run][i].num = int(file_data[i][num_col])
             self.relax.data.res[run][i].name = file_data[i][name_col]
-            self.relax.data.res[run][i].select = 1
+            #self.relax.data.res[run][i].select = 1
 
 
     def sort(self, run=None):




Related Messages


Powered by MHonArc, Updated Wed Mar 15 16:20:04 2006