This example docks several proteins using excluded volume and crosslinking terms. To set the pdbs and crosslinks to use, edit the data at the start of the python script.
15 import networkx.algorithms
17 print "Script requires networkx to run"
24 pdbs=[IMP.get_example_path(
'dock_data/chainf.pdb'),
25 IMP.get_example_path(
'dock_data/chaind.pdb')]
27 (256,
"D", 89,
"F", 17, 0.1),
28 (259,
"D", 84,
"F", 17, 0.1),
29 (259,
"D", 89,
"F", 17, 0.1),
30 (269,
"D", 89,
"F", 17, 0.1),
31 (128,
"F", 275,
"D", 17, 0.1),
32 (130,
"F", 275,
"D", 17, 0.1),
33 (144,
"F", 269,
"D", 17, 0.1),
34 (150,
"F", 256,
"D", 17, 0.1),
35 (150,
"F", 259,
"D", 17, 0.1),
36 (150,
"F", 269,
"D", 17, 0.1),
37 (150,
"F", 179,
"D", 17, 0.1),
38 (166,
"F", 186,
"D", 17, 0.1),
39 (170,
"D", 89,
"F", 17, 0.1),
40 (179,
"D", 84,
"F", 17, 0.1)]
43 def read_pdbs(list_pdb_file):
44 """read pdbs from an external list file
45 create a simplified representation"""
57 return chains,chain_id
59 def setup_radii(chains):
60 "setup the radii for each residue"
63 for res
in c.get_children():
71 def add_excluded_volume(chains):
72 """add excluded volume score on the coarse grained c-alpha model
73 residues are represented by beads with conveniently defined excluded volume radius"""
83 restraints[
'excluded_volume']=rs
86 def setup_move_them_all_MonteCarlo_internal(chains,mc_dx=0.3,mc_dang=0.1,mc_kt=1.0):
87 """setup rigid body monte carlo move set
88 mc_dx is the traslation move
89 mc_dang is the rotation angle"""
92 mc.set_return_best(
False)
101 def setup_move_them_all_MonteCarlo_external(connected_chain_list,rb_ext_list=[],
102 mc_dx=0.3,mc_dang=0.1,mc_kt=1.0,return_best=
False):
103 """setup rigid body monte carlo move set
104 mc_dx is the traslation move
105 mc_dang is the rotation angle"""
107 print 'RIGID EXT BODY LIST', [r.get_name()
for r
in rb_ext_list]
108 for rb
in rb_ext_list:
114 mc.set_return_best(return_best)
117 print connected_chain_list
118 for c
in connected_chain_list:
123 rb_tmp_list.append(rba)
125 print 'RIGID BODY LIST', [r.get_name( )
for r
in rb_tmp_list]
127 p.set_name(
"root rigid body "+str(chain_id[s]))
129 rb_ext_list.append(rb)
132 return mc,rb_ext_list
134 def setup_move_them_all_MonteCarlo_internal_2(chains,rb_ext_list=[],
135 mc_dx=0.3,mc_dang=0.1,mc_kt=1.0):
136 """setup rigid body monte carlo move set
137 mc_dx is the traslation move
138 mc_dang is the rotation angle"""
140 print 'RIGID EXT BODY LIST', [r.get_name()
for r
in rb_ext_list]
141 for rb
in rb_ext_list:
148 mc.set_return_best(
False)
153 rb_ext_list.append(rb)
156 return mc,rb_ext_list
158 def shuffle_configuration(chains,bounding_box_length=200.0):
159 "shuffle configuration, used to restart the optimization"
160 hbbl=bounding_box_length/2
174 """Handle the restraints defined above
175 sintax: resid1 chain1 resid2 chain2 max_distance strength_of_potential
176 example: 226 H 272 N 15.0 10.0"""
180 for tokens
in xlinks:
189 p1=s1.get_selected_particles()[0]
191 print "residue %d of chain %s not found" % (r1,c1)
195 p2=s2.get_selected_particles()[0]
197 print "residue %d of chain %s not found" % (r2,c2)
205 a=
'cross_link-'+`r1`+
'.'+c1+
'-'+`r2`+
'.'+c2+
'.lower'
208 restraints_map[a]=(c1,c2)
212 restraints[
'cross_links']=rs
213 return restraints,restraints_map
215 def setup_md(temp=300.0, tau=0.01):
218 md.assign_velocities(temp)
219 md.set_time_step(1.0)
221 md.add_optimizer_state(st)
224 def init_pdb(prefix='models'):
225 "append models to a pdb file"
226 pdbfile = prefix+
'.pdb'
227 flpdb=open(pdbfile,
'w')
231 "append zero score models (solutions) to a pdb file"
232 pdbfile = prefix+
'.pdb'
233 flpdb=open(pdbfile,
'a')
236 fltmp=open(tmpfile,
'r')
242 def chain_pair_list(chains,nop_cutoff=0):
248 if chain_id[s]>chain_id[c]:
253 nop=aaa.get_number_of_particle_pairs()
254 if nop > nop_cutoff :
255 pair_list.append((c,s))
257 pair_list.append((c,c))
258 pair_list.append((s,s))
262 def chain_pair_list_based_on_restraint(chains,nop_cutoff=0):
264 id_chain=invert_dict(chain_id)
265 for i
in restraints.keys():
266 (chaina_id,chainb_id)=restraints_map[i]
267 chaina=invert_dict(chaina_id)
268 chainb=invert_dict(chainb_id)
275 if chain_id[s]>chain_id[c]:
280 nop=aaa.get_number_of_particle_pairs()
281 if nop > nop_cutoff :
282 pair_list.append((c,s))
284 pair_list.append((c,c))
285 pair_list.append((s,s))
289 def create_graph(chains,nop_cutoff=0):
291 while len(connected)<=1:
293 pair_list=chain_pair_list(chains,nop_cutoff)
294 G.add_edges_from(pair_list)
295 connected=nx.algorithms.connected_components(G)
298 return connected,nop_cutoff
302 for k, v
in d.iteritems():
303 keys = inv.setdefault(v, [])
317 init_pdb(
"solutions")
319 chains,chain_id=read_pdbs(
"pdb.list")
322 add_excluded_volume(chains)
324 shuffle_configuration(chains,300.0)
335 mc_int=setup_move_them_all_MonteCarlo_internal(chains,delta_r,delta_a,temp)
346 number_of_steps = 10000
351 for steps
in range(number_of_steps):
354 connected_chains_list,nop_cutoff=create_graph(chains,nop_cutoff)
355 mc_int,rb_ext_list = setup_move_them_all_MonteCarlo_external(connected_chains_list,rb_ext_list,delta_r,delta_a,temp,return_best=
False)
356 mc_int.optimize(nsteps_ext)
357 print ' INTERNAL', m.evaluate(
False)
362 connected_chains_list,nop_cutoff=create_graph(chains,nop_cutoff)
363 mc_ext,rb_ext_list = setup_move_them_all_MonteCarlo_external(connected_chains_list,rb_ext_list,delta_r,delta_a,temp,return_best=
False)
364 mc_ext.optimize(nsteps_ext)
365 print ' EXTERNAL', m.evaluate(
False)
368 nfs=mc_ext.get_number_of_forward_steps()
369 acceptance=float(nfs)/nsteps_ext
375 print 'ACCEPTANCE 1', acceptance, delta_r, delta_a
379 connected_chains_list,nop_cutoff=create_graph(chains,nop_cutoff)
380 mc_int,rb_ext_list = setup_move_them_all_MonteCarlo_external(connected_chains_list,rb_ext_list,delta_r_best,delta_a_best,temp,return_best=
True)
381 mc_int.optimize(nsteps_ext)
382 print ' INTERNAL', m.evaluate(
False)
387 connected_chains_list,nop_cutoff=create_graph(chains,nop_cutoff)
388 mc_ext,rb_ext_list = setup_move_them_all_MonteCarlo_external(connected_chains_list,rb_ext_list,delta_r_best,delta_a_best,temp,return_best=
True)
389 mc_ext.optimize(nsteps_ext)
390 print ' EXTERNAL', m.evaluate(
False)
393 nfs=mc_ext.get_number_of_forward_steps()
394 acceptance=float(nfs)/nsteps_ext
397 delta_r_best=delta_r_best/2
400 delta_r_best=delta_r_best*2
401 print 'ACCEPTANCE 2', acceptance, delta_r_best, delta_a_best
405 score=m.evaluate(
False)
406 for i
in restraints.keys():
407 print i, restraints[i].evaluate(
False)
412 shuffle_configuration(chains,300.0)