From 5d2bd179a9c09c810314c399dd332e114d520f16 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Mon, 21 Aug 2023 15:05:47 -0400 Subject: [PATCH 1/6] 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 117c19644cf..1c455eb5fa3 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + ############################################################################### # # @@ -1684,9 +1684,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 40952c604b73b801b70c9b3488ce196aaaeadb8e Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Wed, 19 Feb 2025 16:21:18 -0500 Subject: [PATCH 2/6] 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 1c455eb5fa3..ca1c9fdc267 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1687,9 +1687,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 @@ -1703,17 +1707,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 9de072675c06231a61e26f2abe337d30db3b8e7f Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 11:20:27 -0500 Subject: [PATCH 3/6] 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 ca1c9fdc267..7afc98381d5 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1628,6 +1628,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} @@ -1750,9 +1752,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 2b0200b2309132f290dcd81fae5c0e44b07db7a2 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 11:25:27 -0500 Subject: [PATCH 4/6] 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 7afc98381d5..a37fb6ec1e2 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1800,9 +1800,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 6c0db091f279da3a69c20ba07b1c99824e0e8e71 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 11:40:52 -0500 Subject: [PATCH 5/6] 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 a37fb6ec1e2..de40c973d8d 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -1716,9 +1716,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') @@ -1739,12 +1756,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 b397bfb09db724a80dc42c387cd9a35957523517 Mon Sep 17 00:00:00 2001 From: Sevy Harris Date: Fri, 21 Feb 2025 12:05:44 -0500 Subject: [PATCH 6/6] 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 de40c973d8d..79143a6f2e9 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -38,7 +38,7 @@ from rmgpy.exceptions import DatabaseError, InputError from rmgpy.molecule import Molecule from rmgpy.molecule.group import Group -from rmgpy.quantity import Quantity, Energy, RateCoefficient, SurfaceConcentration +from rmgpy.quantity import Quantity, Energy, RateCoefficient, SurfaceConcentration, Concentration from rmgpy.rmg.model import CoreEdgeReactionModel from rmgpy.rmg.settings import ModelSettings, SimulatorSettings from rmgpy.solver.termination import TerminationTime, TerminationConversion, TerminationRateRatio @@ -647,7 +647,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 " @@ -1741,6 +1741,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')