Method: Chem::KEGG::KCFRXN#setup_bonds

Defined in:
lib/chem/db/kcf.rb

#setup_bondsObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/chem/db/kcf.rb', line 161

def setup_bonds
  @edges = []
  @reactant.atoms.each do |atom|
    if atom && ! @matched_reactants.member?(atom)
      @nodes.push(RXNNode.new(atom, nil))
    end
  end
  @product.atoms.each do |atom|
    if atom && ! @matched_products.member?(atom)
      @nodes.push(RXNNode.new(nil, atom))
    end
  end

  @reactant.bonds.each do |bond|
    bond.e.next_atom[bond.b] = bond
    bond.b.next_atom[bond.e] = bond
  end
  @product.bonds.each do |bond|
    bond.e.next_atom[bond.b] = bond
    bond.b.next_atom[bond.e] = bond
  end
  @nodes.each_with_index do |node, index|
    index.upto(@nodes.length - 1) do |n|
      r_edge = p_edge = nil
      if @nodes[n].reactant_node && @nodes[n].reactant_node.next_atom.has_key?(node.reactant_node)
        r_edge = @nodes[n].reactant_node.next_atom[node.reactant_node]
      end
      if @nodes[n].product_node && @nodes[n].product_node.next_atom.has_key?(node.product_node)
        p_edge = @nodes[n].product_node.next_atom[node.product_node]
      end
      if r_edge || p_edge
        edge = RXNEdge.new
        edge.reactant_edge = r_edge
        edge.product_edge = p_edge
        @edges.push(edge)
      end
    end
  end
  @edges.each do |edge|
    from = edge.reactant_edge ? edge.reactant_edge.multiplicity : 0
    to = edge.product_edge ? edge.product_edge.multiplicity : 0
    puts "%3d %3d" % [from, to]
  end
end