IMP logo
IMP Reference Guide  2.13.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.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))
RMF::FrameID save_frame(RMF::FileHandle file, std::string name="")
Save the current state of the linked objects as a new RMF frame.
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Various classes to hold sets of particles.
XYZRs create_xyzr_particles(Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
A container which contains all consecutive particle pairs from an input list.
Return all close unordered pairs of particles taken from the SingletonContainer.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
void add_hierarchy(RMF::FileHandle fh, atom::Hierarchy hs)
Store a list of ParticleIndexes.
static Mass setup_particle(Model *m, ParticleIndex pi, Float mass)
Definition: Mass.h:48
A simple sampler.
Definition: MCCGSampler.h:40
void set_log_level(LogLevel l)
Set the current global log level.
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
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.