Class: Bio::PDB::Model

Inherits:
Object show all
Includes:
AtomFinder, ChainFinder, HetatmFinder, HeterogenFinder, ResidueFinder, Utils, Comparable, Enumerable
Defined in:
lib/bio/db/pdb/model.rb

Overview

Bio::PDB::Model is a class to store a model.

The object would contain some chains (Bio::PDB::Chain objects).

Constant Summary

Constants included from Utils

Utils::ElementMass

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HeterogenFinder

#each_heterogen, #find_heterogen, #heterogens

Methods included from HetatmFinder

#each_hetatm, #find_hetatm, #hetatms

Methods included from ChainFinder

#find_chain

Methods included from ResidueFinder

#each_residue, #find_residue, #residues

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(serial = nil, structure = nil) ⇒ Model

Creates a new Model object



39
40
41
42
43
44
45
46
# File 'lib/bio/db/pdb/model.rb', line 39

def initialize(serial = nil, structure = nil)
  
  @serial = serial
  @structure = structure
  @chains = []
  @chains_hash = {}
  @solvents = Chain.new('', self)
end

Instance Attribute Details

#chainsObject (readonly)

chains in this model



49
50
51
# File 'lib/bio/db/pdb/model.rb', line 49

def chains
  @chains
end

#serialObject Also known as: model_serial

serial number of this model. (Integer or nil)



55
56
57
# File 'lib/bio/db/pdb/model.rb', line 55

def serial
  @serial
end

#solventsObject (readonly)

(OBSOLETE) solvents (water, HOH) in this model



52
53
54
# File 'lib/bio/db/pdb/model.rb', line 52

def solvents
  @solvents
end

#structureObject (readonly)

(reserved for future extension)



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

def structure
  @structure
end

Instance Method Details

#<=>(other) ⇒ Object

Operator aimed to sort models based on serial number



112
113
114
# File 'lib/bio/db/pdb/model.rb', line 112

def <=>(other)
  return @serial <=> other.model_serial
end

#[](key) ⇒ Object

Keyed access to chains



117
118
119
120
# File 'lib/bio/db/pdb/model.rb', line 117

def [](key)
  #chain = @chains.find{ |chain| key == chain.id }
  @chains_hash[key]
end

#addChain(chain) ⇒ Object

Adds a chain to this model



64
65
66
67
68
69
70
71
72
73
# File 'lib/bio/db/pdb/model.rb', line 64

def addChain(chain)
  raise "Expecting a Bio::PDB::Chain" unless chain.is_a? Bio::PDB::Chain
  @chains.push(chain)
  if @chains_hash[chain.chain_id] then
    $stderr.puts "Warning: chain_id #{chain.chain_id.inspect} is already used" if $VERBOSE
  else
    @chains_hash[chain.chain_id] = chain
  end
  self
end

#addSolvent(solvent) ⇒ Object

(OBSOLETE) Adds a solvent molecule to this model



94
95
96
97
# File 'lib/bio/db/pdb/model.rb', line 94

def addSolvent(solvent)
  raise "Expecting a Bio::PDB::Residue" unless solvent.is_a? Bio::PDB::Residue
  @solvents.addResidue(solvent)
end

#each(&x) ⇒ Object Also known as: each_chain

Iterates over each chain



105
106
107
# File 'lib/bio/db/pdb/model.rb', line 105

def each(&x) #:yields: chain
  @chains.each(&x)
end

#inspectObject

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



140
141
142
# File 'lib/bio/db/pdb/model.rb', line 140

def inspect
  "#<#{self.class.to_s} serial=#{serial.inspect} chains.size=#{chains.size}>"
end

#rehashObject

rehash chains hash



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bio/db/pdb/model.rb', line 76

def rehash
  begin
    chains_bak = @chains
    chains_hash_bak = @chains_hash
    @chains = []
    @chains_hash = {}
    chains_bak.each do |chain|
      self.addChain(chain)
    end
  rescue RuntimeError
    @chains = chains_bak
    @chains_hash = chains_hash_bak
    raise
  end
  self
end

#removeSolventObject

(OBSOLETE) not recommended to use this method



100
101
102
# File 'lib/bio/db/pdb/model.rb', line 100

def removeSolvent
  @solvents = nil
end

#to_sObject

stringifies to chains



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/bio/db/pdb/model.rb', line 123

def to_s
  string = ""
  if model_serial
    string = "MODEL     #{model_serial}\n" #Should use proper formatting
  end
  @chains.each{ |chain| string << chain.to_s }
  #if solvent
  #  string << @solvent.to_s
  #end
  if model_serial
    string << "ENDMDL\n"
  end
  return string
end