The Graph-Tool Orbital of the Hydrogen Atom
If you know what this is going to be about by just reading the title, please contact me and I will treat you to the courtesy of your favourite beverage based on the fermentation of barley. For the rest of you (honest) folks, I’ll be explaining how to set up an interactive coding environment for a powerful tool used in network science called graph-tool.

Graph-tool is a fully documented python module created by Tiago Peixoto for manipulation and statistical analysis of networks with lots of features, perty visualization capabilities (see fig. 1), and awesome performance. You don’t get this performance for free though: the core data structures and algorithms of this module are implemented in C++, which means that its installation is not as simple as that of a pure python module. Lucky for us it’s 2018 and Docker exists in the world (and Tiago knows this). This does not only ease installation, it also helps us tackle those nasty issues in reproducibility that plague the research community.
Now for the interactive part. There is this very nifty Atom package by nteract called Hydrogen that makes the whole development experience way more pleasant.

The tricky thing is that executing graph-tool from within a docker container means setting up Hydrogen in such a way that they are able to talk to each other. So first we need a docker image with a) graph-tool and b) configured to work with a remote kernel Hydrogen can connect to. I built an image that fits this description and pushed it to the hub, but if you wish to build one yourself, your dockerfile should look something like this:
FROM jupyter/minimal-notebook
ADD https://github.com/krallin/tini/releases/download/v0.14.0/tini /tini
USER root
RUN chmod +x /tini
ENV JUPYTER_TOKEN=my_secret_token
EXPOSE 8888
ENTRYPOINT [“/tini”, “ — “]
CMD [“jupyter-notebook”, “ — allow-root”, “ — no-browser”, “ — port=8888”]FROM tiagopeixoto/graph-tool
Remember that one does not simply use root — think about the security vulnerabilities this can open up in your setup.
Now open up the Hydrogen settings in Atom and insert the following value for the kernel gateways:
[{ "name": "graph-tool-hydro", "options": {"baseUrl": "http://0.0.0.0:8888"} }]
To get the container with graph-tool up and running you should type something like this into your terminal:
docker run \
-p 8888:8888 \
-p 6006:6006 \
-ti \
-u user \
-w /home/user \
--name $MYCONTAINER \
--mount type=bind,source=$LOCAL,target=$REMOTE,readonly \
-v $LOCAL:$REMOTE:Z \
graph-tool-hydro \
bash -c \
"jupyter notebook --ip 0.0.0.0 \
--NotebookApp.token= \
--NotebookApp.disable_check_xsrf=True"
For my current setup it was easier to employ bind mounts, but in general it’s recommendable to use volumes. — mount
in my case isreadonly
because that folder contains the datasets I’m analyzing and altering them without knowing would make me feel the pain. Please note the :Z
at-v
can be dangerous and that the last two lines are just pure #YOLO / an invitation card for malicious attacks depending on your setup.
Finally hit Ctrl+Shift+p
to open the command palette in Atom, type Hydrogen: Connect To Remote Kernel
, and press Enter
s.
You’re ready to go.