Class: ChemScanner::Interpreter::Reaction
- Inherits:
-
Object
- Object
- ChemScanner::Interpreter::Reaction
- Defined in:
- lib/chem_scanner/interpreter/element/reaction.rb
Overview
Reaction
Instance Attribute Summary collapse
-
#arrow ⇒ Object
Returns the value of attribute arrow.
-
#arrow_id ⇒ Object
Returns the value of attribute arrow_id.
-
#clone_from ⇒ Object
Returns the value of attribute clone_from.
-
#description ⇒ Object
Returns the value of attribute description.
-
#details ⇒ Object
Returns the value of attribute details.
-
#product_ids ⇒ Object
Returns the value of attribute product_ids.
-
#products ⇒ Object
Returns the value of attribute products.
-
#reactant_ids ⇒ Object
Returns the value of attribute reactant_ids.
-
#reactants ⇒ Object
Returns the value of attribute reactants.
-
#reagent_abbs ⇒ Object
Returns the value of attribute reagent_abbs.
-
#reagent_ids ⇒ Object
Returns the value of attribute reagent_ids.
-
#reagent_smiles ⇒ Object
Returns the value of attribute reagent_smiles.
-
#reagents ⇒ Object
Returns the value of attribute reagents.
-
#steps ⇒ Object
Returns the value of attribute steps.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
-
#text_ids ⇒ Object
Returns the value of attribute text_ids.
-
#time ⇒ Object
Returns the value of attribute time.
-
#yield ⇒ Object
Returns the value of attribute yield.
Instance Method Summary collapse
- #all_ids ⇒ Object
- #clone ⇒ Object
- #debug_print ⇒ Object
- #debug_print_smiles ⇒ Object
- #delete_id(id) ⇒ Object
- #delete_molecule_by_id(id) ⇒ Object
-
#initialize ⇒ Reaction
constructor
A new instance of Reaction.
- #inspect ⇒ Object
- #molecule_ids ⇒ Object
- #product_molfiles ⇒ Object
- #reactant_molfiles ⇒ Object
- #reaction_smiles ⇒ Object
- #reagent_molfiles ⇒ Object
- #replace_id(old_id, new_id) ⇒ Object
- #replace_molecule(old_id, new_mol) ⇒ Object
- #status ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Reaction
Returns a new instance of Reaction.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 14 def initialize @arrow = nil @reactant_ids = [] @reagent_ids = [] @product_ids = [] @text_ids = [] @reactants = [] @reagents = [] @products = [] @reagent_smiles = [] @reagent_abbs = [] @description = "" @temperature = "" @yield = "" @time = "" @details = OpenStruct.new @steps = [] end |
Instance Attribute Details
#arrow ⇒ Object
Returns the value of attribute arrow.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def arrow @arrow end |
#arrow_id ⇒ Object
Returns the value of attribute arrow_id.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def arrow_id @arrow_id end |
#clone_from ⇒ Object
Returns the value of attribute clone_from.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def clone_from @clone_from end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def description @description end |
#details ⇒ Object
Returns the value of attribute details.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def details @details end |
#product_ids ⇒ Object
Returns the value of attribute product_ids.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def product_ids @product_ids end |
#products ⇒ Object
Returns the value of attribute products.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def products @products end |
#reactant_ids ⇒ Object
Returns the value of attribute reactant_ids.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def reactant_ids @reactant_ids end |
#reactants ⇒ Object
Returns the value of attribute reactants.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def reactants @reactants end |
#reagent_abbs ⇒ Object
Returns the value of attribute reagent_abbs.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def reagent_abbs @reagent_abbs end |
#reagent_ids ⇒ Object
Returns the value of attribute reagent_ids.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def reagent_ids @reagent_ids end |
#reagent_smiles ⇒ Object
Returns the value of attribute reagent_smiles.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def reagent_smiles @reagent_smiles end |
#reagents ⇒ Object
Returns the value of attribute reagents.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def reagents @reagents end |
#steps ⇒ Object
Returns the value of attribute steps.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def steps @steps end |
#temperature ⇒ Object
Returns the value of attribute temperature.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def temperature @temperature end |
#text_ids ⇒ Object
Returns the value of attribute text_ids.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def text_ids @text_ids end |
#time ⇒ Object
Returns the value of attribute time.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def time @time end |
#yield ⇒ Object
Returns the value of attribute yield.
7 8 9 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 7 def yield @yield end |
Instance Method Details
#all_ids ⇒ Object
73 74 75 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 73 def all_ids @reagent_ids + molecule_ids end |
#clone ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 122 def clone cloned = self.class.new unless @arrow.nil? cloned.arrow_id = @arrow.get_tempid cloned.arrow = @arrow.clone end %w[reactant reagent product].each do |group| cloned_groups = cloned.send("#{group}s") groups = instance_variable_get("@#{group}s") groups.each { |m| cloned_groups.push(m.clone) } cloned.send("#{group}_ids=", cloned_groups.map(&:id)) end cloned.reagent_smiles = @reagent_smiles.dup cloned.description = @description.dup cloned.temperature = @temperature.dup cloned.yield = @yield.dup cloned.time = @time.dup cloned.details = @details.dup cloned.clone_from = @clone_from.nil? ? arrow_id : @clone_from cloned end |
#debug_print ⇒ Object
59 60 61 62 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 59 def debug_print "reaction #{@arrow_id}: "\ "#{reactant_ids} > #{reagent_ids} > #{product_ids}" end |
#debug_print_smiles ⇒ Object
64 65 66 67 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 64 def debug_print_smiles "reaction #{@arrow_id}: "\ "#{reactant_ids} - #{reagent_ids} - #{product_ids}: #{reaction_smiles}" end |
#delete_id(id) ⇒ Object
77 78 79 80 81 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 77 def delete_id(id) [@reactant_ids, @reagent_ids, @product_ids].each do |group| group.delete(id) if group.include?(id) end end |
#delete_molecule_by_id(id) ⇒ Object
107 108 109 110 111 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 107 def delete_molecule_by_id(id) [@reactants, @reagents, @products].each do |group| group.delete_if { |mol| mol.id == id } end end |
#inspect ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 166 def inspect ( "#<Reaction: id=#{@arrow.id}, " + "reactant_ids=#{@reactant_ids}, " + "reagent_ids=#{@reagent_ids}, " + "product_ids=#{@product_ids}, " + "text_ids=#{@text_ids}, " + "reactants=#{@reactants}, " + "reagents=#{@reagents}, " + "products=#{@products}, " + "reagent_smiles=#{@reagent_smiles}, " + "description=#{@description}, " + "temperature=#{@temperature}, " + "yield=#{@yield}, " + "time=#{@time}, " + "details=#{@details} >" ) end |
#molecule_ids ⇒ Object
69 70 71 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 69 def molecule_ids @reactant_ids + @product_ids end |
#product_molfiles ⇒ Object
55 56 57 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 55 def product_molfiles @products.map { |r| r[:mdl] } end |
#reactant_molfiles ⇒ Object
47 48 49 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 47 def reactant_molfiles @reactants.map { |r| r[:mdl] } end |
#reaction_smiles ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 37 def reaction_smiles reactant_smiles = @reactants.map(&:cano_smiles).join(".") product_smiles = @products.map(&:cano_smiles).join(".") reagent_smiles = @reagents.map(&:cano_smiles).compact reagent_smiles = reagent_smiles.concat(@reagent_smiles).join(".") "#{reactant_smiles}>#{reagent_smiles}>#{product_smiles}" end |
#reagent_molfiles ⇒ Object
51 52 53 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 51 def reagent_molfiles @reagents.map { |r| r[:mdl] } end |
#replace_id(old_id, new_id) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 83 def replace_id(old_id, new_id) [@reactant_ids, @reagent_ids, @product_ids].each do |group| next unless group.include?(old_id) group.delete(old_id) group.push(new_id) end end |
#replace_molecule(old_id, new_mol) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 92 def replace_molecule(old_id, new_mol) oid = old_id [@reactants, @reagents, @products].each do |group| idx = group.index { |m| [m.id, m.clone_from].include?(old_id) } next if idx.nil? m = group[idx] oid = m.clone_from unless m.clone_from.nil? group[idx] = new_mol end replace_id(oid, new_mol.id) end |
#status ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 113 def status return "Failed" if @arrow.cross return "Planned" if @arrow.line_type == 1 return "Failed" unless @products.detect(&:check_red).nil? "Succesful" end |
#to_hash ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/chem_scanner/interpreter/element/reaction.rb', line 150 def to_hash { id: arrow_id, reactants: @reactants.sort_by(&:cano_smiles).map(&:to_hash), reagents: @reagents.sort_by(&:cano_smiles).map(&:to_hash), products: @products.sort_by(&:cano_smiles).map(&:to_hash), steps: @steps.map(&:to_hash), reagent_smiles: reagent_smiles.sort, description: @description, temperature: @temperature, yield: @yield, time: @time, details: @details.to_h, } end |