IMP  2.2.1
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
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()]
A base class for Keys.
Definition: kernel/Key.h:46
See IMP.container for more information.
void set_log_level(LogLevel l)
Set the current global log level.
Return all close unordered pairs of particles taken from the SingletonContainer.
Vector3D get_random_vector_in(const Cylinder3D &c)
Generate a random vector in a cylinder with uniform density.
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: XYZR.h:48
Store a kernel::ParticleIndexes.
Abstract predicate function.
Class to handle individual model particles.
See IMP.core for more information.
See IMP.algebra for more information.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72