IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
6import IMP.atom
7import IMP.core
8import RMF
9import IMP.container
10import IMP.rmf
11import sys
12
13IMP.setup_from_argv(sys.argv, "Chain example")
14
15# A trivial example that constructs a set of particles which are restrained
16# to form a chain via bonds between successive particles. In addition
17# the head and the tail of the chain are restrained to be close to one
18# another.
19
20IMP.set_log_level(IMP.TERSE)
21m = IMP.Model()
22m.set_log_level(IMP.SILENT)
23h = IMP.atom.Hierarchy.setup_particle(m, m.add_particle("root"))
24# The particles in the chain
25ps = IMP.core.create_xyzr_particles(m, 10, 1.0)
26for p in ps:
27 # build a hierarchy with all the particles
29 # things are expected to have mass
31chain = IMP.container.ListSingletonContainer(m, ps, "chain")
32
33restraints = []
34# create a spring between successive particles
37chainr = IMP.container.PairsRestraint(hdps, bonds)
38chainr.set_name("The chain restraint")
39restraints.append(chainr)
40
41# Prevent non-bonded particles from penetrating one another
42nbl = IMP.container.ClosePairContainer(chain, 0, 2)
43bpc = IMP.container.ConsecutivePairFilter(bonds) # exclude existing bonds
44nbl.add_pair_filter(bpc)
46 "excluded volume")
47restraints.append(lr)
48
49# Tie the ends of the chain
51 (ps[0].get_particle_index(),
52 ps[-1].get_particle_index()))
53tie.set_name("tie ends")
54restraints.append(tie)
55
56s = IMP.core.MCCGSampler(m) # sample using MC and CG
57for r in restraints:
58 # set a criteria for what makes a good score
59 r.set_maximum_score(.1)
60s.set_scoring_function(restraints)
61s.set_number_of_attempts(10)
62
63confs = s.create_sample()
64print("Found", confs.get_number_of_configurations(), "configurations")
65fh = RMF.create_rmf_file("solutions.rmfz")
67for i in range(0, confs.get_number_of_configurations()):
68 confs.load_configuration(i)
69 IMP.rmf.save_frame(fh, str(i))
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
static Mass setup_particle(Model *m, ParticleIndex pi, Float mass)
Definition Mass.h:48
Return all close unordered pairs of particles taken from the SingletonContainer.
A container which contains all consecutive particle pairs from an input list.
Applies a PairScore to each Pair in a list.
Score distance between two particle centers using a harmonic function.
A simple sampler.
Definition MCCGSampler.h:40
Applies a PairScore to a Pair.
Functionality for loading, creating, manipulating and scoring atomic structures.
Various classes to hold sets of particles.
Basic functionality that is expected to be used by a wide variety of IMP users.
XYZRs create_xyzr_particles(Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
Support for the RMF file format for storing hierarchical molecular data and markup.
RMF::FrameID save_frame(RMF::FileHandle file, std::string name="")
Save the current state of the linked objects as a new RMF frame.
void add_hierarchy(RMF::FileHandle fh, atom::Hierarchy hs)
void set_log_level(LogLevel l)
Set the current global log level.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.