mailr3141 - /1.3/data/mol_res_spin.py


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

Header


Content

Posted by edward on March 10, 2007 - 00:42:
Author: bugman
Date: Sat Mar 10 00:42:21 2007
New Revision: 3141

URL: http://svn.gna.org/viewcvs/relax?rev=3141&view=rev
Log:
Completion of the core of the molecule-residue-spin data structures.

All of the initialisation of the class variables and objects in all six 
classes have been shifted
into __init__() methods so that new copies of the objects are created when 
molecules, residues, or
spins are added to the structure.

The __repr__() methods of all classes have been updated and return a proper 
text representation of
the objects.

The XList class docstrings have been updated.


Modified:
    1.3/data/mol_res_spin.py

Modified: 1.3/data/mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/data/mol_res_spin.py?rev=3141&r1=3140&r2=3141&view=diff
==============================================================================
--- 1.3/data/mol_res_spin.py (original)
+++ 1.3/data/mol_res_spin.py Sat Mar 10 00:42:21 2007
@@ -36,36 +36,69 @@
 class SpinContainer:
     """Class containing all the spin system specific data."""
 
-
-    def __repr__(self):
+    def __init__(self):
+        """Set up the default objects of the spin system data container."""
+
+        # The spin system name and number.
+        self.name = None
+        self.num = None
+        self.select = 1
+
+
+    def __repr__(self):
+        """The string representation of the object.
+
+        Rather than using the standard Python conventions (either the string 
representation of the
+        value or the "<...desc...>" notation), a rich-formatted description 
of the object is given.
+        """
 
         # Intro.
         text = "Class containing all the spin system specific data.\n\n"
 
-        # Empty.
-        if not len(self):
-            text = text + "The class contains no data.\n"
-
-        # Not empty.
-        else:
-            text = text + "The spin system container has the following 
keys:\n"
-            for key in self:
-                text = text + "    " + `key` + "\n"
-            text = text + "\nThese can be accessed by typing 
'relax_data_store.res[key]'.\n"
+        # Objects.
+        text = text + "\n"
+        text = text + "Objects:\n"
+        for name in dir(self):
+            # Spin systems.
+            if name == 'spin':
+                text = text + "  spin: The list of spin systems of the 
residues\n"
+
+            # Skip certain objects.
+            if match("^_", name) or name == 'spin':
+                continue
+
+            # Add the object's attribute to the text string.
+            text = text + "  " + name + ": " + `getattr(self, name)` + "\n"
 
         return text
 
 
 class SpinList(ListType):
-    """Empty data container for spin system specific data."""
-
-
-    def __repr__(self):
+    """List type data container for spin system specific data."""
+
+    def __init__(self):
+        """Set up the first spin system data container."""
+
+        # Add the initial spin system container at index 0.
+        self.append(SpinContainer())
+
+
+    def __repr__(self):
+        """The string representation of the object.
+
+        Rather than using the standard Python conventions (either the string 
representation of the
+        value or the "<...desc...>" notation), a rich-formatted description 
of the object is given.
+        """
+
+        # Intro.
         text = "Spin systems.\n\n"
+
+        # Residue data.
         text = text + "%-8s%-8s%-8s%-10s" % ("Index", "Number", "Name", 
"Selected") + "\n"
         for i in xrange(len(self)):
-            text = text + "%-8i%-8i%-8s%-10i" % (i, self[i].num, 
self[i].name, self[i].select) + "\n"
-        text = text + "\nThese can be accessed by typing 
'relax_data_store.res[key][index]'.\n"
+            text = text + "%-8i%-8s%-8s%-10i" % (i, `self[i].num`, 
self[i].name, self[i].select) + "\n"
+        text = text + "\nThese can be accessed by typing 
'D.mol[i].res[j].spin[k]', where D is the relax data storage object.\n"
+
         return text
 
 
@@ -82,40 +115,71 @@
 class ResidueContainer:
     """Class containing all the residue specific data."""
 
-
-    def __repr__(self):
-        text = "Class containing all the residue specific data.\n\n"
-
-        # Empty.
-        if not len(self):
-            text = text + "The class contains no data.\n"
-
-        # Not empty.
-        else:
-            text = text + "The residue container has the following keys:\n"
-            for key in self:
-                text = text + "    " + `key` + "\n"
-            text = text + "\nThese can be accessed by typing 
'relax_data_store.res[key]'.\n"
-
-        return text
-
-
-    def add_list(self, key):
-        """Function for adding an empty container to the dictionary."""
-
-        self[key] = ResidueList()
+    def __init__(self):
+        """Set up the default objects of the residue data container."""
+
+        # The residue name and number.
+        self.name = None
+        self.num = None
+
+        # The empty spin system list.
+        self.spin = SpinList()
+
+
+    def __repr__(self):
+        """The string representation of the object.
+
+        Rather than using the standard Python conventions (either the string 
representation of the
+        value or the "<...desc...>" notation), a rich-formatted description 
of the object is given.
+        """
+
+        # Intro.
+        text = "Class containing all the residue specific data.\n"
+
+        # Objects.
+        text = text + "\n"
+        text = text + "Objects:\n"
+        for name in dir(self):
+            # Spin systems.
+            if name == 'spin':
+                text = text + "  spin: The list of spin systems of the 
residues\n"
+
+            # Skip certain objects.
+            if match("^_", name) or name == 'spin':
+                continue
+
+            # Add the object's attribute to the text string.
+            text = text + "  " + name + ": " + `getattr(self, name)` + "\n"
+
+        return text
 
 
 class ResidueList(ListType):
-    """Empty data container for residue specific data."""
-
-
-    def __repr__(self):
-        text = "Sequence data.\n\n"
-        text = text + "%-8s%-8s%-8s%-10s" % ("Index", "Number", "Name", 
"Selected") + "\n"
+    """List type data container for residue specific data."""
+
+    def __init__(self):
+        """Set up the first residue data container."""
+
+        # Add the initial residue container at index 0.
+        self.append(ResidueContainer())
+
+
+    def __repr__(self):
+        """The string representation of the object.
+
+        Rather than using the standard Python conventions (either the string 
representation of the
+        value or the "<...desc...>" notation), a rich-formatted description 
of the object is given.
+        """
+
+        # Intro.
+        text = "Residues.\n\n"
+
+        # Residue data.
+        text = text + "%-8s%-8s%-8s" % ("Index", "Number", "Name") + "\n"
         for i in xrange(len(self)):
-            text = text + "%-8i%-8i%-8s%-10i" % (i, self[i].num, 
self[i].name, self[i].select) + "\n"
-        text = text + "\nThese can be accessed by typing 
'relax_data_store.res[key][index]'.\n"
+            text = text + "%-8i%-8s%-8s" % (i, `self[i].num`, self[i].name) 
+ "\n"
+        text = text + "\nThese can be accessed by typing 'D.mol[i].res[j]', 
where D is the relax data storage object.\n"
+
         return text
 
 
@@ -132,11 +196,14 @@
 class MoleculeContainer:
     """Class containing all the molecule specific data."""
 
-    # The name of the molecule, corresponding to that of the structure file 
if specified.
-    name = None
-
-    # The empty residue list.
-    res = ResidueList()
+    def __init__(self):
+        """Set up the default objects of the molecule data container."""
+
+        # The name of the molecule, corresponding to that of the structure 
file if specified.
+        self.name = None
+
+        # The empty residue list.
+        self.res = ResidueList()
 
 
     def __repr__(self):
@@ -155,7 +222,7 @@
         for name in dir(self):
             # Residue list.
             if name == 'res':
-                text = text + "  res: The list of the residues of the 
molecule is the object\n"
+                text = text + "  res: The list of the residues of the 
molecule\n"
 
             # Skip certain objects.
             if match("^_", name) or name == 'res':
@@ -168,7 +235,13 @@
 
 
 class MoleculeList(ListType):
-    """Empty data container for the molecule specific data."""
+    """List type data container for the molecule specific data."""
+
+    def __init__(self):
+        """Set up the first molecule data container."""
+
+        # Add the initial molecule container at index 0.
+        self.append(MoleculeContainer())
 
 
     def __repr__(self):
@@ -176,7 +249,7 @@
         text = text + "%-8s%-8s" % ("Index", "Name") + "\n"
         for i in xrange(len(self)):
             text = text + "%-8i%-8s" % (i, self[i].name) + "\n"
-        text = text + "\nThese can be accessed by typing 'D.mol[index]', 
where D is the relax data storage object.\n"
+        text = text + "\nThese can be accessed by typing 'D.mol[i]', where D 
is the relax data storage object.\n"
         return text
 
 




Related Messages


Powered by MHonArc, Updated Sat Mar 10 01:20:07 2007