This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Writting/editing PDB files

I am editting a PDB file. I successfully edit the columns using pandas but I can not write the right spacing between the column. My PDB file looks like this:

HETATM 4 OM MEG A 1 -13.151 3.216 0.791 O

I name the columns as ['A','B','C','D',..............] I control the spaces like this:

dx['I'] = dx['I'].map('{:8.3f}'.format)

If anyone is sure that Biopython can do this, please tell me how?

panda python formatting

1 answer

Opinions differ on what tools to use given a particular problem, but I can state with certainty that pandas is not the best tool for editing PDB files. If you still would like to do it the hard way, the meaning of columns and spacing is described here. You will have to scroll down for ATOM and HETATM records.

If you have minor edits, those can be done by hand in any text editor - PDB files are in simple text format that is human-readable.

As to using BioPython, it has multiple functions to manipulate PDB files, see here and here. It is not meant for file editing per se, so whether it can do the job you want will depend on what kind of edits you have in mind.

Mensur Dlakic Thanks a lot for the reply. My PDB file still not working. What is the best tool to edit pdb files?

I have no idea what the best tool is to edit PDB files, as I usually have no need for it. On those rare occasions when the editing is needed, I use Wordpad.

Also, editing a PDB file is a bit of a general statement. Most people would have no need to edit the headers of the descriptive portion of the file. Most definitely atom coordinates should not be edited. So if by editing you mean extracting a certain chain, or renumbering the residues, BioPython has functions for those tasks, and there are many other programs that can do the same. PDB files and their parsers existed way before pandas was invented.

Mensur Dlakic Thanks! I had a PDB file for a polymer with one chain, the chain is 3 molecules old, I need it to be 400+ molecules. I did that with pandas, but I can not put the right spaces between columns.

Log in to answer this question.