module Bio::PDB::Utils
Utility methods for PDB data. The methods in this mixin should be applicalbe to all PDB objects.
Bio::PDB::Utils is included by Bio::PDB, Bio::PDB::Model, Bio::PDB::Chain, Bio::PDB::Residue, and Bio::PDB::Heterogen classes.
Constants
- ElementMass
Returns the coords of the centre of gravity for any AtomFinder implementing object Blleurgh! - working out what element it is from the atom name is tricky - this'll work in most cases but not metals etc… a proper element field is included in some PDB files but not all.
Public Class Methods
acos
# File lib/bio/db/pdb/utils.rb, line 168 def acos(x) Math.atan2(Math.sqrt(1 - x**2),x) end
calculates plane
# File lib/bio/db/pdb/utils.rb, line 174 def calculatePlane(coord1, coord2, coord3) a = coord1.y * (coord2.z - coord3.z) + coord2.y * (coord3.z - coord1.z) + coord3.y * (coord1.z - coord2.z) b = coord1.z * (coord2.x - coord3.x) + coord2.z * (coord3.x - coord1.x) + coord3.z * (coord1.x - coord2.x) c = coord1.x * (coord2.y - coord3.y) + coord2.x * (coord3.y - coord1.y) + coord3.x * (coord1.y - coord2.y) d = -1 * ( (coord1.x * (coord2.y * coord3.z - coord3.y * coord2.z)) + (coord2.x * (coord3.y * coord1.z - coord1.y * coord3.z)) + (coord3.x * (coord1.y * coord2.z - coord2.y * coord1.z)) ) return [a,b,c,d] end
Implicit conversion into Vector or Bio::PDB::Coordinate
# File lib/bio/db/pdb/utils.rb, line 139 def convert_to_xyz(obj) unless obj.is_a?(Vector) begin obj = obj.xyz rescue NameError obj = Vector.elements(obj.to_a) end end obj end
Calculates dihedral angle.
# File lib/bio/db/pdb/utils.rb, line 124 def dihedral_angle(coord1, coord2, coord3, coord4) (a1,b1,c1,d) = calculatePlane(coord1,coord2,coord3) (a2,b2,c2) = calculatePlane(coord2,coord3,coord4) torsion = acos((a1*a2 + b1*b2 + c1*c2)/(Math.sqrt(a1**2 + b1**2 + c1**2) * Math.sqrt(a2**2 + b2**2 + c2**2))) if ((a1*coord4.x + b1*coord4.y + c1*coord4.z + d) < 0) -torsion else torsion end end
Calculates distance between coord1 and coord2.
# File lib/bio/db/pdb/utils.rb, line 116 def distance(coord1, coord2) coord1 = convert_to_xyz(coord1) coord2 = convert_to_xyz(coord2) (coord1 - coord2).r end
radian to degree
# File lib/bio/db/pdb/utils.rb, line 162 def rad2deg(r) (r/Math::PI)*180 end
(Deprecated) alias of #convert_to_xyz(obj)
# File lib/bio/db/pdb/utils.rb, line 152 def self.to_xyz(obj) convert_to_xyz(obj) end
Public Instance Methods
calculates centre of gravitiy
# File lib/bio/db/pdb/utils.rb, line 91 def centreOfGravity() x = y = z = total = 0 self.each_atom{ |atom| element = atom.element[0,1] mass = ElementMass[element] total += mass x += atom.x * mass y += atom.y * mass z += atom.z * mass } x = x / total y = y / total z = z / total Coordinate[x,y,z] 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.
The method might be deprecated. You'd better using find_XXX directly.
# File lib/bio/db/pdb/utils.rb, line 201 def finder(findtype, &block) #:yields: obj if findtype == Bio::PDB::Atom return self.find_atom(&block) elsif findtype == Bio::PDB::Residue return self.find_residue(&block) elsif findtype == Bio::PDB::Chain return self.find_chain(&block) elsif findtype == Bio::PDB::Model return self.find_model(&block) else raise TypeError, "You can't find a #{findtype}" end end
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).
# File lib/bio/db/pdb/utils.rb, line 59 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
Private Instance Methods
acos
# File lib/bio/db/pdb/utils.rb, line 168 def acos(x) Math.atan2(Math.sqrt(1 - x**2),x) end
calculates plane
# File lib/bio/db/pdb/utils.rb, line 174 def calculatePlane(coord1, coord2, coord3) a = coord1.y * (coord2.z - coord3.z) + coord2.y * (coord3.z - coord1.z) + coord3.y * (coord1.z - coord2.z) b = coord1.z * (coord2.x - coord3.x) + coord2.z * (coord3.x - coord1.x) + coord3.z * (coord1.x - coord2.x) c = coord1.x * (coord2.y - coord3.y) + coord2.x * (coord3.y - coord1.y) + coord3.x * (coord1.y - coord2.y) d = -1 * ( (coord1.x * (coord2.y * coord3.z - coord3.y * coord2.z)) + (coord2.x * (coord3.y * coord1.z - coord1.y * coord3.z)) + (coord3.x * (coord1.y * coord2.z - coord2.y * coord1.z)) ) return [a,b,c,d] end
Implicit conversion into Vector or Bio::PDB::Coordinate
# File lib/bio/db/pdb/utils.rb, line 139 def convert_to_xyz(obj) unless obj.is_a?(Vector) begin obj = obj.xyz rescue NameError obj = Vector.elements(obj.to_a) end end obj end
Calculates dihedral angle.
# File lib/bio/db/pdb/utils.rb, line 124 def dihedral_angle(coord1, coord2, coord3, coord4) (a1,b1,c1,d) = calculatePlane(coord1,coord2,coord3) (a2,b2,c2) = calculatePlane(coord2,coord3,coord4) torsion = acos((a1*a2 + b1*b2 + c1*c2)/(Math.sqrt(a1**2 + b1**2 + c1**2) * Math.sqrt(a2**2 + b2**2 + c2**2))) if ((a1*coord4.x + b1*coord4.y + c1*coord4.z + d) < 0) -torsion else torsion end end
Calculates distance between coord1 and coord2.
# File lib/bio/db/pdb/utils.rb, line 116 def distance(coord1, coord2) coord1 = convert_to_xyz(coord1) coord2 = convert_to_xyz(coord2) (coord1 - coord2).r end
radian to degree
# File lib/bio/db/pdb/utils.rb, line 162 def rad2deg(r) (r/Math::PI)*180 end