|
47 | 47 | import numpy as np |
48 | 48 | import psutil |
49 | 49 | import yaml |
50 | | -from cantera import ck2yaml |
51 | 50 | from scipy.optimize import brute |
52 | 51 |
|
53 | 52 | import rmgpy.util as util |
54 | 53 | from rmgpy import settings |
| 54 | +from rmgpy.cantera import CanteraWriter |
55 | 55 | from rmgpy.chemkin import ChemkinWriter |
56 | 56 | from rmgpy.constraints import fails_species_constraints |
57 | 57 | from rmgpy.data.base import Entry |
@@ -768,8 +768,8 @@ def register_listeners(self, requires_rms=False): |
768 | 768 | """ |
769 | 769 |
|
770 | 770 | self.attach(ChemkinWriter(self.output_directory)) |
771 | | - |
772 | 771 | self.attach(RMSWriter(self.output_directory)) |
| 772 | + self.attach(CanteraWriter(self.output_directory)) |
773 | 773 |
|
774 | 774 | if self.generate_output_html: |
775 | 775 | self.attach(OutputHTMLWriter(self.output_directory)) |
@@ -1218,25 +1218,6 @@ def execute(self, initialize=True, **kwargs): |
1218 | 1218 |
|
1219 | 1219 | self.run_model_analysis() |
1220 | 1220 |
|
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 | | - |
1240 | 1221 | self.check_model() |
1241 | 1222 | # Write output file |
1242 | 1223 | logging.info("") |
@@ -1802,32 +1783,6 @@ def process_reactions_to_species(self, obj): |
1802 | 1783 | raise TypeError("improper call, obj input was incorrect") |
1803 | 1784 | return potential_spcs |
1804 | 1785 |
|
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 | | - |
1831 | 1786 | def initialize_reaction_threshold_and_react_flags(self): |
1832 | 1787 | num_core_species = len(self.reaction_model.core.species) |
1833 | 1788 |
|
|
0 commit comments