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
76
78 return "<Chain id=%s>" % self.get_id()
79
80
81
83 """Return a list of undisordered residues.
84
85 Some Residue objects hide several disordered residues
86 (DisorderedResidue objects). This method unpacks them,
87 ie. it returns a list of simple Residue objects.
88 """
89 unpacked_list=[]
90 for residue in self.get_list():
91 if residue.is_disordered()==2:
92 for dresidue in residue.disordered_get_list():
93 unpacked_list.append(dresidue)
94 else:
95 unpacked_list.append(residue)
96 return unpacked_list
97
99 """Return 1 if a residue with given id is present.
100
101 The id of a residue is (hetero flag, sequence identifier, insertion code).
102 If id is an int, it is translated to (" ", id, " ") by the _translate_id
103 method.
104
105 Arguments:
106 o id - (string, int, string) or int
107 """
108 id=self._translate_id(id)
109 return Entity.has_id(self, id)
110
111
112
113
115 for r in self:
116 for a in r:
117 yield a
118