IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
rigid_body_excluded_volume.py
1## \example domino/rigid_body_excluded_volume.py
2# This example shows using two rigid bodies and doing excluded volume with
3# them.
4
5import IMP
6import IMP.core
7import IMP.algebra
8import IMP.domino
9import IMP.atom
10import math
11import sys
12
13IMP.setup_from_argv(sys.argv, "rigid body excluded volume")
14
15# create a rigid body per helix
16
17
18def create_representation():
19 m = IMP.Model()
21 'helix_0.pdb'), m, IMP.atom.CAlphaPDBSelector())
23 'helix_1.pdb'), m, IMP.atom.CAlphaPDBSelector())
24 for h in [h0, h1]:
26 return (m, [h0, h1])
27
28
29def create_excluded_volume(m, helices):
30 # this is the interesting function:
31 # it uses a KClosePairsPair score to generate the list of close atoms on
32 # the fly
33 all = []
34 for h in helices:
35 all.extend(IMP.atom.get_by_type(h, IMP.atom.ATOM_TYPE))
38 evr.set_maximum_score(.01)
39 return [evr]
40
41
42# creating the discrete states for domino
43def create_discrete_states(m, helices):
46 IMP.algebra.Vector3D(0, 1, 0), math.pi / 2.0)
47 trs = []
48 zv = IMP.algebra.Vector3D(0, 0, 0)
51 for dx in range(0, 15):
52 tr = IMP.algebra.Vector3D(1.0 * dx, 0, 0)
55 pstate = IMP.domino.RigidBodyStates(trs)
56 for h in helices:
57 pst.set_particle_states(
58 IMP.core.RigidMember(h).get_rigid_body(), pstate)
59 return pst
60
61# setting up domino (and filters)
62
63
64def create_sampler(m, rs, pst):
65 s = IMP.domino.DominoSampler(m, pst)
66 s.set_restraints(rs)
67 filters = []
68 # do not allow particles with the same ParticleStates object
69 # to have the same state index
70 filters.append(IMP.domino.ExclusionSubsetFilterTable(pst))
72 rc.add_restraints(rs)
73 # filter states that score worse than the cutoffs in the Model
76 s.set_assignments_table(states)
77 s.set_subset_filter_tables(filters)
78 return s
79
80
81def display(m, helices, name):
82 m.update()
84 for i, h in enumerate(helices):
86 g.set_color(IMP.display.get_display_color(i))
87 w.add_geometry(g)
88
89
90IMP.set_log_level(IMP.SILENT)
91print("creating representation")
92(m, helices) = create_representation()
93
94print("creating score function")
95rs = create_excluded_volume(m, helices)
96
97print("creating discrete states")
98pst = create_discrete_states(m, helices)
99
100print("creating sampler")
101s = create_sampler(m, rs, pst)
102m.set_log_level(IMP.SILENT)
103IMP.set_log_level(IMP.VERBOSE)
104print("sampling")
105cs = s.create_sample()
106
107print("found ", cs.get_number_of_configurations(), "solutions")
108score = []
110for i in range(cs.get_number_of_configurations()):
111 cs.load_configuration(i)
112 ss = sf.evaluate(False)
113 score.append(ss)
114 print("** solution number:", i, " is:", ss)
115 display(m, helices, "sol_" + str(i) + ".pym")
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
A reference frame in 3D.
Simple 3D transformation class.
Select all CA ATOM records.
Definition pdb.h:148
Display an IMP::atom::Hierarchy particle as balls.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Gather all the molecular particles of a certain level in the hierarchy.
Prevent a set of particles and rigid bodies from inter-penetrating.
Create a scoring function on a list of restraints.
Write a CGO file with the geometry.
Definition PymolWriter.h:34
Sample best solutions using Domino.
Do not allow two particles to be in the same state.
Filter a configuration of the subset using the Model thresholds.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Rotation3D get_rotation_about_axis(const Vector3D &axis, double angle)
Generate a Rotation3D object from a rotation around an axis.
Definition Rotation3D.h:417
VectorD< 3 > Vector3D
Definition VectorD.h:407
Functionality for loading, creating, manipulating and scoring atomic structures.
IMP::core::RigidBody create_rigid_body(const Hierarchies &h, std::string name=std::string("created rigid body"))
Rigidify a molecule or collection of molecules.
Hierarchy read_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector(), bool select_first_model=true)
Read all the molecules in the first model of the PDB file.
Basic functionality that is expected to be used by a wide variety of IMP users.
Color get_display_color(unsigned int i)
Divide-and-conquer inferential optimization in discrete space.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
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.