IMP  2.0.0
The Integrative Modeling Platform
filter_close_pairs.py
1 ## \example container/filter_close_pairs.py
2 ## 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.
3 
4 import IMP
5 import IMP.container
6 import IMP.core
7 import IMP.algebra
8 
9 np=10
11  IMP.algebra.Vector3D(5,5,5))
12 ik= IMP.IntKey("num")
13 IMP.base.set_log_level(IMP.base.SILENT)
14 m= IMP.Model()
15 l= []
16 for i in range(0, np):
17  p= IMP.Particle(m)
18  p.add_attribute(ik, i)
20  l.append(p)
23 
24 m.update()
25 print "without",[(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()]
26 
27 class ConsecutiveFilter(IMP.PairPredicate):
28  def __init__(self):
29  IMP.PairPredicate.__init__(self, "ConsecutiveFilter%1%")
30  def get_value(self, pp):
31  diff= pp[0].get_value(ik) - pp[1].get_value(ik)
32  if diff==-1 or diff ==1:
33  return 1
34  return 0
35  def _do_get_inputs(self, m, pis):
36  return [m.get_particle(i) for i in pis]
37  def do_show(self, out):
38  pass
39 f= ConsecutiveFilter()
40 cpc.add_pair_filter(f)
41 m.update()
42 print "with",[(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()]