From 8790092ea2856ca1fb79213a64e20373aac340d7 Mon Sep 17 00:00:00 2001 From: Chris B <56306881+ChrisBNEU@users.noreply.github.com> Date: Thu, 27 Jul 2023 10:28:59 -0400 Subject: [PATCH 1/5] added input arg for disabling rms yaml write --- rmgpy/rmg/input.py | 6 ++++-- rmgpy/rmg/main.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index e04cd82e2ed..407ae0f0bb6 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1337,8 +1337,8 @@ def pressure_dependence( def options(name='Seed', generateSeedEachIteration=True, saveSeedToDatabase=False, units='si', saveRestartPeriod=None, generateOutputHTML=False, generatePlots=False, saveSimulationProfiles=False, verboseComments=False, - saveEdgeSpecies=False, keepIrreversible=False, trimolecularProductReversible=True, wallTime='00:00:00:00', - saveSeedModulus=-1): + saveEdgeSpecies=False, keepIrreversible=False, trimolecularProductReversible=True, generateRMSEachIter=True, + wallTime='00:00:00:00', saveSeedModulus=-1): if saveRestartPeriod: logging.warning("`saveRestartPeriod` flag was set in the input file, but this feature has been removed. Please " "remove this line from the input file. This will throw an error after RMG-Py 3.1. For " @@ -1352,6 +1352,7 @@ def options(name='Seed', generateSeedEachIteration=True, saveSeedToDatabase=Fals if generateOutputHTML: logging.warning('Generate Output HTML option was turned on. Note that this will slow down model generation.') rmg.generate_output_html = generateOutputHTML + rmg.generate_rms_each_iter = generateRMSEachIter rmg.generate_plots = generatePlots rmg.save_simulation_profiles = saveSimulationProfiles rmg.verbose_comments = verboseComments @@ -1800,6 +1801,7 @@ def save_input_file(path, rmg): f.write('options(\n') f.write(' units = "{0}",\n'.format(rmg.units)) f.write(' generateOutputHTML = {0},\n'.format(rmg.generate_output_html)) + f.write(' generateRMSEachIter = {0},\n'.format(rmg.generate_rms_each_iter)) f.write(' generatePlots = {0},\n'.format(rmg.generate_plots)) f.write(' saveSimulationProfiles = {0},\n'.format(rmg.save_simulation_profiles)) f.write(' saveEdgeSpecies = {0},\n'.format(rmg.save_edge_species)) diff --git a/rmgpy/rmg/main.py b/rmgpy/rmg/main.py index 8df771980dd..1c609c49fe6 100644 --- a/rmgpy/rmg/main.py +++ b/rmgpy/rmg/main.py @@ -723,8 +723,10 @@ def register_listeners(self): """ self.attach(ChemkinWriter(self.output_directory)) - self.attach(RMSWriter(self.output_directory)) + if self.generate_rms_each_iter: + self.attach(RMSWriter(self.output_directory)) + if self.generate_output_html: self.attach(OutputHTMLWriter(self.output_directory)) @@ -1187,6 +1189,24 @@ def execute(self, initialize=True, **kwargs): except Exception: logging.exception("Could not generate Cantera files for some reason.") + # if we're not writing rms files each iteration, only write one at the end. + if not self.generate_rms_each_iter: + from rmgpy.yml import write_yml + + # make rms dir + dirname = os.path.join(self.output_directory, "rms") + if os.path.exists(dirname): + # The directory already exists, so delete it (and all its content!) + shutil.rmtree(dirname) + os.mkdir(dirname) + + # save final rms file + solvent_data = None + if self.solvent: + solvent_data = self.database.solvation.get_solvent_data(self.solvent) + write_yml(self.reaction_model.core.species, self.reaction_model.core.reactions, solvent=self.solvent, solvent_data=solvent_data, + path=os.path.join(dirname, 'chem.rms')) + self.check_model() # Write output file logging.info("") From e4fc18989c447d022c8c06ff37c7c807e47d1032 Mon Sep 17 00:00:00 2001 From: Chris B <56306881+ChrisBNEU@users.noreply.github.com> Date: Wed, 26 Jul 2023 13:30:47 -0400 Subject: [PATCH 2/5] updated documentation --- documentation/source/users/rmg/input.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/documentation/source/users/rmg/input.rst b/documentation/source/users/rmg/input.rst index fbbff659405..e1665abb610 100644 --- a/documentation/source/users/rmg/input.rst +++ b/documentation/source/users/rmg/input.rst @@ -956,6 +956,7 @@ Miscellaneous options:: saveSeedToDatabase=True, units='si', generateOutputHTML=True, + generateRMSEachIter=True, generatePlots=False, saveSimulationProfiles=True, verboseComments=False, @@ -976,6 +977,8 @@ The ``units`` field is set to ``si``. Currently there are no other unit options Setting ``generateOutputHTML`` to ``True`` will let RMG know that you want to save 2-D images (png files in the local ``species`` folder) of all species in the generated core model. It will save a visualized HTML file for your model containing all the species and reactions. Turning this feature off by setting it to ``False`` may save memory if running large jobs. +Setting ``generateRMSEachIter`` to ``True`` will have rmg generate an output yaml file containing the core mechanism for the current iteration, with the number of core species appended to the name of the file (e.g. for 28 core species, the file will be named ``chem28.rms``). If it is ``False`` then only one file will be generated at the end of the run. A value of ``False`` may result in a faster run, as this feature can take up a lot of cpu time. + Setting ``generatePlots`` to ``True`` will generate a number of plots describing the statistics of the RMG job, including the reaction model core and edge size and memory use versus execution time. These will be placed in the output directory in the plot/ folder. Setting ``saveSimulationProfiles`` to ``True`` will make RMG save csv files of the simulation in .csv files in the ``solver/`` folder. The filename will be ``simulation_1_26.csv`` where the first number corresponds to the reaciton system, and the second number corresponds to the total number of species at the point of the simulation. Therefore, the highest second number will indicate the latest simulation that RMG has complete while enlarging the core model. The information inside the csv file will provide the time, reactor volume in m^3, as well as mole fractions of the individual species. From 8d815f8b26ede19ef353b14cb6e174c348ee5f5b Mon Sep 17 00:00:00 2001 From: Jackson Burns <33505528+JacksonBurns@users.noreply.github.com> Date: Wed, 26 Jul 2023 14:28:41 -0400 Subject: [PATCH 3/5] use `molecule.smiles` instead of `molecule.to_smiles()` in yaml writer This should speed up execution time by accessing the property each time instead of regenerating it, see : https://github.com/ReactionMechanismGenerator/RMG-Py/issues/2499#issuecomment-1629009917 --- rmgpy/yml.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmgpy/yml.py b/rmgpy/yml.py index cd8b9de5b58..f4835093856 100644 --- a/rmgpy/yml.py +++ b/rmgpy/yml.py @@ -99,7 +99,7 @@ def get_mech_dict(spcs, rxns, solvent='solvent', solvent_data=None): def get_radicals(spc): - if spc.molecule[0].to_smiles() == "[O][O]": # treat oxygen as stable to improve radical analysis + if spc.molecule[0].smiles == "[O][O]": # treat oxygen as stable to improve radical analysis return 0 else: return spc.molecule[0].multiplicity-1 @@ -112,7 +112,7 @@ def obj_to_dict(obj, spcs, names=None, label="solvent"): result_dict["type"] = "Species" if obj.contains_surface_site(): result_dict["adjlist"] = obj.molecule[0].to_adjacency_list() - result_dict["smiles"] = obj.molecule[0].to_smiles() + result_dict["smiles"] = obj.molecule[0].smiles result_dict["thermo"] = obj_to_dict(obj.thermo, spcs) result_dict["radicalelectrons"] = get_radicals(obj) if obj.liquid_volumetric_mass_transfer_coefficient_data: From 9b1c12dfa8e8953d1e19b708cc114e983be4438e Mon Sep 17 00:00:00 2001 From: Jackson Burns Date: Fri, 28 Jul 2023 07:59:50 -0400 Subject: [PATCH 4/5] disable rms writer in regression tests and input unit test --- test/regression/RMS_CSTR_liquid_oxidation/input.py | 1 + .../RMS_constantVIdealGasReactor_superminimal/input.py | 1 + test/regression/RMS_liquidSurface_ch4o2cat/input.py | 1 + test/regression/aromatics/input.py | 1 + test/regression/liquid_oxidation/input.py | 1 + test/regression/nitrogen/input.py | 1 + test/regression/oxidation/input.py | 1 + test/regression/sulfur/input.py | 1 + test/regression/superminimal/input.py | 1 + test/rmgpy/test_data/mainTest/input.py | 1 + 10 files changed, 10 insertions(+) diff --git a/test/regression/RMS_CSTR_liquid_oxidation/input.py b/test/regression/RMS_CSTR_liquid_oxidation/input.py index 0808cfeecb4..36970247280 100644 --- a/test/regression/RMS_CSTR_liquid_oxidation/input.py +++ b/test/regression/RMS_CSTR_liquid_oxidation/input.py @@ -62,5 +62,6 @@ ) options( + generateRMSEachIter=False, saveEdgeSpecies=True, ) diff --git a/test/regression/RMS_constantVIdealGasReactor_superminimal/input.py b/test/regression/RMS_constantVIdealGasReactor_superminimal/input.py index aa0b2fcad88..6b114e23ada 100644 --- a/test/regression/RMS_constantVIdealGasReactor_superminimal/input.py +++ b/test/regression/RMS_constantVIdealGasReactor_superminimal/input.py @@ -47,4 +47,5 @@ options( units='si', saveEdgeSpecies=True, + generateRMSEachIter=False, ) \ No newline at end of file diff --git a/test/regression/RMS_liquidSurface_ch4o2cat/input.py b/test/regression/RMS_liquidSurface_ch4o2cat/input.py index ad6039eee37..e60c092f320 100644 --- a/test/regression/RMS_liquidSurface_ch4o2cat/input.py +++ b/test/regression/RMS_liquidSurface_ch4o2cat/input.py @@ -85,4 +85,5 @@ options( units="si", saveEdgeSpecies=True, + generateRMSEachIter=False, ) diff --git a/test/regression/aromatics/input.py b/test/regression/aromatics/input.py index 8aacfc9678b..c0311c24b61 100644 --- a/test/regression/aromatics/input.py +++ b/test/regression/aromatics/input.py @@ -57,5 +57,6 @@ saveSimulationProfiles = False, saveEdgeSpecies = True, verboseComments = False, + generateRMSEachIter=False, ) diff --git a/test/regression/liquid_oxidation/input.py b/test/regression/liquid_oxidation/input.py index 8c120decac9..82e453c935c 100644 --- a/test/regression/liquid_oxidation/input.py +++ b/test/regression/liquid_oxidation/input.py @@ -63,4 +63,5 @@ options( saveEdgeSpecies=True, + generateRMSEachIter=False, ) diff --git a/test/regression/nitrogen/input.py b/test/regression/nitrogen/input.py index d307a869c8c..82f8e14a3a2 100644 --- a/test/regression/nitrogen/input.py +++ b/test/regression/nitrogen/input.py @@ -57,6 +57,7 @@ options( units='si', saveEdgeSpecies=True, + generateRMSEachIter=False, ) generatedSpeciesConstraints( diff --git a/test/regression/oxidation/input.py b/test/regression/oxidation/input.py index 19064c2009a..a860c763848 100644 --- a/test/regression/oxidation/input.py +++ b/test/regression/oxidation/input.py @@ -74,6 +74,7 @@ generatePlots=False, saveEdgeSpecies=True, saveSimulationProfiles=False, + generateRMSEachIter=False, ) generatedSpeciesConstraints( diff --git a/test/regression/sulfur/input.py b/test/regression/sulfur/input.py index c5f6da9e519..cde09369b4b 100644 --- a/test/regression/sulfur/input.py +++ b/test/regression/sulfur/input.py @@ -64,6 +64,7 @@ options( generateOutputHTML=False, + generateRMSEachIter=False, generatePlots=False, saveEdgeSpecies=True, saveSimulationProfiles=False, diff --git a/test/regression/superminimal/input.py b/test/regression/superminimal/input.py index f1d4f19e0bc..9d88591155e 100644 --- a/test/regression/superminimal/input.py +++ b/test/regression/superminimal/input.py @@ -56,6 +56,7 @@ units='si', saveRestartPeriod=None, generateOutputHTML=True, + generateRMSEachIter=False, generatePlots=True, saveEdgeSpecies=True, saveSimulationProfiles=True, diff --git a/test/rmgpy/test_data/mainTest/input.py b/test/rmgpy/test_data/mainTest/input.py index 42b34c0f739..f020368b6ab 100644 --- a/test/rmgpy/test_data/mainTest/input.py +++ b/test/rmgpy/test_data/mainTest/input.py @@ -73,6 +73,7 @@ name='testSeed', units='si', generateSeedEachIteration=True, + generateRMSEachIter=False, saveSeedToDatabase=True, generateOutputHTML=False, generatePlots=False, From d400cb2563075ef1bbbbb356c3b0241f179311ca Mon Sep 17 00:00:00 2001 From: Jackson Burns Date: Fri, 28 Jul 2023 09:56:16 -0400 Subject: [PATCH 5/5] move rmsyaml test to the rmg functional tests --- test/rmgpy/rmg/mainTest.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/rmgpy/rmg/mainTest.py b/test/rmgpy/rmg/mainTest.py index cea42c859cb..89ef4000a93 100644 --- a/test/rmgpy/rmg/mainTest.py +++ b/test/rmgpy/rmg/mainTest.py @@ -87,6 +87,12 @@ def test_rmg_execute(self): assert isinstance(self.rmg.database, RMGDatabase) assert self.rmg.done + def test_disable_rms_yaml_writer(self): + """ + generateRMSEachIter = False in input should set the corresponding property in RMG instance + """ + self.assertFalse(self.rmg.generate_rms_each_iter) + def test_rmg_increases_reactions(self): """Test that RMG.execute increases reactions and species.""" assert len(self.rmg.reaction_model.core.reactions) > 0