IMP logo
IMP Reference Guide  2.6.1
The Integrative Modeling Platform
domino/rigid_body_excluded_volume.py

This example shows using two rigid bodies and doing excluded volume with them.

1 ## \example domino/rigid_body_excluded_volume.py
2 # This example shows using two rigid bodies and doing excluded volume with
3 # them.
4 
5 import IMP
6 import IMP.core
7 import IMP.algebra
8 import IMP.domino
9 import IMP.atom
10 import math
11 import sys
12 
13 IMP.setup_from_argv(sys.argv, "rigid body excluded volume")
14 
15 # create a rigid body per helix
16 
17 
18 def 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 
29 def 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
43 def 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)
50  IMP.algebra.Transformation3D(rot00, zv)))
51  for dx in range(0, 15):
52  tr = IMP.algebra.Vector3D(1.0 * dx, 0, 0)
54  IMP.algebra.Transformation3D(rot00, tr)))
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 
64 def 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
75  states = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
76  s.set_assignments_table(states)
77  s.set_subset_filter_tables(filters)
78  return s
79 
80 
81 def display(m, helices, name):
82  m.update()
83  w = IMP.display.PymolWriter(name)
84  for i, h in enumerate(helices):
86  g.set_color(IMP.display.get_display_color(i))
87  w.add_geometry(g)
88 
89 IMP.set_log_level(IMP.SILENT)
90 print("creating representation")
91 (m, helices) = create_representation()
92 
93 print("creating score function")
94 rs = create_excluded_volume(m, helices)
95 
96 print("creating discrete states")
97 pst = create_discrete_states(m, helices)
98 
99 print("creating sampler")
100 s = create_sampler(m, rs, pst)
101 m.set_log_level(IMP.SILENT)
102 IMP.set_log_level(IMP.VERBOSE)
103 print("sampling")
104 cs = s.create_sample()
105 
106 print("found ", cs.get_number_of_configurations(), "solutions")
107 score = []
109 for i in range(cs.get_number_of_configurations()):
110  cs.load_configuration(i)
111  ss = sf.evaluate(False)
112  score.append(ss)
113  print("** solution number:", i, " is:", ss)
114  display(m, helices, "sol_" + str(i) + ".pym")