Skip to content


A biophysicist teaches himself how to code

This is a simple script I wrote a while back which will pull just the ATOM records out of a PDB file and save them into a new file.  It also puts an “END” after the ATOM records, which I needed for doing some modeling.  Handy when trying to do modeling or anything else that doesn’t require all of the other lines that usually clutter up PDBs.



import sys, re
print '--------'
print 'This script is designed to pull all the ATOM records out of a PDB file and write them to a new file in order to prepare for homology modeling'
print 'Any desired heteroatoms should be manually copied from the initial file'
print '--------'
atomrecords = []
dirtyfile = raw_input('What is the filename for the raw PDB? >> ')
cleanfile = raw_input('What would you like to name your cleaned file? >> ')
# Open the file and put the ATOM record lines into a list
inputfile = open(dirtyfile, 'r')
lines = inputfile.readlines()
for line in lines:
    match ='^ATOM', line)
    if match:
# Write out the records
outputfile = open(cleanfile, 'w')

%d bloggers like this: