From 25a23369eacd39c06786390506c032ac071799d5 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Mon, 21 Aug 2023 15:05:47 -0400 Subject: [PATCH 1/7] correct surface_site_density input attribute typo --- rmgpy/rmg/input.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 8c34e815d45..986f45fbadc 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + ############################################################################### # # @@ -1699,9 +1699,9 @@ def save_input_file(path, rmg): f.write(' kineticsEstimator = {0!r},\n'.format(rmg.kinetics_estimator)) f.write(')\n\n') - if rmg.surfaceSiteDenisty or rmg.binding_energies: + if rmg.surface_site_density or rmg.binding_energies: f.write('catalystProperties(\n') - if rmg.surfaceSiteDenisty: + if rmg.surface_site_density: f.write(' surface_site_density = {0!r},'.format(rmg.surface_site_density)) if rmg.binding_energies: f.write(' binding_energies = {0!r},'.format(rmg.binding_energies)) From b04c0c203e263e0a5660be8e9228f751dec620b7 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Wed, 19 Feb 2025 16:21:18 -0500 Subject: [PATCH 2/7] improve formatting for catalyst properties output --- rmgpy/rmg/input.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 986f45fbadc..90536bca5c0 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1702,9 +1702,13 @@ def save_input_file(path, rmg): if rmg.surface_site_density or rmg.binding_energies: f.write('catalystProperties(\n') if rmg.surface_site_density: - f.write(' surface_site_density = {0!r},'.format(rmg.surface_site_density)) + f.write(' surfaceSiteDensity = ({0:g}, "{1!s}"),'.format(rmg.surface_site_density.value, rmg.surface_site_density.units) + '\n') if rmg.binding_energies: - f.write(' binding_energies = {0!r},'.format(rmg.binding_energies)) + f.write(' bindingEnergies = {\n') + for spc, be in rmg.binding_energies.items(): + f.write(' "{0!s}": ({1:g}, "{2!s}"),\n'.format(spc, be.value, be.units)) + f.write(' },\n') + f.write(')\n\n') # Species @@ -1718,17 +1722,36 @@ def save_input_file(path, rmg): f.write('"""),\n') f.write(')\n\n') + def format_temperature(system): + """Get temperature string format for reaction system, whether single value or range""" + if system.T is not None: + return '({0:g},"{1!s}")'.format(system.T.value, system.T.units) + + return f'[({system.Trange[0].value:g}, "{system.Trange[0].units}"), ({system.Trange[1].value:g}, "{system.Trange[1].units}")],' + # Reaction systems for system in rmg.reaction_systems: + # TODO add ranging pressures if rmg.solvent: f.write('liquidReactor(\n') - f.write(' temperature = ({0:g},"{1!s}"),\n'.format(system.T.value, system.T.units)) + f.write(' temperature = ' + format_temperature(system) + '\n') f.write(' initialConcentrations={\n') for spcs, conc in system.initial_concentrations.items(): f.write(' "{0!s}": ({1:g},"{2!s}"),\n'.format(spcs.label, conc.value, conc.units)) + elif isinstance(system, SurfaceReactor): + f.write('surfaceReactor(\n') + f.write(' temperature = ' + format_temperature(system) + '\n') + f.write(' initialPressure = ({0:g},"{1!s}"),\n'.format(system.P_initial.value, system.P_initial.units)) + f.write(' initialGasMoleFractions={\n') + for spcs, molfrac in system.initial_gas_mole_fractions.items(): + f.write(' "{0!s}": {1:g},\n'.format(spcs.label, molfrac)) + f.write(' },\n') + f.write(' initialSurfaceCoverages={\n') + for spcs, cov in system.initial_surface_coverages.items(): + f.write(' "{0!s}": {1:g},\n'.format(spcs.label, cov)) else: f.write('simpleReactor(\n') - f.write(' temperature = ({0:g},"{1!s}"),\n'.format(system.T.value, system.T.units)) + f.write(' temperature = ' + format_temperature(system) + '\n') # Convert the pressure from SI pascal units to bar here # Do something more fancy later for converting to user's desired units for both T and P.. f.write(' pressure = ({0:g},"{1!s}"),\n'.format(system.P.value, system.P.units)) From 3b6f665ec90bdf8f50917ff04e95d129cfa13fb1 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 11:20:27 -0500 Subject: [PATCH 3/7] add termination rate ratio --- rmgpy/rmg/input.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 90536bca5c0..ca86c8ab356 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1643,6 +1643,8 @@ def read_thermo_input_file(path, rmg0): rmg.reaction_model = CoreEdgeReactionModel() rmg.initial_species = [] rmg.reaction_systems = [] + if rmg.output_directory is None: + rmg.output_directory = os.path.dirname(full_path) species_dict = {} global_context = {'__builtins__': None} @@ -1765,9 +1767,12 @@ def format_temperature(system): for term in system.termination: if isinstance(term, TerminationTime): f.write(' terminationTime = ({0:g},"{1!s}"),\n'.format(term.time.value, term.time.units)) - - else: + elif isinstance(term, TerminationRateRatio): + f.write(' terminationRateRatio = {0:g},\n'.format(term.ratio)) + elif isinstance(term, TerminationConversion): conversions += ' "{0:s}": {1:g},\n'.format(term.species.label, term.conversion) + else: + raise NotImplementedError('Termination criteria of type {0} not supported'.format(type(term))) if conversions: f.write(' terminationConversion = {\n') f.write(conversions) From 408cc341b94d1c2dbdc42436d8c1390337b5a234 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 11:25:27 -0500 Subject: [PATCH 4/7] fix pdep settings --- rmgpy/rmg/input.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index ca86c8ab356..45733356157 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1815,9 +1815,9 @@ def format_temperature(system): if rmg.pressure_dependence: f.write('pressureDependence(\n') f.write(' method = {0!r},\n'.format(rmg.pressure_dependence.method)) - f.write(' maximumGrainSize = ({0:g},"{1!s}"),\n'.format(rmg.pressure_dependence.grain_size.value, - rmg.pressure_dependence.grain_size.units)) - f.write(' minimumNumberOfGrains = {0},\n'.format(rmg.pressure_dependence.grain_count)) + f.write(' maximumGrainSize = ({0:g},"{1!s}"),\n'.format(rmg.pressure_dependence.maximum_grain_size.value, + rmg.pressure_dependence.maximum_grain_size.units)) + f.write(' minimumNumberOfGrains = {0},\n'.format(rmg.pressure_dependence.minimum_grain_count)) f.write(' temperatures = ({0:g},{1:g},"{2!s}",{3:d}),\n'.format( rmg.pressure_dependence.Tmin.value, rmg.pressure_dependence.Tmax.value, From 04b6be6ed22011b49bf6a80bf525802411f977c3 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 11:40:52 -0500 Subject: [PATCH 5/7] add ranging mole fractions for simple reactor --- rmgpy/rmg/input.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 45733356157..0203975e562 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1731,9 +1731,26 @@ def format_temperature(system): return f'[({system.Trange[0].value:g}, "{system.Trange[0].units}"), ({system.Trange[1].value:g}, "{system.Trange[1].units}")],' + def format_pressure(system): + """Get pressure string format for reaction system, whether single value or range""" + if system.P is not None: + return '({0:g},"{1!s}")'.format(system.P.value, system.P.units) + + return f'[({system.Prange[0].value:g}, "{system.Prange[0].units}"), ({system.Prange[1].value:g}, "{system.Prange[1].units}")],' + + def format_initial_mole_fractions(system): + """Get initial mole fractions string format for reaction system""" + mole_fractions = '' + for spcs, molfrac in system.initial_mole_fractions.items(): + if isinstance(molfrac, list): + mole_fractions += ' "{0!s}": [{1:g}, {2:g}],\n'.format(spcs.label, molfrac[0], molfrac[1]) + else: + mole_fractions += ' "{0!s}": {1:g},\n'.format(spcs.label, molfrac) + return mole_fractions + + # Reaction systems for system in rmg.reaction_systems: - # TODO add ranging pressures if rmg.solvent: f.write('liquidReactor(\n') f.write(' temperature = ' + format_temperature(system) + '\n') @@ -1754,12 +1771,9 @@ def format_temperature(system): else: f.write('simpleReactor(\n') f.write(' temperature = ' + format_temperature(system) + '\n') - # Convert the pressure from SI pascal units to bar here - # Do something more fancy later for converting to user's desired units for both T and P.. - f.write(' pressure = ({0:g},"{1!s}"),\n'.format(system.P.value, system.P.units)) + f.write(' pressure = ' + format_pressure(system) + '\n') f.write(' initialMoleFractions={\n') - for spcs, molfrac in system.initial_mole_fractions.items(): - f.write(' "{0!s}": {1:g},\n'.format(spcs.label, molfrac)) + f.write(format_initial_mole_fractions(system)) f.write(' },\n') # Termination criteria From 5e31d491f178330a6e635b4214a5f236ed3c94e0 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 12:05:44 -0500 Subject: [PATCH 6/7] fix liquid initial concenctrations units --- rmgpy/rmg/input.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 0203975e562..116691d21b6 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -44,7 +44,7 @@ from rmgpy.molecule import Molecule from rmgpy.molecule.fragment import Fragment from rmgpy.molecule.group import Group -from rmgpy.quantity import Energy, Quantity, RateCoefficient, SurfaceConcentration +from rmgpy.quantity import Energy, Quantity, RateCoefficient, SurfaceConcentration, Concentration from rmgpy.rmg.model import CoreEdgeReactionModel from rmgpy.rmg.reactionmechanismsimulator_reactors import ( ConstantTLiquidSurfaceReactor, @@ -659,7 +659,7 @@ def liquid_cat_reactor(temperature, concentration = Quantity(conc) # check the dimensions are ok # convert to mol/m^3 (or something numerically nice? or must it be SI) - initialConcentrations[spec] = concentration.value_si + initialConcentrations[spec] = concentration.value_si # is this a mistake? shouldn't this also be quantity? else: if len(conc) != 2: raise InputError("Concentration values must either be in the form of (number,units) or a list with 2 " @@ -1756,6 +1756,9 @@ def format_initial_mole_fractions(system): f.write(' temperature = ' + format_temperature(system) + '\n') f.write(' initialConcentrations={\n') for spcs, conc in system.initial_concentrations.items(): + # conc may have been converted to SI, so we need to convert back + if type(conc) == float: + conc = Quantity(conc, Concentration.units) f.write(' "{0!s}": ({1:g},"{2!s}"),\n'.format(spcs.label, conc.value, conc.units)) elif isinstance(system, SurfaceReactor): f.write('surfaceReactor(\n') From 6b6f576d0e21c5b096b56e7038d8256ac4d2457e Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Mon, 9 Feb 2026 15:51:48 -0500 Subject: [PATCH 7/7] delete comment about potential bug that isnt a bug --- rmgpy/rmg/input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 116691d21b6..0bb045af594 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -659,7 +659,7 @@ def liquid_cat_reactor(temperature, concentration = Quantity(conc) # check the dimensions are ok # convert to mol/m^3 (or something numerically nice? or must it be SI) - initialConcentrations[spec] = concentration.value_si # is this a mistake? shouldn't this also be quantity? + initialConcentrations[spec] = concentration.value_si else: if len(conc) != 2: raise InputError("Concentration values must either be in the form of (number,units) or a list with 2 "