IMP  2.3.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 
12 # create a rigid body per helix
13 
14 
15 def create_representation():
16  m = IMP.kernel.Model()
18  'helix_0.pdb'), m, IMP.atom.CAlphaPDBSelector())
20  'helix_1.pdb'), m, IMP.atom.CAlphaPDBSelector())
21  for h in [h0, h1]:
23  return (m, [h0, h1])
24 
25 
26 def create_excluded_volume(m, helices):
27  # this is the interesting function:
28  # it uses a KClosePairsPair score to generate the list of close atoms on
29  # the fly
30  all = []
31  for h in helices:
32  all.extend(IMP.atom.get_by_type(h, IMP.atom.ATOM_TYPE))
35  evr.set_maximum_score(.01)
36  return [evr]
37 
38 
39 # creating the discrete states for domino
40 def create_discrete_states(m, helices):
43  IMP.algebra.Vector3D(0, 1, 0), math.pi / 2.0)
44  trs = []
45  zv = IMP.algebra.Vector3D(0, 0, 0)
47  IMP.algebra.Transformation3D(rot00, zv)))
48  for dx in range(0, 15):
49  tr = IMP.algebra.Vector3D(1.0 * dx, 0, 0)
51  IMP.algebra.Transformation3D(rot00, tr)))
52  pstate = IMP.domino.RigidBodyStates(trs)
53  for h in helices:
54  pst.set_particle_states(
55  IMP.core.RigidMember(h).get_rigid_body(), pstate)
56  return pst
57 
58 # setting up domino (and filters)
59 
60 
61 def create_sampler(m, rs, pst):
62  s = IMP.domino.DominoSampler(m, pst)
63  filters = []
64  # do not allow particles with the same ParticleStates object
65  # to have the same state index
66  filters.append(IMP.domino.ExclusionSubsetFilterTable(pst))
68  rc.add_restraints(rs)
69  # filter states that score worse than the cutoffs in the Model
71  states = IMP.domino.BranchAndBoundAssignmentsTable(pst, filters)
72  s.set_assignments_table(states)
73  s.set_subset_filter_tables(filters)
74  return s
75 
76 
77 def display(m, helices, name):
78  m.update()
79  w = IMP.display.PymolWriter(name)
80  for i, h in enumerate(helices):
82  g.set_color(IMP.display.get_display_color(i))
83  w.add_geometry(g)
84 
85 IMP.base.set_log_level(IMP.base.SILENT)
86 print "creating representation"
87 (m, helices) = create_representation()
88 
89 print "creating score function"
90 rs = create_excluded_volume(m, helices)
91 
92 print "creating discrete states"
93 pst = create_discrete_states(m, helices)
94 
95 print "creating sampler"
96 s = create_sampler(m, rs, pst)
97 m.set_log_level(IMP.base.SILENT)
98 IMP.base.set_log_level(IMP.base.VERBOSE)
99 print "sampling"
100 cs = s.create_sample()
101 
102 print "found ", cs.get_number_of_configurations(), "solutions"
103 score = []
104 for i in range(cs.get_number_of_configurations()):
105  cs.load_configuration(i)
106  ss = m.evaluate(False)
107  score.append(ss)
108  print "** solution number:", i, " is:", ss
109  display(m, helices, "sol_" + str(i) + ".pym")