Class Bio::PDB
In: lib/bio/db/pdb.rb
lib/bio/db/pdb/atom.rb
lib/bio/db/pdb/chain.rb
lib/bio/db/pdb/chemicalcomponent.rb
lib/bio/db/pdb/model.rb
lib/bio/db/pdb/pdb.rb
lib/bio/db/pdb/residue.rb
lib/bio/db/pdb/utils.rb
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 1445
1445:     def initialize(str)
1446:       #Aha! Our entry into the world of PDB parsing, we initialise a PDB
1447:       #object with the whole PDB file as a string
1448:       #each PDB has an array of the lines of the original file
1449:       #a bit memory-tastic! A hash of records and an array of models
1450:       #also has an id
1451: 
1452:       @data = str.split(/[\r\n]+/)
1453:       @hash = {}
1454:       @models = []
1455:       @id = nil
1456: 
1457:       #Flag to say whether the current line is part of a continuation
1458:       cont = false
1459: 
1460:       #Empty current model
1461:       cModel    = Model.new
1462:       cChain    = nil #Chain.new
1463:       cResidue  = nil #Residue.new
1464:       cLigand   = nil #Heterogen.new
1465:       c_atom    = nil
1466: 
1467:       #Goes through each line and replace that line with a PDB::Record
1468:       @data.collect! do |line|
1469:         #Go to next if the previous line was contiunation able, and
1470:         #add_continuation returns true. Line is added by add_continuation
1471:         next if cont and cont = cont.add_continuation(line)
1472: 
1473:         #Make the new record
1474:         f = Record.get_record_class(line).new.initialize_from_string(line)
1475:         #p f
1476:         #Set cont
1477:         cont = f if f.continue?
1478:         #Set the hash to point to this record either by adding to an
1479:         #array, or on it's own
1480:         key = f.record_name
1481:         if a = @hash[key] then
1482:           a << f
1483:         else
1484:           @hash[key] = [ f ]
1485:         end
1486: 
1487:         # Do something for ATOM and HETATM
1488:         if key == 'ATOM' or key == 'HETATM' then
1489:           if cChain and f.chainID == cChain.id
1490:             chain = cChain
1491:           else
1492:             if chain = cModel[f.chainID]
1493:               cChain = chain unless cChain
1494:             else
1495:               # If we don't have chain, add a new chain
1496:               newChain = Chain.new(f.chainID, cModel)
1497:               cModel.addChain(newChain)
1498:               cChain = newChain
1499:               chain = newChain
1500:             end
1501:             # chain might be changed, clearing cResidue and cLigand
1502:             cResidue = nil
1503:             cLigand = nil
1504:           end
1505:         end
1506: 
1507:         case key
1508:         when 'ATOM'
1509:           c_atom = f
1510:           residueID = Residue.get_residue_id_from_atom(f)
1511: 
1512:           if cResidue and residueID == cResidue.id
1513:             residue = cResidue
1514:           else
1515:             if residue = chain.get_residue_by_id(residueID)
1516:               cResidue = residue unless cResidue
1517:             else
1518:               # add a new residue
1519:               newResidue = Residue.new(f.resName, f.resSeq, f.iCode, chain)
1520:               chain.addResidue(newResidue)
1521:               cResidue = newResidue
1522:               residue = newResidue
1523:             end
1524:           end
1525:           
1526:           f.residue = residue
1527:           residue.addAtom(f)
1528: 
1529:         when 'HETATM'
1530:           c_atom = f
1531:           residueID = Heterogen.get_residue_id_from_atom(f)
1532: 
1533:           if cLigand and residueID == cLigand.id
1534:             ligand = cLigand
1535:           else
1536:             if ligand = chain.get_heterogen_by_id(residueID)
1537:               cLigand = ligand unless cLigand
1538:             else
1539:               # add a new heterogen
1540:               newLigand = Heterogen.new(f.resName, f.resSeq, f.iCode, chain)
1541:               chain.addLigand(newLigand)
1542:               cLigand = newLigand
1543:               ligand = newLigand
1544:               #Each model has a special solvent chain. (for compatibility)
1545:               if f.resName == 'HOH'
1546:                 cModel.addSolvent(newLigand)
1547:               end
1548:             end
1549:           end
1550: 
1551:           f.residue = ligand
1552:           ligand.addAtom(f)
1553: 
1554:         when 'MODEL'
1555:           c_atom = nil
1556:           cChain = nil
1557:           cResidue = nil
1558:           cLigand = nil
1559:           if cModel.model_serial or cModel.chains.size > 0 then
1560:             self.addModel(cModel)
1561:           end
1562:           cModel = Model.new(f.serial)
1563: 
1564:         when 'TER'
1565:           if c_atom
1566:             c_atom.ter = f
1567:           else
1568:             #$stderr.puts "Warning: stray TER?"
1569:           end
1570:         when 'SIGATM'
1571:           if c_atom
1572:             #$stderr.puts "Warning: duplicated SIGATM?" if c_atom.sigatm
1573:             c_atom.sigatm = f
1574:           else
1575:             #$stderr.puts "Warning: stray SIGATM?"
1576:           end
1577:         when 'ANISOU'
1578:           if c_atom
1579:             #$stderr.puts "Warning: duplicated ANISOU?" if c_atom.anisou
1580:             c_atom.anisou = f
1581:           else
1582:             #$stderr.puts "Warning: stray ANISOU?"
1583:           end
1584:         when 'SIGUIJ'
1585:           if c_atom and c_atom.anisou
1586:             #$stderr.puts "Warning: duplicated SIGUIJ?" if c_atom.anisou.siguij
1587:             c_atom.anisou.siguij = f
1588:           else
1589:             #$stderr.puts "Warning: stray SIGUIJ?"
1590:           end
1591: 
1592:         else
1593:           c_atom = nil
1594: 
1595:         end
1596:         f
1597:       end #each
1598:       #At the end we need to add the final model
1599:       self.addModel(cModel)
1600:       @data.compact!
1601:     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 1633
1633:     def [](key)
1634:       @models.find{ |model| key == model.model_serial }
1635:     end

Same as Bio::PDB#entry_id.

[Source]

      # File lib/bio/db/pdb/pdb.rb, line 1887
1887:     def accession
1888:       self.entry_id
1889:     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 1615
1615:     def addModel(model)
1616:       raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model
1617:       @models.push(model)
1618:       self
1619:     end

Get authors in "AUTHOR".

[Source]

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

Classification in "HEADER".

[Source]

      # File lib/bio/db/pdb/pdb.rb, line 1863
1863:     def classification
1864:       f = self.record('HEADER').first
1865:       f ? f.classification : nil
1866:     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 1848
1848:     def dbref(chainID = nil)
1849:       if chainID then
1850:         self.record('DBREF').find_all { |f| f.chainID == chainID }
1851:       else
1852:         self.record('DBREF')
1853:       end
1854:     end

Title of this entry in "TITLE".

[Source]

      # File lib/bio/db/pdb/pdb.rb, line 1892
1892:     def definition
1893:       f = self.record('TITLE').first
1894:       f ? f.title : nil
1895:     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 1624
1624:     def each
1625:       @models.each{ |model| yield model }
1626:       self
1627:     end
each_model()

Alias for each

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

[Source]

      # File lib/bio/db/pdb/pdb.rb, line 1878
1878:     def entry_id
1879:       unless @id
1880:         f = self.record('HEADER').first
1881:         @id = f ? f.idCode : nil
1882:       end
1883:       @id
1884:     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 1749
1749:     def helix(helixID = nil)
1750:       if helixID then
1751:         self.record('HELIX').find { |f| f.helixID == helixID }
1752:       else
1753:         self.record('HELIX')
1754:       end
1755:     end

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

[Source]

      # File lib/bio/db/pdb/pdb.rb, line 1905
1905:     def inspect
1906:       "#<#{self.class.to_s} entry_id=#{entry_id.inspect}>"
1907:     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 1730
1730:     def jrnl(sub_record = nil)
1731:       unless defined?(@jrnl)
1732:         @jrnl = make_hash(self.record('JRNL'), :sub_record)
1733:       end
1734:       sub_record ? @jrnl[sub_record] : @jrnl
1735:     end

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

[Source]

      # File lib/bio/db/pdb/pdb.rb, line 1858
1858:     def keywords
1859:       self.record('KEYWDS').collect { |f| f.keywds }.flatten
1860:     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 1696
1696:     def record(name = nil)
1697:       name ? (@hash[name] || []) : @hash
1698:     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 1711
1711:     def remark(nn = nil)
1712:       unless defined?(@remark)
1713:         h = make_hash(self.record('REMARK'), :remarkNum)
1714:         h.each do |i, a|
1715:             a.shift # remove first record (= space only)
1716:           if i != 1 and i != 2 then
1717:             a.collect! { |f| f.text.gsub(/\s+\z/, '') }
1718:           end
1719:         end
1720:         @remark = h
1721:       end
1722:       nn ? @remark[nn] : @remark
1723:     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 1802
1802:     def seqres(chainID = nil)
1803:       unless defined?(@seqres)
1804:         h = make_hash(self.record('SEQRES'), :chainID)
1805:         newHash = {}
1806:         h.each do |k, a|
1807:           a.collect! { |f| f.resName }
1808:           a.flatten!
1809:           # determine nuc or aa?
1810:           tmp = Hash.new(0)
1811:           a[0,13].each { |x| tmp[x.to_s.strip.size] += 1 }
1812:           if tmp[3] >= tmp[1] then
1813:             # amino acid sequence
1814:             a.collect! do |aa|
1815:               #aa is three letter code: i.e. ALA
1816:               #need to look up with Ala
1817:               aa = aa.capitalize
1818:               (begin
1819:                  Bio::AminoAcid.three2one(aa)
1820:                rescue ArgumentError
1821:                  nil
1822:                end || 'X')
1823:             end
1824:             seq = Bio::Sequence::AA.new(a.join(''))
1825:           else
1826:             # nucleic acid sequence
1827:             a.collect! do |na|
1828:               na = na.delete('^a-zA-Z')
1829:               na.size == 1 ? na : 'n'
1830:             end
1831:             seq = Bio::Sequence::NA.new(a.join(''))
1832:           end
1833:           newHash[k] = seq
1834:         end
1835:         @seqres = newHash
1836:       end
1837:       if chainID then
1838:         @seqres[chainID]
1839:       else
1840:         @seqres
1841:       end
1842:     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 1777
1777:     def sheet(sheetID = nil)
1778:       unless defined?(@sheet)
1779:         @sheet = make_grouping(self.record('SHEET'), :sheetID)
1780:       end
1781:       if sheetID then
1782:         @sheet.find_all { |f| f.first.sheetID == sheetID }
1783:       else
1784:         @sheet
1785:       end
1786:     end

Gets SSBOND records.

[Source]

      # File lib/bio/db/pdb/pdb.rb, line 1789
1789:     def ssbond
1790:       self.record('SSBOND')
1791:     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 1647
1647:     def to_s
1648:       string = ""
1649:       @models.each{ |model| string << model.to_s }
1650:       string << "END\n"
1651:       return string
1652:     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 1764
1764:     def turn(turnId = nil)
1765:       if turnId then
1766:         self.record('TURN').find { |f| f.turnId == turnId }
1767:       else
1768:         self.record('TURN')
1769:       end
1770:     end

Current modification number in "REVDAT".

[Source]

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

[Validate]