Skip to content

Commit e64731f

Browse files
committed
Attach the CanteraWriter instead of using ck2yaml
1 parent 4099017 commit e64731f

1 file changed

Lines changed: 2 additions & 47 deletions

File tree

rmgpy/rmg/main.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
import numpy as np
4848
import psutil
4949
import yaml
50-
from cantera import ck2yaml
5150
from scipy.optimize import brute
5251

5352
import rmgpy.util as util
5453
from rmgpy import settings
54+
from rmgpy.cantera import CanteraWriter
5555
from rmgpy.chemkin import ChemkinWriter
5656
from rmgpy.constraints import fails_species_constraints
5757
from rmgpy.data.base import Entry
@@ -768,8 +768,8 @@ def register_listeners(self, requires_rms=False):
768768
"""
769769

770770
self.attach(ChemkinWriter(self.output_directory))
771-
772771
self.attach(RMSWriter(self.output_directory))
772+
self.attach(CanteraWriter(self.output_directory))
773773

774774
if self.generate_output_html:
775775
self.attach(OutputHTMLWriter(self.output_directory))
@@ -1218,25 +1218,6 @@ def execute(self, initialize=True, **kwargs):
12181218

12191219
self.run_model_analysis()
12201220

1221-
# generate Cantera files chem.yaml & chem_annotated.yaml in a designated `cantera` output folder
1222-
try:
1223-
if any([s.contains_surface_site() for s in self.reaction_model.core.species]):
1224-
self.generate_cantera_files(
1225-
os.path.join(self.output_directory, "chemkin", "chem-gas.inp"),
1226-
surface_file=(os.path.join(self.output_directory, "chemkin", "chem-surface.inp")),
1227-
)
1228-
self.generate_cantera_files(
1229-
os.path.join(self.output_directory, "chemkin", "chem_annotated-gas.inp"),
1230-
surface_file=(os.path.join(self.output_directory, "chemkin", "chem_annotated-surface.inp")),
1231-
)
1232-
else: # gas phase only
1233-
self.generate_cantera_files(os.path.join(self.output_directory, "chemkin", "chem.inp"))
1234-
self.generate_cantera_files(os.path.join(self.output_directory, "chemkin", "chem_annotated.inp"))
1235-
except EnvironmentError:
1236-
logging.exception("Could not generate Cantera files due to EnvironmentError. Check read\\write privileges in output directory.")
1237-
except Exception:
1238-
logging.exception("Could not generate Cantera files for some reason.")
1239-
12401221
self.check_model()
12411222
# Write output file
12421223
logging.info("")
@@ -1802,32 +1783,6 @@ def process_reactions_to_species(self, obj):
18021783
raise TypeError("improper call, obj input was incorrect")
18031784
return potential_spcs
18041785

1805-
def generate_cantera_files(self, chemkin_file, **kwargs):
1806-
"""
1807-
Convert a chemkin mechanism chem.inp file to a cantera mechanism file chem.yaml
1808-
and save it in the cantera directory
1809-
"""
1810-
transport_file = os.path.join(os.path.dirname(chemkin_file), "tran.dat")
1811-
file_name = os.path.splitext(os.path.basename(chemkin_file))[0] + ".yaml"
1812-
out_name = os.path.join(self.output_directory, "cantera", file_name)
1813-
if "surface_file" in kwargs:
1814-
out_name = out_name.replace("-gas.", ".")
1815-
cantera_dir = os.path.dirname(out_name)
1816-
try:
1817-
os.makedirs(cantera_dir)
1818-
except OSError:
1819-
if not os.path.isdir(cantera_dir):
1820-
raise
1821-
if os.path.exists(out_name):
1822-
os.remove(out_name)
1823-
parser = ck2yaml.Parser()
1824-
try:
1825-
parser.convert_mech(chemkin_file, transport_file=transport_file, out_name=out_name, quiet=True, permissive=True, **kwargs)
1826-
except ck2yaml.InputError:
1827-
logging.exception("Error converting to Cantera format.")
1828-
logging.info("Trying again without transport data file.")
1829-
parser.convert_mech(chemkin_file, out_name=out_name, quiet=True, permissive=True, **kwargs)
1830-
18311786
def initialize_reaction_threshold_and_react_flags(self):
18321787
num_core_species = len(self.reaction_model.core.species)
18331788

0 commit comments

Comments
 (0)