[BioRuby-cvs] bioruby/lib/bio/db/pdb pdb.rb, 1.10, 1.11 utils.rb,
1.3, 1.4
Naohisa Goto
ngoto at pub.open-bio.org
Thu Jan 5 06:10:12 EST 2006
- Previous message: [BioRuby-cvs]
bioruby/lib/bio/db/pdb pdb.rb, 1.9, 1.10 model.rb, 1.3, 1.4
- Next message: [BioRuby-cvs]
bioruby/lib/bio/db/pdb atom.rb, 1.5, 1.6 chain.rb, 1.3,
1.4 model.rb, 1.4, 1.5 pdb.rb, 1.11, 1.12 residue.rb, 1.7,
1.8 utils.rb, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/repository/bioruby/bioruby/lib/bio/db/pdb
In directory pub.open-bio.org:/tmp/cvs-serv15618
Modified Files:
pdb.rb utils.rb
Log Message:
* utils.rb
* Changed Bio::PDB::Utils.to_xyz(obj) to convert_to_xyz(obj)
(old to_xyz is still available for compatibility).
* In Utils, distance, dihedral_angle, rad2reg, acos, calculatePlane are
now module_function.
* added RDoc.
* added ChainFinder#chains, ResidueFinder#residues, AtomFinder#atoms,
HetatmFinder#hetatms, and HeterogenFinder#heterogens.
* pdb.rb
* modified some documents.
Index: utils.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/utils.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** utils.rb 4 Jan 2006 15:41:50 -0000 1.3
--- utils.rb 5 Jan 2006 11:10:10 -0000 1.4
***************
*** 26,51 ****
module Bio; class PDB
module Utils
- #The methods in this mixin should be applicalbe to all PDB objects
! #Returns the coordinates of the geometric centre (average co-ord)
! #of any AtomFinder (or .atoms) implementing object
! def geometricCentre()
!
x = y = z = count = 0
! self.each_atom{ |atom|
x += atom.x
y += atom.y
z += atom.z
count += 1
! }
!
! x = x / count
! y = y / count
! z = z / count
Coordinate[x,y,z]
-
end
--- 26,54 ----
module Bio; class PDB
+ # Utility methods for PDB data.
+ #
+ # The methods in this mixin should be applicalbe to all PDB objects.
module Utils
! # Returns the coordinates of the geometric centre (average co-ord)
! # of any AtomFinder (or .atoms) implementing object
! #
! # If you want to get the geometric centre of hetatms,
! # call geometricCentre(:each_hetatm).
! def geometricCentre(method = :each_atom)
x = y = z = count = 0
! self.__send__(method) do |atom|
x += atom.x
y += atom.y
z += atom.z
count += 1
! end
+ x = (x / count)
+ y = (y / count)
+ z = (z / count)
+
Coordinate[x,y,z]
end
***************
*** 64,69 ****
}
def centreOfGravity()
-
x = y = z = total = 0
--- 67,72 ----
}
+ # calculates centre of gravitiy
def centreOfGravity()
x = y = z = total = 0
***************
*** 82,98 ****
Coordinate[x,y,z]
-
end
#Perhaps distance and dihedral would be better off as class methods?
#(rather) than instance methods
! def self.distance(coord1,coord2)
! coord1 = to_xyz(coord1)
! coord2 = to_xyz(coord2)
(coord1 - coord2).r
end
! def self.dihedral_angle(coord1,coord2,coord3,coord4)
!
(a1,b1,c1,d) = calculatePlane(coord1,coord2,coord3)
(a2,b2,c2) = calculatePlane(coord2,coord3,coord4)
--- 85,105 ----
Coordinate[x,y,z]
end
+ #--
#Perhaps distance and dihedral would be better off as class methods?
#(rather) than instance methods
! #++
!
! # Calculates distance between _coord1_ and _coord2_.
! def distance(coord1, coord2)
! coord1 = convert_to_xyz(coord1)
! coord2 = convert_to_xyz(coord2)
(coord1 - coord2).r
end
+ module_function :distance
! # Calculates dihedral angle.
! def dihedral_angle(coord1, coord2, coord3, coord4)
(a1,b1,c1,d) = calculatePlane(coord1,coord2,coord3)
(a2,b2,c2) = calculatePlane(coord2,coord3,coord4)
***************
*** 106,112 ****
end
end
! #Implicit conversion into Vector or Bio::PDB::Coordinate
! def self.to_xyz(obj)
unless obj.is_a?(Vector)
begin
--- 113,120 ----
end
end
+ module_function :dihedral_angle
! # Implicit conversion into Vector or Bio::PDB::Coordinate
! def convert_to_xyz(obj)
unless obj.is_a?(Vector)
begin
***************
*** 118,133 ****
obj
end
#Methods required for the dihedral angle calculations
#perhaps these should go in some separate Math module
! def self.rad2deg(r)
(r/Math::PI)*180
end
!
! def self.acos(x)
Math.atan2(Math.sqrt(1 - x**2),x)
end
!
! def self.calculatePlane(coord1,coord2,coord3)
a = coord1.y * (coord2.z - coord3.z) +
coord2.y * (coord3.z - coord1.z) +
--- 126,155 ----
obj
end
+ module_function :convert_to_xyz
+
+ # (Deprecated) alias of convert_to_xyz(obj)
+ def self.to_xyz(obj)
+ convert_to_xyz(obj)
+ end
+ #--
#Methods required for the dihedral angle calculations
#perhaps these should go in some separate Math module
! #++
!
! # radian to degree
! def rad2deg(r)
(r/Math::PI)*180
end
! module_function :rad2deg
!
! # acos
! def acos(x)
Math.atan2(Math.sqrt(1 - x**2),x)
end
! module_function :acos
!
! # calculates plane
! def calculatePlane(coord1, coord2, coord3)
a = coord1.y * (coord2.z - coord3.z) +
coord2.y * (coord3.z - coord1.z) +
***************
*** 147,157 ****
return [a,b,c,d]
-
end
! #Every class in the heirarchy implements finder, this takes
! #a class which determines which type of object to find, the associated
! #block is then run in classic .find style
! def finder(findtype,&block)
if findtype == Bio::PDB::Atom
return self.find_atom(&block)
--- 169,182 ----
return [a,b,c,d]
end
+ module_function :calculatePlane
! # Every class in the heirarchy implements finder, this takes
! # a class which determines which type of object to find, the associated
! # block is then run in classic .find style.
! #
! # The method might be deprecated.
! # You'd better using find_XXX directly.
! def finder(findtype, &block) #:yields: obj
if findtype == Bio::PDB::Atom
return self.find_atom(&block)
***************
*** 167,236 ****
end
end #module Utils
!
#The *Finder modules implement a find_* method which returns
#an array of anything for which the block evals true
#(suppose Enumerable#find_all method).
#The each_* style methods act as classic iterators.
module ModelFinder
! def find_model()
array = []
! self.each_model{ |model|
array.push(model) if yield(model)
! }
return array
end
! end
#The heirarchical nature of the objects allow us to re-use the
#methods from the previous level - e.g. A PDB object can use the .models
#method defined in ModuleFinder to iterate through the models to find the
#chains
module ChainFinder
! def find_chain()
array = []
! self.each_chain{ |chain|
array.push(chain) if yield(chain)
! }
return array
end
! def each_chain()
! self.each_model{ |model|
! model.each{ |chain| yield chain }
! }
end
! end
module ResidueFinder
! def find_residue()
array = []
! self.each_residue{ |residue|
array.push(residue) if yield(residue)
! }
return array
end
! def each_residue()
! self.each_chain{ |chain|
! chain.each{ |residue| yield residue }
! }
end
! end
module AtomFinder
! def find_atom()
array = []
! self.each_atom{ |atom|
array.push(atom) if yield(atom)
! }
return array
end
! def each_atom()
! self.each_residue{ |residue|
! residue.each{ |atom| yield atom }
! }
end
- end
module HetatmFinder
! def find_hetatm()
array = []
self.each_hetatm do |hetatm|
--- 192,315 ----
end
end #module Utils
!
! #--
#The *Finder modules implement a find_* method which returns
#an array of anything for which the block evals true
#(suppose Enumerable#find_all method).
#The each_* style methods act as classic iterators.
+ #++
+
+ # methods to access models
+ #
+ # XXX#each_model must be defined.
module ModelFinder
! # returns an array containing all chains for which given block
! # is not +false+ (similar to Enumerable#find_all).
! def find_model
array = []
! self.each_model do |model|
array.push(model) if yield(model)
! end
return array
end
! end #module ModelFinder
+ #--
#The heirarchical nature of the objects allow us to re-use the
#methods from the previous level - e.g. A PDB object can use the .models
#method defined in ModuleFinder to iterate through the models to find the
#chains
+ #++
+
+ # methods to access chains
+ #
+ # XXX#each_model must be defined.
module ChainFinder
!
! # returns an array containing all chains for which given block
! # is not +false+ (similar to Enumerable#find_all).
! def find_chain
array = []
! self.each_chain do |chain|
array.push(chain) if yield(chain)
! end
return array
end
!
! # iterates over each chain
! def each_chain(&x) #:yields: chain
! self.each_model { |model| model.each(&x) }
end
!
! # returns all chains
! def chains
! array = []
! self.each_model { |model| array.concat(model.chains) }
! return array
! end
! end #module ChainFinder
+ # methods to access residues
+ #
+ # XXX#each_chain must be defined.
module ResidueFinder
!
! # returns an array containing all residues for which given block
! # is not +false+ (similar to Enumerable#find_all).
! def find_residue
array = []
! self.each_residue do |residue|
array.push(residue) if yield(residue)
! end
return array
end
!
! # iterates over each residue
! def each_residue(&x) #:yields: residue
! self.each_chain { |chain| chain.each(&x) }
end
!
! # returns all residues
! def residues
! array = []
! self.each_chain { |chain| array.concat(chain.residues) }
! return array
! end
! end #module ResidueFinder
+ # methods to access atoms
+ #
+ # XXX#each_residue must be defined.
module AtomFinder
! # returns an array containing all atoms for which given block
! # is not +false+ (similar to Enumerable#find_all).
! def find_atom
array = []
! self.each_atom do |atom|
array.push(atom) if yield(atom)
! end
return array
end
!
! # iterates over each atom
! def each_atom(&x) #:yields: atom
! self.each_residue { |residue| residue.each(&x) }
end
+ # returns all atoms
+ def atoms
+ array = []
+ self.each_residue { |residue| array.concat(residue.atoms) }
+ return array
+ end
+ end #module AtomFinder
+
+ # methods to access HETATMs
+ #
+ # XXX#each_heterogen must be defined.
module HetatmFinder
! # returns an array containing all HETATMs for which given block
! # is not +false+ (similar to Enumerable#find_all).
! def find_hetatm
array = []
self.each_hetatm do |hetatm|
***************
*** 239,249 ****
return array
end
def each_hetatm(&x) #:yields: hetatm
self.each_heterogen { |heterogen| heterogen.each(&x) }
end
- end
module HeterogenFinder
! def find_heterogen()
array = []
self.each_heterogen do |heterogen|
--- 318,342 ----
return array
end
+
+ # iterates over each HETATM
def each_hetatm(&x) #:yields: hetatm
self.each_heterogen { |heterogen| heterogen.each(&x) }
end
+ # returns all HETATMs
+ def hetatms
+ array = []
+ self.each_heterogen { |heterogen| array.concat(heterogen.hetatms) }
+ return array
+ end
+ end #module HetatmFinder
+
+ # methods to access heterogens (compounds or ligands)
+ #
+ # XXX#each_chain must be defined.
module HeterogenFinder
! # returns an array containing all heterogens for which given block
! # is not +false+ (similar to Enumerable#find_all).
! def find_heterogen
array = []
self.each_heterogen do |heterogen|
***************
*** 252,259 ****
return array
end
def each_heterogen(&x) #:yields: heterogen
self.each_chain { |chain| chain.each_heterogen(&x) }
end
! end
end; end #module Bio; class PDB
--- 345,361 ----
return array
end
+
+ # iterates over each heterogens
def each_heterogen(&x) #:yields: heterogen
self.each_chain { |chain| chain.each_heterogen(&x) }
end
!
! # returns all heterogens
! def heterogens
! array = []
! self.each_chain { |chain| array.concat(chain.heterogens) }
! return array
! end
! end #module HeterogenFinder
end; end #module Bio; class PDB
Index: pdb.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/pdb.rb,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** pdb.rb 5 Jan 2006 09:24:54 -0000 1.10
--- pdb.rb 5 Jan 2006 11:10:10 -0000 1.11
***************
*** 31,36 ****
module Bio
! #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
class PDB #< DB
--- 31,37 ----
module Bio
! # 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.
! #
class PDB #< DB
***************
*** 48,52 ****
DELIMITER = RS = nil # 1 file 1 entry
! #Modules required by the field definitions
module DataType
--- 49,53 ----
DELIMITER = RS = nil # 1 file 1 entry
! # Modules required by the field definitions
module DataType
***************
*** 1369,1375 ****
attr_reader :hash
attr_reader :models
! #Adds a Bio::Model to the current strucutre
def addModel(model)
raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model
--- 1370,1377 ----
attr_reader :hash
+ # models in this PDB entry
attr_reader :models
! # Adds a Bio::Model object to the current strucutre
def addModel(model)
raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model
***************
*** 1378,1386 ****
end
! #Iterates over the models
def each
@models.each{ |model| yield model }
end
! #Alias needed for Bio::PDB::ModelFinder
alias each_model each
--- 1380,1388 ----
end
! # Iterates over each model
def each
@models.each{ |model| yield model }
end
! # Alias needed for Bio::PDB::ModelFinder
alias each_model each
***************
*** 1390,1394 ****
@models.find{ |model| key == model.model_serial }
end
!
#Stringifies to a list of atom records - we could add the annotation
#as well if needed
--- 1392,1396 ----
@models.find{ |model| key == model.model_serial }
end
!
#Stringifies to a list of atom records - we could add the annotation
#as well if needed
- Previous message: [BioRuby-cvs]
bioruby/lib/bio/db/pdb pdb.rb, 1.9, 1.10 model.rb, 1.3, 1.4
- Next message: [BioRuby-cvs]
bioruby/lib/bio/db/pdb atom.rb, 1.5, 1.6 chain.rb, 1.3,
1.4 model.rb, 1.4, 1.5 pdb.rb, 1.11, 1.12 residue.rb, 1.7,
1.8 utils.rb, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the bioruby-cvs
mailing list