1
2
3
4
5
6 from types import IntType
7
8 __doc__="Class that maps (chain_id, residue_id) to a residue property"
9
10
12 - def __init__(self, property_dict, property_keys, property_list):
13 self.property_dict=property_dict
14 self.property_keys=property_keys
15 self.property_list=property_list
16
19
21 """
22 Return property for a residue.
23
24 @param chain_id: chain id
25 @type chain_id: char
26
27 @param res_id: residue id
28 @type res_id: int or (char, int, char)
29
30 @return: some residue property
31 @rtype: anything (can be a tuple)
32 """
33 translated_id=self._translate_id(key)
34 return self.property_dict[translated_id]
35
37 """
38 Return number of residues for which the property is available.
39
40 @return: number of residues
41 @rtype: int
42 """
43 return len(self.property_dict)
44
46 """
47 Return 1 if the map has a property for this residue, 0 otherwise.
48
49 Example:
50 >>> if map.has_key((chain_id, res_id)):
51 >>> res, property=map[(chain_id, res_id)]
52
53 @param chain_id: chain id
54 @type chain_id: char
55
56 @param res_id: residue id
57 @type res_id: char
58 """
59 translated_id=self._translate_id(id)
60 return self.property_dict.has_key(translated_id)
61
63 """
64 Return the list of residues.
65
66 @return: list of residues for which the property was calculated
67 @rtype: [(chain_id, res_id), (chain_id, res_id),...]
68 """
69 return self.property_keys
70
72 """
73 Iterate over the (entity, property) list. Handy alternative to
74 the dictionary-like access.
75
76 Example:
77 >>> for (res, property) in iter(map):
78 >>> print res, property
79
80 @return: iterator
81 """
82 for i in range(0, len(self.property_list)):
83 yield self.property_list[i]
84
85
87 - def __init__(self, property_dict, property_keys, property_list):
90
92 chain_id, res_id=ent_id
93 if type(res_id)==IntType:
94 ent_id=(chain_id, (' ', res_id, ' '))
95 return ent_id
96
98 - def __init__(self, property_dict, property_keys, property_list):
101
103 if len(ent_id)==4:
104 chain_id, res_id, atom_name, icode=ent_id
105 else:
106 chain_id, res_id, atom_name=ent_id
107 icode=None
108 if type(res_id)==IntType:
109 ent_id=(chain_id, (' ', res_id, ' '), atom_name, icode)
110 return ent_id
111