Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
    def find_all_reactions(self, reactants):
        reactants = Reaction.list_without_state(reactants)
        for reactant in reactants[:-1]:
            try:
                rs = self.reaction_map[reactant]
            except KeyError:
                continue

            for r in rs:
                if sublist_in_list(r.reactants, reactants):
                    yield r
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 def __init__(self, formula_with_state, space, batch, pos=None, render_only=False):
     self.space = space
     self.batch = batch
     self.creation_time = time.time()
     formula, state = Reaction.split_state(formula_with_state)
     self.formula = formula
     self.cml = CachedCml.getMolecule(formula)
     self.cml.normalize_pos()
     self.current_state = self.cml.get_state(state)
     if self.current_state is None and render_only:
         self.current_state = Cml.State("Gas")
     elif self.current_state is None:
         raise Exception("Did not find state for:" + formula_with_state
                 + " existing states are:" + str(self.cml.states.keys()))
     if pos is None:
         pos = (random.randint(10, 600), random.randint(200, 500))
     self.pos = pos
     self.create_atoms()
Exemplo n.º 5
0
 def __init__(self,
              formula_with_state,
              space,
              batch,
              pos=None,
              render_only=False):
     self.space = space
     self.batch = batch
     self.creation_time = time.time()
     formula, state = Reaction.split_state(formula_with_state)
     self.formula = formula
     self.cml = CachedCml.getMolecule(formula)
     self.cml.normalize_pos()
     self.current_state = self.cml.get_state(state)
     if self.current_state is None and render_only:
         self.current_state = Cml.State("Gas")
     elif self.current_state is None:
         raise Exception("Did not find state for:" + formula_with_state +
                         " existing states are:" +
                         str(self.cml.states.keys()))
     if pos is None:
         pos = (random.randint(10, 600), random.randint(200, 500))
     self.pos = pos
     self.create_atoms()