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
39 def initialize(id = nil, model = nil)
40   
41   @chain_id  = id
42   
43   @model    = model
44   
45   @residues   = []
46   @residues_hash = {}
47   @heterogens = []
48   @heterogens_hash = {}
49 end

Public Instance Methods

<=>(other) click to toggle source

Operator aimed to sort based on chain id

    # File lib/bio/db/pdb/chain.rb
165 def <=>(other)
166   return @chain_id <=> other.chain_id
167 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
76 def [](key)
77   get_residue_by_id(key)
78 end
aaseq() click to toggle source

gets an amino acid sequence of this chain from ATOM records

    # File lib/bio/db/pdb/chain.rb
181 def aaseq
182   unless defined? @aaseq
183     string = ""
184     last_residue_num = nil
185     @residues.each do |residue|
186       if last_residue_num and 
187           (x = (residue.resSeq.to_i - last_residue_num).abs) > 1 then
188         x.times { string << 'X' }
189       end
190       tlc = residue.resName.capitalize
191       olc = (begin
192                Bio::AminoAcid.three2one(tlc)
193              rescue ArgumentError
194                nil
195              end || 'X')
196       string << olc
197     end
198     @aaseq = Bio::Sequence::AA.new(string)
199   end
200   @aaseq
201 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
 99 def addLigand(ligand)
100   raise "Expecting a Bio::PDB::Residue" unless ligand.is_a? Bio::PDB::Residue
101   @heterogens.push(ligand)
102   if @heterogens_hash[ligand.residue_id] then
103     $stderr.puts "Warning: heterogen_id (residue_id) #{ligand.residue_id.inspect} is already used" if $VERBOSE
104   else
105     @heterogens_hash[ligand.residue_id] = ligand
106   end
107   self
108 end
addResidue(residue) click to toggle source

Add a residue to this chain

   # File lib/bio/db/pdb/chain.rb
87 def addResidue(residue)
88   raise "Expecting a Bio::PDB::Residue" unless residue.is_a? Bio::PDB::Residue
89   @residues.push(residue)
90   if @residues_hash[residue.residue_id] then
91     $stderr.puts "Warning: residue_id #{residue.residue_id.inspect} is already used" if $VERBOSE
92   else
93     @residues_hash[residue.residue_id] = residue
94   end
95   self
96 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
153 def each(&x) #:yields: residue
154   @residues.each(&x)
155 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
160 def each_heterogen(&x) #:yields: heterogen
161   @heterogens.each(&x)
162 end
each_residue()

Alias to override ResidueFinder#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
81 def get_heterogen_by_id(key)
82   #@heterogens.find { |r| r.residue_id == key }
83   @heterogens_hash[key]
84 end
get_residue_by_id(key) click to toggle source

get the residue by id

   # File lib/bio/db/pdb/chain.rb
66 def get_residue_by_id(key)
67   #@residues.find { |r| r.residue_id == key }
68   @residues_hash[key]
69 end
inspect() click to toggle source

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

    # File lib/bio/db/pdb/chain.rb
176 def inspect
177   "#<#{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}>"
178 end
rehash() click to toggle source

rehash residues hash and heterogens hash

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

rehash heterogens hash

    # File lib/bio/db/pdb/chain.rb
129 def rehash_heterogens
130   begin
131     heterogens_bak = @heterogens
132     heterogens_hash_bak = @heterogens_hash
133     @heterogens = []
134     @heterogens_hash = {}
135     heterogens_bak.each do |heterogen|
136       self.addLigand(heterogen)
137     end
138   rescue RuntimeError
139     @heterogens = heterogens_bak
140     @heterogens_hash = heterogens_hash_bak
141     raise
142   end
143   self
144 end
rehash_residues() click to toggle source

rehash residues hash

    # File lib/bio/db/pdb/chain.rb
111 def rehash_residues
112   begin
113     residues_bak = @residues
114     residues_hash_bak = @residues_hash
115     @residues = []
116     @residues_hash = {}
117     residues_bak.each do |residue|
118       self.addResidue(residue)
119     end
120   rescue RuntimeError
121     @residues = residues_bak
122     @residues_hash = residues_hash_bak
123     raise
124   end
125   self
126 end
to_s() click to toggle source

Stringifies each residue

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