IMP logo
IMP Reference Guide  2.19.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
3 # to view the dependency graph, that is, the graph showing how various
4 # entities relate to one another. In it, an arrow leads from an IMP::Container
5 # or IMP::Particle to an IMP::Restraint if the IMP::Restraint reads from that
6 # container or particle. Similarly, an arrow leads from an IMP::Container or
7 # IMP::Particle to an IMP::ScoreState if the score state reads from it, and
8 # an arrow leads from an IMP::ScoreState to an IMP::Container or IMP::Particle
9 # if the score state updates the particle.
10 #
11 # The resulting pruned dependency graph is:
12 # \dotgraph{ \dot
13 # digraph pruned_dependencies {
14 # 0[label="Nup85-12"];
15 # 1[label="Fragment [213-218)"];
16 # 2[label="Nup145C-4"];
17 # 3[label="Atom k distance restraint 2"];
18 # 4[label="Nup1202-8"];
19 # 5[label="Model 0"];
20 # 6[label="Fragment [239-244)"];
21 # 7[label="Nup1332-10"];
22 # 8[label="Nup1201-12"];
23 # 9[label="Connectivity particles"];
24 # 10[label="Nup84-14"];
25 # 11[label="Atom k distance restraint 3"];
26 # 12[label="MovedSingletonContainer2"];
27 # 13[label="Nup1333-16"];
28 # 14[label="Atom k distance restraint 5"];
29 # 15[label="Atom k distance restraint 4"];
30 # 16[label="normalize rigid bodies"];
31 # 17[label="Atom k distance restraint 0"];
32 # 18[label="ListSingletonContainer2"];
33 # 19[label="Chain A rigid body"];
34 # 20[label="ConnectivityRestraint 0"];
35 # 21[label="MovedSingletonContainer1"];
36 # 22[label="ListSingletonContainer1"];
37 # 23[label="HarmonicUpperBoundSphereDistancePairScore2 and ConnectingPairContainer"];
38 # 24[label="HarmonicUpperBoundSphereDistancePairScore1 and ConnectingPairContainer"];
39 # 25[label="Sec13"];
40 # 26[label="Hierarchy EV"];
41 # 27[label="Chain A rigid body rigid body positions"];
42 # 28[label="rigid bodies list"];
43 # 29[label="Atom k distance restraint 1"];
44 # 30[label="HarmonicUpperBoundSphereDistancePairScore0 and ConnectingPairContainer"];
45 # 31[label="ConnectingPairContainer"];
46 # 32[label="ConnectingPairContainer"];
47 # 33[label="Chain A rigid body"];
48 # 34[label="ListSingletonContainer0"];
49 # 35[label="ConnectivityRestraint 1"];
50 # 36[label="MovedSingletonContainer0"];
51 # 37[label="Chain A rigid body rigid body positions"];
52 # 38[label="ConnectingPairContainer"];
53 # 39[label="Seh1"];
54 # 40[label="Hierarchy EV particles"];
55 # 16->19 ;
56 # 16->33 ;
57 # 27->6 ;
58 # 27->39 ;
59 # 37->25 ;
60 # 37->1 ;
61 # 4->3 ;
62 # 2->3 ;
63 # 11->5 ;
64 # 17->5 ;
65 # 23->5 ;
66 # 14->5 ;
67 # 35->5 ;
68 # 15->5 ;
69 # 30->5 ;
70 # 24->5 ;
71 # 29->5 ;
72 # 26->5 ;
73 # 3->5 ;
74 # 20->5 ;
75 # 13->11 ;
76 # 10->11 ;
77 # 2->12 ;
78 # 18->12 ;
79 # 25->14 ;
80 # 2->14 ;
81 # 1->14 ;
82 # 33->14 ;
83 # 0->15 ;
84 # 6->15 ;
85 # 19->15 ;
86 # 39->15 ;
87 # 28->16 ;
88 # 8->17 ;
89 # 4->17 ;
90 # 13->20 ;
91 # 7->20 ;
92 # 22->21 ;
93 # 10->21 ;
94 # 2->23 ;
95 # 38->23 ;
96 # 31->24 ;
97 # 10->24 ;
98 # 0->26 ;
99 # 13->26 ;
100 # 8->26 ;
101 # 7->26 ;
102 # 4->26 ;
103 # 2->26 ;
104 # 6->26 ;
105 # 19->26 ;
106 # 10->26 ;
107 # 40->26 ;
108 # 1->26 ;
109 # 33->26 ;
110 # 19->27 ;
111 # 0->29 ;
112 # 2->29 ;
113 # 0->30 ;
114 # 32->30 ;
115 # 21->31 ;
116 # 22->31 ;
117 # 10->31 ;
118 # 0->32 ;
119 # 36->32 ;
120 # 34->32 ;
121 # 25->35 ;
122 # 2->35 ;
123 # 10->35 ;
124 # 1->35 ;
125 # 33->35 ;
126 # 0->36 ;
127 # 34->36 ;
128 # 33->37 ;
129 # 12->38 ;
130 # 2->38 ;
131 # 18->38 ;
132 # }
133 # \enddot
134 # }
135 
136 import IMP.atom
137 import IMP.container
138 import sys
139 
140 IMP.setup_from_argv(sys.argv, "Example of dependency graphs")
141 
142 
143 def create_representation():
144  m = IMP.Model()
146  all.set_name("the universe")
147  rs = []
148 
149  def create_protein(name, ds):
150  h = IMP.atom.create_protein(m, name, 10, ds)
151  # leaves = IMP.atom.get_leaves(h)
152  all.add_child(h)
154  [IMP.atom.Selection(c) for c in h.get_children()], 1)
155  if r:
156  rs.append(r)
157 
158  def create_protein_from_pdbs(name, files):
159  def create_from_pdb(file):
160  with IMP.SetLogState(IMP.NONE):
161  t = IMP.atom.read_pdb(
162  IMP.get_example_path("data/" + file), m,
164  # IMP.atom.show_molecular_hierarchy(t)
165  c = IMP.atom.Chain(IMP.atom.get_by_type(t, IMP.atom.CHAIN_TYPE)[0])
166  if c.get_number_of_children() == 0:
168  # there is no reason to use all atoms, just approximate the pdb
169  # shape instead
171  10.0 / 2.0)
172  IMP.atom.destroy(t)
173  # make the simplified structure rigid
175  rb.set_coordinates_are_optimized(True)
176  return s
177  if len(files) > 1:
178  p = IMP.Particle(m)
180  h.set_name(name)
181  for i, f in enumerate(files):
182  c = create_from_pdb(f)
183  h.add_child(c)
184  c.set_name(name + " chain " + str(i))
186  [IMP.atom.Selection(c) for c in h.get_children()], 1)
187  if r:
188  rs.append(r)
189  else:
190  h = create_from_pdb(files[0])
191  h.set_name(name)
192  all.add_child(h)
193  create_protein("Nup85", 570)
194  create_protein("Nup84", 460)
195  create_protein("Nup145C", 442)
196  create_protein("Nup120", [0, 500, 761])
197  create_protein("Nup133", [0, 450, 778, 1160])
198  create_protein_from_pdbs("Seh1", ["seh1.pdb"])
199  create_protein_from_pdbs("Sec13", ["sec13.pdb"])
200  return (m, rs, all)
201 
202 
203 def create_restraints(m, rs, all):
204  def add_connectivity_restraint(s):
206  rs.append(r)
207 
208  def add_distance_restraint(s0, s1):
209  r = IMP.atom.create_distance_restraint(s0, s1, 0, 1)
210  rs.append(r)
212  rs.append(evr)
213  s0 = IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
214  residue_indexes=range(0, 423))
215  s1 = IMP.atom.Selection(hierarchy=all, molecule="Nup84")
216  s2 = IMP.atom.Selection(hierarchy=all, molecule="Sec13")
217  add_connectivity_restraint([s0, s1, s2])
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="Nup85"))
222  add_distance_restraint(
223  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
224  residue_indexes=range(0, 423)),
225  IMP.atom.Selection(hierarchy=all, molecule="Nup120",
226  residue_indexes=range(500, 762)))
227  add_distance_restraint(IMP.atom.Selection(hierarchy=all, molecule="Nup84"),
229  hierarchy=all, molecule="Nup133",
230  residue_indexes=range(778, 1160)))
231  add_distance_restraint(IMP.atom.Selection(hierarchy=all, molecule="Nup85"),
232  IMP.atom.Selection(hierarchy=all, molecule="Seh1"))
233  add_distance_restraint(
234  IMP.atom.Selection(hierarchy=all, molecule="Nup145C",
235  residue_indexes=range(0, 423)),
236  IMP.atom.Selection(hierarchy=all, molecule="Sec13"))
237 
238 
239 # now do the actual work
240 (m, rs, all) = create_representation()
241 create_restraints(m, rs, all)
242 
244 
245 # we can get the full dependency graph for the whole model with all
246 # the restraints but it is pretty complex
249 
250 # better thing to do is to get the "pruned" graph
252 
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.
Create a scoring function on a list of restraints.
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Hierarchy create_protein(Model *m, std::string name, double target_radius, const Ints domain_boundaries)
Select all non-alternative ATOM records.
Definition: pdb.h:67
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:30
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:43
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.
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:70