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