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 """
27 List of ComplexEvolving instances.
28 """
29
30 from Biskit.Dock.ComplexList import ComplexList, ComplexListError
31 from Biskit.Dock.ComplexEvolving import ComplexEvolving
32 import numpy.oldnumeric as N
33
35 """
36 List of ComplexEvolving instances.
37 Used for organising, sorting, and filtering Complexes during refinement.
38
39 @todo: implement plotting functions for evolving Complexes
40 @todo: right now normal Complexes are tolerated
41 @todo: adapt model management
42 @see: L{Dock.ComplexEvolving}
43 """
44
46 """
47 @param lst: list of Complexes
48 @type lst: [ComplexEvolving]
49
50 @raise ComplexListError: if list contains non-Complex item.
51 """
52 ComplexList.__init__( self, lst )
53
54
56 """
57 Version of Dock.Complex
58
59 @return: version of class
60 @rtype: str
61 """
62 return 'ComplexEvolvingList $Revision: 2.10 $'
63
64
66 """
67 Make sure v is a ComplexEvolving
68
69 @param v: any
70 @type v: any
71
72 @raise ComplexListError: if list contains non-Complex item.
73 """
74 if not isinstance(v, ComplexEvolving):
75 raise ComplexListError(
76 str( v ) + " not allowed. ComplexList requires "+
77 str(ComplexEvolving))
78
79
81 """
82 Get all versions of each Complex as a seperate Complex instance.
83
84 @return: ComplexList of normal Complex instances
85 @rtype: ComplexList
86 """
87 r = ComplexList()
88
89 for c in self:
90 try:
91 r += c.toList()
92 except:
93 r += [ c ]
94
95 return r
96
97
99 """
100 Get a ComplexList that contains only a single version of each Complex.
101
102 @param version: version in history, -1 == last [-1] (default: -1)
103 @type version: int
104
105 @return: ComplexList
106 @rtype: ComplexList
107 """
108 return ComplexList( [ c[ version ] for c in self ] )
109
110
111 - def toList( self, version=None ):
112 """
113 Get a simple python list of Complexes. If version==None, the list
114 contains ComplexEvolving instances with all versions, otherwise
115 the list contains Complex instances representing a single version.
116
117 @param version: version in history, -1 == last, None == all
118 (default: None)
119 @type version: int
120
121 @return: python list of Complexes
122 @rtype: [ Complex ]
123 """
124 if version is None:
125 return ComplexList.toList( self )
126
127 return [ c[ version ] for c in self ]
128
129
130 - def valuesOf( self, infoKey, version=None, default=None,
131 indices=None, unique=0 ):
132 """
133 Get all values of a certain info record of all or some Complexes.
134
135 @param infoKey: key for info dict
136 @type infoKey: str
137 @param version: index in history or None (=current) (default: None)
138 @type version: int
139 @param default: default value if infoKey is not found (default: None)
140 @type default: any
141 @param indices: list of int OR None(=all), indices of Complexes
142 (default: None)
143 @type indices: [int] OR None
144 @param unique: report each value only once (set union), (default: 0)
145 @type unique: 1|0
146
147 @return: list of values
148 @rtype: [any]
149 """
150 l = self
151 if indices != None:
152 l = N.take( l, indices )
153
154 if not unique:
155 if version is None:
156 return [ c.get(infoKey, default) for c in l ]
157 return [ c[version].get( infoKey, default) for c in l ]
158
159 r = []
160 for c in l:
161 if version is not None:
162 c = c[ version ]
163
164 if c.info.get(infoKey, default) not in r:
165 r += [ c.info.get( infoKey ) ]
166
167 return r
168
169
170
171
172
173 import Biskit.test as BT
174
175 -class Test(BT.BiskitTest):
176 """Test case"""
177
179 """Dock.ComplexEvolvingList test"""
180
181 import Biskit.tools as t
182 from Biskit.Dock import ComplexEvolving
183 from Biskit.Dock import ComplexEvolvingList
184
185
186 cl = t.Load( t.testRoot() + "/dock/hex/complexes.cl" )
187
188
189 c = ComplexEvolving( cl[0].rec(), cl[0].lig(), cl[0],
190 info={'comment':'test1'})
191
192
193 c = ComplexEvolving( c.rec(), c.lig(), c,
194 info={'comment':'test2'})
195
196
197 cl = ComplexEvolvingList( [c, c] )
198
199 if self.local:
200
201 print cl.valuesOf('comment')
202
203
204 print cl.valuesOf('comment', version=1)
205
206
207 print cl[0].valuesOf('comment')
208
209 globals().update( locals() )
210
211 self.assertEqual( (cl.valuesOf('comment'), cl[0].valuesOf('comment')),
212 (['test2', 'test2'], [None, 'test1', 'test2']) )
213
214 if __name__ == '__main__':
215
216 BT.localTest()
217