Class: Bio::PDB::Chain

Inherits:
Object show all
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

Constant Summary

Constants included from Utils

Utils::ElementMass

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from HeterogenFinder

#find_heterogen

Methods included from HetatmFinder

#each_hetatm, #find_hetatm, #hetatms

Methods included from ResidueFinder

#find_residue

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

- (Chain) initialize(id = nil, model = nil)

Creates a new chain object.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bio/db/pdb/chain.rb', line 40

def initialize(id = nil, model = nil)
  
  @chain_id  = id
  
  @model    = model
  
  @residues   = []
  @residues_hash = {}
  @heterogens = []
  @heterogens_hash = {}
end

Instance Attribute Details

- (Object) chain_id Also known as: id

Identifier of this chain



53
54
55
# File 'lib/bio/db/pdb/chain.rb', line 53

def chain_id
  @chain_id
end

- (Object) heterogens (readonly)

heterogens in this chain



64
65
66
# File 'lib/bio/db/pdb/chain.rb', line 64

def heterogens
  @heterogens
end

- (Object) model (readonly)

the model to which this chain belongs.



58
59
60
# File 'lib/bio/db/pdb/chain.rb', line 58

def model
  @model
end

- (Object) residues (readonly)

residues in this chain



61
62
63
# File 'lib/bio/db/pdb/chain.rb', line 61

def residues
  @residues
end

Instance Method Details

- (Object) <=>(other)

Operator aimed to sort based on chain id



166
167
168
# File 'lib/bio/db/pdb/chain.rb', line 166

def <=>(other)
  return @chain_id <=> other.chain_id
end

- (Object) [](key)

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.



77
78
79
# File 'lib/bio/db/pdb/chain.rb', line 77

def [](key)
  get_residue_by_id(key)
end

- (Object) aaseq Also known as: atom_seq

gets an amino acid sequence of this chain from ATOM records



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/bio/db/pdb/chain.rb', line 182

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

- (Object) addLigand(ligand)

Add a heterogen (ligand) to this chain



100
101
102
103
104
105
106
107
108
109
# File 'lib/bio/db/pdb/chain.rb', line 100

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

- (Object) addResidue(residue)

Add a residue to this chain



88
89
90
91
92
93
94
95
96
97
# File 'lib/bio/db/pdb/chain.rb', line 88

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

- (Object) each(&x) Also known as: each_residue

Iterates over each residue



154
155
156
# File 'lib/bio/db/pdb/chain.rb', line 154

def each(&x) #:yields: residue
  @residues.each(&x)
end

- (Object) each_heterogen(&x)

Iterates over each hetero-compound



161
162
163
# File 'lib/bio/db/pdb/chain.rb', line 161

def each_heterogen(&x) #:yields: heterogen
  @heterogens.each(&x)
end

- (Object) get_heterogen_by_id(key)

get the heterogen (ligand) by id



82
83
84
85
# File 'lib/bio/db/pdb/chain.rb', line 82

def get_heterogen_by_id(key)
  #@heterogens.find { |r| r.residue_id == key }
  @heterogens_hash[key]
end

- (Object) get_residue_by_id(key)

get the residue by id



67
68
69
70
# File 'lib/bio/db/pdb/chain.rb', line 67

def get_residue_by_id(key)
  #@residues.find { |r| r.residue_id == key }
  @residues_hash[key]
end

- (Object) inspect

returns a string containing human-readable representation of this object.



177
178
179
# File 'lib/bio/db/pdb/chain.rb', line 177

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

- (Object) rehash

rehash residues hash and heterogens hash



148
149
150
151
# File 'lib/bio/db/pdb/chain.rb', line 148

def rehash
  rehash_residues
  rehash_heterogens
end

- (Object) rehash_heterogens

rehash heterogens hash



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/bio/db/pdb/chain.rb', line 130

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

- (Object) rehash_residues

rehash residues hash



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/bio/db/pdb/chain.rb', line 112

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

- (Object) to_s

Stringifies each residue



171
172
173
# File 'lib/bio/db/pdb/chain.rb', line 171

def to_s
  @residues.join('') + "TER\n" + @heterogens.join('')
end