IMP logo
IMP Reference Guide  2.7.0
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 
6 import IMP
7 import IMP.core
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "restrain minimum distance")
11 
12 m = IMP.Model()
13 
14 # stuff to create some XYZR particles
15 ds0 = IMP.core.create_xyzr_particles(m, 10, 1, 50)
16 ds1 = IMP.core.create_xyzr_particles(m, 10, 1, 50)
17 
18 # first create a table mapping a sentinenal particle to each set
19 tref = IMP.core.TableRefiner()
20 tref.add_particle(ds0[0], ds0)
21 tref.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
27 ps = IMP.core.KClosePairsPairScore(hps, tref, 1)
28 
29 # create a restraint by binding the pair score to the sentinal particles
30 r = IMP.core.PairRestraint(m, ps, (ds0[0].get_particle_index(),
31  ds1[0].get_particle_index()),
32  "distance")
33 
34 mc = IMP.core.MonteCarlo(m)
35 bm = IMP.core.BallMover(m, ds0 + ds1, 1)
36 mc.add_mover(bm)
37 mc.set_scoring_function([r])
38 mc.optimize(1000)
39 
40 # find out which pair ended up close
41 for p0 in ds0:
42  for p1 in ds1:
43  if IMP.core.get_distance(p0, p1) < .1:
44  print(p0, p1)
A Monte Carlo optimizer.
Definition: MonteCarlo.h:45
Apply a score to a fixed number of close pairs from the two sets.
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
XYZRs create_xyzr_particles(Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
A harmonic score on the distance between two spheres.
Move continuous particle variables by perturbing them within a ball.
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Definition: XYZR.h:89
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
A lookup based particle refiner.
Definition: TableRefiner.h:21
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