home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
2.22.0
The Integrative Modeling Platform
IMP Manual
Reference Guide
Tutorial Index
Modules
Classes
Examples
doc
examples
kernel
graph.py
1
## \example kernel/graph.py
2
# A simple example showing how to use the graph interface in Python.
3
4
import
IMP
5
import
sys
6
7
IMP.setup_from_argv
(sys.argv,
"Graph interface"
)
8
9
m =
IMP.Model
()
10
# An undirected graph with an IMP::Object for each node
11
g =
IMP.DependencyGraph
()
12
vs = []
13
ps = []
14
for
i
in
range(0, 10):
15
ps.append(
IMP.Particle
(m))
16
vs.append(g.add_vertex(ps[-1]))
17
g.add_edge(vs[0], vs[1])
18
g.add_edge(vs[1], vs[2])
19
20
# try to use the altgraph package to visualize
21
IMP.show_graphviz
(g)
22
try
:
23
IMP.show_graphviz
(g)
24
except
:
25
print(
"Oh well, no altgraph"
)
26
27
try
:
28
import
matplotlib
29
# the engine to be used must be selected before pyplot is imported
30
matplotlib.use(
"macosx"
)
31
import
matplotlib.pyplot
32
33
# the method below requires the altgraph Python package
34
xg =
IMP.get_networkx_graph
(g)
35
36
# the networkx visualization tools suck, so skip them
37
# import networkx
38
# networkx.draw(xg)
39
# networkx.draw_shell(xg)
40
# matplotlib.pyplot.show()
41
except
:
42
print(
"networkx not fully installed"
)
43
44
g.remove_vertex(0)
45
46
# we can also try another show method
47
try
:
48
IMP.show_graphviz
(g)
49
except
:
50
print(
"oh well, something not working with graphviz"
)
51
52
# finally, we can
53
# in and out neighbors are the same
54
for
n
in
g.get_in_neighbors(8):
55
print(g.get_vertex_name(n).get_name())
IMP::setup_from_argv
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
IMP::DependencyGraph
boost::graph DependencyGraph
Directed graph on the interactions between the various objects in the model.
Definition:
dependency_graph.h:35
IMP::Model
Class for storing model, its restraints, constraints, and particles.
Definition:
Model.h:86
IMP::Particle
Class to handle individual particles of a Model object.
Definition:
Particle.h:43
IMP::show_graphviz
std::string show_graphviz(Graph g)
IMP::get_networkx_graph
networkx::DiGraph get_networkx_graph(Graph g)