1
2
3
4
5
6
7 from types import IntType
8
9
10 from Entity import Entity
11
12 __doc__="Chain class, used in Structure objects."
13
14
19
20
21
23 """Sort function for residues in a chain
24
25 Residues are first sorted according to their hetatm records.
26 Protein and nucleic acid residues first, hetatm residues next,
27 and waters last. Within each group, the residues are sorted according
28 to their resseq's (sequence identifiers). Finally, residues with the
29 same resseq's are sorted according to icode.
30
31 Arguments:
32 o r1, r2 - Residue objects
33 """
34 hetflag1, resseq1, icode1=r1.id
35 hetflag2, resseq2, icode2=r2.id
36 if hetflag1!=hetflag2:
37 return cmp(hetflag1[0], hetflag2[0])
38 elif resseq1!=resseq2:
39 return cmp(resseq1, resseq2)
40 return cmp(icode1, icode2)
41
43 """
44 A residue id is normally a tuple (hetero flag, sequence identifier,
45 insertion code). Since for most residues the hetero flag and the
46 insertion code are blank (i.e. " "), you can just use the sequence
47 identifier to index a residue in a chain. The _translate_id method
48 translates the sequence identifier to the (" ", sequence identifier,
49 " ") tuple.
50
51 Arguments:
52 o id - int, residue resseq
53 """
54 if type(id)==IntType:
55 id=(' ', id, ' ')
56 return id
57
58
59
61 """Return the residue with given id.
62
63 The id of a residue is (hetero flag, sequence identifier, insertion code).
64 If id is an int, it is translated to (" ", id, " ") by the _translate_id
65 method.
66
67 Arguments:
68 o id - (string, int, string) or int
69 """
70 id=self._translate_id(id)
71 return Entity.__getitem__(self, id)
72
80
82 return "<Chain id=%s>" % self.get_id()
83
84
85
87 """Return a list of undisordered residues.
88
89 Some Residue objects hide several disordered residues
90 (DisorderedResidue objects). This method unpacks them,
91 ie. it returns a list of simple Residue objects.
92 """
93 unpacked_list=[]
94 for residue in self.get_list():
95 if residue.is_disordered()==2:
96 for dresidue in residue.disordered_get_list():
97 unpacked_list.append(dresidue)
98 else:
99 unpacked_list.append(residue)
100 return unpacked_list
101
103 """Return 1 if a residue with given id is present.
104
105 The id of a residue is (hetero flag, sequence identifier, insertion code).
106 If id is an int, it is translated to (" ", id, " ") by the _translate_id
107 method.
108
109 Arguments:
110 o id - (string, int, string) or int
111 """
112 id=self._translate_id(id)
113 return Entity.has_id(self, id)
114
115
116
117
119 for r in self:
120 for a in r:
121 yield a
122