IMP  2.3.1
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
9 
10 # stuff to create some XYZR particles
11 ds0 = IMP.core.create_xyzr_particles(m, 10, 1, 50)
12 ds1 = IMP.core.create_xyzr_particles(m, 10, 1, 50)
13 
14 # first create a table mapping a sentinenal particle to each set
15 tref = IMP.core.TableRefiner()
16 tref.add_particle(ds0[0], ds0)
17 tref.add_particle(ds1[0], ds1)
18 
19 # create a pair score to apply to the closest pair
21 # create the pair score with this refiner telling it to use the
22 # single closest particle
23 ps = IMP.core.KClosePairsPairScore(hps, tref, 1)
24 
25 # create a restraint by binding the pair score to the sentinal particles
26 r = IMP.core.PairRestraint(ps, (ds0[0], ds1[0]), "distance")
27 
28 mc = IMP.core.MonteCarlo(m)
29 bm = IMP.core.BallMover(ds0 + ds1, 1)
30 mc.add_mover(bm)
31 mc.set_scoring_function([r])
32 mc.optimize(1000)
33 
34 # find out which pair ended up close
35 for p0 in ds0:
36  for p1 in ds1:
37  if IMP.core.get_distance(p0, p1) < .1:
38  print p0, p1
A Monte Carlo optimizer.
Definition: MonteCarlo.h:45
A harmonic score on the distance between two spheres.
Modify a set of continuous 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:87
A lookup based particle refiner.
Definition: TableRefiner.h:21
XYZRs create_xyzr_particles(kernel::Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
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
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73