IMP logo
IMP Reference Guide  develop.549d75e6f4,2024/11/20
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 import sys
13 
14 IMP.setup_from_argv(sys.argv, "filter close pairs")
15 
16 np = 10
18  IMP.algebra.Vector3D(5, 5, 5))
19 ik = IMP.IntKey("num")
20 IMP.set_log_level(IMP.SILENT)
21 m = IMP.Model()
22 ll = []
23 for i in range(0, np):
24  p = m.add_particle("p%d" % i)
25  m.add_attribute(ik, p, i)
28  ll.append(p)
31 
32 m.update()
33 print("without", [(m.get_particle_name(x[0]), m.get_particle_name(x[1]))
34  for x in cpc.get_contents()])
35 
36 
37 class ConsecutiveFilter(IMP.PairPredicate):
38 
39  def __init__(self):
40  IMP.PairPredicate.__init__(self, "ConsecutiveFilter%1%")
41 
42  def get_value_index(self, m, pp):
43  diff = m.get_attribute(ik, pp[0]) - m.get_attribute(ik, pp[1])
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 
54 
55 f = ConsecutiveFilter()
56 cpc.add_pair_filter(f)
57 m.update()
58 print("with", [(m.get_particle_name(x[0]), m.get_particle_name(x[1]))
59  for x in cpc.get_contents()])