1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 """
26 organise, sort, and filter list of PDBModels
27 """
28 from DictList import DictList
29 from PDBModel import PDBModel
30 import Biskit.tools as T
31
33 """
34 A list of diverse PDBModels. Special support is given to access and use
35 entries in the info dictionaries for filtering and sorting.
36 Some care is taken to avoid the adding of non-PDBModel objects (but
37 somehow it is, certainly, still possible).
38
39 See DictList for a complete description of all methods!
40
41 Comparison to Trajectory:
42
43 In contrast to Trajectory, ModelList does not require structures
44 with identical atom content. This makes it of course less efficient and
45 less powerful, in many respects. On the other hand, models are kept as
46 seperate PDBModel instances with individual residue/atom profiles and
47 info dictionaries.
48 """
49
51 """
52 @param lst: list
53 @type lst: [ dict ]
54 @param item_type: type, class of allowed items [ dict ]
55 @type item_type: [ dict ]
56
57 @raise DictListError: if list contains non-item_type item.
58 """
59 DictList.__init__( self, lst, item_type )
60
61
63 """
64 Version of class.
65
66 @return: class version number
67 @rtype: str
68 """
69 return DictList.version( self ) + '; ModelList $Revision: 2.5 $'
70
71
73 """
74 Get a value from a given item (dictionary). Overrides DictList method.
75
76 @param item: possible entry of this list
77 @type item: dict
78 @param key: dictionary key
79 @type key: any
80 @param default: return value if key is not found (default: None)
81 @type default: any
82
83 @return: any
84 @rtype: any
85 """
86 return item.info.get( key, default )
87
88
90 """
91 Load PDBModel from file if necessary.
92
93 @param file_or_model: file name or existing model
94 @type file_or_model: str OR PDBModel
95
96 @return: existing model or model loaded from file
97 @rtype: PDBModel
98 """
99 if isinstance( file_or_model, PDBModel ):
100 return file_or_model
101
102 return PDBModel( file_or_model )
103
104
106 """
107 Called before an item is added to the list. Override but call.
108
109 @param i: index
110 @type i: int
111 @param v: value
112 @type v: dict
113
114 @return: value
115 @rtype: dict
116 """
117 v = self.file2model( v )
118
119 return DictList._processNewItem( self, v, i )
120
121
122
123
124
125
127 """
128 Test class
129 """
130
131
132 - def run( self, local=0 ):
133 """
134 run function test
135
136 @param local: transfer local variables to global and perform
137 other tasks only when run locally
138 @type local: 1|0
139
140 @return: list with sequences of models
141 @rtype: [str]
142 """
143 import random
144
145 f_lst = [ T.testRoot() + '/rec/1A2P.pdb',
146 T.testRoot() + '/lig/1A19.pdb',
147 T.testRoot() + '/com/1BGS.pdb' ]
148
149
150 self.l = ModelList( f_lst )
151
152 seq = []
153 for m in self.l:
154 m.info['score'] = random.random()
155 seq += [ m.compress( m.maskProtein() ).sequence() ]
156
157 p = self.l.plot( 'score' )
158
159 if local:
160 print self.l.valuesOf('score')
161 p.show()
162 globals().update( locals() )
163
164 return seq
165
166
167
169 """
170 Precalculated result to check for consistent performance.
171
172 @return: list with sequences of models
173 @rtype: [str]
174 """
175 return ['VINTFDGVADYLQTYHKLPDNYITKSEAQALGWVASKGNLADVAPGKSIGGDIFSNREGKLPGKSGRTWREADINYTSGFRNSDRILYSSDWLIYKTTDHYQTFTKIR', 'KKAVINGEQIRSISDLHQTLKKELALPEYYGENLDALWDCLTGWVEYPLVLEWRQFEQSKQLTENGAESVLQVFREAKAEGADITIILS', 'AQVINTFDGVADYLQTYHKLPDNYITKSEAQALGWVASKGNLADVAPGKSIGGDIFSNREGKLPGKSGRTWREADINYTSGFRNSDRILYSSDWLIYKTTDHYQTFTKIRKKAVINGEQIRSISDLHQTLKKELALPEYYGENLDALWDALTGWVEYPLVLEWRQFEQSKQLTENGAESVLQVFREAKAEGADITIILS']
176
177
178
179 if __name__ == '__main__':
180
181 test = Test()
182
183 assert test.run( local=1 ) == test.expected_result()
184