Search code examples
pymol

Focusing in on specific areas in PyMOL from command line?


I just started using PyMOL and Unix commands to look at .pdb files and I have a task that I want to perform, but I don't know exactly how to implement it.

You can find the task described below:

"Download this tar file and unpack it using the command line.

This file contains 271 .pdb files and I want to focus in on residues numbered 40-55 in all files using PyMOL from the command line.

Once those residues are focused in PyMOL, I want to save the images and export the snapshots to an html page/format."

I would like to do all this using piping in Unix. I have some of the basics down but I need help with some of the more complex tasks. Any help is greatly appreciated!


Solution

  • Since you want to do this using "piping in Unix", I will describe here the plain command line version on how to proceed. I will deliberately omit the part "export the snapshots to an html page/format" because this goes beyond PyMOL and can be done with many other programs or tools.

    First, you want to iterate over the pdb files inside your folder:

    for protein in *.pdb;
    ###launching PyMOL and passing commands here;
    done
    

    these commands you are going to need for PyMOL:

    First, let's start the PyMOL executable from the shell. Depending on the operating system you work on this may vary. I will use macOS as an example. Further help on how to start PyMOL from the command line you can find here.

    /Applications/PyMOL.app/Contents/MacOS/PyMOL -cq $protein -d "###here come the PyMOL commands"
    

    c means, that the PyMOL gui won't start (we don't need it here), and q omits PyMOL's welcome message. $protein is each PDB file we're looping over. d means PyMOL commands are going to be passed. We are going to use the following commands to get your piece of peptide for each PDB file and create a PNG image:

    first we make sure that nothing else will be visible:

    hide everything;
    

    now we select your residues 40 through 55 and name this selection "pieceofpeptide":

    select pieceofpeptide, resi 40-55;
    

    depending on how you want the representation to look (e.g. cartoon, licorice, lines etc.) you choose the style in the next command:

    show cartoon, pieceofpeptide;
    

    Now we make sure that the image is centered (try varying the number, it represents the distance from the object we center):

    zoom center, 20;
    

    Finally, let's save this as an image (adjust resolution to your needs):

    png $protein.png, width=10cm, dpi=150, ray=1
    

    written as a one-liner the final command eventually looks like this:

    for protein in *.pdb; do /Applications/PyMOL.app/Contents/MacOS/PyMOL -cq $protein -d "hide everything;select pieceofpeptide, resi 40-55;show cartoon, pieceofpeptide;zoom center, 20;png $protein.png, width=10cm, dpi=150, ray=1"; done
    

    It is however, much easier to see and edit if you store PyMOL commands in a file like script.pml, or use a Python script, but this is best explained here.