Class: Bio::PDB
- Includes:
- AtomFinder, ChainFinder, HetatmFinder, HeterogenFinder, ModelFinder, ResidueFinder, Utils, Enumerable
- Defined in:
- lib/bio/db/pdb.rb,
lib/bio/db/pdb/pdb.rb,
lib/bio/db/pdb/atom.rb,
lib/bio/db/pdb/chain.rb,
lib/bio/db/pdb/model.rb,
lib/bio/db/pdb/utils.rb,
lib/bio/db/pdb/residue.rb,
lib/bio/db/pdb/chemicalcomponent.rb
Overview
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
Defined Under Namespace
Modules: AtomFinder, ChainFinder, DataType, HetatmFinder, HeterogenFinder, ModelFinder, ResidueFinder, Utils Classes: Chain, ChemicalComponent, Coordinate, Heterogen, Model, Record, Residue
Constant Summary collapse
- DELIMITER =
delimiter for reading via Bio::FlatFile
RS = nil
- Coordinate_fileds =
class Record
{ '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, }
Constants included from Utils
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
all records in this entry as an array.
-
#hash ⇒ Object
readonly
all records in this entry as an hash accessed by record names.
-
#models ⇒ Object
readonly
models in this entry (array).
Instance Method Summary collapse
-
#[](key) ⇒ Object
Provides keyed access to the models based on serial number returns nil if it’s not there.
-
#accession ⇒ Object
Same as
Bio::PDB#entry_id
. -
#addModel(model) ⇒ Object
Adds a
Bio::Model
object to the current strucutre. -
#authors ⇒ Object
Get authors in “AUTHOR”.
-
#classification ⇒ Object
Classification in “HEADER”.
-
#dbref(chainID = nil) ⇒ Object
Gets DBREF records.
-
#definition ⇒ Object
Title of this entry in “TITLE”.
-
#each ⇒ Object
(also: #each_model)
Iterates over each model.
-
#entry_id ⇒ Object
PDB identifier written in “HEADER”.
-
#helix(helixID = nil) ⇒ Object
Gets HELIX records.
-
#initialize(str) ⇒ PDB
constructor
Creates a new Bio::PDB object from given str.
-
#inspect ⇒ Object
returns a string containing human-readable representation of this object.
-
#jrnl(sub_record = nil) ⇒ Object
Gets JRNL records.
-
#keywords ⇒ Object
Keywords in “KEYWDS”.
-
#record(name = nil) ⇒ Object
Gets all records whose record type is name.
-
#remark(nn = nil) ⇒ Object
Gets REMARK records.
-
#seqres(chainID = nil) ⇒ Object
Amino acid or nucleic acid sequence of backbone residues in “SEQRES”.
-
#sheet(sheetID = nil) ⇒ Object
Gets SHEET records.
-
#ssbond ⇒ Object
Gets SSBOND records.
-
#to_s ⇒ Object
Returns a string of Bio::PDB::Models.
-
#turn(turnId = nil) ⇒ Object
Gets TURN records.
-
#version ⇒ Object
Current modification number in “REVDAT”.
Methods included from HeterogenFinder
#each_heterogen, #find_heterogen, #heterogens
Methods included from HetatmFinder
#each_hetatm, #find_hetatm, #hetatms
Methods included from ModelFinder
Methods included from ChainFinder
#chains, #each_chain, #find_chain
Methods included from ResidueFinder
#each_residue, #find_residue, #residues
Methods included from AtomFinder
#atoms, #each_atom, #find_atom
Methods included from Utils
acos, calculatePlane, #centreOfGravity, convert_to_xyz, dihedral_angle, distance, #finder, #geometricCentre, rad2deg, to_xyz
Constructor Details
#initialize(str) ⇒ PDB
Creates a new Bio::PDB object from given str.
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 |
# 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 # chain might be changed, clearing cResidue and cLigand cResidue = nil cLigand = nil 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 cResidue = nil cLigand = 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 |
Instance Attribute Details
#data ⇒ Object (readonly)
all records in this entry as an array.
1603 1604 1605 |
# File 'lib/bio/db/pdb/pdb.rb', line 1603 def data @data end |
#hash ⇒ Object (readonly)
all records in this entry as an hash accessed by record names.
1606 1607 1608 |
# File 'lib/bio/db/pdb/pdb.rb', line 1606 def hash @hash end |
#models ⇒ Object (readonly)
models in this entry (array).
1609 1610 1611 |
# File 'lib/bio/db/pdb/pdb.rb', line 1609 def models @models end |
Instance Method Details
#[](key) ⇒ Object
Provides keyed access to the models based on serial number returns nil if it’s not there
1632 1633 1634 |
# File 'lib/bio/db/pdb/pdb.rb', line 1632 def [](key) @models.find{ |model| key == model.model_serial } end |
#accession ⇒ Object
Same as Bio::PDB#entry_id
.
1886 1887 1888 |
# File 'lib/bio/db/pdb/pdb.rb', line 1886 def accession self.entry_id end |
#addModel(model) ⇒ Object
Adds a Bio::Model
object to the current strucutre. Adds a model to the current structure. Returns self.
1614 1615 1616 1617 1618 |
# File 'lib/bio/db/pdb/pdb.rb', line 1614 def addModel(model) raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model @models.push(model) self end |
#authors ⇒ Object
Get authors in “AUTHOR”.
1868 1869 1870 |
# File 'lib/bio/db/pdb/pdb.rb', line 1868 def self.record('AUTHOR').collect { |f| f. }.flatten end |
#classification ⇒ Object
Classification in “HEADER”.
1862 1863 1864 1865 |
# File 'lib/bio/db/pdb/pdb.rb', line 1862 def classification f = self.record('HEADER').first f ? f.classification : nil end |
#dbref(chainID = nil) ⇒ Object
Gets DBREF records. Returns an array of Bio::PDB::Record::DBREF objects.
If chainID is given, it returns corresponding DBREF records.
1847 1848 1849 1850 1851 1852 1853 |
# File 'lib/bio/db/pdb/pdb.rb', line 1847 def dbref(chainID = nil) if chainID then self.record('DBREF').find_all { |f| f.chainID == chainID } else self.record('DBREF') end end |
#definition ⇒ Object
Title of this entry in “TITLE”.
1891 1892 1893 1894 |
# File 'lib/bio/db/pdb/pdb.rb', line 1891 def definition f = self.record('TITLE').first f ? f.title : nil end |
#each ⇒ Object Also known as: each_model
Iterates over each model. Iterates over each of the models in the structure. Returns self
.
1623 1624 1625 1626 |
# File 'lib/bio/db/pdb/pdb.rb', line 1623 def each @models.each{ |model| yield model } self end |
#entry_id ⇒ Object
PDB identifier written in “HEADER”. (e.g. 1A00)
1877 1878 1879 1880 1881 1882 1883 |
# File 'lib/bio/db/pdb/pdb.rb', line 1877 def entry_id unless @id f = self.record('HEADER').first @id = f ? f.idCode : nil end @id end |
#helix(helixID = nil) ⇒ Object
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.)
1748 1749 1750 1751 1752 1753 1754 |
# File 'lib/bio/db/pdb/pdb.rb', line 1748 def helix(helixID = nil) if helixID then self.record('HELIX').find { |f| f.helixID == helixID } else self.record('HELIX') end end |
#inspect ⇒ Object
returns a string containing human-readable representation of this object.
1904 1905 1906 |
# File 'lib/bio/db/pdb/pdb.rb', line 1904 def inspect "#<#{self.class.to_s} entry_id=#{entry_id.inspect}>" end |
#jrnl(sub_record = nil) ⇒ Object
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.
1729 1730 1731 1732 1733 1734 |
# File 'lib/bio/db/pdb/pdb.rb', line 1729 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 ⇒ Object
Keywords in “KEYWDS”. Returns an array of string.
1857 1858 1859 |
# File 'lib/bio/db/pdb/pdb.rb', line 1857 def keywords self.record('KEYWDS').collect { |f| f.keywds }.flatten end |
#record(name = nil) ⇒ Object
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
1695 1696 1697 |
# File 'lib/bio/db/pdb/pdb.rb', line 1695 def record(name = nil) name ? (@hash[name] || []) : @hash end |
#remark(nn = nil) ⇒ Object
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.
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 |
# File 'lib/bio/db/pdb/pdb.rb', line 1710 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 |
#seqres(chainID = nil) ⇒ Object
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.
1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 |
# File 'lib/bio/db/pdb/pdb.rb', line 1801 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 (begin Bio::AminoAcid.three2one(aa) rescue ArgumentError nil end || 'X') end seq = Bio::Sequence::AA.new(a.to_s) else # nucleic acid sequence a.collect! do |na| na = na.delete('^a-zA-Z') 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 |
#sheet(sheetID = nil) ⇒ Object
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.
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 |
# File 'lib/bio/db/pdb/pdb.rb', line 1776 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 |
#ssbond ⇒ Object
Gets SSBOND records.
1788 1789 1790 |
# File 'lib/bio/db/pdb/pdb.rb', line 1788 def ssbond self.record('SSBOND') end |
#to_s ⇒ Object
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
1646 1647 1648 1649 1650 1651 |
# File 'lib/bio/db/pdb/pdb.rb', line 1646 def to_s string = "" @models.each{ |model| string << model.to_s } string << "END\n" return string end |
#turn(turnId = nil) ⇒ Object
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.)
1763 1764 1765 1766 1767 1768 1769 |
# File 'lib/bio/db/pdb/pdb.rb', line 1763 def turn(turnId = nil) if turnId then self.record('TURN').find { |f| f.turnId == turnId } else self.record('TURN') end end |
#version ⇒ Object
Current modification number in “REVDAT”.
1897 1898 1899 1900 |
# File 'lib/bio/db/pdb/pdb.rb', line 1897 def version f = self.record('REVDAT').first f ? f.modNum : nil end |