Skip to content

Commit 2b516ee

Browse files
authored
Merge pull request #2919 for Chemkin file reading
Improvements to Chemkin file reading/parsing
2 parents 52c2fc3 + 81b3576 commit 2b516ee

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

rmgpy/chemkin.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ from rmgpy.data.kinetics.library import LibraryReaction
4747
from rmgpy.exceptions import ChemkinError
4848
from rmgpy.molecule.element import get_element
4949
from rmgpy.molecule.util import get_element_count
50-
from rmgpy.quantity import Quantity
50+
from rmgpy.quantity import Quantity, QuantityError
5151
from rmgpy.reaction import Reaction
5252
from rmgpy.rmg.pdep import PDepNetwork, PDepReaction
5353
from rmgpy.species import Species
@@ -397,7 +397,7 @@ def _read_kinetics_reaction(line, species_dict, Aunits, Aunits_surf, Eunits):
397397
# this identifies reactions like 'H+H+M=H2+M' as opposed to 'H+H(+M)=H2(+M)' as identified above
398398
third_body = True
399399
elif reactant not in species_dict:
400-
raise ChemkinError('Unexpected reactant "{0}" in reaction {1}.'.format(reactant, reaction))
400+
raise ChemkinError('Unexpected reactant "{0}" in reaction line {1}.'.format(reactant, line))
401401
else:
402402
reactant_species = species_dict[reactant]
403403
if not reactant_species.reactive:
@@ -1405,13 +1405,15 @@ def read_reactions_block(f, species_dict, read_comments=True):
14051405
'{0}^3/({1}*{2})'.format(volume_units, molecule_units, time_units), # Second-order
14061406
'{0}^6/({1}^2*{2})'.format(volume_units, molecule_units, time_units), # Third-order
14071407
'{0}^9/({1}^3*{2})'.format(volume_units, molecule_units, time_units), # Fourth-order
1408+
f"{volume_units}^12/({molecule_units}^4*{time_units})", # Fifth-order
14081409
]
14091410

14101411
Aunits_surf = [
14111412
'', # Zeroth-order
14121413
's^-1'.format(time_units), # First-order
14131414
'{0}^2/({1}*{2})'.format(area_units, molecule_units, time_units), # Second-order
14141415
'{0}^4/({1}^2*{2})'.format(area_units, molecule_units, time_units), # Third-order
1416+
'{0}^6/({1}^3*{2})'.format(area_units, molecule_units, time_units), # Fourth-order
14151417
]
14161418
Eunits = energy_units
14171419

@@ -1481,10 +1483,13 @@ def read_reactions_block(f, species_dict, read_comments=True):
14811483
reaction = read_reaction_comments(reaction, comments, read=read_comments)
14821484
except ChemkinError as e:
14831485
if "Skip reaction!" in str(e):
1484-
logging.warning("Skipping the reaction {0!r}".format(kinetics))
1486+
logging.warning("Skipping the reaction {0!r} because of {e!s}".format(kinetics))
14851487
continue
14861488
else:
14871489
raise
1490+
except QuantityError as e:
1491+
logging.warning(f"Skipping the reaction {kinetics!r} due to units error: {e}")
1492+
continue
14881493
reaction_list.append(reaction)
14891494

14901495
return reaction_list

rmgpy/data/kinetics/family.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,8 @@ def get_labeled_reactants_and_products(self, reactants, products, relabel_atoms=
27082708
template_reactants = [x.item for x in template.reactants]
27092709
else:
27102710
template_reactants = [x.item for x in template.reactants]
2711-
2711+
if (num_reactants := len(reactants0)) != (num_template := len(template_reactants)):
2712+
raise ValueError(f"Reaction has {num_reactants} reactants but template has {num_template} reactants.")
27122713
if len(reactants0) == 1:
27132714
molecule = reactants0[0]
27142715
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=
27442745
reactant_structures = [molecule_a, molecule_b, molecule_c]
27452746
num_mappings = len(mappings_a) * len(mappings_b) * len(mappings_c)
27462747
else:
2747-
raise IndexError('You have {0} reactants, which is unexpected!'.format(len(reactants)))
2748+
raise ValueError('You have {0} reactants, which is unexpected!'.format(len(reactants)))
27482749

27492750
for mapping in mappings:
27502751
try:

rmgpy/data/kinetics/rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ def estimate_kinetics(self, template, degeneracy=1):
449449
kinetics_list = remove_identical_kinetics(saved_kinetics)
450450

451451
if len(kinetics_list) == 0:
452-
raise KineticsError('Unable to determine kinetics for reaction with template {0} in family '
453-
'{1}.'.format(template, self.label))
452+
raise KineticsError("Unable to determine kinetics for reaction "
453+
f"with template {template!r} in family {self.label!s}.")
454454

455455
elif len(kinetics_list) == 1:
456456
kinetics, t = kinetics_list[0]

rmgpy/quantity.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -840,24 +840,23 @@ def RateCoefficient(*args, **kwargs):
840840
# SurfaceRateCoefficient is handled as a special case since it can take various
841841
# units depending on the reaction order
842842
SURFACERATECOEFFICIENT_CONVERSION_FACTORS = {
843-
(1.0 / pq.s).dimensionality: 1.0,
844-
(pq.m ** 3 / pq.s).dimensionality: 1.0,
843+
(1.0 / pq.s).dimensionality: 1.0, # unimolecular
844+
(pq.m ** 3 / pq.s).dimensionality: 1.0, # single site adsorption
845845
(pq.m ** 6 / pq.s).dimensionality: 1.0,
846846
(pq.m ** 9 / pq.s).dimensionality: 1.0,
847-
(pq.m ** 3 / (pq.mol * pq.s)).dimensionality: 1.0,
847+
(pq.m ** 3 / (pq.mol * pq.s)).dimensionality: 1.0, # single site adsorption
848848
(pq.m ** 6 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0,
849849
(pq.m ** 9 / (pq.mol ** 3 * pq.s)).dimensionality: 1.0,
850-
(pq.m ** 2 / pq.s).dimensionality: 1.0,
851-
(pq.m ** 5 / pq.s).dimensionality: 1.0,
852-
(pq.m ** 2 / (pq.mol * pq.s)).dimensionality: 1.0,
853-
(pq.m ** 5 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0,
850+
(pq.m ** 2 / pq.s).dimensionality: 1.0, # bimolecular surface (Langmuir-Hinshelwood)
851+
(pq.m ** 5 / pq.s).dimensionality: 1.0, # dissociative adsorption
852+
(pq.m ** 2 / (pq.mol * pq.s)).dimensionality: 1.0, # bimolecular surface (Langmuir-Hinshelwood)
853+
(pq.m ** 5 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0, # dissociative adsorption
854854
(pq.m ** 4 / (pq.mol ** 2 * pq.s)).dimensionality: 1.0,
855855
}
856856
SURFACERATECOEFFICIENT_COMMON_UNITS = [
857857
's^-1', # unimolecular
858858
'm^3/(mol*s)', 'cm^3/(mol*s)', 'm^3/(molecule*s)', 'cm^3/(molecule*s)', # single site adsorption
859-
'm^2/(mol*s)', 'cm^2/(mol*s)', 'm^2/(molecule*s)', 'cm^2/(molecule*s)',
860-
# bimolecular surface (Langmuir-Hinshelwood)
859+
'm^2/(mol*s)', 'cm^2/(mol*s)', 'm^2/(molecule*s)', 'cm^2/(molecule*s)', # bimolecular surface (Langmuir-Hinshelwood)
861860
'm^5/(mol^2*s)', 'cm^5/(mol^2*s)', 'm^5/(molecule^2*s)', 'cm^5/(molecule^2*s)', # dissociative adsorption
862861
'm^4/(mol^2*s)', 'cm^4/(mol^2*s)', 'm^4/(molecule^2*s)', 'cm^4/(molecule^2*s)', # Surface_Bidentate_Dissociation
863862
]

0 commit comments

Comments
 (0)