1
2
3
4
5
6 """
7 Module to represent the NDB Atlas structure (a minimal subset of PDB format).
8
9 Hetero, Crystal and Chain exist to represent the NDB Atlas structure. Atlas
10 is a minimal subset of the PDB format. Heteo supports a 3 alphameric code.
11 The NDB web interface is located at http://ndbserver.rutgers.edu/NDB/index.html
12 """
13
14 import copy
15
16
19
20
22 output = ''
23 for i in range(0, len(line), 80):
24 output = output + '%s\n' % line[ i: i + 80 ]
25 return output
26
27
29 if not isinstance(key, str):
30 raise CrystalError('chain requires a string label')
31 if len(key) != 1:
32 raise CrystalError('chain label should contain one letter')
33
34
36 """
37 This class exists to support the PDB hetero codes.
38
39 Supports only the 3 alphameric code.
40 The annotation is available from http://alpha2.bmc.uu.se/hicup/
41 """
43
44 if not isinstance(data, str):
45 raise CrystalError('Hetero data must be an alphameric string')
46 if data.isalnum() == 0:
47 raise CrystalError('Hetero data must be an alphameric string')
48 if len(data) > 3:
49 raise CrystalError('Hetero data may contain up to 3 characters')
50 if len(data) < 1:
51 raise CrystalError('Hetero data must not be empty')
52
53 self.data = data[:].lower()
54
57
59 """Returns true iff self is not equal to other."""
60 return not self.__eq__(other)
61
63 return "%s" % self.data
64
66 return "%s" % self.data
67
70
71
73 """This class represents a sequence of Hetero elements."""
74
76 self.data = []
77 if isinstance(residues, str):
78 residues = residues.replace('*', ' ')
79 residues = residues.strip()
80 elements = residues.split()
81 self.data = map(Hetero, elements)
82 elif isinstance(residues, list):
83 for element in residues:
84 if not isinstance(element, Hetero):
85 raise CrystalError('Text must be a string')
86 for residue in residues:
87 self.data.append(residue)
88 elif isinstance(residues, Chain):
89 for residue in residues:
90 self.data.append(residue)
91 self.validate()
92
97
99 if not isinstance(element, Hetero):
100 raise TypeError
101
103 output = ''
104 for element in self.data:
105 output = output + '%s ' % element
106 output = output.strip()
107 output = wrap_line(output)
108 return output
109
111 if len(self.data) != len(other.data):
112 return 0
113 ok = reduce(lambda x, y: x and y, map(lambda x, y: x == y, self.data, other.data))
114 return ok
115
117 """Returns true iff self is not equal to other."""
118 return not self.__eq__(other)
119
121 return len(self.data)
122
124 if isinstance(index, int):
125 return self.data[index]
126 elif isinstance(index, slice):
127 return self.__class__(self.data[index])
128 else:
129 raise TypeError
130
149
152
159
166
173
177
184
191
199
207
216
217
219 """This class represents a dictionary of labeled chains from the
220 same structure"""
221
228
230 data = self.data
231 for key in data:
232 element = data[key]
233 if isinstance(element, Chain):
234 pass
235 elif isinstance(element, str):
236 data[key] = Chain(element)
237 else:
238 raise TypeError
239
241 output = ''
242 keys = self.data.keys()
243 keys.sort()
244 for key in keys:
245 output = output + '%s : %s\n' % (key, self.data[ key ])
246 return output
247
249 output = ''
250 keys = self.data.keys()
251 keys.sort()
252 for key in keys:
253 output = output + '%s : %s\n' % (key, self.data[ key ])
254 return output
255
258
260 return len(self.data)
261
263 return self.data[key]
264
266 if isinstance(item, Chain):
267 self.data[key] = item
268 elif isinstance(item, str):
269 self.data[ key ] = Chain(item)
270 else:
271 raise TypeError
272
275
278
281
284
287
290
293
295 return key in self.data
296
297 - def get(self, key, failobj=None):
298 return self.data.get(key, failobj)
299
301 if key not in self.data:
302 self.data[key] = failobj
303 return self.data[key]
304
307