IMP logo
IMP Reference Guide  2.10.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 from __future__ import print_function
9 import IMP
10 import IMP.container
11 import IMP.core
12 import IMP.algebra
13 import sys
14 
15 IMP.setup_from_argv(sys.argv, "filter close pairs")
16 
17 np = 10
19  IMP.algebra.Vector3D(5, 5, 5))
20 ik = IMP.IntKey("num")
21 IMP.set_log_level(IMP.SILENT)
22 m = IMP.Model()
23 l = []
24 for i in range(0, np):
25  p = m.add_particle("p%d" % i)
26  m.add_attribute(ik, p, i)
29  l.append(p)
32 
33 m.update()
34 print("without", [(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()])
35 
36 
37 class ConsecutiveFilter(IMP.PairPredicate):
38 
39  def __init__(self):
40  IMP.PairPredicate.__init__(self, "ConsecutiveFilter%1%")
41 
42  def get_value(self, pp):
43  diff = pp[0].get_value(ik) - pp[1].get_value(ik)
44  if diff == -1 or diff == 1:
45  return 1
46  return 0
47 
48  def do_get_inputs(self, m, pis):
49  return [m.get_particle(i) for i in pis]
50 
51  def do_show(self, out):
52  pass
53 f = ConsecutiveFilter()
54 cpc.add_pair_filter(f)
55 m.update()
56 print("with", [(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()])