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, 'ENDMDL' => true, 'ATOM' => true, 'HETATM' => true, 'SIGATM' => true, 'SIGUIJ' => true, 'ANISOU' => 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.
-
#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.
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 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 |
# File 'lib/bio/db/pdb/pdb.rb', line 1430 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 |
Instance Attribute Details
#data ⇒ Object (readonly)
all records in this entry as an array.
1584 1585 1586 |
# File 'lib/bio/db/pdb/pdb.rb', line 1584 def data @data end |
#hash ⇒ Object (readonly)
all records in this entry as an hash accessed by record names.
1587 1588 1589 |
# File 'lib/bio/db/pdb/pdb.rb', line 1587 def hash @hash end |
#models ⇒ Object (readonly)
models in this entry (array).
1590 1591 1592 |
# File 'lib/bio/db/pdb/pdb.rb', line 1590 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
1613 1614 1615 |
# File 'lib/bio/db/pdb/pdb.rb', line 1613 def [](key) @models.find{ |model| key == model.model_serial } end |
#accession ⇒ Object
Same as Bio::PDB#entry_id
.
1863 1864 1865 |
# File 'lib/bio/db/pdb/pdb.rb', line 1863 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.
1595 1596 1597 1598 1599 |
# File 'lib/bio/db/pdb/pdb.rb', line 1595 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”.
1845 1846 1847 |
# File 'lib/bio/db/pdb/pdb.rb', line 1845 def self.record('AUTHOR').collect { |f| f. }.flatten end |
#classification ⇒ Object
Classification in “HEADER”.
1839 1840 1841 1842 |
# File 'lib/bio/db/pdb/pdb.rb', line 1839 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.
1824 1825 1826 1827 1828 1829 1830 |
# File 'lib/bio/db/pdb/pdb.rb', line 1824 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”.
1868 1869 1870 1871 |
# File 'lib/bio/db/pdb/pdb.rb', line 1868 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
.
1604 1605 1606 1607 |
# File 'lib/bio/db/pdb/pdb.rb', line 1604 def each @models.each{ |model| yield model } self end |
#entry_id ⇒ Object
PDB identifier written in “HEADER”. (e.g. 1A00)
1854 1855 1856 1857 1858 1859 1860 |
# File 'lib/bio/db/pdb/pdb.rb', line 1854 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.)
1729 1730 1731 1732 1733 1734 1735 |
# File 'lib/bio/db/pdb/pdb.rb', line 1729 def helix(helixID = nil) if helixID then self.record('HELIX').find { |f| f.helixID == helixID } else self.record('HELIX') end 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.
1710 1711 1712 1713 1714 1715 |
# File 'lib/bio/db/pdb/pdb.rb', line 1710 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.
1834 1835 1836 |
# File 'lib/bio/db/pdb/pdb.rb', line 1834 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
1676 1677 1678 |
# File 'lib/bio/db/pdb/pdb.rb', line 1676 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.
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
# File 'lib/bio/db/pdb/pdb.rb', line 1691 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.
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 |
# File 'lib/bio/db/pdb/pdb.rb', line 1782 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 |
#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.
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 |
# File 'lib/bio/db/pdb/pdb.rb', line 1757 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.
1769 1770 1771 |
# File 'lib/bio/db/pdb/pdb.rb', line 1769 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
1627 1628 1629 1630 1631 1632 |
# File 'lib/bio/db/pdb/pdb.rb', line 1627 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.)
1744 1745 1746 1747 1748 1749 1750 |
# File 'lib/bio/db/pdb/pdb.rb', line 1744 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”.
1874 1875 1876 1877 |
# File 'lib/bio/db/pdb/pdb.rb', line 1874 def version f = self.record('REVDAT').first f ? f.modNum : nil end |