IMP logo
IMP Reference Guide  2.10.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.atom
8 import IMP.core
9 import random
10 import RMF
11 import IMP.container
12 import IMP.rmf
13 import sys
14 
15 IMP.setup_from_argv(sys.argv, "Chain example")
16 
17 # A trivial example that constructs a set of particles which are restrained
18 # to form a chain via bonds between successive particles. In addition
19 # the head and the tail of the chain are restrained to be close to one
20 # another.
21 
22 IMP.set_log_level(IMP.TERSE)
23 m = IMP.Model()
24 m.set_log_level(IMP.SILENT)
25 h = IMP.atom.Hierarchy.setup_particle(m, m.add_particle("root"))
26 # The particles in the chain
27 ps = IMP.core.create_xyzr_particles(m, 10, 1.0)
28 for p in ps:
29  # build a hierarchy with all the particles
30  h.add_child(IMP.atom.Hierarchy.setup_particle(p))
31  # things are expected to have mass
33 chain = IMP.container.ListSingletonContainer(m, ps, "chain")
34 
35 restraints = []
36 # create a spring between successive particles
39 chainr = IMP.container.PairsRestraint(hdps, bonds)
40 chainr.set_name("The chain restraint")
41 restraints.append(chainr)
42 
43 # Prevent non-bonded particles from penetrating one another
44 nbl = IMP.container.ClosePairContainer(chain, 0, 2)
45 bpc = IMP.container.ConsecutivePairFilter(bonds) # exclude existing bonds
46 nbl.add_pair_filter(bpc)
48  "excluded volume")
49 restraints.append(lr)
50 
51 # Tie the ends of the chain
53  (ps[0].get_particle_index(),
54  ps[-1].get_particle_index()))
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))