Skip to content

Commit acb928b

Browse files
committed
improve formatting for catalyst properties output
1 parent 6f17135 commit acb928b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

rmgpy/rmg/input.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,9 +1687,13 @@ def save_input_file(path, rmg):
16871687
if rmg.surface_site_density or rmg.binding_energies:
16881688
f.write('catalystProperties(\n')
16891689
if rmg.surface_site_density:
1690-
f.write(' surface_site_density = {0!r},'.format(rmg.surface_site_density))
1690+
f.write(' surfaceSiteDensity = ({0:g}, "{1!s}"),'.format(rmg.surface_site_density.value, rmg.surface_site_density.units) + '\n')
16911691
if rmg.binding_energies:
1692-
f.write(' binding_energies = {0!r},'.format(rmg.binding_energies))
1692+
f.write(' bindingEnergies = {\n')
1693+
for spc, be in rmg.binding_energies.items():
1694+
f.write(' "{0!s}": ({1:g}, "{2!s}"),\n'.format(spc, be.value, be.units))
1695+
f.write(' },\n')
1696+
16931697
f.write(')\n\n')
16941698

16951699
# Species
@@ -1703,17 +1707,36 @@ def save_input_file(path, rmg):
17031707
f.write('"""),\n')
17041708
f.write(')\n\n')
17051709

1710+
def format_temperature(system):
1711+
"""Get temperature string format for reaction system, whether single value or range"""
1712+
if system.T is not None:
1713+
return '({0:g},"{1!s}")'.format(system.T.value, system.T.units)
1714+
1715+
return f'[({system.Trange[0].value:g}, "{system.Trange[0].units}"), ({system.Trange[1].value:g}, "{system.Trange[1].units}")],'
1716+
17061717
# Reaction systems
17071718
for system in rmg.reaction_systems:
1719+
# TODO add ranging pressures
17081720
if rmg.solvent:
17091721
f.write('liquidReactor(\n')
1710-
f.write(' temperature = ({0:g},"{1!s}"),\n'.format(system.T.value, system.T.units))
1722+
f.write(' temperature = ' + format_temperature(system) + '\n')
17111723
f.write(' initialConcentrations={\n')
17121724
for spcs, conc in system.initial_concentrations.items():
17131725
f.write(' "{0!s}": ({1:g},"{2!s}"),\n'.format(spcs.label, conc.value, conc.units))
1726+
elif isinstance(system, SurfaceReactor):
1727+
f.write('surfaceReactor(\n')
1728+
f.write(' temperature = ' + format_temperature(system) + '\n')
1729+
f.write(' initialPressure = ({0:g},"{1!s}"),\n'.format(system.P_initial.value, system.P_initial.units))
1730+
f.write(' initialGasMoleFractions={\n')
1731+
for spcs, molfrac in system.initial_gas_mole_fractions.items():
1732+
f.write(' "{0!s}": {1:g},\n'.format(spcs.label, molfrac))
1733+
f.write(' },\n')
1734+
f.write(' initialSurfaceCoverages={\n')
1735+
for spcs, cov in system.initial_surface_coverages.items():
1736+
f.write(' "{0!s}": {1:g},\n'.format(spcs.label, cov))
17141737
else:
17151738
f.write('simpleReactor(\n')
1716-
f.write(' temperature = ({0:g},"{1!s}"),\n'.format(system.T.value, system.T.units))
1739+
f.write(' temperature = ' + format_temperature(system) + '\n')
17171740
# Convert the pressure from SI pascal units to bar here
17181741
# Do something more fancy later for converting to user's desired units for both T and P..
17191742
f.write(' pressure = ({0:g},"{1!s}"),\n'.format(system.P.value, system.P.units))

0 commit comments

Comments
 (0)