コード例 #1
0
    def test_deterministic_reaction_template_matching(self):
        """
        Test RMG work flow can match reaction template for kinetics estimation 
        deterministically. 

        In this test, a change of molecules order in a reacting species should 
        not change the reaction template matched.

        However, this is inherently impossible with the existing reaction
        generation algorithm. Currently, the first reaction will be the one
        that is kept if the reactions are identical. If different templates
        are a result of different transition states, all are kept.
        
        {O=C-[C]=C, [O]-C=C=C} -> H + C=C=C=O
        """

        # react
        spc = Species().from_smiles("O=C[C]=C")
        spc.generate_resonance_structures()
        new_reactions = react_species((spc, ))

        # try to pick out the target reaction
        mol_H = Molecule().from_smiles("[H]")
        mol_C3H2O = Molecule().from_smiles("C=C=C=O")

        target_rxns = find_target_rxns_containing(mol_H, mol_C3H2O,
                                                  new_reactions)
        self.assertEqual(len(target_rxns), 2)

        # reverse the order of molecules in spc
        spc.molecule = list(reversed(spc.molecule))

        # react again
        new_reactions_reverse = []
        new_reactions_reverse.extend(react_species((spc, )))

        # try to pick out the target reaction
        target_rxns_reverse = find_target_rxns_containing(
            mol_H, mol_C3H2O, new_reactions_reverse)
        self.assertEqual(len(target_rxns_reverse), 2)

        # whatever order of molecules in spc, the reaction template matched should be same
        self.assertEqual(target_rxns[0].template,
                         target_rxns_reverse[0].template)
コード例 #2
0
ファイル: rmgTest.py プロジェクト: Casinix/RMG-Py
    def testRestartFileGenerationAndParsing(self):

        # react
        spc1 = Species().fromSMILES("[H]")
        spc2 = Species().fromSMILES("C=C=C=O")

        self.rmg.reactionModel.core.species.append(spc1)
        self.rmg.reactionModel.core.species.append(spc2)

        newReactions = []
        newReactions.extend(react_species((spc1, spc2)))

        # process newly generated reactions to make sure no duplicated reactions
        self.rmg.reactionModel.processNewReactions(newReactions, spc2, None)

        # save restart file
        restart_folder = os.path.join(os.path.dirname(rmgpy.__file__),
                                      'rmg/test_data/restartFile')
        if not os.path.exists(restart_folder):
            os.mkdir(restart_folder)

        restart_path = os.path.join(restart_folder, 'restart.pkl')
        saveRestartFile(restart_path, self.rmg)

        # load the generated restart file
        rmg_load = RMG()
        rmg_load.loadRestartFile(restart_path)

        core_species_num_orig = len(self.rmg.reactionModel.core.species)
        core_rxn_num_orig = len(self.rmg.reactionModel.core.reactions)
        core_species_num_load = len(rmg_load.reactionModel.core.species)
        core_rxn_num_load = len(rmg_load.reactionModel.core.reactions)

        edge_species_num_orig = len(self.rmg.reactionModel.edge.species)
        edge_rxn_num_orig = len(self.rmg.reactionModel.edge.reactions)
        edge_species_num_load = len(rmg_load.reactionModel.edge.species)
        edge_rxn_num_load = len(rmg_load.reactionModel.edge.reactions)

        self.assertEqual(core_species_num_orig, core_species_num_load)
        self.assertEqual(core_rxn_num_orig, core_rxn_num_load)

        self.assertEqual(edge_species_num_orig, edge_species_num_load)
        self.assertEqual(edge_rxn_num_orig, edge_rxn_num_load)

        import shutil
        shutil.rmtree(restart_folder)
コード例 #3
0
ファイル: pdep.py プロジェクト: zhedian/RMG-Py
    def explore_isomer(self, isomer):
        """
        Explore a previously-unexplored unimolecular `isomer` in this partial
        network using the provided core-edge reaction model `reaction_model`,
        returning the new reactions and new species.
        """

        if isomer in self.explored:
            logging.warning(
                'Already explored isomer {0} in pressure-dependent network #{1:d}'
                .format(isomer, self.index))
            return []

        assert isomer not in self.source, "Attempted to explore isomer {0}, but that is the source configuration for this network.".format(
            isomer)

        for product in self.products:
            if product.species == [isomer]:
                break
        else:
            raise Exception(
                'Attempted to explore isomer {0}, but that species not found in product channels.'
                .format(isomer))

        logging.info(
            'Exploring isomer {0} in pressure-dependent network #{1:d}'.format(
                isomer, self.index))

        for mol in isomer.molecule:
            mol.update()

        self.explored.append(isomer)
        self.isomers.append(product)
        self.products.remove(product)
        # Find reactions involving the found species as unimolecular
        # reactant or product (e.g. A <---> products)

        # Don't find reactions involving the new species as bimolecular
        # reactants or products with itself (e.g. A + A <---> products)
        # Don't find reactions involving the new species as bimolecular
        # reactants or products with other core species (e.g. A + B <---> products)

        new_reactions = react_species((isomer, ))

        return new_reactions