IMP  2.1.1
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
7 import IMP.core
8 import random
9 import IMP.display
10 import IMP.container
11 
12 
13 # A trivial example that constructs a set of particles which are restrained
14 # to form a chain via bonds between successive particles. In addition
15 # the head and the tail of the chain are restrained to be close to one
16 # another.
17 
18 IMP.base.set_log_level(IMP.base.TERSE)
19 m = IMP.kernel.Model()
20 m.set_log_level(IMP.base.SILENT)
21 # The particles in the chain
22 ps = IMP.core.create_xyzr_particles(m, 10, 1.0)
23 chain = IMP.container.ListSingletonContainer(ps, "chain")
24 
25 # create a spring between successive particles
28 chainr = IMP.container.PairsRestraint(hdps, bonds)
29 chainr.set_name("The chain restraint")
30 m.add_restraint(chainr)
31 
32 # If you want to inspect the particles
33 # Notice that each bond is a particle
34 for p in m.get_particles():
35  p.show()
36 
37 # Prevent non-bonded particles from penetrating one another
38 nbl = IMP.container.ClosePairContainer(chain, 0, 2)
39 bpc = IMP.container.ConsecutivePairFilter(bonds) # exclude existing bonds
40 nbl.add_pair_filter(bpc)
42  "excluded volume")
43 m.add_restraint(lr)
44 
45 # Tie the ends of the chain
47  (ps[0], ps[-1]))
48 tie.set_name("tie ends")
49 m.add_restraint(tie)
50 
51 s = IMP.core.MCCGSampler(m) # sample using MC and CG
52 s.set_number_of_attempts(10)
53 m.set_maximum_score(1)
54 confs = s.get_sample()
55 print "Found", confs.get_number_of_configurations(), "configurations"
56 for i in range(0, confs.get_number_of_configurations()):
57  confs.load_configuration(i)
58  d = IMP.display.ChimeraWriter("solution" + str(i) + ".py")
59  for p in chain.get_particles():
60  d.add_geometry(IMP.core.XYZRGeometry(p))
61 
62 # print out info about used modules so that the versions are known
63 # IMP.show_used_modules()
Write geometry to a python file for Chimera to read.
Definition: ChimeraWriter.h:29
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.
Return all close unordered pairs of particles taken from the SingletonContainer.
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
See IMP.core for more information.
Applies a PairScore to a Pair.
Definition: PairRestraint.h:30
See IMP.display for more information.
Definition: BildWriter.h:20
Applies a PairScore to each Pair in a list.
Class for storing model, its restraints, constraints, and particles.
Display an IMP::core::XYZR particle as a ball.
Definition: XYZR.h:160