IMP  2.2.0
The Integrative Modeling Platform
kernel/chain.py

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.

1 ## \example kernel/chain.py
2 # This example shows how to set up an optimization involving several
3 # particles constrained to be connected in a loop. It uses non bonded
4 # lists and a variety of restraints.
5 
6 import IMP.kernel
7 import IMP.atom
8 import IMP.core
9 import random
10 import RMF
11 import IMP.container
12 import IMP.rmf
13 import IMP.base
14 import sys
15 
16 IMP.base.setup_from_argv(sys.argv, "Chain example")
17 
18 # A trivial example that constructs a set of particles which are restrained
19 # to form a chain via bonds between successive particles. In addition
20 # the head and the tail of the chain are restrained to be close to one
21 # another.
22 
23 IMP.base.set_log_level(IMP.base.TERSE)
24 m = IMP.kernel.Model()
25 m.set_log_level(IMP.base.SILENT)
26 h = IMP.atom.Hierarchy.setup_particle(m, m.add_particle("root"))
27 # The particles in the chain
28 ps = IMP.core.create_xyzr_particles(m, 10, 1.0)
29 for p in ps:
30  # build a hierarchy with all the particles
31  h.add_child(IMP.atom.Hierarchy.setup_particle(p))
32  # things are expected to have mass
34 chain = IMP.container.ListSingletonContainer(ps, "chain")
35 
36 restraints = []
37 # create a spring between successive particles
40 chainr = IMP.container.PairsRestraint(hdps, bonds)
41 chainr.set_name("The chain restraint")
42 restraints.append(chainr)
43 
44 # Prevent non-bonded particles from penetrating one another
45 nbl = IMP.container.ClosePairContainer(chain, 0, 2)
46 bpc = IMP.container.ConsecutivePairFilter(bonds) # exclude existing bonds
47 nbl.add_pair_filter(bpc)
49  "excluded volume")
50 restraints.append(lr)
51 
52 # Tie the ends of the chain
54  (ps[0], ps[-1]))
55 tie.set_name("tie ends")
56 restraints.append(tie)
57 
58 s = IMP.core.MCCGSampler(m) # sample using MC and CG
59 for r in restraints:
60  # set a criteria for what makes a good score
61  r.set_maximum_score(.1)
62 s.set_scoring_function(restraints)
63 s.set_number_of_attempts(10)
64 
65 confs = s.create_sample()
66 print "Found", confs.get_number_of_configurations(), "configurations"
67 fh = RMF.create_rmf_file("solutions.rmfz")
69 for i in range(0, confs.get_number_of_configurations()):
70  confs.load_configuration(i)
71  IMP.rmf.save_frame(fh, str(i))