Skip to content

Commit da14f28

Browse files
committed
Make RMG more robust
1 parent 6deb2e4 commit da14f28

5 files changed

Lines changed: 16 additions & 7 deletions

File tree

rmgpy/data/kinetics/database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ def load_libraries(self, path, libraries=None):
246246
library_file = os.path.join(path, library_name, 'reactions.py')
247247
if os.path.exists(library_name):
248248
library_file = os.path.join(library_name, 'reactions.py')
249+
if not os.path.exists(library_file):
250+
continue
249251
short_library_name = os.path.basename(library_name.rstrip(os.path.sep))
250252
logging.info(f'Loading kinetics library {short_library_name} from {library_name}...')
251253
library = KineticsLibrary(label=short_library_name)

rmgpy/data/kinetics/family.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ def add_reverse_attribute(self, rxn, react_non_reactive=True):
18681868
"\n".format(len(reactions), self.label, str(rxn)))
18691869
# raise KineticsError("Did not find reverse reaction in reaction family {0} for reaction "
18701870
# "{1}.".format(self.label, str(rxn)))
1871-
return False
1871+
return True
18721872
elif (len(reactions) > 1 and
18731873
not all([reactions[0].is_isomorphic(other, strict=False, check_template_rxn_products=True)
18741874
for other in reactions])):
@@ -1931,7 +1931,9 @@ def calculate_degeneracy(self, reaction, resonance=True):
19311931
logging.error(('Unable to calculate degeneracy for reaction {0} '
19321932
'in reaction family {1}. Expected 1 reaction '
19331933
'but generated {2}').format(reaction, self.label, len(reactions)))
1934-
return 1
1934+
if not len(reactions):
1935+
return 1
1936+
reactions[0].degeneracy = 1
19351937
return reactions[0].degeneracy
19361938

19371939
def _generate_reactions(self, reactants, products=None, forward=True, prod_resonance=True,
@@ -4760,7 +4762,7 @@ def average_kinetics(kinetics_list):
47604762
average log A (geometric average)
47614763
"""
47624764
if type(kinetics_list[0]) not in [Arrhenius,SurfaceChargeTransfer,ArrheniusChargeTransfer,Marcus]:
4763-
raise Exception('Invalid kinetics type {0!r} for {1!r}.'.format(type(kinetics), self))
4765+
raise Exception('Invalid kinetics type')
47644766

47654767
Aunits = kinetics_list[0].A.units
47664768
if Aunits in {'cm^3/(mol*s)', 'cm^3/(molecule*s)', 'm^3/(molecule*s)'}:

rmgpy/rmg/pdep.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ def get_maximum_leak_species(self, T, P):
234234

235235
# Make sure we've identified a species
236236
if max_species is None:
237-
raise NetworkError('No unimolecular isomers left to explore!')
237+
# raise NetworkError('No unimolecular isomers left to explore!')
238+
pass
238239
# Return the species
239240
return max_species
240241

@@ -270,6 +271,8 @@ def explore_isomer(self, isomer):
270271
network using the provided core-edge reaction model `reaction_model`,
271272
returning the new reactions and new species.
272273
"""
274+
if isomer is None:
275+
return []
273276

274277
if isomer in self.explored:
275278
logging.warning('Already explored isomer {0} in pressure-dependent network #{1:d}'.format(isomer,
@@ -282,7 +285,8 @@ def explore_isomer(self, isomer):
282285
if product.species == [isomer]:
283286
break
284287
else:
285-
raise Exception('Attempted to explore isomer {0}, but that species not found in product channels.'.format(isomer))
288+
# raise Exception('Attempted to explore isomer {0}, but that species not found in product channels.'.format(isomer))
289+
product = Configuration(isomer)
286290

287291
logging.info('Exploring isomer {0} in pressure-dependent network #{1:d}'.format(isomer, self.index))
288292

rmgpy/solver/base.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ from rmgpy.reaction import Reaction
5757
from rmgpy.quantity import Quantity
5858
from rmgpy.species import Species
5959
from rmgpy.solver.termination import TerminationTime, TerminationConversion, TerminationRateRatio
60+
from rmgpy.exceptions import NetworkError
6061
################################################################################
6162

6263
cdef class ReactionSystem(DASx):
@@ -733,7 +734,7 @@ cdef class ReactionSystem(DASx):
733734
self.step(step_time)
734735
if np.isnan(self.y).any():
735736
raise DASxError("nans in moles")
736-
except DASxError as e:
737+
except (DASxError, NetworkError) as e:
737738
logging.error("Trying to step from time {0} to {1} resulted in a solver (DASPK) error: "
738739
"{2!s}".format(prev_time, step_time, e))
739740

rmgpy/tools/mergemodels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def get_models_to_merge(input_model_files):
137137

138138
def combine_models(models):
139139
"""
140-
Takes in a list of ReactionModels and and merges them into a single ReactionModel
140+
Takes in a list of ReactionModels and merges them into a single ReactionModel
141141
Reindexes species with the same label and index
142142
"""
143143
final_model = ReactionModel()

0 commit comments

Comments
 (0)