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