IMP logo
IMP Reference Guide  2.12.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 dependency 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.atom
130 import IMP.container
131 import sys
132 
133 IMP.setup_from_argv(sys.argv, "Example of dependency graphs")
134 
135 
136 def create_representation():
137  m = IMP.Model()
139  all.set_name("the universe")
140  rs = []
141 
142  def create_protein(name, ds):
143  h = IMP.atom.create_protein(m, name, 10, ds)
144  leaves = IMP.atom.get_leaves(h)
145  all.add_child(h)
147  for c in h.get_children()],
148  1)
149  if r:
150  rs.append(r)
151 
152  def create_protein_from_pdbs(name, files):
153  def create_from_pdb(file):
154  with IMP.SetLogState(IMP.NONE):
155  t = IMP.atom.read_pdb(
156  IMP.get_example_path("data/" + file), m,
158  # IMP.atom.show_molecular_hierarchy(t)
159  c = IMP.atom.Chain(IMP.atom.get_by_type(t, IMP.atom.CHAIN_TYPE)[0])
160  if c.get_number_of_children() == 0:
162  # there is no reason to use all atoms, just approximate the pdb
163  # shape instead
165  10.0 / 2.0)
166  IMP.atom.destroy(t)
167  # make the simplified structure rigid
169  rb.set_coordinates_are_optimized(True)
170  return s
171  if len(files) > 1:
172  p = IMP.Particle(m)
174  h.set_name(name)
175  for i, f in enumerate(files):
176  c = create_from_pdb(f)
177  h.add_child(c)
178  c.set_name(name + " chain " + str(i))
180  for c in h.get_children(
181  )],
182  1)
183  if r:
184  rs.append(r)
185  else:
186  h = create_from_pdb(files[0])
187  h.set_name(name)
188  all.add_child(h)
189  create_protein("Nup85", 570)
190  create_protein("Nup84", 460)
191  create_protein("Nup145C", 442)
192  create_protein("Nup120", [0, 500, 761])
193  create_protein("Nup133", [0, 450, 778, 1160])
194  create_protein_from_pdbs("Seh1", ["seh1.pdb"])
195  create_protein_from_pdbs("Sec13", ["sec13.pdb"])
196  return (m, rs, all)
197 
198 
199 def create_restraints(m, rs, all):
200  def add_connectivity_restraint(s):
202  rs.append(r)
203 
204  def add_distance_restraint(s0, s1):
205  r = IMP.atom.create_distance_restraint(s0, s1, 0, 1)
206  rs.append(r)
208  rs.append(evr)
209  s0 = IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
210  residue_indexes=range(0, 423))
211  s1 = IMP.atom.Selection(hierarchy=all, molecule="Nup84")
212  s2 = IMP.atom.Selection(hierarchy=all, molecule="Sec13")
213  add_connectivity_restraint([s0, s1, s2])
214  add_distance_restraint(
215  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
216  residue_indexes=range(0, 423)),
217  IMP.atom.Selection(hierarchy=all, molecule="Nup85"))
218  add_distance_restraint(
219  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
220  residue_indexes=range(0, 423)),
221  IMP.atom.Selection(hierarchy=all, molecule="Nup120",
222  residue_indexes=range(500, 762)))
223  add_distance_restraint(IMP.atom.Selection(hierarchy=all, molecule="Nup84"),
224  IMP.atom.Selection(hierarchy=all, molecule="Nup133",
225  residue_indexes=range(778, 1160)))
226  add_distance_restraint(IMP.atom.Selection(hierarchy=all, molecule="Nup85"),
227  IMP.atom.Selection(hierarchy=all, molecule="Seh1"))
228  add_distance_restraint(
229  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
230  residue_indexes=range(0, 423)),
231  IMP.atom.Selection(hierarchy=all, molecule="Sec13"))
232 
233 # now do the actual work
234 (m, rs, all) = create_representation()
235 create_restraints(m, rs, all)
236 
238 
239 # we can get the full dependency graph for the whole model with all the restraints
240 # but it is pretty complex
243 
244 # better thing to do is to get the "pruned" graph
246 
void show_molecular_hierarchy(Hierarchy h)
Print out the molecular hierarchy.
DependencyGraph get_dependency_graph(Model *m)
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Various classes to hold sets of particles.
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Hierarchy create_protein(Model *m, std::string name, double target_radius, const Ints domain_boundaries)
Select all non-alternative ATOM records.
Definition: pdb.h:64
static Hierarchy setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor children=ParticleIndexesAdaptor())
Create a Hierarchy of level t by adding the needed attributes.
Hierarchy create_protein(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.
A class to change and restore log state.
Definition: SetLogState.h:31
DependencyGraph get_pruned_dependency_graph(Model *m)
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
Hierarchy create_simplified_along_backbone(Chain input, const IntRanges &residue_segments, bool keep_detailed=false)
Restraints create_restraints(RMF::FileConstHandle fh, Model *m)
IMP::core::RigidBody create_rigid_body(Hierarchy h)
Class to handle individual particles of a Model object.
Definition: Particle.h:41
std::string show_graphviz(Graph g)
Restraint * create_distance_restraint(const Selection &n0, const Selection &n1, double x0, double k, std::string name="Distance%1%")
Store info for a chain of a protein.
Definition: Chain.h:61
Restraint * create_connectivity_restraint(const Selections &s, double x0, double k, std::string name="Connectivity%1%")
Create a restraint connecting the selections.
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)
Restraint * create_excluded_volume_restraint(const Selections &s)
Create an excluded volume restraint for a list of selections.
Select hierarchy particles identified by the biological name.
Definition: Selection.h:66