Skip to content

Commit 8c9e6f3

Browse files
committed
Write species concentration range in the RMG input file
1 parent c4a35ae commit 8c9e6f3

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

t3/utils/writer.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def write_rmg_input_file(rmg: dict,
9494

9595
# reactors
9696
reactors = rmg['reactors']
97-
gas_batch_constant_t_p_template_template = """
97+
gas_batch_constant_t_p_template = """
9898
simpleReactor(
9999
temperature=${temperature},
100100
pressure=${pressure},
@@ -104,7 +104,12 @@ def write_rmg_input_file(rmg: dict,
104104
)
105105
<%def name="concentrations()">
106106
% for spc in species_list:
107+
% if isinstance(spc["concentration"], (int, float)):
107108
'${spc["label"]}': ${spc["concentration"]},
109+
% endif
110+
% if isinstance(spc["concentration"], (tuple, list)):
111+
'${spc["label"]}': [${spc["concentration"][0]}, ${spc["concentration"][1]}],
112+
% endif
108113
% endfor
109114
</%def>
110115
"""
@@ -117,7 +122,12 @@ def write_rmg_input_file(rmg: dict,
117122
)
118123
<%def name="concentrations()">
119124
% for spc in species_list:
125+
% if isinstance(spc["concentration"], (int, float)):
120126
'${spc["label"]}': (${spc["concentration"]}, 'mol/cm^3'),
127+
% endif
128+
% if isinstance(spc["concentration"], (tuple, list)):
129+
'${spc["label"]}': [(${spc["concentration"][0]}, 'mol/cm^3'), (${spc["concentration"][1]}, 'mol/cm^3')],
130+
% endif
121131
% endfor
122132
</%def>
123133
"""
@@ -129,8 +139,13 @@ def write_rmg_input_file(rmg: dict,
129139
else:
130140
raise ValueError(f"The reactor temperature must be a float or a list,\n"
131141
f"got {reactor['T']} which is a {type(reactor['T'])}.")
132-
species_list = [{'label': spc['label'], 'concentration': spc['concentration']} for spc in species]
133-
species_list.sort(key=lambda spc: spc['concentration'], reverse=True)
142+
species_list = [{'label': spc['label'], 'concentration': spc['concentration']} for spc in species
143+
if isinstance(spc['concentration'], (list, tuple))
144+
or spc['concentration'] > 0
145+
or spc['balance'] or not spc['reactive']]
146+
species_list.sort(key=lambda spc: spc['concentration'][0] if isinstance(spc['concentration'], (tuple, list))
147+
else spc['concentration'], reverse=True)
148+
print(species_list)
134149
termination = ''
135150
if reactor['termination_conversion'] is not None:
136151
termination += f"terminationConversion={reactor['termination_conversion']},"
@@ -161,7 +176,7 @@ def write_rmg_input_file(rmg: dict,
161176
if spc['balance']:
162177
balance = f"\n balanceSpecies='{spc['label']}',"
163178
break
164-
rmg_input += Template(gas_batch_constant_t_p_template_template).render(
179+
rmg_input += Template(gas_batch_constant_t_p_template).render(
165180
temperature=temperature,
166181
pressure=pressure,
167182
species_list=species_list,

0 commit comments

Comments
 (0)