예제 #1
0
파일: react.py 프로젝트: Alborzi/RMG-Py
def react(spcA, speciesList=[]):
    """
    Generate reactions between spcA and the list of 
    species for all the reaction families available.
    """
    if not spcA.reactive: return []
    
    molsA = [(mol, spcA.index) for mol in spcA.molecule]

    molsB = molsB = [spcB.molecule for spcB in speciesList if spcB.reactive]
    molsB = list(itertools.chain.from_iterable(molsB))
    molsB = [(mol, spcB.index) for mol in molsB]

    if not molsB:
        combos = [(t,) for t in molsA]
    else:
        combos = list(itertools.product(molsA, molsB))

    results = map_(
                WorkerWrapper(reactMolecules),
                combos
            )

    reactionList = itertools.chain.from_iterable(results)
    return reactionList
예제 #2
0
def simple_react(n_cp, n_iter):
    # load RMG database to create reactions
    database = RMGDatabase()

    database.load(
        path=settings['database.directory'],
        thermoLibraries=['primaryThermoLibrary'
                         ],  # can add others if necessary
        kineticsFamilies='all',
        reactionLibraries=[],
        kineticsDepositories='')

    kinetics_db = database.kinetics
    mol0 = Molecule().fromSMILES('CCCCCCCCC1CCCc2ccccc21')

    mol1 = Molecule().fromSMILES('CCCCCCCCC1CCCC2C=CC=CC=21')

    mol_tuple = (mol0, mol1)

    reactions = []
    for i in range(n_iter):
        mol_tuples = [mol_tuple] * n_cp
        results = map_(react_molecules_wrapper, mol_tuples)

        reactions_iter = itertools.chain.from_iterable(results)
        print "{0} iter: {1} reactions.".format(i, len(list(reactions_iter)))
예제 #3
0
파일: reduction.py 프로젝트: nyee/RMG-Py
def findImportantReactions(rmg, tolerance):
    """
    This function:

    - loops over all the species involved in a specific reaction
    - decides whether the specific reaction is important for the species.

    Whenever it is found that a reaction is important for a species, we break
    the species loop, and keep the reaction in the model.


    Returns:
        a list of rxns that can be removed.
    """
    
    # run the simulation, creating concentration profiles for each reaction system defined in input.
    simdata = simulateAll(rmg)


    reduceReactions = retrieveReactions()

    def chunks(l, n):
        """Yield successive n-sized chunks from l."""
        for i in xrange(0, len(l), n):
            yield l[i:i+n]

    CHUNKSIZE = 40
    boolean_array = []
    for chunk in chunks(reduceReactions,CHUNKSIZE):
        N = len(chunk)
        partial_results = list(
            map_(
                WorkerWrapper(assessReaction), chunk, [rmg.reactionSystems] * N, [tolerance] * N, [simdata] * N
                )
            )
        boolean_array.extend(partial_results)

    """
    Assuming that the order of the reduced reactions array and the core reactions of the reaction model
    are identical, iterate over the boolean array and retain those reactions of the reaction model
    that are deemed 'important'.
    """
    importantRxns = []
    for isImport, rxn in zip(boolean_array, rmg.reactionModel.core.reactions):
        logging.debug('Is rxn {rxn} important? {isImport}'.format(**locals()))
        if isImport:
            importantRxns.append(rxn)


    return importantRxns
예제 #4
0
def findImportantReactions(rmg, tolerance):
    """
    This function:

    - loops over all the species involved in a specific reaction
    - decides whether the specific reaction is important for the species.

    Whenever it is found that a reaction is important for a species, we break
    the species loop, and keep the reaction in the model.


    Returns:
        a list of rxns that can be removed.
    """
    
    # run the simulation, creating concentration profiles for each reaction system defined in input.
    simdata = simulateAll(rmg)


    reduceReactions = retrieveReactions()

    def chunks(l, n):
        """Yield successive n-sized chunks from l."""
        for i in xrange(0, len(l), n):
            yield l[i:i+n]

    CHUNKSIZE = 40
    boolean_array = []
    for chunk in chunks(reduceReactions,CHUNKSIZE):
        N = len(chunk)
        partial_results = list(
            map_(
                assessReaction, chunk, [rmg.reactionSystems] * N, [tolerance] * N, [simdata] * N
                )
            )
        boolean_array.extend(partial_results)

    """
    Assuming that the order of the reduced reactions array and the core reactions of the reaction model
    are identical, iterate over the boolean array and retain those reactions of the reaction model
    that are deemed 'important'.
    """
    importantRxns = []
    for isImport, rxn in zip(boolean_array, rmg.reactionModel.core.reactions):
        logging.debug('Is rxn {rxn} important? {isImport}'.format(**locals()))
        if isImport:
            importantRxns.append(rxn)


    return importantRxns
예제 #5
0
파일: react.py 프로젝트: nyee/RMG-Py
def react(spcA, speciesList=None):
    """
    Generate reactions between spcA and the list of 
    species for all the reaction families available.

    Returns an empty list if the spcA is non-reactive.

    For the spcA, a list of tuples is created for each
    resonance isomer of the species. Each tuple consists of (Molecule, index)
    with the index the species index of the Species object.

    For each Species in the the speciesList, its corresponding
    resonance isomers are stored in a tuple ([Molecule], index) with the index 
    the species index of the Species object.

    Each tuple ([Molecule], index) is expanded into a list of tuples (Molecule, index)
    resulting in one large list [(Molecule, index)].

    Possible combinations between the spcA, and a species from the 
    speciesList is obtained by taking the combinatorial product of the
    two generated [(Molecule, index)] lists.
    """
    speciesList = speciesList if speciesList else []
    if not spcA.reactive: return []
    
    molsA = [(mol, spcA.index) for mol in spcA.molecule]

    molsB = [(spcB.molecule, spcB.index) for spcB in speciesList if spcB.reactive]

    temp = []
    for mols, index in molsB:
        for molB in mols:
            temp.append((molB, index))
    molsB = temp

    if not molsB:
        combos = [(t,) for t in molsA]
    else:
        combos = list(itertools.product(molsA, molsB))

    results = map_(
                WorkerWrapper(reactMolecules),
                combos
            )

    reactionList = itertools.chain.from_iterable(results)
    return reactionList
예제 #6
0
def react(spcA, speciesList=[]):
    """
    Generate reactions between spcA and the list of 
    species for all the reaction families available.

    Returns an empty list if the spcA is non-reactive.

    For the spcA, a list of tuples is created for each
    resonance isomer of the species. Each tuple consists of (Molecule, index)
    with the index the species index of the Species object.

    For each Species in the the speciesList, its corresponding
    resonance isomers are stored in a tuple ([Molecule], index) with the index 
    the species index of the Species object.

    Each tuple ([Molecule], index) is expanded into a list of tuples (Molecule, index)
    resulting in one large list [(Molecule, index)].

    Possible combinations between the spcA, and a species from the 
    speciesList is obtained by taking the combinatorial product of the
    two generated [(Molecule, index)] lists.
    """
    if not spcA.reactive: return []

    molsA = [(mol, spcA.index) for mol in spcA.molecule]

    molsB = [(spcB.molecule, spcB.index) for spcB in speciesList
             if spcB.reactive]

    temp = []
    for mols, index in molsB:
        for molB in mols:
            temp.append((molB, index))
    molsB = temp

    if not molsB:
        combos = [(t, ) for t in molsA]
    else:
        combos = list(itertools.product(molsA, molsB))

    results = map_(WorkerWrapper(reactMolecules), combos)

    reactionList = itertools.chain.from_iterable(results)
    return reactionList
예제 #7
0
def react(spcA, speciesList=[]):
    """
    Generate reactions between spcA and the list of 
    species for all the reaction families available.
    """
    if not spcA.reactive: return []

    molsA = [(mol, spcA.index) for mol in spcA.molecule]

    molsB = molsB = [spcB.molecule for spcB in speciesList if spcB.reactive]
    molsB = list(itertools.chain.from_iterable(molsB))
    molsB = [(mol, spcB.index) for mol in molsB]

    if not molsB:
        combos = [(t, ) for t in molsA]
    else:
        combos = list(itertools.product(molsA, molsB))

    results = map_(WorkerWrapper(reactMolecules), combos)

    reactionList = itertools.chain.from_iterable(results)
    return reactionList
예제 #8
0
파일: react.py 프로젝트: yplitw/RMG-Py
def react(*spcTuples):
    """
    Generate reactions between the species in the 
    list of species tuples for all the reaction families available.

    For each tuple of one or more Species objects [(spc1,), (spc2, spc3), ...]
    the following is done:

    A list of tuples is created for each resonance isomer of the species.
    Each tuple consists of (Molecule, index) with the index the species index of the Species object.

    Possible combinations between the first spc in the tuple, and the second species in the tuple
    is obtained by taking the combinatorial product of the two generated [(Molecule, index)] lists.

    Returns a flat generator object containing the generated Reaction objects.
    """

    results = map_(reactSpecies, spcTuples)

    reactions = itertools.chain.from_iterable(results)

    return reactions
예제 #9
0
def react(*spcTuples):
    """
    Generate reactions between the species in the 
    list of species tuples for all the reaction families available.

    For each tuple of one or more Species objects [(spc1,), (spc2, spc3), ...]
    the following is done:

    A list of tuples is created for each resonance isomer of the species.
    Each tuple consists of (Molecule, index) with the index the species index of the Species object.

    Possible combinations between the first spc in the tuple, and the second species in the tuple
    is obtained by taking the combinatorial product of the two generated [(Molecule, index)] lists.

    Returns a flat generator object containing the generated Reaction objects.
    """
    
    combos = []

    for t in spcTuples:
        t = tuple([spc.copy(deep=True) for spc in t])
        if len(t) == 1:#unimolecular reaction
            spc, = t
            mols = [(mol, spc.index) for mol in spc.molecule]
            combos.extend([(combo,) for combo in mols])
        elif len(t) == 2:#bimolecular reaction
            spcA, spcB = t
            molsA = [(mol, spcA.index) for mol in spcA.molecule]
            molsB = [(mol, spcB.index) for mol in spcB.molecule]
            combos.extend(itertools.product(molsA, molsB))

    results = map_(
                reactMolecules,
                combos
            )

    reactionList = itertools.chain.from_iterable(results)
    return reactionList
예제 #10
0
파일: react.py 프로젝트: cainja/RMG-Py
def react(*spcTuples):
    """
    Generate reactions between the species in the 
    list of species tuples for all the reaction families available.

    For each tuple of one or more Species objects [(spc1,), (spc2, spc3), ...]
    the following is done:

    A list of tuples is created for each resonance isomer of the species.
    Each tuple consists of (Molecule, index) with the index the species index of the Species object.

    Possible combinations between the first spc in the tuple, and the second species in the tuple
    is obtained by taking the combinatorial product of the two generated [(Molecule, index)] lists.

    Returns a flat generator object containing the generated Reaction objects.
    """

    results = map_(
                reactSpecies,
                spcTuples)

    reactions = itertools.chain.from_iterable(results)

    return reactions