示例#1
0
    def test_make_new_reaction(self):
        """
        Test that CoreEdgeReactionModel.make_new_reaction method correctly works.
        """

        procnum = 2
        spcA = Species().from_smiles('[OH]')
        spcs = [Species().from_smiles('CC'), Species().from_smiles('[CH3]')]
        spc_tuples = [((spcA, spc), ['H_Abstraction']) for spc in spcs]

        rxns = list(itertools.chain.from_iterable(react(spc_tuples, procnum)))

        cerm = CoreEdgeReactionModel()

        for rxn in rxns:
            cerm.make_new_reaction(rxn)
        """
        3 expected H-abstraction reactions:
            OH + CC = H2O + C[CH2]
            OH + [CH3] = H2O + [CH2]
            OH + [CH3] = [O] + C
        """

        # count no. of entries in reactionDict:
        counter = 0
        for fam, v1 in cerm.reaction_dict.items():
            for key2, v2 in v1.items():
                for key3, rxnList in v2.items():
                    counter += len(rxnList)

        self.assertEquals(counter, 3)
示例#2
0
    def test_add_new_surface_objects(self):
        """
        basic test that surface movement object management works properly
        """

        # create object with ReactionSystem behavior
        class rsys:
            pass

        class item:
            pass

        T = item()
        P = item()
        T.value_si = 1000.0
        P.value_si = 101000.0
        rsys.T = T
        rsys.P = P
        procnum = 2

        cerm = CoreEdgeReactionModel()

        spcA = Species().from_smiles('[OH]')
        spcs = [Species().from_smiles('CC'), Species().from_smiles('[CH3]')]
        spc_tuples = [((spcA, spc), ['H_Abstraction']) for spc in spcs]

        rxns = list(itertools.chain.from_iterable(react(spc_tuples, procnum)))
        rxns += list(
            itertools.chain.from_iterable(
                react([((spcs[0], spcs[1]), ['H_Abstraction'])], procnum)))

        for rxn in rxns:
            cerm.make_new_reaction(rxn)

        cerm.core.species = [spcA] + spcs

        corerxns = []
        edgerxns = []
        edgespcs = set()
        for rxn in rxns:
            if set(rxn.reactants + rxn.products) <= set(cerm.core.species):
                corerxns.append(rxn)
            else:
                edgespcs |= set(
                    cerm.core.species) - set(rxn.reactants + rxn.products)
                edgerxns.append(rxn)

        cerm.edge.species += list(edgespcs)

        cerm.core.reactions = corerxns
        cerm.edge.reactions = edgerxns

        cerm.surface.species = []
        cerm.surface.reactions = []

        new_surface_reactions = [cerm.edge.reactions[0]]
        new_surface_species = []
        obj = new_surface_reactions

        cerm.add_new_surface_objects(obj, new_surface_species,
                                     new_surface_reactions, rsys)

        empty = set()

        self.assertEqual(cerm.new_surface_spcs_add, empty)
        self.assertEqual(cerm.new_surface_spcs_loss, empty)
        self.assertEqual(cerm.new_surface_rxns_loss, empty)
        self.assertEqual(cerm.new_surface_rxns_add,
                         set([cerm.edge.reactions[0]]))