IMP  2.0.1
The Integrative Modeling Platform
chain.py
1 ## \example kernel/chain.py
2 ## This example shows how to set up an optimization involving several particles constrained to be connected in a loop. It uses non bonded lists and a variety of restraints.
3 
4 import IMP
5 import IMP.core
6 import random
7 import IMP.display
8 import IMP.container
9 
10 # A trivial example that constructs a set of particles which are restrained
11 # to form a chain via bonds between successive particles. In addition
12 # the head and the tail of the chain are restrained to be close to one
13 # another.
14 
15 IMP.base.set_log_level(IMP.base.TERSE)
16 m= IMP.Model()
17 m.set_log_level(IMP.base.SILENT)
18 # The particles in the chain
19 ps=IMP.core.create_xyzr_particles(m, 10, 1.0)
20 chain= IMP.container.ListSingletonContainer(ps, "chain")
21 
22 # create a spring between successive particles
25 chainr= IMP.container.PairsRestraint(hdps,bonds)
26 chainr.set_name("The chain restraint")
27 m.add_restraint(chainr)
28 
29 # If you want to inspect the particles
30 # Notice that each bond is a particle
31 for p in m.get_particles():
32  p.show()
33 
34 # Prevent non-bonded particles from penetrating one another
35 nbl= IMP.container.ClosePairContainer(chain, 0,2)
36 bpc=IMP.container.ConsecutivePairFilter(bonds) # exclude existing bonds
37 nbl.add_pair_filter(bpc)
39  "excluded volume")
40 m.add_restraint(lr)
41 
42 # Tie the ends of the chain
44  (ps[0], ps[-1]))
45 tie.set_name("tie ends")
46 m.add_restraint(tie)
47 
48 s= IMP.core.MCCGSampler(m) # sample using MC and CG
49 s.set_number_of_attempts(10)
50 m.set_maximum_score(1)
51 confs= s.get_sample()
52 print "Found", confs.get_number_of_configurations(), "configurations"
53 for i in range(0, confs.get_number_of_configurations()):
54  confs.load_configuration(i)
55  d=IMP.display.ChimeraWriter("solution"+str(i)+".py")
56  for p in chain.get_particles():
57  d.add_geometry(IMP.core.XYZRGeometry(p))
58 
59 # print out info about used modules so that the versions are known
60 #IMP.show_used_modules()