Class Bio::PDB
In: lib/bio/db/pdb.rb  (CVS)
lib/bio/db/pdb/atom.rb  (CVS)
lib/bio/db/pdb/chain.rb  (CVS)
lib/bio/db/pdb/chemicalcomponent.rb  (CVS)
lib/bio/db/pdb/model.rb  (CVS)
lib/bio/db/pdb/pdb.rb  (CVS)
lib/bio/db/pdb/residue.rb  (CVS)
lib/bio/db/pdb/utils.rb  (CVS)
Parent: Object

This is the main PDB class which takes care of parsing, annotations and is the entry way to the co-ordinate data held in models.

There are many related classes.

Bio::PDB::Model Bio::PDB::Chain Bio::PDB::Residue Bio::PDB::Heterogen Bio::PDB::Record::ATOM Bio::PDB::Record::HETATM Bio::PDB::Record::* Bio::PDB::Coordinate

Methods

[]   accession   addModel   authors   classification   dbref   definition   each   each_model   entry_id   helix   inspect   jrnl   keywords   new   record   remark   seqres   sheet   ssbond   to_s   turn   version  

Included Modules

Utils AtomFinder ResidueFinder ChainFinder ModelFinder HetatmFinder HeterogenFinder Enumerable

Classes and Modules

Module Bio::PDB::AtomFinder
Module Bio::PDB::ChainFinder
Module Bio::PDB::DataType
Module Bio::PDB::HetatmFinder
Module Bio::PDB::HeterogenFinder
Module Bio::PDB::ModelFinder
Module Bio::PDB::ResidueFinder
Module Bio::PDB::Utils
Class Bio::PDB::Chain
Class Bio::PDB::ChemicalComponent
Class Bio::PDB::Coordinate
Class Bio::PDB::Heterogen
Class Bio::PDB::Model
Class Bio::PDB::Record
Class Bio::PDB::Residue

Constants

DELIMITER = RS = nil   delimiter for reading via Bio::FlatFile
Coordinate_fileds = { 'MODEL' => true, :MODEL => true, 'ENDMDL' => true, :ENDMDL => true, 'ATOM' => true, :ATOM => true, 'HETATM' => true, :HETATM => true, 'SIGATM' => true, :SIGATM => true, 'SIGUIJ' => true, :SIGUIJ => true, 'ANISOU' => true, :ANISOU => true, 'TER' => true, :TER => true, }

Attributes

data  [R]  all records in this entry as an array.
hash  [R]  all records in this entry as an hash accessed by record names.
models  [R]  models in this entry (array).

Public Class methods

Creates a new Bio::PDB object from given str.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1444
    def initialize(str)
      #Aha! Our entry into the world of PDB parsing, we initialise a PDB
      #object with the whole PDB file as a string
      #each PDB has an array of the lines of the original file
      #a bit memory-tastic! A hash of records and an array of models
      #also has an id

      @data = str.split(/[\r\n]+/)
      @hash = {}
      @models = []
      @id = nil

      #Flag to say whether the current line is part of a continuation
      cont = false

      #Empty current model
      cModel    = Model.new
      cChain    = nil #Chain.new
      cResidue  = nil #Residue.new
      cLigand   = nil #Heterogen.new
      c_atom    = nil

      #Goes through each line and replace that line with a PDB::Record
      @data.collect! do |line|
        #Go to next if the previous line was contiunation able, and
        #add_continuation returns true. Line is added by add_continuation
        next if cont and cont = cont.add_continuation(line)

        #Make the new record
        f = Record.get_record_class(line).new.initialize_from_string(line)
        #p f
        #Set cont
        cont = f if f.continue?
        #Set the hash to point to this record either by adding to an
        #array, or on it's own
        key = f.record_name
        if a = @hash[key] then
          a << f
        else
          @hash[key] = [ f ]
        end

        # Do something for ATOM and HETATM
        if key == 'ATOM' or key == 'HETATM' then
          if cChain and f.chainID == cChain.id
            chain = cChain
          else
            if chain = cModel[f.chainID]
              cChain = chain unless cChain
            else
              # If we don't have chain, add a new chain
              newChain = Chain.new(f.chainID, cModel)
              cModel.addChain(newChain)
              cChain = newChain
              chain = newChain
            end
          end
        end

        case key
        when 'ATOM'
          c_atom = f
          residueID = Residue.get_residue_id_from_atom(f)

          if cResidue and residueID == cResidue.id
            residue = cResidue
          else
            if residue = chain.get_residue_by_id(residueID)
              cResidue = residue unless cResidue
            else
              # add a new residue
              newResidue = Residue.new(f.resName, f.resSeq, f.iCode, chain)
              chain.addResidue(newResidue)
              cResidue = newResidue
              residue = newResidue
            end
          end
          
          f.residue = residue
          residue.addAtom(f)

        when 'HETATM'
          c_atom = f
          residueID = Heterogen.get_residue_id_from_atom(f)

          if cLigand and residueID == cLigand.id
            ligand = cLigand
          else
            if ligand = chain.get_heterogen_by_id(residueID)
              cLigand = ligand unless cLigand
            else
              # add a new heterogen
              newLigand = Heterogen.new(f.resName, f.resSeq, f.iCode, chain)
              chain.addLigand(newLigand)
              cLigand = newLigand
              ligand = newLigand
              #Each model has a special solvent chain. (for compatibility)
              if f.resName == 'HOH'
                cModel.addSolvent(newLigand)
              end
            end
          end

          f.residue = ligand
          ligand.addAtom(f)

        when 'MODEL'
          c_atom = nil
          cChain = nil
          if cModel.model_serial or cModel.chains.size > 0 then
            self.addModel(cModel)
          end
          cModel = Model.new(f.serial)

        when 'TER'
          if c_atom
            c_atom.ter = f
          else
            #$stderr.puts "Warning: stray TER?"
          end
        when 'SIGATM'
          if c_atom
            #$stderr.puts "Warning: duplicated SIGATM?" if c_atom.sigatm
            c_atom.sigatm = f
          else
            #$stderr.puts "Warning: stray SIGATM?"
          end
        when 'ANISOU'
          if c_atom
            #$stderr.puts "Warning: duplicated ANISOU?" if c_atom.anisou
            c_atom.anisou = f
          else
            #$stderr.puts "Warning: stray ANISOU?"
          end
        when 'SIGUIJ'
          if c_atom and c_atom.anisou
            #$stderr.puts "Warning: duplicated SIGUIJ?" if c_atom.anisou.siguij
            c_atom.anisou.siguij = f
          else
            #$stderr.puts "Warning: stray SIGUIJ?"
          end

        else
          c_atom = nil

        end
        f
      end #each
      #At the end we need to add the final model
      self.addModel(cModel)
      @data.compact!
    end

Public Instance methods

Provides keyed access to the models based on serial number returns nil if it‘s not there

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1627
    def [](key)
      @models.find{ |model| key == model.model_serial }
    end

Same as Bio::PDB#entry_id.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1877
    def accession
      self.entry_id
    end

Adds a Bio::Model object to the current strucutre. Adds a model to the current structure. Returns self.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1609
    def addModel(model)
      raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model
      @models.push(model)
      self
    end

Get authors in "AUTHOR".

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1859
    def authors
      self.record('AUTHOR').collect { |f| f.authorList }.flatten
    end

Classification in "HEADER".

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1853
    def classification
      f = self.record('HEADER').first
      f ? f.classification : nil
    end

Gets DBREF records. Returns an array of Bio::PDB::Record::DBREF objects.

If chainID is given, it returns corresponding DBREF records.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1838
    def dbref(chainID = nil)
      if chainID then
        self.record('DBREF').find_all { |f| f.chainID == chainID }
      else
        self.record('DBREF')
      end
    end

Title of this entry in "TITLE".

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1882
    def definition
      f = self.record('TITLE').first
      f ? f.title : nil
    end

Iterates over each model. Iterates over each of the models in the structure. Returns self.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1618
    def each
      @models.each{ |model| yield model }
      self
    end
each_model()

Alias for each

PDB identifier written in "HEADER". (e.g. 1A00)

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1868
    def entry_id
      unless @id
        f = self.record('HEADER').first
        @id = f ? f.idCode : nil
      end
      @id
    end

Gets HELIX records. If no arguments are given, it returns all HELIX records. (Returns an array of Bio::PDB::Record::HELIX instances.) If helixID is given, it only returns records corresponding to given helixID. (Returns an Bio::PDB::Record::HELIX instance.)

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1743
    def helix(helixID = nil)
      if helixID then
        self.record('HELIX').find { |f| f.helixID == helixID }
      else
        self.record('HELIX')
      end
    end

returns a string containing human-readable representation of this object.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1895
    def inspect
      "#<#{self.class.to_s} entry_id=#{entry_id.inspect}>"
    end

Gets JRNL records. If no arguments, it returns all JRNL records as a hash. If sub record name is specified, it returns only corresponding records as an array of Bio::PDB::Record instances.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1724
    def jrnl(sub_record = nil)
      unless defined?(@jrnl)
        @jrnl = make_hash(self.record('JRNL'), :sub_record)
      end
      sub_record ? @jrnl[sub_record] : @jrnl
    end

Keywords in "KEYWDS". Returns an array of string.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1848
    def keywords
      self.record('KEYWDS').collect { |f| f.keywds }.flatten
    end

Gets all records whose record type is name. Returns an array of Bio::PDB::Record::* objects.

if name is nil, returns hash storing all record data.

Example: p pdb.record(‘HETATM’) p pdb.record[‘HETATM’]

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1690
    def record(name = nil)
      name ? (@hash[name] || []) : @hash
    end

Gets REMARK records. If no arguments, it returns all REMARK records as a hash. If remark number is specified, returns only corresponding REMARK records. If number == 1 or 2 ("REMARK 1" or "REMARK 2"), returns an array of Bio::PDB::Record instances. Otherwise, returns an array of strings.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1705
    def remark(nn = nil)
      unless defined?(@remark)
        h = make_hash(self.record('REMARK'), :remarkNum)
        h.each do |i, a|
            a.shift # remove first record (= space only)
          if i != 1 and i != 2 then
            a.collect! { |f| f.text.gsub(/\s+\z/, '') }
          end
        end
        @remark = h
      end
      nn ? @remark[nn] : @remark
    end

Amino acid or nucleic acid sequence of backbone residues in "SEQRES". If chainID is given, it returns corresponding sequence as an array of string. Otherwise, returns a hash which contains all sequences.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1796
    def seqres(chainID = nil)
      unless defined?(@seqres)
        h = make_hash(self.record('SEQRES'), :chainID)
        newHash = {}
        h.each do |k, a|
          a.collect! { |f| f.resName }
          a.flatten!
          # determine nuc or aa?
          tmp = Hash.new(0)
          a[0,13].each { |x| tmp[x.to_s.strip.size] += 1 }
          if tmp[3] >= tmp[1] then
            # amino acid sequence
            a.collect! do |aa|
              #aa is three letter code: i.e. ALA
              #need to look up with Ala
              aa = aa.capitalize
              (Bio::AminoAcid.three2one(aa) or 'X')
            end
            seq = Bio::Sequence::AA.new(a.to_s)
          else
            # nucleic acid sequence
            a.collect! do |na|
              na = na.strip
              na.size == 1 ? na : 'n'
            end
            seq = Bio::Sequence::NA.new(a.to_s)
          end
          newHash[k] = seq
        end
        @seqres = newHash
      end
      if chainID then
        @seqres[chainID]
      else
        @seqres
      end
    end

Gets SHEET records. If no arguments are given, it returns all SHEET records as an array of arrays of Bio::PDB::Record::SHEET instances. If sheetID is given, it returns an array of Bio::PDB::Record::SHEET instances.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1771
    def sheet(sheetID = nil)
      unless defined?(@sheet)
        @sheet = make_grouping(self.record('SHEET'), :sheetID)
      end
      if sheetID then
        @sheet.find_all { |f| f.first.sheetID == sheetID }
      else
        @sheet
      end
    end

Gets SSBOND records.

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1783
    def ssbond
      self.record('SSBOND')
    end

Returns a string of Bio::PDB::Models. This propogates down the heirarchy till you get to Bio::PDB::Record::ATOM which are outputed in PDB format

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1641
    def to_s
      string = ""
      @models.each{ |model| string << model.to_s }
      string << "END\n"
      return string
    end

Gets TURN records. If no arguments are given, it returns all TURN records. (Returns an array of Bio::PDB::Record::TURN instances.) If turnId is given, it only returns a record corresponding to given turnId. (Returns an Bio::PDB::Record::TURN instance.)

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1758
    def turn(turnId = nil)
      if turnId then
        self.record('TURN').find { |f| f.turnId == turnId }
      else
        self.record('TURN')
      end
    end

Current modification number in "REVDAT".

[Source]

# File lib/bio/db/pdb/pdb.rb, line 1888
    def version
      f = self.record('REVDAT').first
      f ? f.modNum : nil
    end

[Validate]