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