IMP  2.4.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
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 
14 np = 10
16  IMP.algebra.Vector3D(5, 5, 5))
17 ik = IMP.IntKey("num")
18 IMP.base.set_log_level(IMP.base.SILENT)
19 m = IMP.kernel.Model()
20 l = []
21 for i in range(0, np):
22  p = IMP.kernel.Particle(m)
23  p.add_attribute(ik, i)
26  l.append(p)
29 
30 m.update()
31 print("without", [(x[0].get_name(), x[1].get_name()) for x in cpc.get_particle_pairs()])
32 
33 
34 class ConsecutiveFilter(IMP.PairPredicate):
35 
36  def __init__(self):
37  IMP.PairPredicate.__init__(self, "ConsecutiveFilter%1%")
38 
39  def get_value(self, pp):
40  diff = pp[0].get_value(ik) - pp[1].get_value(ik)
41  if diff == -1 or diff == 1:
42  return 1
43  return 0
44 
45  def do_get_inputs(self, m, pis):
46  return [m.get_particle(i) for i in pis]
47 
48  def do_show(self, out):
49  pass
50 f = ConsecutiveFilter()
51 cpc.add_pair_filter(f)
52 m.update()
53 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
Various classes to hold sets of particles.
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.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73