Module Bio::PDB::Utils
In: lib/bio/db/pdb/utils.rb  (CVS)

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.

Methods

Constants

ElementMass = { 'H' => 1, 'C' => 12, 'N' => 14, 'O' => 16, 'S' => 32, 'P' => 31   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

(Deprecated) alias of convert_to_xyz(obj)

[Source]

# File lib/bio/db/pdb/utils.rb, line 150
    def self.to_xyz(obj)
      convert_to_xyz(obj)
    end

Public Instance methods

acos

[Source]

# File lib/bio/db/pdb/utils.rb, line 166
    def acos(x)
      Math.atan2(Math.sqrt(1 - x**2),x)
    end

calculates plane

[Source]

# File lib/bio/db/pdb/utils.rb, line 172
    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

calculates centre of gravitiy

[Source]

# File lib/bio/db/pdb/utils.rb, line 89
    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

Implicit conversion into Vector or Bio::PDB::Coordinate

[Source]

# File lib/bio/db/pdb/utils.rb, line 137
    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.

[Source]

# File lib/bio/db/pdb/utils.rb, line 122
    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_.

[Source]

# File lib/bio/db/pdb/utils.rb, line 114
    def distance(coord1, coord2)
      coord1 = convert_to_xyz(coord1)
      coord2 = convert_to_xyz(coord2)
      (coord1 - coord2).r
    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.

[Source]

# File lib/bio/db/pdb/utils.rb, line 199
    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).

[Source]

# File lib/bio/db/pdb/utils.rb, line 57
    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

radian to degree

[Source]

# File lib/bio/db/pdb/utils.rb, line 160
    def rad2deg(r)
      (r/Math::PI)*180
    end

[Validate]