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 Create Complexes with random orientation from a receptor and ligand structure.
29 """
30
31 from Biskit.Dock.Complex import Complex
32 import Biskit.mathUtils as ma
33 import Biskit.molUtils as mol
34 import Biskit.tools as t
35 import numpy.oldnumeric.random_array as ra
36 import numpy.oldnumeric as N
37 from Biskit import Xplorer, PCRModel
38
39 import tempfile
40
42 """
43 Create Biskit.Dock.Complex(es) with random orientation
44 """
45
46 - def __init__( self, mrec, mlig, rec_out=None, lig_out=None, debug=0 ):
47 """
48 @param mrec: receptor model
49 @type mrec: PCRModel
50 @param mlig: ligand model
51 @type mlig: PCRModel
52 @param rec_out: rec output(default: None)
53 @type rec_out: str
54 @param lig_out: lig output (default: None)
55 @type lig_out: str
56 @param debug: 1, keep temporary xplor files (default: 0)
57 @type debug: 1|0
58 """
59
60 self.rec = self.__center_model( mrec )
61 self.lig = self.__center_model( mlig )
62
63
64 if rec_out:
65 self.rec.saveAs( rec_out )
66 if lig_out:
67 self.lig.saveAs( lig_out )
68
69
70 self.d_max_rec = self.__max_distance( self.rec )
71 self.d_max_lig = self.__max_distance( self.lig )
72
73 self.xp_log = tempfile.mktemp('rb_min_xplor_log')
74
75
76 self.debug = debug
77
78
80 """
81 translate PDBModel so that it's center is in 0,0,0
82
83 @param model: model to center
84 @type model: PDBModel
85
86 @return: PDBModel (clone of model)
87 @rtype: PDBModel
88 """
89 r = model.clone()
90 r.keep( N.nonzero( N.logical_not( r.maskH2O() ) ) )
91 center = r.centerOfMass()
92 r.setXyz( r.getXyz() - center )
93
94 return r
95
96
98 """
99 largest center to any other atom distance
100
101 @param model: model with centered coordinates
102 @type model: PDBModel
103
104 @return: largest distance
105 @rtype: float
106 """
107 center = model.centerOfMass()
108 dist = N.sqrt( N.sum( ( model.getXyz()-center )**2 , 1 ) )
109
110 return max( dist )
111
112
114 """
115 Random translation on a sphere around 0,0,0 with fixed radius
116 The radius is the sum of the (max) radius of receptor and ligand
117
118 @return: translation array 3 x 1 of float
119 @rtype: array
120 """
121 radius = (self.d_max_rec + self.d_max_lig) / 2.0
122 xyz = ra.random( 3 ) - 0.5
123
124 scale = radius*1.0 / N.sqrt( N.sum( xyz**2 ) )
125
126 return scale * xyz
127
128
130 """
131 Random rotation matrix.
132
133 @return: 4 x 4 array of float, random rotation and translation matrix
134 @rtype: array
135 """
136 r = ma.randomRotation()
137
138 t = self.__random_translation()
139
140
141 result = N.concatenate( (r, N.transpose( [ t.tolist() ] )), 1)
142
143
144 result = N.concatenate( (result, N.array([[0,0,0,1]], N.Float32)), 0 )
145
146 return result
147
148
150 """
151 Create a complex where the recrptor and ligand have random
152 orientations but are spaced within contact distance.
153
154 @return: rec & lig spaced r_rec + r_lig apart in random orientation
155 @rtype: Complex
156 """
157 return Complex( self.rec, self.lig,
158 ligMatrix= self.__random_matrix() )
159
160
162 """
163 Use Xplor to rigid body minimize the random complex.
164
165 @param com: random complex
166 @type com: Complex
167 """
168 xp = ComplexMinimizer( com, t.tempDir(), log=self.xp_log )
169 xp.run()
170
171
187
188
190 """
191 Rigid-body minimize receptor and ligand of a Complex
192 using soft vdW pot.
193 """
194
195 - def __init__( self, com, debug=0, **params ):
196
197 self.com = com
198
199 self.rec_psf = com.rec().getPsfFile()
200 self.lig_psf = com.lig().getPsfFile()
201
202 recCode = com.rec().getPdbCode()
203 ligCode = com.lig().getPdbCode()
204
205 self.rec_in = tempfile.mktemp( recCode + ".pdb" )
206 self.lig_in = tempfile.mktemp( ligCode + ".pdb" )
207
208 self.lig_out = tempfile.mktemp( "lig_out.pdb" )
209 self.rec_out = tempfile.mktemp( "rec_out.pdb" )
210
211 self.inp_template = t.projectRoot() +\
212 '/external/xplor/rb_minimize_complex.inp'
213
214 self.param19 = t.projectRoot() + \
215 '/external/xplor/toppar/param19.pro'
216
217 self.result = None
218
219 Xplorer.__init__( self, self.inp_template, debug=debug, **params )
220
221
223 """
224 Prepare for calculation. Write input files.
225 """
226 self.com.rec().writePdb( self.rec_in )
227 self.com.lig().writePdb( self.lig_in )
228
229
243
244
251
252
253
254
255
256
257 import Biskit.test as BT
258
259 -class Test(BT.BiskitTest):
260 """Test case
261
262 The test generates 3 random complexes. In interactive mode,
263 the 3 complexes are displayed as movie in Pymol. They are
264 written out as Amber trajectory if debug=True.
265 """
266
267 TAGS = [ BT.EXE, BT.LONG ]
268
270 import tempfile
271 self.f_pfb = tempfile.mktemp('_test.pdb')
272 self.f_crd = tempfile.mktemp('_test.crd')
273
277
311
312
314 """Display random complexes as trajectory in Pymol.
315 Only run in local interactive mode.
316 """
317 from Biskit import Pymoler
318
319 print "activate debug switch to get random complexes written to disc!"
320 if self.DEBUG:
321 print "writing random complex as trajectory to file..."
322 traj.ref.writePdb( self.f_pfb )
323 traj.writeCrd( self.f_crd )
324 print 'Wrote reference pdb file to: %s' % self.f_pfb
325 print 'Wrote crd file to: %s' % self.f_crd
326
327 self.pm = Pymoler( full=0 )
328
329 mname = self.pm.addMovie( [ traj[i] for i in range(len(traj)) ] )
330 self.pm.add('hide all')
331 self.pm.add('show cartoon')
332 self.pm.add('spectrum')
333 self.pm.add('mplay')
334
335 self.pm.run()
336
337
338 if __name__ == '__main__':
339
340 BT.localTest()
341