forked from ReactionMechanismGenerator/RMG-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportKineticsLibraryToChemkin.py
71 lines (56 loc) · 2.47 KB
/
exportKineticsLibraryToChemkin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# encoding: utf-8
"""
This script exports an individual RMG-Py kinetics library to a chemkin
and dictionary file. Thermo is taken from RMG's estimates and libraries.
In order to use more specific thermo, you must tweak the thermoLibraries and
estimators in use when loading the database. The script will save the
chem.inp and species_dictionary.txt files in the local directory.
usage:
exportKineticsLibrarytoChemkin.py [-h] LIBRARYNAME
positional arguments:
LIBRARYNAME the libraryname of the RMG-Py format kinetics library
"""
import argparse
from rmgpy.data.rmg import RMGDatabase
from rmgpy.chemkin import saveChemkinFile, saveSpeciesDictionary
from rmgpy.rmg.model import Species
################################################################################
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('library', metavar='LIBRARYNAME', type=str, nargs=1,
help='the name of the kinetic library to be exported')
args = parser.parse_args()
libraryName = args.library[0]
print 'Loading RMG-Py database...'
database = RMGDatabase()
database.load('input/', kineticsFamilies='all', kineticsDepositories='all')
print 'Loading {0} library'.format(libraryName)
kineticLibrary = database.kinetics.libraries[libraryName]
reactionList = []
for index, entry in kineticLibrary.entries.iteritems():
reaction = entry.item
reaction.kinetics = entry.data
reactionList.append(reaction)
speciesList = []
index = 0
for spec in kineticLibrary.getSpecies().values():
index = index + 1
species = Species(molecule = spec.molecule)
species.generateThermoData(database)
species.index = index
speciesList.append(species)
for reaction in reactionList:
for reactant in reaction.reactants:
for spec in speciesList:
if reactant.isIsomorphic(spec):
reactant.index = spec.index
spec.label = reactant.label
for product in reaction.products:
for spec in speciesList:
if product.isIsomorphic(spec):
product.index = spec.index
spec.label = product.label
print 'Saving the chem.inp and species_dictionary.txt to local directory'
saveChemkinFile('chem.inp', speciesList, reactionList)
saveSpeciesDictionary('species_dictionary.txt', speciesList)