class Bio::PDB
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
Constants
- Coordinate_fileds
- DELIMITER
-
delimiter for reading via
Bio::FlatFile
Attributes
all records in this entry as an array.
all records in this entry as an hash accessed by record names.
models in this entry (array).
Public Class Methods
Source
# File lib/bio/db/pdb/pdb.rb 1446 def initialize(str) 1447 #Aha! Our entry into the world of PDB parsing, we initialise a PDB 1448 #object with the whole PDB file as a string 1449 #each PDB has an array of the lines of the original file 1450 #a bit memory-tastic! A hash of records and an array of models 1451 #also has an id 1452 1453 @data = str.split(/[\r\n]+/) 1454 @hash = {} 1455 @models = [] 1456 @id = nil 1457 1458 #Flag to say whether the current line is part of a continuation 1459 cont = false 1460 1461 #Empty current model 1462 cModel = Model.new 1463 cChain = nil #Chain.new 1464 cResidue = nil #Residue.new 1465 cLigand = nil #Heterogen.new 1466 c_atom = nil 1467 1468 #Goes through each line and replace that line with a PDB::Record 1469 @data.collect! do |line| 1470 #Go to next if the previous line was contiunation able, and 1471 #add_continuation returns true. Line is added by add_continuation 1472 next if cont and cont = cont.add_continuation(line) 1473 1474 #Make the new record 1475 f = Record.get_record_class(line).new.initialize_from_string(line) 1476 #p f 1477 #Set cont 1478 cont = f if f.continue? 1479 #Set the hash to point to this record either by adding to an 1480 #array, or on it's own 1481 key = f.record_name 1482 if a = @hash[key] then 1483 a << f 1484 else 1485 @hash[key] = [ f ] 1486 end 1487 1488 # Do something for ATOM and HETATM 1489 if key == 'ATOM' or key == 'HETATM' then 1490 if cChain and f.chainID == cChain.id 1491 chain = cChain 1492 else 1493 if chain = cModel[f.chainID] 1494 cChain = chain unless cChain 1495 else 1496 # If we don't have chain, add a new chain 1497 newChain = Chain.new(f.chainID, cModel) 1498 cModel.addChain(newChain) 1499 cChain = newChain 1500 chain = newChain 1501 end 1502 # chain might be changed, clearing cResidue and cLigand 1503 cResidue = nil 1504 cLigand = nil 1505 end 1506 end 1507 1508 case key 1509 when 'ATOM' 1510 c_atom = f 1511 residueID = Residue.get_residue_id_from_atom(f) 1512 1513 if cResidue and residueID == cResidue.id 1514 residue = cResidue 1515 else 1516 if residue = chain.get_residue_by_id(residueID) 1517 cResidue = residue unless cResidue 1518 else 1519 # add a new residue 1520 newResidue = Residue.new(f.resName, f.resSeq, f.iCode, chain) 1521 chain.addResidue(newResidue) 1522 cResidue = newResidue 1523 residue = newResidue 1524 end 1525 end 1526 1527 f.residue = residue 1528 residue.addAtom(f) 1529 1530 when 'HETATM' 1531 c_atom = f 1532 residueID = Heterogen.get_residue_id_from_atom(f) 1533 1534 if cLigand and residueID == cLigand.id 1535 ligand = cLigand 1536 else 1537 if ligand = chain.get_heterogen_by_id(residueID) 1538 cLigand = ligand unless cLigand 1539 else 1540 # add a new heterogen 1541 newLigand = Heterogen.new(f.resName, f.resSeq, f.iCode, chain) 1542 chain.addLigand(newLigand) 1543 cLigand = newLigand 1544 ligand = newLigand 1545 #Each model has a special solvent chain. (for compatibility) 1546 if f.resName == 'HOH' 1547 cModel.addSolvent(newLigand) 1548 end 1549 end 1550 end 1551 1552 f.residue = ligand 1553 ligand.addAtom(f) 1554 1555 when 'MODEL' 1556 c_atom = nil 1557 cChain = nil 1558 cResidue = nil 1559 cLigand = nil 1560 if cModel.model_serial or cModel.chains.size > 0 then 1561 self.addModel(cModel) 1562 end 1563 cModel = Model.new(f.serial) 1564 1565 when 'TER' 1566 if c_atom 1567 c_atom.ter = f 1568 else 1569 #$stderr.puts "Warning: stray TER?" 1570 end 1571 when 'SIGATM' 1572 if c_atom 1573 #$stderr.puts "Warning: duplicated SIGATM?" if c_atom.sigatm 1574 c_atom.sigatm = f 1575 else 1576 #$stderr.puts "Warning: stray SIGATM?" 1577 end 1578 when 'ANISOU' 1579 if c_atom 1580 #$stderr.puts "Warning: duplicated ANISOU?" if c_atom.anisou 1581 c_atom.anisou = f 1582 else 1583 #$stderr.puts "Warning: stray ANISOU?" 1584 end 1585 when 'SIGUIJ' 1586 if c_atom and c_atom.anisou 1587 #$stderr.puts "Warning: duplicated SIGUIJ?" if c_atom.anisou.siguij 1588 c_atom.anisou.siguij = f 1589 else 1590 #$stderr.puts "Warning: stray SIGUIJ?" 1591 end 1592 1593 else 1594 c_atom = nil 1595 1596 end 1597 f 1598 end #each 1599 #At the end we need to add the final model 1600 self.addModel(cModel) 1601 @data.compact! 1602 end
Creates a new Bio::PDB
object from given str.
Public Instance Methods
Source
# File lib/bio/db/pdb/pdb.rb 1634 def [](key) 1635 @models.find{ |model| key == model.model_serial } 1636 end
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 1888 def accession 1889 self.entry_id 1890 end
Same as Bio::PDB#entry_id
.
Source
# File lib/bio/db/pdb/pdb.rb 1616 def addModel(model) 1617 raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model 1618 @models.push(model) 1619 self 1620 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 1864 def classification 1865 f = self.record('HEADER').first 1866 f ? f.classification : nil 1867 end
Classification in “HEADER”.
Source
# File lib/bio/db/pdb/pdb.rb 1849 def dbref(chainID = nil) 1850 if chainID then 1851 self.record('DBREF').find_all { |f| f.chainID == chainID } 1852 else 1853 self.record('DBREF') 1854 end 1855 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 1893 def definition 1894 f = self.record('TITLE').first 1895 f ? f.title : nil 1896 end
Title of this entry in “TITLE”.
Source
# File lib/bio/db/pdb/pdb.rb 1625 def each 1626 @models.each{ |model| yield model } 1627 self 1628 end
Iterates over each model. Iterates over each of the models in the structure. Returns self
.
Source
# File lib/bio/db/pdb/pdb.rb 1879 def entry_id 1880 unless @id 1881 f = self.record('HEADER').first 1882 @id = f ? f.idCode : nil 1883 end 1884 @id 1885 end
PDB
identifier written in “HEADER”. (e.g. 1A00)
Source
# File lib/bio/db/pdb/pdb.rb 1750 def helix(helixID = nil) 1751 if helixID then 1752 self.record('HELIX').find { |f| f.helixID == helixID } 1753 else 1754 self.record('HELIX') 1755 end 1756 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 1906 def inspect 1907 "#<#{self.class.to_s} entry_id=#{entry_id.inspect}>" 1908 end
returns a string containing human-readable representation of this object.
Source
# File lib/bio/db/pdb/pdb.rb 1731 def jrnl(sub_record = nil) 1732 unless defined?(@jrnl) 1733 @jrnl = make_hash(self.record('JRNL'), :sub_record) 1734 end 1735 sub_record ? @jrnl[sub_record] : @jrnl 1736 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 1859 def keywords 1860 self.record('KEYWDS').collect { |f| f.keywds }.flatten 1861 end
Keywords in “KEYWDS”. Returns an array of string.
Source
# File lib/bio/db/pdb/pdb.rb 1697 def record(name = nil) 1698 name ? (@hash[name] || []) : @hash 1699 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
Source
# File lib/bio/db/pdb/pdb.rb 1712 def remark(nn = nil) 1713 unless defined?(@remark) 1714 h = make_hash(self.record('REMARK'), :remarkNum) 1715 h.each do |i, a| 1716 a.shift # remove first record (= space only) 1717 if i != 1 and i != 2 then 1718 a.collect! { |f| f.text.gsub(/\s+\z/, '') } 1719 end 1720 end 1721 @remark = h 1722 end 1723 nn ? @remark[nn] : @remark 1724 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 1803 def seqres(chainID = nil) 1804 unless defined?(@seqres) 1805 h = make_hash(self.record('SEQRES'), :chainID) 1806 newHash = {} 1807 h.each do |k, a| 1808 a.collect! { |f| f.resName } 1809 a.flatten! 1810 # determine nuc or aa? 1811 tmp = Hash.new(0) 1812 a[0,13].each { |x| tmp[x.to_s.strip.size] += 1 } 1813 if tmp[3] >= tmp[1] then 1814 # amino acid sequence 1815 a.collect! do |aa| 1816 #aa is three letter code: i.e. ALA 1817 #need to look up with Ala 1818 aa = aa.capitalize 1819 (begin 1820 Bio::AminoAcid.three2one(aa) 1821 rescue ArgumentError 1822 nil 1823 end || 'X') 1824 end 1825 seq = Bio::Sequence::AA.new(a.join('')) 1826 else 1827 # nucleic acid sequence 1828 a.collect! do |na| 1829 na = na.delete('^a-zA-Z') 1830 na.size == 1 ? na : 'n' 1831 end 1832 seq = Bio::Sequence::NA.new(a.join('')) 1833 end 1834 newHash[k] = seq 1835 end 1836 @seqres = newHash 1837 end 1838 if chainID then 1839 @seqres[chainID] 1840 else 1841 @seqres 1842 end 1843 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 1778 def sheet(sheetID = nil) 1779 unless defined?(@sheet) 1780 @sheet = make_grouping(self.record('SHEET'), :sheetID) 1781 end 1782 if sheetID then 1783 @sheet.find_all { |f| f.first.sheetID == sheetID } 1784 else 1785 @sheet 1786 end 1787 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 1790 def ssbond 1791 self.record('SSBOND') 1792 end
Gets SSBOND records.
Source
# File lib/bio/db/pdb/pdb.rb 1648 def to_s 1649 string = String.new 1650 @models.each{ |model| string << model.to_s } 1651 string << "END\n" 1652 return string 1653 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 1765 def turn(turnId = nil) 1766 if turnId then 1767 self.record('TURN').find { |f| f.turnId == turnId } 1768 else 1769 self.record('TURN') 1770 end 1771 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 1899 def version 1900 f = self.record('REVDAT').first 1901 f ? f.modNum : nil 1902 end
Current modification number in “REVDAT”.