def react(self, molecule): ions = molecule.to_aqueous() if ions != None and len(ions) > 0: print(molecule.formula, "-(Water)>", ions) cml = Cml.Reaction([molecule.formula],ions) reaction = Reaction.Reaction(cml,[molecule.state_formula]) return reaction elif Config.current.DEBUG: print("Water beaker didnt react with:", molecule.formula)
def react(self, reactants, K = 298, trace = False): """ check if all elements needed for the reaction exists in in the reacting elements and that the reaction is spontaneous in the given temperature. Return the reaction if it will occur otherwise None """ reactionCmls = self.find_reactions(reactants) if len(reactionCmls) == 0 and trace: print("No reaction found for this reactants") elif len(reactionCmls) == 0: return None reactions = list() for reactionCml in reactionCmls: r = Reaction.Reaction(reactionCml, reactants) reactions.append((r.energyChange(K), r)) free_energy, reaction = min(reactions) if len(reactions) > 1 and trace: print("Multiple possible reactions:") for t in reactions: r = t[1] energy = t[0] print("Reactants:", r.reactants, "Products:", r.products, "Energy:", energy) if Reaction.isSpontaneous(free_energy): return reaction elif trace: print("free_energy wasnt enough for reaction!") reaction.trace = True reaction.isSpontaneous(K) return None else: return None