IMP  2.2.0
The Integrative Modeling Platform
chain.py
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))
void save_frame(RMF::FileHandle file, unsigned int, std::string name="")
Definition: frames.h:42
See IMP.container for more information.
void set_log_level(LogLevel l)
Set the current global log level.
A container which contains all consecutive pairs from an input list.
See IMP.base for more information.
Definition: base/Array.h:20
Return all close unordered pairs of particles taken from the SingletonContainer.
void add_hierarchy(RMF::FileHandle fh, atom::Hierarchy hs)
static Hierarchy setup_particle(kernel::Model *m, kernel::ParticleIndex pi, kernel::ParticleIndexesAdaptor children=kernel::ParticleIndexesAdaptor())
Store a kernel::ParticleIndexes.
See IMP.kernel for more information.
XYZRs create_xyzr_particles(kernel::Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
A simple sampler.
Definition: MCCGSampler.h:40
static Mass setup_particle(kernel::Model *m, ParticleIndex pi, Float mass)
Definition: Mass.h:44
See IMP.core for more information.
Applies a PairScore to a Pair.
Definition: PairRestraint.h:29
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
See IMP.atom for more information.
See IMP.rmf for more information.
Definition: associations.h:20
Applies a PairScore to each Pair in a list.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72