class Bio::PDB::Chain

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).

Attributes

chain_id[RW]

Identifier of this chain

heterogens[R]

heterogens in this chain

id[RW]

Identifier of this chain

model[R]

the model to which this chain belongs.

residues[R]

residues in this chain

Public Class Methods

new(id = nil, model = nil) click to toggle source

Creates a new chain object.

# 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

Public Instance Methods

<=>(other) click to toggle source

Operator aimed to sort based on chain id

# File lib/bio/db/pdb/chain.rb, line 165
def <=>(other)
  return @chain_id <=> other.chain_id
end
[](key) click to toggle source

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.

# File lib/bio/db/pdb/chain.rb, line 76
def [](key)
  get_residue_by_id(key)
end
aaseq() click to toggle source

gets an amino acid sequence of this chain from ATOM records

# 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
Also aliased as: atom_seq
addLigand(ligand) click to toggle source

Add a heterogen (ligand) to this chain

# 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) click to toggle source

Add a residue to this chain

# 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
atom_seq()

for backward compatibility

Alias for: aaseq
each() { |residue| ... } click to toggle source

Iterates over each residue

# File lib/bio/db/pdb/chain.rb, line 153
def each(&x) #:yields: residue
  @residues.each(&x)
end
Also aliased as: each_residue
each_heterogen() { |heterogen| ... } click to toggle source

Iterates over each hetero-compound

# File lib/bio/db/pdb/chain.rb, line 160
def each_heterogen(&x) #:yields: heterogen
  @heterogens.each(&x)
end
each_residue()
Alias for: each
get_heterogen_by_id(key) click to toggle source

get the heterogen (ligand) by id

# 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) click to toggle source

get the residue by id

# 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() click to toggle source

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

# 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() click to toggle source

rehash residues hash and heterogens hash

# File lib/bio/db/pdb/chain.rb, line 147
def rehash
  rehash_residues
  rehash_heterogens
end
rehash_heterogens() click to toggle source

rehash heterogens hash

# 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() click to toggle source

rehash residues hash

# 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() click to toggle source

Stringifies each residue

# File lib/bio/db/pdb/chain.rb, line 170
def to_s
  @residues.join('') + "TER\n" + @heterogens.join('')
end