Generating thumbnail previews automatically from PDB files
4
0
Entering edit mode
2.5 years ago
Michael 55k

I anticipate that this problem might be slightly more complicated than it sounds at first because I haven't found a good solution by googling yet:

I have predicted 3D structures for over 200 protein sequences by using AlphaFold2. Now I want to generate preview images or thumbnails automagically to use on an overview page or in a table. It would be best if that script could be run directly from the Unix command line without any interaction. So far so good, but of course, the structure needed to be analyzed, centered and oriented to set up some sort of preliminary scene, possibly a cartoon view would be sufficient. Does anybody have a python/pymol, Chimera, or whatever script for this task? Anything that works is fine. In fact, what I need is exactly what the MolScript/MolAuto software would have done years ago. But unfortunately, the tool is no longer available.

MolAuto can be part of a UNIX pipe with MolScript, for example when producing 
a quick display of a PDB structure using the OpenGL implementation in MolScript:
% molauto pdb1rbp.ent | molscript -opengl
pymol chimera image PDB • 2.8k views
ADD COMMENT
0
Entering edit mode

not really a python approach but I think that imagemagick is capable of generating tumbnails from any image using cmdline .

ADD REPLY
0
Entering edit mode

Sorry, I don't have an image file yet, what I have are the PDB files from AlphaFold, that's it.

The output directories contain the following files and the msas directory, no images:

features.pkl  ranked_4.pdb         relaxed_model_5.pdb  timings.json
msas          ranking_debug.json   result_model_1.pkl   unrelaxed_model_1.pdb
ranked_0.pdb  relaxed_model_1.pdb  result_model_2.pkl   unrelaxed_model_2.pdb
ranked_1.pdb  relaxed_model_2.pdb  result_model_3.pkl   unrelaxed_model_3.pdb
ranked_2.pdb  relaxed_model_3.pdb  result_model_4.pkl   unrelaxed_model_4.pdb
ranked_3.pdb  relaxed_model_4.pdb  result_model_5.pkl   unrelaxed_model_5.pdb
ADD REPLY
1
Entering edit mode
2.5 years ago
GenoMax 148k

Michael Dondrup software seems to be here https://github.com/pekrau/MolScript.git Is it not compiling?

ADD COMMENT
0
Entering edit mode

Thanks for finding this. I guess the makefile will need a few tweaks to compile on Mac or Linux, trying it out now.

Indeed, it works, (simply xD) compile the binaries, start XQuartz, then run: molauto ranked_0.pdb | molscript -png none -out bla.png -size 300 300

Result

enter image description here

ADD REPLY
0
Entering edit mode

So, indeed I managed to finally compile a version on the Mac from source using a s***t-load of duct tape, the code wasn't really portable (developed for a 20 year old IRIX compiler and 'needs adaptation' for Windows 95/NT, so in a sense it is quite a miracle it worked at all). So now let's see how the binaries work out.

ADD REPLY
1
Entering edit mode
2.5 years ago
Joe 21k

This can be done with a bit of python (and pychimera) and UCSF Chimera's native command language I suspect.

When you say a thumbnail, are you specifically looking to create images of a given aspect ratio? e.g. 400x400px?

It's been a while since I've done something like this, but you can probably use this for inspiration: https://github.com/jrjhealey/chimera/blob/master/tools/SSCalc.py

All you'd need to do is use the chimera commands:

runCommand("focus")
runCommand("copy")

https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/print.html

You can pass various parameters like image size etc to it.

ADD COMMENT
0
Entering edit mode

In fact, I found a better old script of mine for inspiration. I don't think I ever finished it, but it might be useful.

#!/usr/bin/python

# Import and render images of PDBs in a Goodsell-esque manner
# PDB's molecules of the month are in this style.

# This script uses USCF Chimera, so ensure it is installed.
# Pychimera is also recommended.

import warnings
import traceback
import sys
import os

import pychimera

import chimera
from chimera import openModels, Molecule, actions
import MultiScale

from chimera import runCommand as rc

# Logging and status options

#from chimera import replyobj
# replyobj.status("Processing " + fn)
#from chimera.tkgui import saveReplyLog
#saveReplyLog("~/reply-log.txt")


def parseArgs():
    """Parse commandline arguments"""

    import argparse
    try:
        parser = argparse.ArgumentParser(description='This script creates PDB "Molecule of the Month" like figures in the style of David S. Goodsell.')
        parser.add_argument(
            '-p',
            '--PDB',
            action='store',
            help='The PDB ID to render.')
        parser.add_argument(
            '-v',
            '--verbose',
            action='store_true',
            help='Print additional messages to screen. Default behaviour is false.')
        parser.add_argument(
            '-o',
            '--outfile',
            action='store',
            default='None',
            help='Output file name. The image will be given this name followed by the extension you provide. If you elect to save a session too, the session will also be given this name.')            
        parser.add_argument(
            '-d',
            '--device',
            action='store',
            choices=['.eps','.jpg',',jpeg','.ps', '.png', '.tif', '.tiff', '.ppm'])
            help='Specify what type of output image you want.'
    except:
        print "An exception occured with argument parsing. Check your provided options."
        traceback.print_exc()

    return parser.parse_args()


    # Color atoms by element
    # 2btv does not have biological oligomer (BIOMT) matrices.
    # So get 120 matrices for a crystal unit cell with 2 virus particles
    # and use only first 60 to get just one particle.
    import PDBmatrices
    # Make copies of molecule.
    from MultiScale import molecule_copies
    mcopies = molecule_copies(m, matrices)

    # Define groups and colors.
    from MultiScale import make_chain_groups, make_group

    import MultiScale
    mm = MultiScale.multiscale_manager()
    mm.add_models([capsid])


def getOutfile(pdb, device):
    indir, filename = os.path.split(os.path.abspath(pdb))
    path_plus_filename = os.path.splitext(os.path.abspath(pdb))[0]
    session = path_plus_filename + '.py'
    image = path_plus_filename + device

    return indir, filename, path_plus_filename, session, image


def main():

    args = parseArgs()

    pdb = args.pdb
    verbose = args.verbose
    outfile = args.outfile
    device = args.device


    model = chimera.openModels.open(top_hit,type="PDB")[0]
    d = MultiScale.show_multiscale_model_dialog()
    d.make_multimers([m])

    chimera.viewer.viewAll() #  Centers the molecule within view


    rc('save {0}_session.py'.format(outfile))
    chimera.closeSession()
    print("Chimera exited. All done. All results are in: " + outdir)
    rc('stop now')
    sys.exit(0)

if __name__ == '__main__':
    main()
ADD REPLY
0
Entering edit mode

Which python version is this?

ADD REPLY
0
Entering edit mode

This is pretty old code, so would need revising for newer versions I expect - can't give you an exact number.

The way pychimera (https://github.com/insilichem/pychimera) works is to give you access to the bundled copy of the python interpreter that chimera uses so it is exposed to the commandline - your actual system binaries aren't important.

Currently this limits you to whatever version of python Chimera is using (2.7 last I checked i think).

ADD REPLY
0
Entering edit mode

Hi, thank you. I will maybe try to adapt the script later because the rendering quality will likely be much better with Chimera than with MolScript. But for now, I have already generated all 200 thumbnails and am now struggling with VBA to get them imported into my Excel sheet, but that is another story.

ADD REPLY
1
Entering edit mode

I will maybe try to adapt the script later because the rendering quality will likely be much better with Chimera than with MolScript.

Opinions vary about molecular display programs, but I don't think there is any way possible than any of them would be much better than MolScript, especially when coupled with Raster3D. The image below was made with MolScript/Raster3D almost 20 years ago when PyMol was about 5 years old, and Chimera wasn't much older.

enter image description here

ADD REPLY
0
Entering edit mode

Great! Compiling from source ....

ADD REPLY
0
Entering edit mode
2.5 years ago
Mensur Dlakic ★ 28k

There used to be a tool exactly for this purpose. It would automatically find the best projection for a molecule from PDB files.

https://academic.oup.com/bioinformatics/article/19/7/882/197662

The website is not available any more, but it is in your neck of the woods (generally speaking) so you may be able to contact the authors. Its idea is fairly straightforwrd and it would not surprise me if someone re-implemented it more recently.

Once the molecule is oriented, there should be many PyMol scripts that automatically read the PDB file and create an image.

ADD COMMENT
0
Entering edit mode
2.5 years ago
Jiyao Wang ▴ 380

You can also use a python script based on iCn3D to export PNG files in command line. One example script is at https://github.com/ncbi/icn3d/tree/master/icn3dpython/batch_export_png.py .

ADD COMMENT

Login before adding your answer.

Traffic: 2554 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6