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 """
28 Analyze HEX docking result.
29 """
30
31 import Biskit.tools as t
32 from Biskit import Trajectory, mathUtils, molUtils
33
34
35 import numpy.oldnumeric as N
36 import numpy.oldnumeric.random_array as RandomArray
37 import copy
38
39 import biggles
40
42 pass
43
45
46 - def __init__( self, verbose=1, **options ):
47 """
48 @param verbose: verbosity level (default: 1)
49 @type verbose: 1|0
50 @param options: needs::
51 rec,lig - file name, receptor, ligand trajectories
52 ref - file name, pickled reference complex
53 @type options: any
54
55 @raise AnalyzeError: if atoms are not aligned
56 """
57 self.options = options
58
59 if verbose: t.flushPrint("\nLoading...")
60 self.t_lig = t.Load( options['lig'] )
61 self.t_rec = t.Load( options['rec'] )
62 self.com= t.Load( options['ref'] )
63
64
65 self.t_lig.removeAtoms( self.t_lig.getRef().maskH() )
66 self.t_rec.removeAtoms( self.t_rec.getRef().maskH() )
67
68 self.com.rec_model.remove( self.com.rec_model.maskH() )
69 self.com.lig_model.remove( self.com.lig_model.maskH() )
70 self.com.lig_transformed = None
71
72
73 if verbose: t.flushPrint('\nCasting...')
74
75 bnd_rec = self.com.rec()
76 bnd_lig = self.com.lig_model
77
78 self.t_rec.sortAtoms()
79 self.t_lig.sortAtoms()
80
81 bnd_rec = bnd_rec.sort()
82 bnd_lig = bnd_lig.sort()
83
84
85
86
87 i_bnd_rec, i_t_rec = bnd_rec.compareAtoms( self.t_rec.getRef() )
88 i_bnd_lig, i_t_lig = bnd_lig.compareAtoms( self.t_lig.getRef() )
89
90
91
92
93 self.t_rec = self.t_rec.takeAtoms( i_t_rec )
94 self.t_lig = self.t_lig.takeAtoms( i_t_lig )
95
96
97
98 self.i_free_lig = i_t_lig
99 self.i_free_rec = i_t_rec
100
101
102
103 bnd_rec = bnd_rec.take( i_bnd_rec )
104 bnd_lig = bnd_lig.take( i_bnd_lig )
105
106
107
108 self.i_bnd_rec = i_bnd_rec
109 self.i_bnd_lig = i_bnd_lig
110
111
112 self.com.rec_model = bnd_rec
113 self.com.lig_model = bnd_lig
114 self.com.lig_transformed = None
115
116
117 if not self.t_rec.getRef().equals( self.com.rec() )[1] or \
118 not self.t_lig.getRef().equals( self.com.lig() )[1]:
119
120 raise AnalyzeError('Atoms are not aligned.')
121
122
123 self.contacts = self.com.atomContacts()
124
125 self.hexContacts = None
126
127
129 """
130 Compare complexes of list to native complex to see if
131 their contact surfaces overlapp with the native complex.
132
133 @param cutoff: fraction cutoff for defining a overlap (default: 0.1)
134 @type cutoff: float
135
136 @return: list of len(self.hexContacts) overlapping with
137 native contact surface of lig and rec (0 - no overlap,
138 1 - rec OR lig overlapps, 2- rec AND lig overlapps)
139 @rtype: [0|1|2]
140 """
141 result = [ self.com.fractionNativeSurface( c, self.contacts )
142 for c in self.hexContacts ]
143
144 result = [ N.sum( N.greater( o, cutoff ) ) for o in result ]
145 return result
146
147
149 """
150 add contact matrices of hex-generated (wrong) complexes for comparison
151
152 @param com_lst: ComplexList with contacts calculated
153 @type com_lst: ComplexList
154 """
155 t.flushPrint('adding hex-generated complexes')
156
157 self.hexContacts = []
158
159
160
161 i = 0
162 while i < n:
163
164 com = com_lst[i]
165 t.flushPrint('#')
166
167 try:
168 if com['fractNatCont'] == 0.0:
169 com.rec_model.remove( com.rec().maskH() )
170 com.lig_model.remove( com.lig_model.maskH() )
171
172 com.rec_model = com.rec_model.sort()
173 com.lig_model = com.lig_model.sort()
174
175 com.rec_model.keep( self.i_free_rec )
176 com.lig_model.keep( self.i_free_lig )
177 com.lig_transformed = None
178
179 self.hexContacts += [ com.atomContacts() ]
180
181 else:
182 n += 1
183 i+= 1
184 except:
185 print t.lastError()
186
187 self.hexSurfaces = self.__categorizeHexSurf( 0.2 )
188
189
235
236
238 """
239 shuffle order of lst
240
241 @param lst: list to shuffle
242 @type lst: [any]
243
244 @return: shuffeled list
245 @rtype: [any]
246 """
247 pos = RandomArray.permutation( len( lst ))
248 return N.take( lst, pos )
249
250
252 """
253 shuffle order of a list n times, leaving masked(0) elements untouched
254
255 @param n: number of times to shuffle the list
256 @type n: int
257 @param lst: list to shuffle
258 @type lst: [any]
259 @param mask: mask to be applied to lst
260 @type mask: [1|0]
261
262 @return: list of shuffeled lists
263 @rtype: [[any]]
264 """
265 if not mask:
266 mask = N.ones( len(lst) )
267
268 if type( lst ) == list:
269 lst = N.array( lst )
270
271 pos = N.nonzero( mask )
272
273 rand_pos = N.array( [ self.__shuffleList( pos ) for i in range(n) ] )
274
275 result = []
276 for p in rand_pos:
277
278 r = copy.copy( lst )
279 N.put( r, p, N.take( lst, pos ) )
280 result += [r]
281
282 return result
283
284
286 """
287 add curve to current plot, with x1..xn = 0..n and y1..yn = |list|
288
289 @param list: list to plot
290 @type list: [any]
291 """
292
293 self.plot.add( biggles.Curve( range( len(list) ), list, **arg ) )
294
295 if arg.has_key('label'):
296 self.plot.lastY -= .05
297
298 self.plot.add( biggles.PlotLabel( self.plot.lastX, self.plot.lastY,
299 arg['label'], **arg ))
300
302 """
303 override for actual plotting
304 """
305 pass
306
307
309 """
310 override for plot creation
311 """
312 self.page = biggles.FramedPlot()
313 self.plot = self.page
314
315
323
324
325
326
327
328
329 import Biskit.test as BT
330
331 -class Test(BT.BiskitTest):
332 """Hmmer test"""
333
334
336 import tempfile
337 self.f_out = tempfile.mktemp( '_test_rec.traj' )
338
341
367
368
369 if __name__ == '__main__':
370
371 BT.localTest()
372