IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
8import IMP
9import IMP.container
10import IMP.core
11import IMP.algebra
12import sys
13
14IMP.setup_from_argv(sys.argv, "filter close pairs")
15
16np = 10
18 IMP.algebra.Vector3D(5, 5, 5))
19ik = IMP.IntKey("num")
20IMP.set_log_level(IMP.SILENT)
21m = IMP.Model()
22ll = []
23for 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
32m.update()
33print("without", [(m.get_particle_name(x[0]), m.get_particle_name(x[1]))
34 for x in cpc.get_contents()])
35
36
37class ConsecutiveFilter(IMP.PairPredicate):
38
39 def __init__(self):
40 super().__init__("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
55f = ConsecutiveFilter()
56cpc.add_pair_filter(f)
57m.update()
58print("with", [(m.get_particle_name(x[0]), m.get_particle_name(x[1]))
59 for x in cpc.get_contents()])
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Abstract predicate function.
Return all close unordered pairs of particles taken from the SingletonContainer.
static XYZR setup_particle(Model *m, ParticleIndex pi)
Definition XYZR.h:48
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition VectorD.h:407
VectorD< D > get_random_vector_in(const BoundingBoxD< D > &bb)
Generate a random vector in a box with uniform density.
Various classes to hold sets of particles.
Basic functionality that is expected to be used by a wide variety of IMP users.
void set_log_level(LogLevel l)
Set the current global log level.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.