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