From bbe49f45018ab423aee843ea7779070060e5bddc 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] 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 ++-- test/rmgpy/rmg/inputTest.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 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: diff --git a/test/rmgpy/rmg/inputTest.py b/test/rmgpy/rmg/inputTest.py index ef69ab6ade0..c435f59a586 100644 --- a/test/rmgpy/rmg/inputTest.py +++ b/test/rmgpy/rmg/inputTest.py @@ -93,7 +93,20 @@ def test_importing_database_reaction_libraries_from_true_tuple(self): assert rmg.reaction_libraries[0][1] -class TestInputMLEstimator: +class TestRMSYAMLWriterDisable(unittest.TestCase): + """ + Default behavior of RMG is to enable so test ability to disable + """ + + def test_disable_rms_yaml_writer(self): + """ + generateRMSEachIter = False in input should set the corresponding property in RMG instance + """ + global rmg + self.assertFalse(rmg.generate_rms_each_iter) + + +class TestInputMLEstimator(unittest.TestCase): """ Contains unit tests rmgpy.rmg.input.mlEstimator """