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