IMP  2.4.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 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))
void save_frame(RMF::FileHandle file, unsigned int, std::string name="")
Definition: frames.h:42
Various classes to hold sets of particles.
void set_log_level(LogLevel l)
Set the current global log level.
A container which contains all consecutive particle pairs from an input list.
Low level functionality (logging, error handling, profiling, command line flags etc) that is used by ...
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.
Base functionality and abstract base classes for representation, scoring and sampling.
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
Basic functionality that is expected to be used by a wide variety of IMP users.
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)
Functionality for loading, creating, manipulating and scoring atomic structures.
Support for the RMF file format for storing hierarchical molecular data and markup.
Applies a PairScore to each Pair in a list.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73