Skip to content
Naohisa Goto edited this page Jun 14, 2016 · 1 revision

PDB is Protein Data Bank, which stores many atomic coordinates of biological molecules. http://www.pdb.org/

Fetching PDB using ruby

Following program can be used to obtain and save a pdb entry.

module Bio
  class PDB
    def PDB.fetch(id)
      serv = Bio::Fetch.new("http://www.ebi.ac.uk/cgi-bin/dbfetch")
      entry = serv.fetch('pdb', id)
      return nil if entry[0,5].downcase == 'error'
      return nil if entry[0,10].downcase == 'no entries'
      # get header
      pdb = Bio::PDB.new(entry)
      return pdb
    end

    def save(filename)
      fp = File.open(filename, "w")
      fp << self.to_s
      fp.close
    end
  end
end


pdb = Bio::PDB.fetch(ARGV[0])
pdb.save(ARGV[0] + ".pdb")
Clone this wiki locally