IMP  2.2.1
The Integrative Modeling Platform
container/filter_close_pairs.py

This example shows how to filter the list of close pairs generated in the IMP.container.ClosePairContainer (or IMP.container.CloseBipartitePairContainer). Eventually the filter should probably be implemented in C++, for speed but implementing the filter in python is good for prototyping.

1 ## \example container/filter_close_pairs.py
2 # This example shows how to filter the list of close pairs generated in
3 # the IMP.container.ClosePairContainer (or
4 # IMP.container.CloseBipartitePairContainer). Eventually the filter should
5 # probably be implemented in C++, for speed but implementing the filter in
6 # python is good for prototyping.
7 
8 import IMP
9 import IMP.container
10 import IMP.core
11 import IMP.algebra
12 
13 np = 10
15  IMP.algebra.Vector3D(5, 5, 5))
16 ik = IMP.IntKey("num")
17 IMP.base.set_log_level(IMP.base.SILENT)
18 m = IMP.kernel.Model()
19 l = []
20 for i in range(0, np):
21  p = IMP.kernel.Particle(m)
22  p.add_attribute(ik, i)
25  l.append(p)
28 
29 m.update()
30 print "without", [(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()]
31 
32 
33 class ConsecutiveFilter(IMP.PairPredicate):
34 
35  def __init__(self):
36  IMP.PairPredicate.__init__(self, "ConsecutiveFilter%1%")
37 
38  def get_value(self, pp):
39  diff = pp[0].get_value(ik) - pp[1].get_value(ik)
40  if diff == -1 or diff == 1:
41  return 1
42  return 0
43 
44  def do_get_inputs(self, m, pis):
45  return [m.get_particle(i) for i in pis]
46 
47  def do_show(self, out):
48  pass
49 f = ConsecutiveFilter()
50 cpc.add_pair_filter(f)
51 m.update()
52 print "with", [(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()]