def ask_user(): pdbid = raw_input("Enter PDB code(s): ").upper() for info in getDescription([pdbid]): print "%s\t%s" % (info["structureId"].lower(), info["title"].title()) for name, value in info.iteritems(): print "\t%s:\t%s" % (name, value) def getDescription(pdbidList): dom = _getFromPDB(pdbidList) return _extractInfo(dom) def _getFromPDB(pdbidList): "Return the PDB document object model (DOM) for the given id" PDB_URL = "http://www.rcsb.org/pdb/rest/describePDB" req = "%s?structureId=%s" % (PDB_URL, ",".join(pdbidList)) print req from urllib2 import urlopen f = urlopen(req) from xml.dom.minidom import parse dom = parse(f) f.close() return dom def _extractInfo(dom): "Extract fields for all PDB elements in document" info = list() for e in dom.getElementsByTagName("PDB"): attrMap = e.attributes d = dict() for i in range(attrMap.length): a = attrMap.item(i) d[a.name] = a.value info.append(d) return info if __name__ == "__main__": ask_user()