IMP  2.0.1
The Integrative Modeling Platform
kernel/dependency_graph.py

When trying to understand what is going on in IMP, it can often be useful to view the dependency graph, that is, the graph showing how various entities relate to one another. In it, an arrow leads from an IMP::Container or IMP::Particle to an IMP::Restraint if the IMP::Restraint reads from that container or particle. Similarly, an arrow leads from an IMP::Container or IMP::Particle to an IMP::ScoreState if the score state reads from it, and an arrow leads from an IMP::ScoreState to an IMP::Container or IMP::Particle if the score state updates the particle.

The resulting pruned depenency graph is:

1 ## \example kernel/dependency_graph.py
2 ## When trying to understand what is going on in \imp, it can often be useful to view the dependency graph, that is, the graph showing how various entities relate to one another. In it, an arrow leads from an IMP::Container or IMP::Particle to an IMP::Restraint if the IMP::Restraint reads from that container or particle. Similarly, an arrow leads from an IMP::Container or IMP::Particle to an IMP::ScoreState if the score state reads from it, and an arrow leads from an IMP::ScoreState to an IMP::Container or IMP::Particle if the score state updates the particle.
3 ##
4 ## The resulting pruned depenency graph is:
5 ## \dotgraph{ \dot
6 ## digraph pruned_dependencies {
7 ## 0[label="Nup85-12"];
8 ## 1[label="Fragment [213-218)"];
9 ## 2[label="Nup145C-4"];
10 ## 3[label="Atom k distance restraint 2"];
11 ## 4[label="Nup1202-8"];
12 ## 5[label="Model 0"];
13 ## 6[label="Fragment [239-244)"];
14 ## 7[label="Nup1332-10"];
15 ## 8[label="Nup1201-12"];
16 ## 9[label="Connectivity particles"];
17 ## 10[label="Nup84-14"];
18 ## 11[label="Atom k distance restraint 3"];
19 ## 12[label="MovedSingletonContainer2"];
20 ## 13[label="Nup1333-16"];
21 ## 14[label="Atom k distance restraint 5"];
22 ## 15[label="Atom k distance restraint 4"];
23 ## 16[label="normalize rigid bodies"];
24 ## 17[label="Atom k distance restraint 0"];
25 ## 18[label="ListSingletonContainer2"];
26 ## 19[label="Chain A rigid body"];
27 ## 20[label="ConnectivityRestraint 0"];
28 ## 21[label="MovedSingletonContainer1"];
29 ## 22[label="ListSingletonContainer1"];
30 ## 23[label="HarmonicUpperBoundSphereDistancePairScore2 and ConnectingPairContainer"];
31 ## 24[label="HarmonicUpperBoundSphereDistancePairScore1 and ConnectingPairContainer"];
32 ## 25[label="Sec13"];
33 ## 26[label="Hierarchy EV"];
34 ## 27[label="Chain A rigid body rigid body positions"];
35 ## 28[label="rigid bodies list"];
36 ## 29[label="Atom k distance restraint 1"];
37 ## 30[label="HarmonicUpperBoundSphereDistancePairScore0 and ConnectingPairContainer"];
38 ## 31[label="ConnectingPairContainer"];
39 ## 32[label="ConnectingPairContainer"];
40 ## 33[label="Chain A rigid body"];
41 ## 34[label="ListSingletonContainer0"];
42 ## 35[label="ConnectivityRestraint 1"];
43 ## 36[label="MovedSingletonContainer0"];
44 ## 37[label="Chain A rigid body rigid body positions"];
45 ## 38[label="ConnectingPairContainer"];
46 ## 39[label="Seh1"];
47 ## 40[label="Hierarchy EV particles"];
48 ## 16->19 ;
49 ## 16->33 ;
50 ## 27->6 ;
51 ## 27->39 ;
52 ## 37->25 ;
53 ## 37->1 ;
54 ## 4->3 ;
55 ## 2->3 ;
56 ## 11->5 ;
57 ## 17->5 ;
58 ## 23->5 ;
59 ## 14->5 ;
60 ## 35->5 ;
61 ## 15->5 ;
62 ## 30->5 ;
63 ## 24->5 ;
64 ## 29->5 ;
65 ## 26->5 ;
66 ## 3->5 ;
67 ## 20->5 ;
68 ## 13->11 ;
69 ## 10->11 ;
70 ## 2->12 ;
71 ## 18->12 ;
72 ## 25->14 ;
73 ## 2->14 ;
74 ## 1->14 ;
75 ## 33->14 ;
76 ## 0->15 ;
77 ## 6->15 ;
78 ## 19->15 ;
79 ## 39->15 ;
80 ## 28->16 ;
81 ## 8->17 ;
82 ## 4->17 ;
83 ## 13->20 ;
84 ## 7->20 ;
85 ## 22->21 ;
86 ## 10->21 ;
87 ## 2->23 ;
88 ## 38->23 ;
89 ## 31->24 ;
90 ## 10->24 ;
91 ## 0->26 ;
92 ## 13->26 ;
93 ## 8->26 ;
94 ## 7->26 ;
95 ## 4->26 ;
96 ## 2->26 ;
97 ## 6->26 ;
98 ## 19->26 ;
99 ## 10->26 ;
100 ## 40->26 ;
101 ## 1->26 ;
102 ## 33->26 ;
103 ## 19->27 ;
104 ## 0->29 ;
105 ## 2->29 ;
106 ## 0->30 ;
107 ## 32->30 ;
108 ## 21->31 ;
109 ## 22->31 ;
110 ## 10->31 ;
111 ## 0->32 ;
112 ## 36->32 ;
113 ## 34->32 ;
114 ## 25->35 ;
115 ## 2->35 ;
116 ## 10->35 ;
117 ## 1->35 ;
118 ## 33->35 ;
119 ## 0->36 ;
120 ## 34->36 ;
121 ## 33->37 ;
122 ## 12->38 ;
123 ## 2->38 ;
124 ## 18->38 ;
125 ## }
126 ## \enddot
127 ## }
128 
129 import IMP
130 import IMP.atom
131 import IMP.container
132 
133 def create_representation():
134  m= IMP.Model()
136  all.set_name("the universe")
137  def create_protein(name, ds):
138  h=IMP.atom.create_protein(m, name, 10, ds)
139  leaves= IMP.atom.get_leaves(h)
140  all.add_child(h)
142  for c in h.get_children()],
143  1)
144  if r:
145  m.add_restraint(r)
146  def create_protein_from_pdbs(name, files):
147  def create_from_pdb(file):
148  sls=IMP.base.SetLogState(IMP.base.NONE)
149  t=IMP.atom.read_pdb( IMP.get_example_path("data/"+file), m,
151  del sls
152  #IMP.atom.show_molecular_hierarchy(t)
153  c=IMP.atom.Chain(IMP.atom.get_by_type(t, IMP.atom.CHAIN_TYPE)[0])
154  if c.get_number_of_children()==0:
155  IMP.atom.show_molecular_hierarchy(t)
156  # there is no reason to use all atoms, just approximate the pdb shape instead
158  10.0/2.0)
160  # make the simplified structure rigid
162  rb.set_coordinates_are_optimized(True)
163  return s
164  if len(files) >1:
165  p= IMP.Particle(m)
167  h.set_name(name)
168  for i, f in enumerate(files):
169  c=create_from_pdb(f)
170  h.add_child(c)
171  c.set_name(name+" chain "+str(i))
173  for c in h.get_children()],
174  1)
175  if r:
176  m.add_restraint(r)
177  else:
178  h= create_from_pdb(files[0])
179  h.set_name(name)
180  all.add_child(h)
181  create_protein("Nup85", 570)
182  create_protein("Nup84", 460)
183  create_protein("Nup145C", 442)
184  create_protein("Nup120", [0, 500, 761])
185  create_protein("Nup133", [0, 450, 778, 1160])
186  create_protein_from_pdbs("Seh1", ["seh1.pdb"])
187  create_protein_from_pdbs("Sec13", ["sec13.pdb"])
188  return (m, all)
189 
190 def create_restraints(m, all):
191  def add_connectivity_restraint(s):
193  m.add_restraint(r)
194  def add_distance_restraint(s0, s1):
196  m.add_restraint(r)
198  m.add_restraint(evr)
200  s0=S(hierarchy=all, molecule="Nup145C", residue_indexes=[(0,423)])
201  s1=S(hierarchy=all, molecule="Nup84")
202  s2=S(hierarchy=all, molecule="Sec13")
203  add_connectivity_restraint([s0,s1,s2])
204  add_distance_restraint(S(hierarchy=all, molecule="Nup145C", residue_indexes=[(0,423)]),
205  S(hierarchy=all, molecule="Nup85"))
206  add_distance_restraint(S(hierarchy=all, molecule="Nup145C", residue_indexes=[(0,423)]),
207  S(hierarchy=all, molecule="Nup120",
208  residue_indexes= [(500, 762)]))
209  add_distance_restraint(S(hierarchy=all, molecule="Nup84"),
210  S(hierarchy=all, molecule="Nup133",
211  residue_indexes=[(778, 1160)]))
212  add_distance_restraint(S(hierarchy=all, molecule="Nup85"),
213  S(hierarchy=all, molecule="Seh1"))
214  add_distance_restraint(S(hierarchy=all, molecule="Nup145C",
215  residue_indexes=[(0,423)]),
216  S(hierarchy=all, molecule="Sec13"))
217 
218 # now do the actual work
219 (m,all)= create_representation()
220 create_restraints(m, all)
221 
222 # we can get the full dependency graph for the whole model with all the restraints
223 # but it is pretty complex
224 dg= IMP.get_dependency_graph(m)
225 IMP.show_graphviz(dg);
226 
227 # better thing to do is to get the "pruned" graph
228 pdg= IMP.get_pruned_dependency_graph(m)
229 
230 IMP.show_graphviz(pdg)