IMP logo
IMP Reference Guide  2.20.2
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 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 ll = []
24 for i in range(0, np):
25  p = m.add_particle("p%d" % i)
26  m.add_attribute(ik, p, i)
29  ll.append(p)
32 
33 m.update()
34 print("without", [(m.get_particle_name(x[0]), m.get_particle_name(x[1]))
35  for x in cpc.get_contents()])
36 
37 
38 class ConsecutiveFilter(IMP.PairPredicate):
39 
40  def __init__(self):
41  IMP.PairPredicate.__init__(self, "ConsecutiveFilter%1%")
42 
43  def get_value_index(self, m, pp):
44  diff = m.get_attribute(ik, pp[0]) - m.get_attribute(ik, pp[1])
45  if diff == -1 or diff == 1:
46  return 1
47  return 0
48 
49  def do_get_inputs(self, m, pis):
50  return [m.get_particle(i) for i in pis]
51 
52  def do_show(self, out):
53  pass
54 
55 
56 f = ConsecutiveFilter()
57 cpc.add_pair_filter(f)
58 m.update()
59 print("with", [(m.get_particle_name(x[0]), m.get_particle_name(x[1]))
60  for x in cpc.get_contents()])
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Various classes to hold sets of particles.
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition: XYZR.h:48
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.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Store a list of ParticleIndexes.
void set_log_level(LogLevel l)
Set the current global log level.
Basic functionality that is expected to be used by a wide variety of IMP users.
Abstract predicate function.
Definition: PairPredicate.h:31
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition: VectorD.h:425