IMP  2.0.0
The Integrative Modeling Platform
kernel/python_only.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/python_only.h \brief Build dependency graphs on models.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPKERNEL_PYTHON_ONLY_H
9 #define IMPKERNEL_PYTHON_ONLY_H
10 
11 #include <IMP/kernel/kernel_config.h>
12 #include "Model.h"
13 #include <boost/graph/adjacency_list.hpp>
14 
15 IMPKERNEL_BEGIN_NAMESPACE
16 
17 #ifdef IMP_DOXYGEN
18 /** \name Python Only
19  The following functions are only available in python.
20  @{
21 */
22 /** The boost graphs used on the C++ side in \imp cannot easily be
23  exported to python. Instead we provide a simple graph wrapper and
24  a set of helper functions.
25 
26  Each node of the graph has an associated vertex name, the exact type
27  of which depends on the graph.
28 
29  \pythononlyclass
30 */
32 public:
33  class VertexDescriptor;
34  class VertexDescriptors;
35  class VertexName;
36  Vertices get_vertices() const;
37  VertexName get_vertex_name(VertexDescriptor v) const;
38  VertexDescriptors get_in_neighbors(VertexDescriptor) const;
39  VertexDescriptors get_out_neighbors(VertexDescriptor) const;
40  void add_edge(VertexDescriptor, VertexDescriptor);
41  VertexDescriptor add_vertex(VertexName);
42  void remove_vertex(VertexDescriptor);
43  /** Show the graph in the graphviz format.
44  \note The vertices are not output in order, but have
45  their indices shown.
46  */
47  void show(std::ostream &out=std::cout) const;
48 };
49 
50 /** Use the python \external{http://packages.python.org/altgraph/core.html,altgraph}
51  package to graphically display a graph.
52  Note that is requires X11 to be running (you can find it in
53  your Utilities folder in MacOS) and the window produced is shockingly
54  retro.
55 
56  An alterntative is to write the graph to a \c dot file
57  \code
58  g.show_graphviz(open("graph.dot", "w"));
59  \endcode
60  then turn it to pdf with \c dot
61  \command{dot -Tpdf graph.dot > graph.pdf}
62  and finally view the pdf.
63 */
64 void show_altgraph(Graph g);
65 /** Export an IMP graph to a \external{http://networkx.lanl.gov/,networkx} graph.
66  The resulting graph can be analyzed and displaye, although the graph
67  layout algorithms in networkx seem to be quite poor compared to
68  graphviz.
69 
70  One a mac, such graphs can be displayed by
71 \code
72 import matplotlib
73 # the engine to be used must be selected before pyplot is imported
74 matplotlib.use("macosx")
75 import matplotlib.pyplot as plt
76 
77 import networkx
78 networkx.draw_spring(xg)
79 plt.show()
80 \endcode
81  */
82 networkx::DiGraph get_networkx_graph(Graph g);
83 
84 
85 /** Generate a nice pdf of the graph and attempt to open the pdf. The name
86  of the pdf will be returned in case the attempt to open it fails.
87 */
88 std::string show_graphviz(Graph g);
89 /** @} */
90 #endif
91 
92 IMPKERNEL_END_NAMESPACE
93 
94 #endif /* IMPKERNEL_PYTHON_ONLY_H */