Sign inSign up

jysgro/pymol

By jysgro

Updated over 1 year ago

PyMOL molecular graphics for command-line access.

Image
Data science
0

1.2K

jysgro/pymol repository overview

Open Source PyMOL in Ubuntu and/or Debian12.

The Ubuntu version defines which pymol is installed since command apt-get install -y libqt5gui5 pymol does not specify PyMOL version.

Dockerfiles modified from "pymol" entry at github.com/pegi3s/dockerfiles

See below for test usage in paragraph Test usage for _sc tags.

For "plain PyMOL" versions use commands like:

docker run -it --rm -v ${PWD}:/data -w /data jysgro/pymol:2.5.0
docker run -it --rm -v ${PWD}:/data -w /data jysgro/pymol:2.3.0
docker run -it --rm -v ${PWD}:/data -w /data jysgro/pymol:1.8.4
docker run -it --rm -v ${PWD}:/data -w /data jysgro/pymol:1.7.2.1

Pymol 2.5.0

Dockerfile modified for USA central time

FROM ubuntu:23.04
ENV TZ=America/Chicago
RUN apt-get update && \
	ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
	apt-get install -y libqt5gui5 pymol

PyMOL 2.3.0

FROM ubuntu:20.04
ENV TZ=America/Chicago
RUN apt-get update && \
	ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
	apt-get install -y libqt5gui5 pymol

PyMOL 1.8.4

FROM ubuntu:18.04
ENV TZ=America/Chicago
RUN apt-get update && \
	ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
	apt-get install -y libqt5gui5 pymol

PyMOL 1.7.2.1

FROM ubuntu:16.04
ENV TZ=America/Chicago
RUN apt-get update && \
	ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
	apt-get install -y libqt5gui5 pymol

PyMOL versions with _sc TAG suffix

Inspired and based on paper Shortcuts for faster image creation in PyMOL PMC
Repo: github.com/MooersLab/PyMOLshortcuts](https://github.com/MooersLab/PyMOLshortcuts)

These Docker files are extended to add the shortcuts so that they run automatically when calling PyMOL through the .pymolrc file installed in the $HOME directory for user pymoluser which is listed as a "sudoer" i.e. sudo commands are allowed. Two acripts are installed in ~/Scripts/PyMOLScripts:

There are 3 versions with different Python versions:

  • Docker image TAG 1.8.4_sc contains open-source PyMOL 1.8.4.0 and contains Python 2.7.17.
  • Docker image TAG 2.5.0_sc contains open-source PyMOL 2.5.0 and contains Python 3.11.4.
  • Docker image TAG deb12-2.5.0_sc contains open-source PyMOL 2.5.0 and contains Python 3.9 installed with conda.

These _sc versions contain scripts in ~/Scripts/PyMOLScripts. Python3 versions have a few modifications in the scripts (see below) as the original was for python 2.7.x.

While most of the commands work with both Python 2.7.x and Python 3.x, the one that causes problems is BU (build Biological Unit) which has been fixed with the modifications detailed below (but may not be ideal computationally.)

The script pymolshortcuts.py in ~/Scripts/PyMOLScripts are invoked each time PyMOL is started thanks to file ~/.pymolrc. (See pymolwiki.)

ISSUES: While most of the commands are working, there are specific issues with some of the commands due to the Python difference and the naming of the quat.py script:

  • Script pymolshortcuts.py refers to quat.py as quat3.py at least once. I never found anywhere on the Internet a version with this name. Thus I created a symbolic link in ~/Scripts/PyMOLScripts

  • Script pymolshortcuts.py is written for Python 2.7.x.

SOME adaptation can be made to allow this script to run under SOME of the Python 3 software, but not necessarily all by adding __future__ options and/or making a minor change with the python package six:

Adding __future__ options for Python 3 compatibility

For the _sc versions that use python 3 I added __future__ options in quant.py on the line numbers shown at left:

11	from __future__ import (absolute_import, division,
12	                        print_function, unicode_literals)
13	from builtins import *
14	import six

For the _sc versions that use python 3 I added __future__ options in pymolshortcuts.py on the line numbers shown at left:

 99	from __future__ import (absolute_import, division,
100	                        print_function, unicode_literals)
101	from builtins import *
103	import six
updating basetring to six.string.types for Python 3 compatibility

In addition the following lines were changed by substituting basetring with six.string_types as explained in https://portingguide.readthedocs.io/en/latest/strings.html Archived.

 11340	    if not isinstance(filename, six.string_types):
 11359	    if not isinstance(filename, six.string_types):

PyMOL 2.5.0_sc

Note: in spite of changes, this version causes Segmentation fault when using the BU (Biological Unit) command. Thus, for successful "BU" command use other Docker image with tag: jysgro/pymol:deb12-2.5.0_sc.

Dockerfile:

# https://hub.docker.com/r/pegi3s/pymol/dockerfile

FROM ubuntu:23.04
ENV TZ=America/Chicago
RUN apt-get update && \
	ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
	apt-get install -y libqt5gui5 pymol
	
RUN apt-get install -y wget nano git

# Update some Python stuff
# need to subsitute "basetring" in original script to "six.string_types"
# See https://portingguide.readthedocs.io/en/latest/strings.html

RUN apt update && apt install -y  python3-pip && \
    apt install -y python3-six

RUN cd /usr/bin &&\
    ln -s python3 python

# Make non-root user
# FROM: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
# ARG USERNAME=user-name-goes-here
ARG USERNAME=pymoluser
ARG USER_UID=1010
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    #
    # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
    && apt-get update \
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME

# ********************************************************
# * Anything else you want to do like clean up goes here *
# ********************************************************

USER $USERNAME

# RUN cd $HOME && \
#    mkdir -p $HOME/Scripts/PyMOLScripts &&\
#    cd $HOME/Scripts/PyMOLScripts 
#    wget https://raw.githubusercontent.com/MooersLab/pymolshortcuts/master/pymolshortcuts.py &&\
#    wget https://raw.githubusercontent.com/MooersLab/EasyPyMOL/master/quat.py &&\

COPY ./pymolshortcuts_for_python_3/pymolshortcuts.py /home/$USERNAME/Scripts/PyMOLScripts/pymolshortcuts.py
COPY ./pymolshortcuts_for_python_3/quat.py  /home/$USERNAME/Scripts/PyMOLScripts/quat.py

RUN  cd /home/$USERNAME/Scripts/PyMOLScripts  && \
     sudo chown $USERNAME . &&\
     sudo chown $USERNAME * &&\
     ln -s quat.py quat3.py && \
     echo 'run $HOME/Scripts/PyMOLScripts/pymolshortcuts.py' > ~/.pymolrc

WORKDIR /home/pymoluser

PyMOL 2.5.0 TAG: deb12-2.5.0_sc

This version is installed with Conda that makes the Docker image much larger. However, it contains the python package six already (See basestring discussion above.)

Inspired by Docker image at biopod/pymol:2.5.0 with Dockerfile available at https://github.com/bio-pod/PyMOL

Dockerfile:

# https://github.com/bio-pod/PyMOL/blob/main/Dockerfile.biopod.pymol.2.5.0
# Raw: https://raw.githubusercontent.com/bio-pod/PyMOL/main/Dockerfile.biopod.pymol.2.5.0
#############################
# syntax=docker/dockerfile:1
FROM debian:12.0-slim AS build
LABEL Description="pymol:2.5.0 build"

ENV TZ=America/Chicago \
    DEBIAN_FRONTEND=noninteractive

WORKDIR /app
SHELL ["/bin/bash", "-c"]

RUN apt-get update && \
    apt-get -y --no-install-recommends install \
    wget nano libgl1 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh &&\
# wget locally and COPY as they did, just change the PATH
COPY ./Miniconda3-py39_4.12.0-Linux-x86_64.sh /app/

# mv Miniconda3-py39_4.12.0-Linux-x86_64.sh /app/
# IF building on an `arm64` M1 Silicon mac:
# ERROR: The certificate of 'repo.anaconda.com' is not trusted.
#  qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
# Thus => only build AMD64 version.
    
RUN cd /app/ && /bin/bash ./Miniconda3-py39_4.12.0-Linux-x86_64.sh -b -p /app/miniconda
ENV PATH=/app/miniconda/bin:${PATH}

# Install conda packages
RUN conda install -c conda-forge pymol-open-source=2.5.0
    # conda install -y -q numpy=1.20.3


FROM debian:12.0-slim AS runtime
LABEL Description="pymol:2.5.0 runtime"

ENV TZ=America/Chicago \
    DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get -y --no-install-recommends install \
    nano wget libgl1 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

COPY --from=build /app/miniconda /app/miniconda
ENV PATH=/app/miniconda/bin:${PATH}

# WORKDIR /mnt
###################
# Make non-root user
# FROM: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
# ARG USERNAME=user-name-goes-here
ARG USERNAME=pymoluser
ARG USER_UID=1010
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    #
    # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
    && apt-get update \
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME

# ********************************************************
# * Anything else you want to do like clean up goes here *
# ********************************************************

USER $USERNAME

# RUN cd $HOME && \
#    mkdir -p $HOME/Scripts/PyMOLScripts &&\
#    cd $HOME/Scripts/PyMOLScripts 
#    wget https://raw.githubusercontent.com/MooersLab/pymolshortcuts/master/pymolshortcuts.py &&\
#    wget https://raw.githubusercontent.com/MooersLab/EasyPyMOL/master/quat.py &&\

COPY ./pymolshortcuts_for_python_3/pymolshortcuts.py /home/$USERNAME/Scripts/PyMOLScripts/pymolshortcuts.py
COPY ./pymolshortcuts_for_python_3/quat.py  /home/$USERNAME/Scripts/PyMOLScripts/quat.py

RUN  cd /home/$USERNAME/Scripts/PyMOLScripts  && \
     sudo chown $USERNAME . &&\
     sudo chown $USERNAME * &&\
     ln -s quat.py quat3.py && \
     echo 'run $HOME/Scripts/PyMOLScripts/pymolshortcuts.py' > ~/.pymolrc

WORKDIR /home/pymoluser

Test usage for _sc tags

The main purpose of these Docker images is to use PyMOL without GUI with a file containing instructions, e.g.: pymol -qc commands.pml

To test command BU here is a short command file using 1DUD which biological assembly is a trimer of the crystallographic unit. The scripts only work with PDB and not CIF file formats. Hence it is necessary to download the PDB version. The command contains the download command, which can be changed to load once the download has occurred once.

File commands.pml example:

 fetch 1dud, type=pdb
# load 1dud.pdb
remove solvent
BU
center
turn z, -10
BW
png test.png

Save file commands.pml in current directory. THE, start container with:
docker run -it --rm -v ${PWD}:/data -w /data jysgro/pymol:deb12-2.5.0_sc
OR docker run -it --rm -v ${PWD}:/data -w /data jysgro/pymol:1.8.4_sc

Issue command: pymol -qc commands.pml

This will create a PNG file of 640x480 pixel by default, with a black-and-white outline of the triplet.

Note: TAG 2.5.0_sc (see above) causes Segmentation fault when invoking the BU command.


**---------------------------**
I made these images with the idea to run them **without** GUI. However, the following info might be useful for using the GUI anyway...
**---------------------------**

NOTE ORIGINAL INFORMATION FROM github.com/pegi3s/dockerfiles

This image belongs to a larger project called Bioinformatics Docker Images Project (http://pegi3s.github.io/dockerfiles)

(Please note that the original software licenses still apply)

Using the PyMOL image in Linux

Please note that the following instructions must be executed in Linux environments only.

You should adapt and run the following command: docker run --rm -ti -e USERID=$UID -e USER=$USER -e DISPLAY=$DISPLAY -v /var/db:/var/db:Z -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/home/developer/.Xauthority --device /dev/dri/ -v "/your/data/dir:/data" pegi3s/pymol pymol

If the above command fails, try running xhost + first. In this command, you should replace:

  • /your/data/dir to point to the directory that you want to have available at PyMOL.

Running this command opens the PyMOL Graphical User Interface. Your data directory will be available through the file browser at /data.

Test data

To test the previous command, a Protein Data Bank (PDB) file is available here.

Tag summary

Content type

Image

Digest

sha256:c34d7b442

Size

368.6 MB

Last updated

over 1 year ago

docker pull jysgro/pymol:3.1.0_amd_arm