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

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 152
152:     def self.to_xyz(obj)
153:       convert_to_xyz(obj)
154:     end

Public Instance methods

acos

[Source]

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

calculates plane

[Source]

     # File lib/bio/db/pdb/utils.rb, line 174
174:     def calculatePlane(coord1, coord2, coord3)
175:       a = coord1.y * (coord2.z - coord3.z) +
176:           coord2.y * (coord3.z - coord1.z) + 
177:           coord3.y * (coord1.z - coord2.z)
178:       b = coord1.z * (coord2.x - coord3.x) +
179:           coord2.z * (coord3.x - coord1.x) + 
180:           coord3.z * (coord1.x - coord2.x)
181:       c = coord1.x * (coord2.y - coord3.y) +
182:           coord2.x * (coord3.y - coord1.y) + 
183:           coord3.x * (coord1.y - coord2.y)
184:       d = -1 *
185:           (
186:            (coord1.x * (coord2.y * coord3.z - coord3.y * coord2.z)) +
187:            (coord2.x * (coord3.y * coord1.z - coord1.y * coord3.z)) +
188:            (coord3.x * (coord1.y * coord2.z - coord2.y * coord1.z))
189:            )
190: 
191:       return [a,b,c,d]
192:     end

calculates centre of gravitiy

[Source]

     # File lib/bio/db/pdb/utils.rb, line 91
 91:     def centreOfGravity()
 92:       x = y = z = total = 0
 93:       
 94:       self.each_atom{ |atom|
 95:         element = atom.element[0,1]
 96:         mass    = ElementMass[element]
 97:         total += mass
 98:         x += atom.x * mass
 99:         y += atom.y * mass
100:         z += atom.z * mass
101:       }
102:       
103:       x = x / total
104:       y = y / total
105:       z = z / total
106:       
107:       Coordinate[x,y,z]
108:     end

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

[Source]

     # File lib/bio/db/pdb/utils.rb, line 139
139:     def convert_to_xyz(obj)
140:       unless obj.is_a?(Vector)
141:         begin
142:           obj = obj.xyz
143:         rescue NameError
144:           obj = Vector.elements(obj.to_a)
145:         end
146:       end
147:       obj
148:     end

Calculates dihedral angle.

[Source]

     # File lib/bio/db/pdb/utils.rb, line 124
124:     def dihedral_angle(coord1, coord2, coord3, coord4)
125:       (a1,b1,c1,d) = calculatePlane(coord1,coord2,coord3)
126:       (a2,b2,c2)   = calculatePlane(coord2,coord3,coord4)
127:       
128:       torsion = acos((a1*a2 + b1*b2 + c1*c2)/(Math.sqrt(a1**2 + b1**2 + c1**2) * Math.sqrt(a2**2 + b2**2 + c2**2)))
129:       
130:       if ((a1*coord4.x + b1*coord4.y + c1*coord4.z + d) < 0)
131:         -torsion
132:       else
133:         torsion
134:       end
135:     end

Calculates distance between _coord1_ and _coord2_.

[Source]

     # File lib/bio/db/pdb/utils.rb, line 116
116:     def distance(coord1, coord2)
117:       coord1 = convert_to_xyz(coord1)
118:       coord2 = convert_to_xyz(coord2)
119:       (coord1 - coord2).r
120:     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 201
201:     def finder(findtype, &block) #:yields: obj
202:       if findtype == Bio::PDB::Atom
203:         return self.find_atom(&block)
204:       elsif findtype == Bio::PDB::Residue
205:         return self.find_residue(&block)
206:       elsif findtype == Bio::PDB::Chain
207:         return self.find_chain(&block)
208:       elsif findtype == Bio::PDB::Model
209:         return self.find_model(&block)
210:       else
211:         raise TypeError, "You can't find a #{findtype}"
212:       end
213:     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 59
59:     def geometricCentre(method = :each_atom)
60:       x = y = z = count = 0
61:       
62:       self.__send__(method) do |atom|
63:         x += atom.x
64:         y += atom.y
65:         z += atom.z
66:         count += 1
67:       end
68:       
69:       x = (x / count)
70:       y = (y / count)
71:       z = (z / count)
72:      
73:       Coordinate[x,y,z]
74:     end

radian to degree

[Source]

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

[Validate]