1
2
3
4
5
6 """Class that maps (chain_id, residue_id) to a residue property."""
7
8
10 - def __init__(self, property_dict, property_keys, property_list):
11 self.property_dict=property_dict
12 self.property_keys=property_keys
13 self.property_list=property_list
14
17
19 """True if the mapping has a property for this residue.
20
21 Example:
22 >>> if (chain_id, res_id) in apmap:
23 ... res, prop = apmap[(chain_id, res_id)]
24
25 @param chain_id: chain id
26 @type chain_id: char
27
28 @param res_id: residue id
29 @type res_id: char
30 """
31 translated_id = self._translate_id(id)
32 return (translated_id in self.property_dict)
33
35 """
36 Return property for a residue.
37
38 @param chain_id: chain id
39 @type chain_id: char
40
41 @param res_id: residue id
42 @type res_id: int or (char, int, char)
43
44 @return: some residue property
45 @rtype: anything (can be a tuple)
46 """
47 translated_id=self._translate_id(key)
48 return self.property_dict[translated_id]
49
51 """
52 Return number of residues for which the property is available.
53
54 @return: number of residues
55 @rtype: int
56 """
57 return len(self.property_dict)
58
60 """True if the mapping has a property for this residue.
61
62 (Obsolete; use "id in mapping" instead.)
63
64 Example:
65
66 >>> if apmap.has_key((chain_id, res_id)):
67 ... res, prop = apmap[(chain_id, res_id)]
68
69 Is equivalent to:
70
71 >>> if (chain_id, res_id) in apmap:
72 ... res, prop = apmap[(chain_id, res_id)]
73
74 @param chain_id: chain id
75 @type chain_id: char
76
77 @param res_id: residue id
78 @type res_id: char
79 """
80 import warnings
81 warnings.warn("This function is obsolete; use 'id in mapping' instead", PendingDeprecationWarning)
82 return (id in self)
83
85 """
86 Return the list of residues.
87
88 @return: list of residues for which the property was calculated
89 @rtype: [(chain_id, res_id), (chain_id, res_id),...]
90 """
91 return self.property_keys
92
94 """
95 Iterate over the (entity, property) list. Handy alternative to
96 the dictionary-like access.
97
98 Example:
99 >>> for (res, property) in iter(map):
100 ... print res, property
101
102 @return: iterator
103 """
104 for i in range(0, len(self.property_list)):
105 yield self.property_list[i]
106
107
109 - def __init__(self, property_dict, property_keys, property_list):
112
114 chain_id, res_id=ent_id
115 if isinstance(res_id, int):
116 ent_id=(chain_id, (' ', res_id, ' '))
117 return ent_id
118
119
121 - def __init__(self, property_dict, property_keys, property_list):
124
126 if len(ent_id)==4:
127 chain_id, res_id, atom_name, icode=ent_id
128 else:
129 chain_id, res_id, atom_name=ent_id
130 icode=None
131 if isinstance(res_id, int):
132 ent_id=(chain_id, (' ', res_id, ' '), atom_name, icode)
133 return ent_id
134