Docker PyMOL

PyMOL is a great program that runs  natively on all 3 major platforms. However, I wanted to use a docker image that allegedly can run PyMOL (albeit an older version 1.8.2.) The reason might not be apparent at first but while the 3D interactivity would be slow, there can be other reason such a contraption could be useful, one of them could be to use PyMOL as a python interpreter, or to use PyMOL without a graphical interface to manipulate coordinates within a script, for example changing a chain name from A to B.

X11 – the tricky part

Docker is inherently a Linux process at the base and therefore the graphical interface of PyMOL within a (Linux-based) docker would have to be X11. So an X11 software must be installed on the local machine XQuarz for Mac, and e.g. Xming on Windows

There are a few docker images for PyMOL on the Docker hub, some have not been updated in years. I have identified two that work, even though one was updated only 15 days ago it runs the same PyMOL version of 1.8.x as the one last updated 3 years ago.

In testing I had to issue some commands that may or may not be relevant to all, but seemed to make a difference for my Mac running the current  XQuarz (2.7.11) and macOS 10.14.6 (Mojave.)

Here are the commands that made a difference to avoid X11 errors, both entered on a terminal.

This one is specific for Mac (see bugs.freedesktop.org [archived 03/03/2020: https://bit.ly/2TBoj9b])

  • defaults write org.macosforge.xquartz.X11 enable_iglx -bool true

The above command should be given while XQuarz is Not running.

The Xquartz set-up must accept network connections, which is not the default. Follow these steps:

  • Start XQuartz go to menu:
    • Xquartz > Preferences...
    • click on Security tab
    • activate option “Allow connections from network clients

The local computer must be instructed that X11 information should go through. This is done with program xhost that will create an authorized list:

  • xhost + 127.0.0.1

An alternate command is:

  • xhost + localhost

Display

This is the final most tricky command and defines how graphics coming from the container can reach the screen of the Mac…

See explanations on docs.docker.com/docker-for-mac/networking and How to show X11 windows with Docker on Mac by Marc Reichelt https://bit.ly/2usa0bB (Archived June 2019 at https://bit.ly/2rwEk5Y)

Starting PyMOL from container

If all went well, it should be possible to start any of these 2 containers with command:

docker run --rm --user root -it -e DISPLAY=docker.for.mac.localhost:0 edwinksl/pymol

or the more recent image:

docker run --rm -it -e DISPLAY=docker.for.mac.localhost:0 pegi3s/pymol pymol

Or with the alternative DISPLAY option:

docker run --rm -it -e DISPLAY=host.docker.internal:0   pegi3s/pymol pymol

PyMOL 1.8.x as X11 display from docker
PyMOL 1.8.x as X11 display running from a docker container

PyMOL without graphics

It is possible indeed to use PyMOL without its graphical interface as stated above, for example invoking PyMOL with command line

pymol -cq somescript.py

The details can be found on the PyMOL Wiki “Launching from a script” (Archived July 16, 2016: https://bit.ly/38h1IEt)

This may be the subject of a future workshop.