forked from ReactionMechanismGenerator/RMG-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportChemkinLibrary.py
76 lines (65 loc) · 2.94 KB
/
importChemkinLibrary.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
71
72
73
74
75
76
#!/usr/bin/env python
# encoding: utf-8
"""
This script imports a chemkin file (along with RMG dictionary) from a local directory and saves a set of
RMG-Py kinetics library and thermo library files. These py files are automatically added to the
input/kinetics/libraries and input/thermo/libraries folder under the user-specified `name` for the chemkin library.
"""
import argparse
import time
import logging
import os
from rmgpy.data.thermo import ThermoLibrary
from rmgpy.data.kinetics import KineticsLibrary
from rmgpy.data.base import Entry
from rmgpy.molecule import Molecule
from rmgpy.chemkin import loadChemkinFile
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('chemkinPath', metavar='CHEMKIN', type=str, nargs=1,
help='The path of the chemkin file')
parser.add_argument('dictionaryPath', metavar='DICTIONARY', type=str, nargs=1,
help='The path of the RMG dictionary file')
parser.add_argument('name', metavar='NAME', type=str, nargs=1,
help='Name of the chemkin library to be saved')
args = parser.parse_args()
chemkinPath = args.chemkinPath[0]
dictionaryPath = args.dictionaryPath[0]
name = args.name[0]
speciesList, reactionList = loadChemkinFile(chemkinPath, dictionaryPath)
# load thermo library entries
thermoLibrary = ThermoLibrary()
for i in range(len(speciesList)):
species = speciesList[i]
if species.thermo:
thermoLibrary.loadEntry(index = i + 1,
label = species.label,
molecule = species.molecule[0].toAdjacencyList(),
thermo = species.thermo,
shortDesc = species.thermo.comment
)
else:
logging.warning('Species {0} did not contain any thermo data and was omitted from the thermo library.'.format(str(species)))
# load kinetics library entries
kineticsLibrary = KineticsLibrary()
kineticsLibrary.entries = {}
for i in range(len(reactionList)):
reaction = reactionList[i]
entry = Entry(
index = i+1,
label = str(reaction),
item = reaction,
data = reaction.kinetics,
)
entry.longDesc = reaction.kinetics.comment
kineticsLibrary.entries[i+1] = entry
kineticsLibrary.checkForDuplicates()
kineticsLibrary.convertDuplicatesToMulti()
# Save in Py format
try:
os.makedirs(os.join('input/kinetics/libraries/',name))
except:
pass
thermoLibrary.save(os.path.join('input/thermo/libraries', name + '.py'))
kineticsLibrary.save(os.path.join('input/kinetics/libraries/', name, 'reactions.py'))
kineticsLibrary.saveDictionary(os.path.join('input/kinetics/libraries/', name, 'dictionary.txt'))