Module data
[hide private]
[frames] | no frames]

Source Code for Module data

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003, 2004 Edward d'Auvergne                                  # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23   
 24  from math import pi 
 25  from re import match 
 26  from types import DictType, ListType 
 27   
 28   
 29  # Global data. 
 30  ############## 
 31   
32 -class Data:
33 - def __init__(self):
34 """Class containing all the program data.""" 35 36 # Fundamental constants. 37 #self.h = 6.6260755e-34 38 self.h = 6.62606876e-34 39 self.h_bar = self.h / ( 2.0*pi ) 40 self.mu0 = 4.0 * pi * 1e-7 41 42 # PDB data. 43 self.pdb = SpecificData() 44 45 # Diffusion data. 46 self.diff = SpecificData() 47 48 # The residue specific data. 49 self.res = Residue() 50 51 # The name of the runs. 52 self.run_names = [] 53 54 # The type of the runs. 55 self.run_types = [] 56 57 # Global minimisation statistics. 58 self.chi2 = {} 59 self.iter = {} 60 self.f_count = {} 61 self.g_count = {} 62 self.h_count = {} 63 self.warning = {}
64 65 66
67 - def __repr__(self):
68 text = "The data class containing all permanent program data.\n" 69 text = text + "The class contains the following objects:\n" 70 for name in dir(self): 71 if match("^__", name): 72 continue 73 text = text + " " + name + ", " + `type(getattr(self, name))` + "\n" 74 return text
75 76 77 78 # Empty data container. 79 ####################### 80
81 -class Element:
82 - def __init__(self):
83 """Empty data container."""
84 85
86 - def __repr__(self):
87 # Header. 88 text = "%-25s%-100s\n\n" % ("Data structure", "Value") 89 90 # Data structures. 91 for name in dir(self): 92 if match("^__", name): 93 continue 94 text = text + "%-25s%-100s\n" % (name, `getattr(self, name)`) 95 96 # Return the lot. 97 return text
98 99 100 # Specific data class. 101 ###################### 102
103 -class SpecificData(DictType):
104 - def __init__(self):
105 """Dictionary type class for specific data."""
106 107
108 - def __repr__(self):
109 text = "Data:\n" 110 if len(self) == 0: 111 text = text + " {}\n" 112 else: 113 i = 0 114 for key in self.keys(): 115 if i == 0: 116 text = text + " { " 117 else: 118 text = text + " , " 119 text = text + "Key " + `key` + ":\n" 120 for name in dir(self[key]): 121 if match("^__", name): 122 continue 123 text = text + " " + name + ", " + `type(getattr(self[key], name))` + "\n" 124 i = i + 1 125 text = text + " }\n" 126 127 return text
128 129
130 - def add_item(self, key):
131 """Function for adding an empty container to the dictionary.""" 132 133 self[key] = Element()
134 135 136 137 # Residue specific data. 138 ######################## 139
140 -class Residue(DictType):
141 - def __init__(self):
142 """Class containing all the residue specific data."""
143 144
145 - def __repr__(self):
146 text = "Class containing all the residue specific data.\n\n" 147 148 # Empty. 149 if not len(self): 150 text = text + "The class contains no data.\n" 151 152 # Not empty. 153 else: 154 text = text + "The residue container contains the following keys:\n" 155 for key in self: 156 text = text + " " + `key` + "\n" 157 text = text + "\nThese can be accessed by typing 'self.relax.data.res[key]'.\n" 158 159 return text
160 161
162 - def add_list(self, key):
163 """Function for adding an empty container to the dictionary.""" 164 165 self[key] = ResidueList()
166 167
168 -class ResidueList(ListType):
169 - def __init__(self):
170 """Empty data container for residue specific data."""
171 172
173 - def __repr__(self):
174 text = "Sequence data.\n\n" 175 text = text + "%-8s%-8s%-8s%-10s" % ("Index", "Number", "Name", "Selected") + "\n" 176 for i in xrange(len(self)): 177 text = text + "%-8i%-8i%-8s%-10i" % (i, self[i].num, self[i].name, self[i].select) + "\n" 178 text = text + "\nThese can be accessed by typing 'self.relax.data.res[key][index]'.\n" 179 return text
180 181
182 - def add_item(self):
183 """Function for appending an empty container to the list.""" 184 185 self.append(Element())
186