IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
restrain_minimum_distance.py
1## \example core/restrain_minimum_distance.py
2# This example shows how to restrain based on the minimum distance between
3# two arbitrary sets of particles. You should also see
4# IMP::atom::create_distance_restraint() for a related helper function.
5
6import IMP
7import IMP.core
8import sys
9
10IMP.setup_from_argv(sys.argv, "restrain minimum distance")
11
12m = IMP.Model()
13
14# stuff to create some XYZR particles
15ds0 = IMP.core.create_xyzr_particles(m, 10, 1, 50)
16ds1 = IMP.core.create_xyzr_particles(m, 10, 1, 50)
17
18# first create a table mapping a sentinel particle to each set
20tref.add_particle(ds0[0], ds0)
21tref.add_particle(ds1[0], ds1)
22
23# create a pair score to apply to the closest pair
25# create the pair score with this refiner telling it to use the
26# single closest particle
27ps = IMP.core.KClosePairsPairScore(hps, tref, 1)
28
29# create a restraint by binding the pair score to the sentinel particles
30r = IMP.core.PairRestraint(m, ps, (ds0[0].get_particle_index(),
31 ds1[0].get_particle_index()),
32 "distance")
33
35bm = IMP.core.BallMover(m, ds0 + ds1, 1)
36mc.add_mover(bm)
37mc.set_scoring_function([r])
38mc.optimize(1000)
39
40# find out which pair ended up close
41for p0 in ds0:
42 for p1 in ds1:
43 if IMP.core.get_distance(p0, p1) < .1:
44 print(p0, p1)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Move continuous particle variables by perturbing them within a ball.
A harmonic score on the distance between two spheres.
Apply a score to a fixed number of close pairs from the two sets.
A Monte Carlo optimizer.
Definition MonteCarlo.h:46
Applies a PairScore to a Pair.
A lookup based particle refiner.
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.
double get_distance(const Surface &s, const XYZR &d)
Get distance from sphere to surface.
Definition Surface.h:153
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.