[BioRuby-cvs] bioruby/lib/bio/db/pdb pdb.rb, 1.6, 1.7 residue.rb, 1.4, 1.5

Naohisa Goto ngoto at pub.open-bio.org
Wed Jan 4 08:01:11 EST 2006


Update of /home/repository/bioruby/bioruby/lib/bio/db/pdb
In directory pub.open-bio.org:/tmp/cvs-serv11954

Modified Files:
	pdb.rb residue.rb 
Log Message:
* created new class to store HETATM:
  Bio::PDB::HeteroCompound < Bio::PDB::Residue
* added Bio::PDB::Residue.get_residue_id_from_atom(atom). 
* Bio::PDB::Residue#id is now an alias of Bio::PDB::Residue#residue_id.


Index: residue.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/residue.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** residue.rb	18 Dec 2005 17:34:47 -0000	1.4
--- residue.rb	4 Jan 2006 13:01:09 -0000	1.5
***************
*** 33,42 ****
        include Enumerable
        include Comparable
!       
!       attr_reader :resName, :resSeq, :iCode, :id, :chain, :hetatm
!       attr_writer :resName, :chain, :hetatm
!       
        def initialize(resName = nil, resSeq = nil, iCode = nil, 
!                      chain = nil, hetatm = false)
          
          @resName = resName
--- 33,45 ----
        include Enumerable
        include Comparable
! 
!       # Creates residue id from an ATOM (or HETATM) object.
!       def self.get_residue_id_from_atom(atom)
!         "#{atom.resSeq}#{atom.iCode.strip}".strip
!       end
! 
!       # Creates a new Residue object.
        def initialize(resName = nil, resSeq = nil, iCode = nil, 
!                      chain = nil)
          
          @resName = resName
***************
*** 44,90 ****
          @iCode   = iCode
          
-         @hetatm  = hetatm
-         
-         #Residue id is required because resSeq doesn't uniquely identify
-         #a residue. ID is constructed from resSeq and iCode and is appended
-         #to 'LIGAND' if the residue is a HETATM
-         if (!@resSeq and !@iCode)
-           @id = nil
-         else
-           @id = "#{@resSeq}#{@iCode.strip}"
-           if @hetatm
-             @id = 'LIGAND' + @id
-           end
-         end
-         
          @chain   = chain
!         
!         @atoms   = Array.new
!         
        end
!       
        #Keyed access to atoms based on element e.g. ["CA"]
        def [](key)
          atom = @atoms.find{ |atom| key == atom.element }
        end
!       
!       #Need to define these to make sure id is correctly updated
        def resSeq=(resSeq)
          @resSeq = resSeq.to_i
!         @id      = "#{@resSeq}#{@iCode.strip}"
!         if @hetatm
!           @id = 'LIGAND' + @id
!         end
        end
!       
        def iCode=(iCode)
          @iCode = iCode
!         @id    = "#{@resSeq}#{@iCode.strip}"
!         if @hetatm
!           @id = 'LIGAND' + @id
!         end
        end
        
!       #Adds an atom to this residue
        def addAtom(atom)
          raise "Expecting ATOM or HETATM" unless atom.is_a? Bio::PDB::Record::ATOM
--- 47,108 ----
          @iCode   = iCode
          
          @chain   = chain
!         @atoms   = []
! 
!         update_residue_id
        end
! 
!       # atoms in this residue. (Array)
!       attr_reader :atoms
! 
!       # the chain to which this residue belongs
!       attr_accessor :chain
! 
!       # resName (residue name)
!       attr_accessor :resName
! 
!       # residue id (String or nil)
!       attr_reader   :residue_id
! 
!       # Now, Residue#id is an alias of residue_id.
!       alias id residue_id
! 
        #Keyed access to atoms based on element e.g. ["CA"]
        def [](key)
          atom = @atoms.find{ |atom| key == atom.element }
        end
! 
!       # Updates residue id. This is a private method.
!       # Need to call this method to make sure id is correctly updated.
!       def update_residue_id
!         if !@resSeq and !@iCode
!           @residue_id = nil
!         else
!           @residue_id = "#{@resSeq}#{@iCode.to_s.strip}".strip
!         end
!       end
!       private :update_residue_id
! 
!       # resSeq
!       attr_reader :resSeq
! 
!       # resSeq=()
        def resSeq=(resSeq)
          @resSeq = resSeq.to_i
!         update_residue_id
!         @resSeq
        end
! 
!       # iCode
!       attr_reader :iCode
! 
!       # iCode=()
        def iCode=(iCode)
          @iCode = iCode
!         update_residue_id
!         @iCode
        end
        
!       # Adds an atom to this residue
        def addAtom(atom)
          raise "Expecting ATOM or HETATM" unless atom.is_a? Bio::PDB::Record::ATOM
***************
*** 93,97 ****
        end
        
!       #Iterator over the atoms
        def each
          @atoms.each{ |atom| yield atom }
--- 111,115 ----
        end
        
!       # Iterator over the atoms
        def each
          @atoms.each{ |atom| yield atom }
***************
*** 100,104 ****
        alias each_atom each
        
!       #Sorts based on resSeq and iCode if need be
        def <=>(other)
          if @resSeq != other.resSeq
--- 118,122 ----
        alias each_atom each
        
!       # Sorts based on resSeq and iCode if need be
        def <=>(other)
          if @resSeq != other.resSeq
***************
*** 109,113 ****
        end
        
!       #Stringifies each atom
        def to_s
          string = ""
--- 127,131 ----
        end
        
!       # Stringifies each atom
        def to_s
          string = ""
***************
*** 115,122 ****
          return string
        end
-       
-     end
  
!   end
  
! end
--- 133,172 ----
          return string
        end
  
!       # If the residue is HETATM, returns true.
!       # Otherwise, returns false.
!       def hetatm
!         false
!       end
!     end #class Residue
  
!     class HeteroCompound < Residue
! 
!       # Creates residue id from an ATOM (or HETATM) object.
!       # 
!       # We add 'LIGAND' to the id if it's a HETATM.
!       # I think this is neccessary because some PDB files reuse
!       # numbers for HETATMS.
!       def self.get_residue_id_from_atom(atom)
!         'LIGAND' + super
!       end
! 
!       # Residue id is required because resSeq doesn't uniquely identify
!       # a residue. ID is constructed from resSeq and iCode and is appended
!       # to 'LIGAND' if the residue is a HETATM
!       def update_residue_id
!         super
!         @residue_id = 'LIGAND' + @residue_id if @residue_id
!       end
!       private :update_residue_id
! 
!       # If the residue is HETATM, returns true.
!       # Otherwise, returns false.
!       def hetatm
!         true
!       end
!     end #class HeteroCompound
! 
!   end #class PDB
! 
! end #module Bio

Index: pdb.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/pdb.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** pdb.rb	18 Dec 2005 17:37:14 -0000	1.6
--- pdb.rb	4 Jan 2006 13:01:09 -0000	1.7
***************
*** 1212,1218 ****
  
        #Empty current model
!       cModel   = Bio::PDB::Model.new
!       cChain   = Bio::PDB::Chain.new
!       cResidue = Bio::PDB::Residue.new
  
        #Goes through each line and replace that line with a PDB::Record
--- 1212,1219 ----
  
        #Empty current model
!       cModel    = Model.new
!       cChain    = Chain.new
!       cResidue  = Residue.new
!       #cCompound = HeteroCompound.new
  
        #Goes through each line and replace that line with a PDB::Record
***************
*** 1239,1243 ****
          case key
          when 'ATOM'
!           residueID = "#{f.resSeq}#{f.iCode.strip}".strip
            #p f
  
--- 1240,1244 ----
          case key
          when 'ATOM'
!           residueID = Residue.get_residue_id_from_atom(f)
            #p f
  
***************
*** 1270,1275 ****
            #I can fix this if really needed
            if f.resName == 'HOH'
!             solvent =   Residue.new(f.resName, f.resSeq, f.iCode,
!                                     cModel.solvent, true)
              #p solvent
              f.residue = solvent
--- 1271,1276 ----
            #I can fix this if really needed
            if f.resName == 'HOH'
!             solvent =   HeteroCompound.new(f.resName, f.resSeq, f.iCode,
!                                            cModel.solvent)
              #p solvent
              f.residue = solvent
***************
*** 1279,1287 ****
            else
  
!             #Make residue we add 'LIGAND' to the id if it's a HETATM
!             #I think this is neccessary because some PDB files reuse
!             #numbers for HETATMS
!             residueID = "#{f.resSeq}#{f.iCode.strip}".strip
!             residueID = "LIGAND" + residueID
              #p f
              #p residueID
--- 1280,1284 ----
            else
  
!             residueID = HeteroCompound.get_residue_id_from_atom(f)
              #p f
              #p residueID
***************
*** 1300,1305 ****
                residue = cResidue
              elsif newChain or !(residue = chain[residueID])
!               newResidue = Residue.new(f.resName, f.resSeq, f.iCode,
!                                        chain, true)
                chain.addLigand(newResidue)
                cResidue = newResidue
--- 1297,1302 ----
                residue = cResidue
              elsif newChain or !(residue = chain[residueID])
!               newResidue = HeteroCompound.new(f.resName, f.resSeq, f.iCode,
!                                               chain)
                chain.addLigand(newResidue)
                cResidue = newResidue



More information about the bioruby-cvs mailing list