IMP logo
IMP Reference Guide  2.6.1
The Integrative Modeling Platform
core/restrain_minimum_distance.py

This example shows how to restrain based on the minimum distance between two arbitrary sets of particles. You should also see IMP::atom::create_distance_restraint() for a related helper function.

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(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)