Class: Bio::PDB::Chain
- Includes:
- AtomFinder, HetatmFinder, HeterogenFinder, ResidueFinder, Utils, Comparable, Enumerable
- Defined in:
- lib/bio/db/pdb/chain.rb
Overview
Bio::PDB::Chain is a class to store a chain.
The object would contain some residues (Bio::PDB::Residue objects) and some heterogens (Bio::PDB::Heterogen objects).
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#chain_id ⇒ Object
(also: #id)
Identifier of this chain.
-
#heterogens ⇒ Object
readonly
heterogens in this chain.
-
#model ⇒ Object
readonly
the model to which this chain belongs.
-
#residues ⇒ Object
readonly
residues in this chain.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Operator aimed to sort based on chain id.
-
#[](key) ⇒ Object
get the residue by id.
-
#aaseq ⇒ Object
(also: #atom_seq)
gets an amino acid sequence of this chain from ATOM records.
-
#addLigand(ligand) ⇒ Object
Add a heterogen (ligand) to this chain.
-
#addResidue(residue) ⇒ Object
Add a residue to this chain.
-
#each(&x) ⇒ Object
(also: #each_residue)
Iterates over each residue.
-
#each_heterogen(&x) ⇒ Object
Iterates over each hetero-compound.
-
#get_heterogen_by_id(key) ⇒ Object
get the heterogen (ligand) by id.
-
#get_residue_by_id(key) ⇒ Object
get the residue by id.
-
#initialize(id = nil, model = nil) ⇒ Chain
constructor
Creates a new chain object.
-
#inspect ⇒ Object
returns a string containing human-readable representation of this object.
-
#rehash ⇒ Object
rehash residues hash and heterogens hash.
-
#rehash_heterogens ⇒ Object
rehash heterogens hash.
-
#rehash_residues ⇒ Object
rehash residues hash.
-
#to_s ⇒ Object
Stringifies each residue.
Methods included from HeterogenFinder
Methods included from HetatmFinder
#each_hetatm, #find_hetatm, #hetatms
Methods included from ResidueFinder
Methods included from AtomFinder
#atoms, #each_atom, #find_atom
Methods included from Utils
acos, calculatePlane, #centreOfGravity, convert_to_xyz, dihedral_angle, distance, #finder, #geometricCentre, rad2deg, to_xyz
Constructor Details
#initialize(id = nil, model = nil) ⇒ Chain
Creates a new chain object.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bio/db/pdb/chain.rb', line 39 def initialize(id = nil, model = nil) @chain_id = id @model = model @residues = [] @residues_hash = {} @heterogens = [] @heterogens_hash = {} end |
Instance Attribute Details
#chain_id ⇒ Object Also known as: id
Identifier of this chain
52 53 54 |
# File 'lib/bio/db/pdb/chain.rb', line 52 def chain_id @chain_id end |
#heterogens ⇒ Object (readonly)
heterogens in this chain
63 64 65 |
# File 'lib/bio/db/pdb/chain.rb', line 63 def heterogens @heterogens end |
#model ⇒ Object (readonly)
the model to which this chain belongs.
57 58 59 |
# File 'lib/bio/db/pdb/chain.rb', line 57 def model @model end |
#residues ⇒ Object (readonly)
residues in this chain
60 61 62 |
# File 'lib/bio/db/pdb/chain.rb', line 60 def residues @residues end |
Instance Method Details
#<=>(other) ⇒ Object
Operator aimed to sort based on chain id
165 166 167 |
# File 'lib/bio/db/pdb/chain.rb', line 165 def <=>(other) return @chain_id <=> other.chain_id end |
#[](key) ⇒ Object
get the residue by id.
Compatibility Note: Now, you cannot find HETATMS in this method. To add “LIGAND” to the id is no longer available. To get heterogens, you must use get_heterogen_by_id
.
76 77 78 |
# File 'lib/bio/db/pdb/chain.rb', line 76 def [](key) get_residue_by_id(key) end |
#aaseq ⇒ Object Also known as: atom_seq
gets an amino acid sequence of this chain from ATOM records
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/bio/db/pdb/chain.rb', line 181 def aaseq unless defined? @aaseq string = "" last_residue_num = nil @residues.each do |residue| if last_residue_num and (x = (residue.resSeq.to_i - last_residue_num).abs) > 1 then x.times { string << 'X' } end tlc = residue.resName.capitalize olc = (begin Bio::AminoAcid.three2one(tlc) rescue ArgumentError nil end || 'X') string << olc end @aaseq = Bio::Sequence::AA.new(string) end @aaseq end |
#addLigand(ligand) ⇒ Object
Add a heterogen (ligand) to this chain
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/bio/db/pdb/chain.rb', line 99 def addLigand(ligand) raise "Expecting a Bio::PDB::Residue" unless ligand.is_a? Bio::PDB::Residue @heterogens.push(ligand) if @heterogens_hash[ligand.residue_id] then $stderr.puts "Warning: heterogen_id (residue_id) #{ligand.residue_id.inspect} is already used" if $VERBOSE else @heterogens_hash[ligand.residue_id] = ligand end self end |
#addResidue(residue) ⇒ Object
Add a residue to this chain
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bio/db/pdb/chain.rb', line 87 def addResidue(residue) raise "Expecting a Bio::PDB::Residue" unless residue.is_a? Bio::PDB::Residue @residues.push(residue) if @residues_hash[residue.residue_id] then $stderr.puts "Warning: residue_id #{residue.residue_id.inspect} is already used" if $VERBOSE else @residues_hash[residue.residue_id] = residue end self end |
#each(&x) ⇒ Object Also known as: each_residue
Iterates over each residue
153 154 155 |
# File 'lib/bio/db/pdb/chain.rb', line 153 def each(&x) #:yields: residue @residues.each(&x) end |
#each_heterogen(&x) ⇒ Object
Iterates over each hetero-compound
160 161 162 |
# File 'lib/bio/db/pdb/chain.rb', line 160 def each_heterogen(&x) #:yields: heterogen @heterogens.each(&x) end |
#get_heterogen_by_id(key) ⇒ Object
get the heterogen (ligand) by id
81 82 83 84 |
# File 'lib/bio/db/pdb/chain.rb', line 81 def get_heterogen_by_id(key) #@heterogens.find { |r| r.residue_id == key } @heterogens_hash[key] end |
#get_residue_by_id(key) ⇒ Object
get the residue by id
66 67 68 69 |
# File 'lib/bio/db/pdb/chain.rb', line 66 def get_residue_by_id(key) #@residues.find { |r| r.residue_id == key } @residues_hash[key] end |
#inspect ⇒ Object
returns a string containing human-readable representation of this object.
176 177 178 |
# File 'lib/bio/db/pdb/chain.rb', line 176 def inspect "#<#{self.class.to_s} id=#{chain_id.inspect} model.serial=#{(model ? model.serial : nil).inspect} residues.size=#{residues.size} heterogens.size=#{heterogens.size} aaseq=#{aaseq.inspect}>" end |
#rehash ⇒ Object
rehash residues hash and heterogens hash
147 148 149 150 |
# File 'lib/bio/db/pdb/chain.rb', line 147 def rehash rehash_residues rehash_heterogens end |
#rehash_heterogens ⇒ Object
rehash heterogens hash
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/bio/db/pdb/chain.rb', line 129 def rehash_heterogens begin heterogens_bak = @heterogens heterogens_hash_bak = @heterogens_hash @heterogens = [] @heterogens_hash = {} heterogens_bak.each do |heterogen| self.addLigand(heterogen) end rescue RuntimeError @heterogens = heterogens_bak @heterogens_hash = heterogens_hash_bak raise end self end |
#rehash_residues ⇒ Object
rehash residues hash
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/bio/db/pdb/chain.rb', line 111 def rehash_residues begin residues_bak = @residues residues_hash_bak = @residues_hash @residues = [] @residues_hash = {} residues_bak.each do |residue| self.addResidue(residue) end rescue RuntimeError @residues = residues_bak @residues_hash = residues_hash_bak raise end self end |
#to_s ⇒ Object
Stringifies each residue
170 171 172 |
# File 'lib/bio/db/pdb/chain.rb', line 170 def to_s @residues.join('') + "TER\n" + @heterogens.join('') end |