| 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.
| 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. |
(Deprecated) alias of convert_to_xyz(obj)
# File lib/bio/db/pdb/utils.rb, line 150
150: def self.to_xyz(obj)
151: convert_to_xyz(obj)
152: end
calculates plane
# File lib/bio/db/pdb/utils.rb, line 172
172: def calculatePlane(coord1, coord2, coord3)
173: a = coord1.y * (coord2.z - coord3.z) +
174: coord2.y * (coord3.z - coord1.z) +
175: coord3.y * (coord1.z - coord2.z)
176: b = coord1.z * (coord2.x - coord3.x) +
177: coord2.z * (coord3.x - coord1.x) +
178: coord3.z * (coord1.x - coord2.x)
179: c = coord1.x * (coord2.y - coord3.y) +
180: coord2.x * (coord3.y - coord1.y) +
181: coord3.x * (coord1.y - coord2.y)
182: d = -1 *
183: (
184: (coord1.x * (coord2.y * coord3.z - coord3.y * coord2.z)) +
185: (coord2.x * (coord3.y * coord1.z - coord1.y * coord3.z)) +
186: (coord3.x * (coord1.y * coord2.z - coord2.y * coord1.z))
187: )
188:
189: return [a,b,c,d]
190: end
calculates centre of gravitiy
# File lib/bio/db/pdb/utils.rb, line 89
89: def centreOfGravity()
90: x = y = z = total = 0
91:
92: self.each_atom{ |atom|
93: element = atom.element[0,1]
94: mass = ElementMass[element]
95: total += mass
96: x += atom.x * mass
97: y += atom.y * mass
98: z += atom.z * mass
99: }
100:
101: x = x / total
102: y = y / total
103: z = z / total
104:
105: Coordinate[x,y,z]
106: end
Implicit conversion into Vector or Bio::PDB::Coordinate
# File lib/bio/db/pdb/utils.rb, line 137
137: def convert_to_xyz(obj)
138: unless obj.is_a?(Vector)
139: begin
140: obj = obj.xyz
141: rescue NameError
142: obj = Vector.elements(obj.to_a)
143: end
144: end
145: obj
146: end
Calculates dihedral angle.
# File lib/bio/db/pdb/utils.rb, line 122
122: def dihedral_angle(coord1, coord2, coord3, coord4)
123: (a1,b1,c1,d) = calculatePlane(coord1,coord2,coord3)
124: (a2,b2,c2) = calculatePlane(coord2,coord3,coord4)
125:
126: torsion = acos((a1*a2 + b1*b2 + c1*c2)/(Math.sqrt(a1**2 + b1**2 + c1**2) * Math.sqrt(a2**2 + b2**2 + c2**2)))
127:
128: if ((a1*coord4.x + b1*coord4.y + c1*coord4.z + d) < 0)
129: -torsion
130: else
131: torsion
132: end
133: 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 199
199: def finder(findtype, &block) #:yields: obj
200: if findtype == Bio::PDB::Atom
201: return self.find_atom(&block)
202: elsif findtype == Bio::PDB::Residue
203: return self.find_residue(&block)
204: elsif findtype == Bio::PDB::Chain
205: return self.find_chain(&block)
206: elsif findtype == Bio::PDB::Model
207: return self.find_model(&block)
208: else
209: raise TypeError, "You can't find a #{findtype}"
210: end
211: 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 57
57: def geometricCentre(method = :each_atom)
58: x = y = z = count = 0
59:
60: self.__send__(method) do |atom|
61: x += atom.x
62: y += atom.y
63: z += atom.z
64: count += 1
65: end
66:
67: x = (x / count)
68: y = (y / count)
69: z = (z / count)
70:
71: Coordinate[x,y,z]
72: end