import os import urllib #Note the %s where the PDB code should go: src = "http://www.rcsb.org/pdb/downloadFile.do" \ + "?fileFormat=pdb&compression=NO&structureId=%s" #Store all the downloads in this subdirectory: assert os.path.isdir("top500") input_file = open("top500.tsv","r") lines = input_file.readlines() input_file.close() for line in lines : (pdb, chains) = line.split("\t") filename = os.path.join("top500", pdb+".pdb") if os.path.isfile(filename) : print "Already have " + pdb else : print "Downloading " + pdb urllib.urlretrieve(src % pdb, filename)