IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
doc/examples/misc/decay.py
1## \example misc/decay.py
2# Use the IMP::misc::DecayPairContainerOptimizerState to gradually break
3# the bonds in a bd simulation.
4
5import IMP.atom
6import IMP.container
7import IMP.misc
8import IMP.display
9import IMP.example
10import sys
11import IMP.rmf
12import RMF
13import random
14
16 sys.argv,
17 "Use the IMP::misc::DecayPairContainerOptimizerState to gradually "
18 "break the bonds in a bd simulation")
19
20if IMP.get_bool_flag("run_quick_test"):
21 np = 8
22 nb = 8
23 prob = .5
24 period = 2
25 steps = 10
26else:
27 np = 20
28 nb = 40
29 prob = .9
30 period = 10
31 steps = 10000
32
33m = IMP.Model()
34
36 IMP.algebra.Vector3D(100, 100, 100))
37ps = []
38for i in range(0, np):
39 p = m.add_particle("p")
41 d.set_coordinates(
42 IMP.algebra.Vector3D(10. * (i / 10), 10. * (i % 10), 10.))
43 d.set_radius(10)
44 d.set_coordinates_are_optimized(True)
48 ps.append(p)
50
51bds = []
52for i in range(0, nb):
53 pp = random.sample(ps, 2)
54 if pp not in bds and [pp[1], pp[0]] not in bds:
55 bds.append(pp)
56
58dos = IMP.misc.DecayPairContainerOptimizerState(m, cf, bds, "decay")
59dos.set_period(period)
60dos.set_log_level(IMP.SILENT) # VERBOSE
61
62# create restraints
63rs = []
66ps_container = IMP.container.ListSingletonContainer(m, ps)
67rs.append(IMP.container.SingletonsRestraint(box_score, ps_container, "box"))
69rs.append(IMP.container.PairsRestraint(bond_score,
70 dos.get_output_container(),
71 "bonds"))
72ev = IMP.core.ExcludedVolumeRestraint(ps_container, 10, 10)
73IMP.set_log_level(IMP.SILENT)
74
75# set up simulator
77bd.set_maximum_time_step(1000)
78bd.set_scoring_function(rs + [ev])
79bd.add_optimizer_state(dos)
80
81# set up display
82fn = IMP.create_temporary_file_name("decay", ".rmf")
83rmf = RMF.create_rmf_file(fn)
84print("setting up file")
86IMP.rmf.add_restraints(rmf, rs + [ev])
90os.set_period(max(steps / 100, 1))
91bd.add_optimizer_state(os)
92
93# actually optimize things
94print("running")
95bd.optimize(steps)
96
97print("see", fn)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Simple Brownian dynamics simulator.
static Diffusion setup_particle(Model *m, ParticleIndex pi, Float D)
Setup the particle with the specified diffusion coefficient.
Definition Diffusion.h:76
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
Applies a PairScore to each Pair in a list.
Applies a SingletonScore to each Singleton in a list.
Return true (1) with a fixed probability.
Prevent a set of particles and rigid bodies from inter-penetrating.
A harmonic upper bound on the distance between two spheres.
Upper bound harmonic function (non-zero when feature > mean).
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition XYZR.h:48
static Colored setup_particle(Model *m, ParticleIndex pi, Color color)
Definition Colored.h:62
Maintain a pair container with a decaying list of pairs.
Periodically dump the state of all associated objects into the RMF file.
VectorD< 3 > Vector3D
Definition VectorD.h:407
Functionality for loading, creating, manipulating and scoring atomic structures.
Various classes to hold sets of particles.
Output IMP model data in various file formats.
Color get_display_color(unsigned int i)
Example module.
Miscellaneous functionality that is not expected to be used by many IMP users.
Support for the RMF file format for storing hierarchical molecular data and markup.
void add_geometries(RMF::FileHandle file, const display::GeometriesTemp &r)
Add geometries to the file.
void add_restraints(RMF::FileHandle fh, const Restraints &hs)
void add_hierarchies(RMF::FileHandle fh, const atom::Hierarchies &hs)
void set_log_level(LogLevel l)
Set the current global log level.
bool get_bool_flag(std::string name)
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
std::string create_temporary_file_name(std::string prefix="imp_temp", std::string suffix="")
Create a temporary file.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.