Skip to content

Commit 242798e

Browse files
committed
Added completedNetworks option to prevent exploring PDep networks that are complete.
Sometimes you have a pressure-dependent network that has been studied in great detail and put in a seed mechanism or reaction library, (such as CH2O2) and you don't want RMG to add reactions to the network and your model, because doing so will make it worse. Any reactions net reactions that are in your seed mechanism won't be changed, but currently if there's a new reaction RMG would add it. This option lets you specify in the input file that you don't want RMG to expand certain networks further. You specify them with a line in your pressureDependence block of your input file like completedNetworks = ['CH2O2', 'C2H6'],
1 parent accc609 commit 242798e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

examples/rmg/ethane-oxidation/input.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
temperatures=(300,3000,'K',8),
6262
pressures=(0.001,100,'bar',5),
6363
interpolation=('Chebyshev', 6, 4),
64+
completedNetworks=['C2H6'],
6465
)
6566

6667
options(

rmgpy/rmg/input.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,7 @@ def pressure_dependence(
13261326
minimumNumberOfGrains=0,
13271327
interpolation=None,
13281328
maximumAtoms=None,
1329+
completedNetworks=None,
13291330
):
13301331
from arkane.pdep import PressureDependenceJob
13311332

@@ -1367,6 +1368,10 @@ def pressure_dependence(
13671368
rmg.pressure_dependence.active_k_rotor = True
13681369
rmg.pressure_dependence.rmgmode = True
13691370

1371+
if completedNetworks:
1372+
for formula in completedNetworks:
1373+
rmg.reaction_model.add_completed_pdep_network(formula)
1374+
13701375

13711376
def options(name='Seed', generateSeedEachIteration=True, saveSeedToDatabase=False, units='si', saveRestartPeriod=None,
13721377
generateOutputHTML=False, generatePlots=False, generatePESDiagrams=False, saveSimulationProfiles=False, verboseComments=False,
@@ -1804,6 +1809,11 @@ def save_input_file(path, rmg):
18041809
))
18051810
f.write(' interpolation = {0},\n'.format(rmg.pressure_dependence.interpolation_model))
18061811
f.write(' maximumAtoms = {0}, \n'.format(rmg.pressure_dependence.maximum_atoms))
1812+
if rmg.reaction_model.completed_pdep_networks:
1813+
def formula(elements):
1814+
return ''.join(f'{el}{count}' if count > 1 else f'{el}' for el, count in elements)
1815+
f.write(' completedNetworks = {0},\n'.format(
1816+
[formula(net) for net in rmg.reaction_model.completed_pdep_networks]))
18071817
f.write(')\n\n')
18081818

18091819
# Quantum Mechanics

rmgpy/rmg/model.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import itertools
3636
import logging
3737
import os
38+
import re
3839

3940
import numpy as np
4041

@@ -248,6 +249,27 @@ def __init__(self, core=None, edge=None, surface=None):
248249
"""
249250
)
250251
]
252+
self.completed_pdep_networks = set()
253+
254+
def add_completed_pdep_network(self, formula):
255+
"""
256+
Add a completed pressure-dependent network formula to the set.
257+
"""
258+
# turn C2H4 into {'C':2,'H':4}
259+
if not isinstance(formula, str):
260+
raise TypeError("Expected string for formula, got {0}".format(formula.__class__))
261+
pattern = r'([A-Z][a-z]?)(\d*)'
262+
element_count = {}
263+
264+
for match in re.finditer(pattern, formula):
265+
element = match.group(1)
266+
count = int(match.group(2)) if match.group(2) else 1
267+
element_count[element] = count
268+
# must be hashable and match what is done in add_reaction_to_unimolecular_networks
269+
key = tuple(sorted(element_count.items()))
270+
self.completed_pdep_networks.add(key)
271+
logging.info(f"Added {formula} to list of completed PDep networks that will not be further explored.")
272+
251273

252274
def check_for_existing_species(self, molecule):
253275
"""
@@ -1893,6 +1915,20 @@ def add_reaction_to_unimolecular_networks(self, newReaction, new_species, networ
18931915

18941916
source = tuple(reactants)
18951917

1918+
if len(reactants) == 1:
1919+
elements = reactants[0].molecule[0].get_element_count()
1920+
elif len(products) == 1:
1921+
elements = products[0].molecule[0].get_element_count()
1922+
else:
1923+
raise ValueError("Unimolecular reaction networks can only be formed for unimolecular reactions or isomerizations.")
1924+
# make a hashable key from the elements dict
1925+
elements_key = tuple(sorted(elements.items()))
1926+
if elements_key in self.completed_pdep_networks:
1927+
formula = ''.join(f'{el}{count}' if count>1 else el for el, count in elements_key)
1928+
logging.info(f"Not adding reaction {newReaction} to unimolecular networks because the network for {formula} is marked as completed.")
1929+
return
1930+
1931+
18961932
# Only search for a network if we don't specify it as a parameter
18971933
if network is None:
18981934
if len(reactants) == 1:

0 commit comments

Comments
 (0)