# How to delete everything but a specific ligand from a PDB file using Linux-compatible free software?

I would like to delete everything from a PDB file except a specific ligand that I know the PDB code for. Is there a simple way to using free Linux-compatible software? If you want a specific example for your answer 1YAT and its ligand FK5 (tacrolimus) is an example I'm presently working on. I think PyMOL might have this capability using the delete command but running:

delete /1YAT/A


which should delete the macromolecule (chain A) at least but I saw no visually-obvious change. I have viewed the PyMOL Wiki article on the delete command but it was not helpful as what name meant was not obvious to me.

By free software I mean free of charge not free as in freedom. One piece of software that I used to do this with on Windows was Accelrys (or BIOVIA) Discovery Studio Visualizer, tried to run it on Arch Linux, however, as it has a Linux binary, but it failed to run. This is presumably because it is for Red Hat Enterprise Linux/SUSE Linux Enterprise which has too old of system libraries for Arch Linux compatibility.

• The PDB is human readable, so the quickest way is just to use a text editor and delete all the bits you don't want; its messy but if you have only to do it once then probably ok. Alternatively if you have many files use python (with, say, Atom(apple mac) or notepad++(PC) code editors) to read line by line and print same for only the header parts (those not starting with word 'ATOM' ) and then print the 'HETATM' parts you want. Python, Atom and Notepad++ are all free and there is lots of online help to use python. Jul 25 '17 at 10:40
• Sed and/or vim. Jul 25 '17 at 20:59
• I'm having trouble envisioning why you want to get the conformation of the ligand using this method. There is a plethora of open-source, linux-compatible chemoinformatic software to do this. Here's an example using rdkit: nbviewer.jupyter.org/github/tentrillion/ipython_notebooks/blob/… . (Note that you should be able to pan/zoom with the mouse on "Out[6]" to look at the conformation in detail). There are similar capabilities, I'm sure, in cdk and other software. Jul 25 '17 at 23:46
• I usually use Avogadro, Jmol, Mercury and PyMOL only and I was unaware of ways to remove everything but the ligand with any of these pieces of software. Guessing that was what you were asking since your rdkit example was along the line of suggesting another method of doing this. If you're asking why this method of determining the 3D structure as opposed to optimization and other methods well I want to draw structures for Wikipedia (e.g. here is one of mine commons.wikimedia.org/wiki/File:Tianeptine-xtal-2012.png) and crystal structures are preferred there. Jul 26 '17 at 0:12

You can do this with Avogadro

First, open the PDB file. Then choose Select > Select by Residue

Now pick Select > Invert Selection followed by Edit > Clear

Done. (Well, save the new file... :-)

• I'll note that there must be some way to do this with PyMol, but it's pretty easy to do in Avogadro. Jul 25 '17 at 18:56
• Is it possible to do this with Avogadro2? I don't see a "Select by Residue" option in is Select menu, only All, None and Invert Selection. May 19 '18 at 19:26
• @BH2017 - Avogadro2 at the moment is in beta and has no residue/biomolecule support yet. May 19 '18 at 20:06

grep -w " AAA " file.pdb > ligand.pdb


? Where you substitute AAA with the name of the residue you want.

• While you don't get visual confirmation of the ligand match, I think this is a nice hack. :-) Jul 26 '17 at 14:05
• Well, usually before redirecting the output to a file you try few things. grep -w is not immediate, one learns it step by step. First you grep only and then you refine the command, maybe even piping to sed or head or whatever. Or you redirect using tee. Or maybe I misunderstood and you meant "visual" as in "actually visualizing the structure"...but I don't think it's really necessary!
– Anon
Jul 26 '17 at 16:15
• I meant "actually visualizing the structure" but agree that all the points you mention are important in building up such hacks. Jul 26 '17 at 20:59

In Pymol:

1. create a new object for your residue:

create myobj, r. fk5

1. delete the original object with the entire protein:

delete 1yat

I have written some simple code in python to do what you ask. ( It has to be inserted as an image because of the way markdown changes the text.) (Note that python uses 4 spaces or a tab for each part of the code at the same level in any loop of if statement)

• For me this script returns the error (and yes 1yat.pdb does exist in the folder where I am running the script) shown here gist.github.com/fusion809/11278bea129cee1adfa495e0767c8439. The script is also shown at that gist. Jul 25 '17 at 16:49
• Does indenting the whole thing by four spaces, to enable code formatting, not make it render correctly? Jul 25 '17 at 16:59
• I used tabs but I did use it for each separate level. So, for example, for the if vals[0] line I used two tabs as it is level 2. While for line in f: is level 1 so one tab. Jul 25 '17 at 17:02
• Oh, sorry, @BH2017, I wasn't referring to the error you observed; I was asking porphyrin about his troubles getting the code to render correctly in his post here. Jul 25 '17 at 17:09
• @BH2017 It looks like you're running this as a shells script instead of a python script. To fix this, add the following line as the first line of the script: #!/usr/bin/python3 Jul 25 '17 at 17:33