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

Source Code for Module data

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003, 2004, 2006 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 # Old low precision value. 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 = DiffTensorData() 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 # Hybrid models. 58 self.hybrid_runs = {} 59 60 # Global minimisation statistics. 61 self.chi2 = {} 62 self.iter = {} 63 self.f_count = {} 64 self.g_count = {} 65 self.h_count = {} 66 self.warning = {}
67 68 69
70 - def __repr__(self):
71 text = "The data class containing all permanent program data.\n" 72 text = text + "The class contains the following objects:\n" 73 for name in dir(self): 74 if match("^__", name): 75 continue 76 text = text + " " + name + ", " + `type(getattr(self, name))` + "\n" 77 return text
78 79 80 81 # Empty data container. 82 ####################### 83
84 -class Element:
85 - def __init__(self):
86 """Empty data container."""
87 88
89 - def __repr__(self):
90 # Header. 91 text = "%-25s%-100s\n\n" % ("Data structure", "Value") 92 93 # Data structures. 94 for name in dir(self): 95 if match("^__", name): 96 continue 97 text = text + "%-25s%-100s\n" % (name, `getattr(self, name)`) 98 99 # Return the lot. 100 return text
101 102 103 # Specific data class. 104 ###################### 105
106 -class SpecificData(DictType):
107 - def __init__(self):
108 """Dictionary type class for specific data."""
109 110
111 - def __repr__(self):
112 text = "Data:\n" 113 if len(self) == 0: 114 text = text + " {}\n" 115 else: 116 i = 0 117 for key in self.keys(): 118 if i == 0: 119 text = text + " { " 120 else: 121 text = text + " , " 122 text = text + "Key " + `key` + ":\n" 123 for name in dir(self[key]): 124 if match("^__", name): 125 continue 126 text = text + " " + name + ", " + `type(getattr(self[key], name))` + "\n" 127 i = i + 1 128 text = text + " }\n" 129 130 return text
131 132
133 - def add_item(self, key):
134 """Function for adding an empty container to the dictionary.""" 135 136 self[key] = Element()
137 138 139 140 # Diffusion tensor specific data. 141 ################################# 142
143 -class DiffTensorData(SpecificData):
144 - def __init__(self):
145 """Dictionary type class for the diffusion tensor data. 146 147 The non-default diffusion parameters are calculated on the fly. 148 """
149 150
151 - def add_item(self, key):
152 """Function for adding an empty container to the dictionary. 153 154 This overwrites the function from the parent class SpecificData. 155 """ 156 157 self[key] = DiffTensorElement()
158 159 160
161 -class DiffTensorElement(Element):
162 - def __init__(self):
163 """An empty data container for the diffusion tensor elements."""
164 165
166 - def __getattr__(self, name):
167 """Function for calculating the parameters on the fly.""" 168 169 # All tensor types. 170 ################### 171 172 # Diso. 173 if name == 'Diso': 174 return 1.0 / (6.0 * self.tm) 175 176 177 # Spheroidal diffusion. 178 ####################### 179 180 # Dper = Diso - 1/3Da. 181 if name == 'Dper': 182 return self.Diso - 1.0/3.0 * self.Da 183 184 # Dpar = Diso + 2/3Da. 185 if name == 'Dpar': 186 return self.Diso + 2.0/3.0 * self.Da 187 188 # Dratio = Dpar / Dper. 189 if name == 'Dratio': 190 return self.Dpar / self.Dper 191 192 193 # Ellipsoidal diffusion. 194 ######################## 195 196 # Dx = Diso - 1/3Da(1 + 3Dr). 197 if name == 'Dx': 198 return self.Diso - 1.0/3.0 * self.Da * (1.0 + 3.0*self.Dr) 199 200 # Dy = Diso - 1/3Da(1 - 3Dr). 201 if name == 'Dy': 202 return self.Diso - 1.0/3.0 * self.Da * (1.0 - 3.0*self.Dr) 203 204 # Dz = Diso + 2/3Da. 205 if name == 'Dz': 206 return self.Diso + 2.0/3.0 * self.Da 207 208 209 # The attribute asked for does not exist. 210 raise AttributeError, name
211 212 213 214 # Residue specific data. 215 ######################## 216
217 -class Residue(DictType):
218 - def __init__(self):
219 """Class containing all the residue specific data."""
220 221
222 - def __repr__(self):
223 text = "Class containing all the residue specific data.\n\n" 224 225 # Empty. 226 if not len(self): 227 text = text + "The class contains no data.\n" 228 229 # Not empty. 230 else: 231 text = text + "The residue container contains the following keys:\n" 232 for key in self: 233 text = text + " " + `key` + "\n" 234 text = text + "\nThese can be accessed by typing 'self.relax.data.res[key]'.\n" 235 236 return text
237 238
239 - def add_list(self, key):
240 """Function for adding an empty container to the dictionary.""" 241 242 self[key] = ResidueList()
243 244
245 -class ResidueList(ListType):
246 - def __init__(self):
247 """Empty data container for residue specific data."""
248 249
250 - def __repr__(self):
251 text = "Sequence data.\n\n" 252 text = text + "%-8s%-8s%-8s%-10s" % ("Index", "Number", "Name", "Selected") + "\n" 253 for i in xrange(len(self)): 254 text = text + "%-8i%-8i%-8s%-10i" % (i, self[i].num, self[i].name, self[i].select) + "\n" 255 text = text + "\nThese can be accessed by typing 'self.relax.data.res[key][index]'.\n" 256 return text
257 258
259 - def add_item(self):
260 """Function for appending an empty container to the list.""" 261 262 self.append(Element())
263