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