IMP  2.4.0
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
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)