diff --git a/rmgpy/chemkin.pyx b/rmgpy/chemkin.pyx index 636cbe0926..3699be19bb 100644 --- a/rmgpy/chemkin.pyx +++ b/rmgpy/chemkin.pyx @@ -47,7 +47,7 @@ from rmgpy.data.kinetics.library import LibraryReaction from rmgpy.exceptions import ChemkinError from rmgpy.molecule.element import get_element from rmgpy.molecule.util import get_element_count -from rmgpy.quantity import Quantity +from rmgpy.quantity import Quantity, QuantityError from rmgpy.reaction import Reaction from rmgpy.rmg.pdep import PDepNetwork, PDepReaction from rmgpy.species import Species @@ -397,7 +397,7 @@ def _read_kinetics_reaction(line, species_dict, Aunits, Aunits_surf, Eunits): # this identifies reactions like 'H+H+M=H2+M' as opposed to 'H+H(+M)=H2(+M)' as identified above third_body = True elif reactant not in species_dict: - raise ChemkinError('Unexpected reactant "{0}" in reaction {1}.'.format(reactant, reaction)) + raise ChemkinError('Unexpected reactant "{0}" in reaction line {1}.'.format(reactant, line)) else: reactant_species = species_dict[reactant] if not reactant_species.reactive: @@ -1405,6 +1405,7 @@ def read_reactions_block(f, species_dict, read_comments=True): '{0}^3/({1}*{2})'.format(volume_units, molecule_units, time_units), # Second-order '{0}^6/({1}^2*{2})'.format(volume_units, molecule_units, time_units), # Third-order '{0}^9/({1}^3*{2})'.format(volume_units, molecule_units, time_units), # Fourth-order + f"{volume_units}^12/({molecule_units}^4*{time_units})", # Fifth-order ] Aunits_surf = [ @@ -1412,6 +1413,7 @@ def read_reactions_block(f, species_dict, read_comments=True): 's^-1'.format(time_units), # First-order '{0}^2/({1}*{2})'.format(area_units, molecule_units, time_units), # Second-order '{0}^4/({1}^2*{2})'.format(area_units, molecule_units, time_units), # Third-order + '{0}^6/({1}^3*{2})'.format(area_units, molecule_units, time_units), # Fourth-order ] Eunits = energy_units @@ -1481,10 +1483,13 @@ def read_reactions_block(f, species_dict, read_comments=True): reaction = read_reaction_comments(reaction, comments, read=read_comments) except ChemkinError as e: if "Skip reaction!" in str(e): - logging.warning("Skipping the reaction {0!r}".format(kinetics)) + logging.warning("Skipping the reaction {0!r} because of {e!s}".format(kinetics)) continue else: raise + except QuantityError as e: + logging.warning(f"Skipping the reaction {kinetics!r} due to units error: {e}") + continue reaction_list.append(reaction) return reaction_list diff --git a/rmgpy/data/kinetics/family.py b/rmgpy/data/kinetics/family.py index 685d92cd77..f57ce12b2e 100644 --- a/rmgpy/data/kinetics/family.py +++ b/rmgpy/data/kinetics/family.py @@ -2708,7 +2708,8 @@ def get_labeled_reactants_and_products(self, reactants, products, relabel_atoms= template_reactants = [x.item for x in template.reactants] else: template_reactants = [x.item for x in template.reactants] - + if (num_reactants := len(reactants0)) != (num_template := len(template_reactants)): + raise ValueError(f"Reaction has {num_reactants} reactants but template has {num_template} reactants.") if len(reactants0) == 1: molecule = reactants0[0] mappings = self._match_reactant_to_template(molecule, template_reactants[0]) @@ -2744,7 +2745,7 @@ def get_labeled_reactants_and_products(self, reactants, products, relabel_atoms= reactant_structures = [molecule_a, molecule_b, molecule_c] num_mappings = len(mappings_a) * len(mappings_b) * len(mappings_c) else: - raise IndexError('You have {0} reactants, which is unexpected!'.format(len(reactants))) + raise ValueError('You have {0} reactants, which is unexpected!'.format(len(reactants))) for mapping in mappings: try: diff --git a/rmgpy/data/kinetics/rules.py b/rmgpy/data/kinetics/rules.py index 7a71070937..7dfc5424c1 100644 --- a/rmgpy/data/kinetics/rules.py +++ b/rmgpy/data/kinetics/rules.py @@ -449,8 +449,8 @@ def estimate_kinetics(self, template, degeneracy=1): kinetics_list = remove_identical_kinetics(saved_kinetics) if len(kinetics_list) == 0: - raise KineticsError('Unable to determine kinetics for reaction with template {0} in family ' - '{1}.'.format(template, self.label)) + raise KineticsError("Unable to determine kinetics for reaction " + f"with template {template!r} in family {self.label!s}.") elif len(kinetics_list) == 1: kinetics, t = kinetics_list[0] diff --git a/rmgpy/quantity.py b/rmgpy/quantity.py index 5d73546d45..877e44b748 100644 --- a/rmgpy/quantity.py +++ b/rmgpy/quantity.py @@ -840,24 +840,23 @@ def RateCoefficient(*args, **kwargs): # SurfaceRateCoefficient is handled as a special case since it can take various # units depending on the reaction order SURFACERATECOEFFICIENT_CONVERSION_FACTORS = { - (1.0 / pq.s).dimensionality: 1.0, - (pq.m ** 3 / pq.s).dimensionality: 1.0, + (1.0 / pq.s).dimensionality: 1.0, # unimolecular + (pq.m ** 3 / pq.s).dimensionality: 1.0, # single site adsorption (pq.m ** 6 / pq.s).dimensionality: 1.0, (pq.m ** 9 / pq.s).dimensionality: 1.0, - (pq.m ** 3 / (pq.mol * pq.s)).dimensionality: 1.0, + (pq.m ** 3 / (pq.mol * pq.s)).dimensionality: 1.0, # single site adsorption (pq.m ** 6 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0, (pq.m ** 9 / (pq.mol ** 3 * pq.s)).dimensionality: 1.0, - (pq.m ** 2 / pq.s).dimensionality: 1.0, - (pq.m ** 5 / pq.s).dimensionality: 1.0, - (pq.m ** 2 / (pq.mol * pq.s)).dimensionality: 1.0, - (pq.m ** 5 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0, + (pq.m ** 2 / pq.s).dimensionality: 1.0, # bimolecular surface (Langmuir-Hinshelwood) + (pq.m ** 5 / pq.s).dimensionality: 1.0, # dissociative adsorption + (pq.m ** 2 / (pq.mol * pq.s)).dimensionality: 1.0, # bimolecular surface (Langmuir-Hinshelwood) + (pq.m ** 5 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0, # dissociative adsorption (pq.m ** 4 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0, } SURFACERATECOEFFICIENT_COMMON_UNITS = [ 's^-1', # unimolecular 'm^3/(mol*s)', 'cm^3/(mol*s)', 'm^3/(molecule*s)', 'cm^3/(molecule*s)', # single site adsorption - 'm^2/(mol*s)', 'cm^2/(mol*s)', 'm^2/(molecule*s)', 'cm^2/(molecule*s)', - # bimolecular surface (Langmuir-Hinshelwood) + 'm^2/(mol*s)', 'cm^2/(mol*s)', 'm^2/(molecule*s)', 'cm^2/(molecule*s)', # bimolecular surface (Langmuir-Hinshelwood) 'm^5/(mol^2*s)', 'cm^5/(mol^2*s)', 'm^5/(molecule^2*s)', 'cm^5/(molecule^2*s)', # dissociative adsorption 'm^4/(mol^2*s)', 'cm^4/(mol^2*s)', 'm^4/(molecule^2*s)', 'cm^4/(molecule^2*s)', # Surface_Bidentate_Dissociation ]