Пример #1
0
# ## Initialize Species Used For Reaction
# First, we need to describe our species as pMuTT objects. For this example, we will be importing the thermdat from the [combustion database by Berkeley](http://combustion.berkeley.edu/gri_mech/version30/files30/thermo30.dat). We will store the species in a dictionary for code clarity later on.

# In[1]:


from pprint import pprint
from pMuTT.io_.thermdat import read_thermdat
from pMuTT import pMuTT_list_to_dict

# The output will be a list
species_list = read_thermdat(filename='thermdat')

# This function converts the list to a dict for easier usage downstream
species_dict = pMuTT_list_to_dict(pMuTT_list=species_list, key='name')

# (Optional) Print the species_dict to see what's in it
pprint(species_dict)


# To calculate transition state properties, we will need to represent the transition state species as a pMuTT object. For this example, we will create a new ``Nasa`` object based on the H2O entry but modify the a6 parameter arbitrarily to give it a higher enthalpy.

# In[2]:


from copy import deepcopy

# Make a copy so we don't edit the original H2O
H2O_TS = deepcopy(species_dict['H2O'])
Пример #2
0
import json

import numpy as np
from matplotlib import pyplot as plt

from pMuTT import pMuTT_list_to_dict
from pMuTT.reaction import Reaction
from pMuTT.io_.thermdat import read_thermdat
from pMuTT.io_.excel import read_excel
from pMuTT.io_.json import pMuTTEncoder

os.chdir(os.path.dirname(__file__))

'''Read species'''
nasa_species = read_thermdat('thermdat')
nasa_dict = pMuTT_list_to_dict(nasa_species)

'''Read reactions'''
rxns_data = read_excel('reactions.xlsx')
rxns = [Reaction.from_string(species=nasa_dict, **rxn_data) for rxn_data in rxns_data]

'''Save reactions as json'''
with open('reactions.json', 'w') as f_ptr:
    json.dump(rxns, f_ptr, cls=pMuTTEncoder, indent=True)

'''
Get thermodynamics from Reaction
'''
T = np.linspace(200., 3500.)
for rxn in rxns:
    HoRT_rxn = rxn.get_delta_HoRT(T=T)
Пример #3
0
def read_reactions(filename, species=None):
    """Directly read reactions from Chemkin gas.inp or surf.inp files

    Parameters
    ----------
        filename : str
            Input filename for Chemkin surf or gas .inp file
        species : list of :class:`~pMuTT.empirical.nasa.Nasa` objects
            List of NASA objects containing thermodynamic properties for
            all Reactants and Products in Reactions
            default = None. Will not return React_obj and Prod_obj
    Returns
    -------
        Reactions   : list of reactions
        Reactants   : list of reactants found in reactions
        React_obj   : list of NASA polynomials for each Reactant
                      If species object list is supplied
        React_stoic : list of reaction stoichiometries for Reactants
        Products    : list of products found in reactions
        Prod_obj    : list of NASA polynomials for each Product
                      If species object list is supplied
        Prod_stoic  : list of reaction stoichiometries for Products
    Raises
    ------
        FileNotFoundError
            If the surf.inp or gas.inp file isn't found.
        NameError
            If the species file does not exist
        AttributeError
            If the species list is incorrect format
    """
    if species is not None:
        species_dict = pMuTT_list_to_dict(species)

    rxns = []
    with open(filename, 'r') as lines:
        for line in lines:
            if re.findall(r'(^[^\!].+)( *<*(?<![0-9][eE])[=\-]>* *)', line):
                rxns.append(line.strip())
    RHS = []
    LHS = []
    for rxn in rxns:
        LHS.append(re.split(r' *<*(?<![0-9][eE])[=\-]>* *', rxn)[0])
        RHS.append(re.split(r' *<*(?<![0-9][eE])[=\-]>* *', rxn)[1])
    Reactants = []
    Products = []
    React_obj = []
    Prod_obj = []
    React_stoic = []
    Prod_stoic = []
    for Reacs, Prods in zip(LHS, RHS):
        Reactants.append(re.split(r' *\+ *| +', Reacs))
        Products.append(re.split(r' *\+ *| +', Prods)[0:-3])
        R = []
        RS = []
        Rx = []
        for RR in Reactants[-1]:
            stoic = re.findall(r'^[0-9]*', RR)[0]
            if stoic == '':
                stoic = 1
            else:
                RR = RR.replace(stoic, "")
                stoic = int(stoic)
            Rx.append(RR)
            RS.append(stoic)
            if species is not None:
                R.append(species_dict[RR])
        Reactants[-1] = Rx
        React_stoic.append(RS)
        P = []
        PS = []
        Px = []
        for PP in Products[-1]:
            stoic = re.findall(r'^[0-9]*', PP)[0]
            if stoic == '':
                stoic = 1
            else:
                PP = PP.replace(stoic, "")
                stoic = int(stoic)
            Px.append(PP)
            PS.append(stoic)
            if species is not None:
                P.append(species_dict[PP])
        Products[-1] = Px
        Prod_stoic.append(PS)
        React_obj.append(R)
        Prod_obj.append(P)
    Reactions = []
    for rxn, Prods in zip(rxns, Products):
        Reactions.append(rxn[0:rxn.rindex(Prods[-1]) + len(Prods[-1])])
    if species is not None:
        return (Reactions, Reactants, React_obj, React_stoic, Products,
                Prod_obj, Prod_stoic)
    else:
        return (Reactions, Reactants, React_stoic, Products, Prod_stoic)
import os
import numpy as np
from matplotlib import pyplot as plt
from pMuTT.io_.thermdat import read_thermdat
from pMuTT import pMuTT_list_to_dict
from pMuTT import reaction as rxn

'''
Read the thermdat
'''
base_path = os.path.dirname(__file__)
nasa_list = read_thermdat(os.path.join(base_path, 'thermdat'))
nasa_dict = pMuTT_list_to_dict(nasa_list, key='name')

'''
Create the reaction object
'''
reaction_str = 'H2+0.5O2=H2O'
rxn_nasa = rxn.Reaction.from_string(reaction_str=reaction_str,
                                    species=nasa_dict)

'''
Check that the equation is balanced
'''
rxn_nasa.check_element_balance()

'''
Get thermodynamics from Reaction
'''
T = np.linspace(200., 3500.)
HoRT_rxn = rxn_nasa.get_delta_HoRT(T=T)
Пример #5
0
# [0]: https://vlachosgroup.github.io/pMuTT/io.html#pMuTT.io_.thermdat.read_thermdat

# ## Reactions
# You can also evaluate reactions properties. The most straightforward way to do this is to initialize using strings.

# In[15]:


from pMuTT.io_.thermdat import read_thermdat
from pMuTT import pMuTT_list_to_dict
from pMuTT.reaction import Reaction

# Get a dictionary of species
thermdat_H2O_path = os.path.join(notebook_folder, 'thermdat_H2O')
species_list = read_thermdat(thermdat_H2O_path)
species_dict = pMuTT_list_to_dict(species_list)

# Initialize the reaction
rxn_H2O = Reaction.from_string('H2 + 0.5O2 = H2O', species=species_dict)

# Calculate reaction properties
H_rxn = rxn_H2O.get_delta_H(T=298., units='kJ/mol')
S_rxn = rxn_H2O.get_delta_S(T=298., units='J/mol/K')
print('H_rxn(T=298) = {:.1f} kJ/mol'.format(H_rxn))
print('S_rxn(T=298) = {:.2f} J/mol/K'.format(S_rxn))


# ## Exercise
# Write a script to calculate the Enthalpy of adsorption (in kcal/mol) of H2O on Cu(111) at T = 298 K. Some important details are given below.
# 
# ### Information Required