IMP  2.1.1
The Integrative Modeling Platform
dependency_graph.py
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 
134 def create_representation():
135  m = IMP.kernel.Model()
137  all.set_name("the universe")
138 
139  def create_protein(name, ds):
140  h = IMP.atom.create_protein(m, name, 10, ds)
141  leaves = IMP.atom.get_leaves(h)
142  all.add_child(h)
144  for c in h.get_children()],
145  1)
146  if r:
147  m.add_restraint(r)
148 
149  def create_protein_from_pdbs(name, files):
150  def create_from_pdb(file):
151  sls = IMP.base.SetLogState(IMP.base.NONE)
152  t = IMP.atom.read_pdb(IMP.get_example_path("data/" + file), m,
154  del sls
155  # IMP.atom.show_molecular_hierarchy(t)
156  c = IMP.atom.Chain(IMP.atom.get_by_type(t, IMP.atom.CHAIN_TYPE)[0])
157  if c.get_number_of_children() == 0:
158  IMP.atom.show_molecular_hierarchy(t)
159  # there is no reason to use all atoms, just approximate the pdb
160  # shape instead
162  10.0 / 2.0)
164  # make the simplified structure rigid
166  rb.set_coordinates_are_optimized(True)
167  return s
168  if len(files) > 1:
169  p = IMP.kernel.Particle(m)
171  h.set_name(name)
172  for i, f in enumerate(files):
173  c = create_from_pdb(f)
174  h.add_child(c)
175  c.set_name(name + " chain " + str(i))
177  for c in h.get_children(
178  )],
179  1)
180  if r:
181  m.add_restraint(r)
182  else:
183  h = create_from_pdb(files[0])
184  h.set_name(name)
185  all.add_child(h)
186  create_protein("Nup85", 570)
187  create_protein("Nup84", 460)
188  create_protein("Nup145C", 442)
189  create_protein("Nup120", [0, 500, 761])
190  create_protein("Nup133", [0, 450, 778, 1160])
191  create_protein_from_pdbs("Seh1", ["seh1.pdb"])
192  create_protein_from_pdbs("Sec13", ["sec13.pdb"])
193  return (m, all)
194 
195 
196 def create_restraints(m, all):
197  def add_connectivity_restraint(s):
199  m.add_restraint(r)
200 
201  def add_distance_restraint(s0, s1):
202  r = IMP.atom.create_distance_restraint(s0, s1, 0, 1)
203  m.add_restraint(r)
205  m.add_restraint(evr)
206  s0 = IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
207  residue_indexes=range(0, 423))
208  s1 = IMP.atom.Selection(hierarchy=all, molecule="Nup84")
209  s2 = IMP.atom.Selection(hierarchy=all, molecule="Sec13")
210  add_connectivity_restraint([s0, s1, s2])
211  add_distance_restraint(
212  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
213  residue_indexes=range(0, 423)),
214  IMP.atom.Selection(hierarchy=all, molecule="Nup85"))
215  add_distance_restraint(
216  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
217  residue_indexes=range(0, 423)),
218  IMP.atom.Selection(hierarchy=all, molecule="Nup120",
219  residue_indexes=range(500, 762)))
220  add_distance_restraint(IMP.atom.Selection(hierarchy=all, molecule="Nup84"),
221  IMP.atom.Selection(hierarchy=all, molecule="Nup133",
222  residue_indexes=range(778, 1160)))
223  add_distance_restraint(IMP.atom.Selection(hierarchy=all, molecule="Nup85"),
224  IMP.atom.Selection(hierarchy=all, molecule="Seh1"))
225  add_distance_restraint(
226  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
227  residue_indexes=range(0, 423)),
228  IMP.atom.Selection(hierarchy=all, molecule="Sec13"))
229 
230 # now do the actual work
231 (m, all) = create_representation()
232 create_restraints(m, all)
233 
234 # we can get the full dependency graph for the whole model with all the restraints
235 # but it is pretty complex
236 dg = IMP.get_dependency_graph(m)
237 IMP.show_graphviz(dg)
238 
239 # better thing to do is to get the "pruned" graph
240 pdg = IMP.get_pruned_dependency_graph(m)
241 
242 IMP.show_graphviz(pdg)
Hierarchy create_protein(kernel::Model *m, std::string name, double resolution, const Ints domain_boundaries)
See IMP.container for more information.
kernel::Restraints create_restraints(RMF::FileConstHandle fh, kernel::Model *m)
kernel::Restraint * create_distance_restraint(const Selection &n0, const Selection &n1, double x0, double k, std::string name="Distance%1%")
A class to change and restore log state.
kernel::Restraint * create_excluded_volume_restraint(const Selections &s)
Select all non-alternative ATOM records.
Definition: pdb.h:63
static Hierarchy setup_particle(kernel::Model *m, kernel::ParticleIndex pi, kernel::ParticleIndexesAdaptor children=kernel::ParticleIndexesAdaptor())
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
kernel::Restraint * create_connectivity_restraint(const Selections &s, double x0, double k, std::string name="Connectivity%1%")
Class to handle individual model particles.
void destroy(Hierarchy d)
Delete the Hierarchy.
Hierarchy create_simplified_along_backbone(Chain input, const IntRanges &residue_segments, bool keep_detailed=false)
IMP::core::RigidBody create_rigid_body(Hierarchy h)
Store info for a chain of a protein.
Definition: Chain.h:21
See IMP.atom for more information.
void read_pdb(base::TextInput input, int model, Hierarchy h)
Hierarchies get_leaves(const Selection &h)
Hierarchy create_protein(kernel::Model *m, std::string name, double resolution, int number_of_residues, int first_residue_index=0, double volume=-1)
Create a coarse grained molecule.
Class for storing model, its restraints, constraints, and particles.