[BioRuby-cvs] bioruby/lib/bio/db/pdb pdb.rb,1.16,1.17

Naohisa Goto ngoto at dev.open-bio.org
Tue Mar 27 16:29:34 UTC 2007


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

Modified Files:
	pdb.rb 
Log Message:
Atom name of ATOM record output changed to be more precisely
(Mailing list: [BioRuby] Bug in writing PDB ATOM).
For the purpose, private method justify_atomname was added to
Bio::PDB::Record::ATOM.


Index: pdb.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/pdb.rb,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** pdb.rb	27 Jun 2006 14:23:45 -0000	1.16
--- pdb.rb	27 Mar 2007 16:29:32 -0000	1.17
***************
*** 1011,1020 ****
          end
  
!         def to_s
            atomname = self.name.to_s
            elem = self.element.to_s.strip
!           if elem.length == 1 and atomname.lstrip[0, 1] == elem then
!             atomname = ' ' + atomname
            end
            sprintf("%-6s%5d %-4s%-1s%3s %-1s%4d%-1s   %8.3f%8.3f%8.3f%6.2f%6.2f      %-4s%2s%-2s\n",
                    self.record_name,
--- 1011,1063 ----
          end
  
!         def justify_atomname
            atomname = self.name.to_s
+           return atomname[0, 4] if atomname.length >= 4
+           case atomname.length
+           when 0
+             return '    '
+           when 1
+             return ' ' + atomname + '  '
+           when 2
+             if /\A[0-9]/ =~ atomname then
+               return sprintf('%-4s', atomname)
+             elsif /[0-9]\z/ =~ atomname then
+               return sprintf(' %-3s', atomname)
+             end
+           when 3
+             if /\A[0-9]/ =~ atomname then
+               return sprintf('%-4s', atomname)
+             end
+           end
+           # ambiguous case for two- or three-letter name
            elem = self.element.to_s.strip
!           if elem.size > 0 and i = atomname.index(elem) then
!             if i == 0 and elem.size == 1 then
!               return sprintf(' %-3s', atomname)
!             else
!               return sprintf('%-4s', atomname)
!             end
!           end
!           if self.class == HETATM then
!             if /\A(B[^AEHIKR]|C[^ADEFLMORSU]|F[^EMR]|H[^EFGOS]|I[^NR]|K[^R]|N[^ABDEIOP]|O[^S]|P[^ABDMORTU]|S[^BCEGIMNR]|V|W|Y[^B])/ =~
!                 atomname then
!               return sprintf(' %-3s', atomname)
!             else
!               return sprintf('%-4s', atomname)
!             end
!           else # ATOM
!             if /\A[CHONS]/ =~ atomname then
!               return sprintf(' %-3s', atomname)
!             else
!               return sprintf('%-4s', atomname)
!             end
            end
+           # could not be reached here
+           raise 'bug!'
+         end
+         private :justify_atomname
+ 
+         def to_s
+           atomname = justify_atomname
            sprintf("%-6s%5d %-4s%-1s%3s %-1s%4d%-1s   %8.3f%8.3f%8.3f%6.2f%6.2f      %-4s%2s%-2s\n",
                    self.record_name,




More information about the bioruby-cvs mailing list