IMP logo
IMP Reference Guide  2.13.0
The Integrative Modeling Platform
python_only.h
Go to the documentation of this file.
1 /**
2  * \file IMP/python_only.h \brief Build dependency graphs on models.
3  *
4  * Copyright 2007-2020 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_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
51  \external{https://pypi.python.org/pypi/altgraph/,altgraph}
52  package to graphically display a graph.
53  Note that is requires X11 to be running (you can find it in
54  your Utilities folder in MacOS) and the window produced is shockingly
55  retro.
56 
57  An alternative is to write the graph to a \c dot file
58  \code
59  g.show_graphviz(open("graph.dot", "w"));
60  \endcode
61  then turn it to pdf with \c dot
62  \command{dot -Tpdf graph.dot > graph.pdf}
63  and finally view the pdf.
64 */
65 void show_altgraph(Graph g);
66 /** Export an IMP graph to a \external{https://networkx.github.io/,networkx}
67 graph.
68  The resulting graph can be analyzed and displayed, although the graph
69  layout algorithms in networkx seem to be quite poor compared to
70  graphviz.
71 
72  On a Mac, such graphs can be displayed by
73 \code
74 import matplotlib
75 # the engine to be used must be selected before pyplot is imported
76 matplotlib.use("macosx")
77 import matplotlib.pyplot as plt
78 
79 import networkx
80 networkx.draw_spring(xg)
81 plt.show()
82 \endcode
83  */
84 networkx::DiGraph get_networkx_graph(Graph g);
85 
86 /** Generate a nice pdf of the graph and attempt to open the pdf. The name
87  of the pdf will be returned in case the attempt to open it fails.
88 */
89 std::string show_graphviz(Graph g);
90 /** @} */
91 #endif
92 
93 IMPKERNEL_END_NAMESPACE
94 
95 #endif /* IMPKERNEL_PYTHON_ONLY_H */
Vector< VectorD< D > > get_vertices(const BoundingBoxD< D > &bb)
Return a list of the 2^D bounding points for the bounding box.
Definition: BoundingBoxD.h:274
Storage of a model, its restraints, constraints and particles.
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
std::string show_graphviz(Graph g)
networkx::DiGraph get_networkx_graph(Graph g)
void show_altgraph(Graph g)