diff --git a/rmgpy/chemkin.pyx b/rmgpy/chemkin.pyx index d62c0b6456..1a0232fd3c 100644 --- a/rmgpy/chemkin.pyx +++ b/rmgpy/chemkin.pyx @@ -1969,22 +1969,22 @@ def mark_duplicate_reaction(test_reaction, reaction_list): # duplicates of one another. # RHW question: why can't TemplateReaction be duplicate of LibraryReaction, in Chemkin terms? I guess it shouldn't happen in RMG. continue - same_dir_match = (reaction1.reactants == reaction2.reactants and reaction1.products == reaction2.products) - opposite_dir_match = (reaction1.products == reaction2.reactants and reaction1.reactants == reaction2.products) + same_dir_match = (sorted(reaction1.reactants) == sorted(reaction2.reactants) and sorted(reaction1.products) == sorted(reaction2.products)) + opposite_dir_match = (sorted(reaction1.products) == sorted(reaction2.reactants) and sorted(reaction1.reactants) == sorted(reaction2.products)) if (same_dir_match or opposite_dir_match) and (reaction1.specific_collider == reaction2.specific_collider): if reaction1.duplicate and reaction2.duplicate: if reaction1.kinetics.is_pressure_dependent() != reaction2.kinetics.is_pressure_dependent(): # Reactions with mixed pressure dependence do not need to be marked duplicate in Chemkin - logging.warning('Marked reaction {0} as not duplicate because of mixed pressure dependence ' - 'for saving to Chemkin file.'.format(reaction1)) - reaction1.duplicate = False - reaction2.duplicate = False + logging.warning('Reaction {0} is marked as duplicate but for Chemkin file it ' + 'doesn\'t need to be because of mixed pressure dependence' + '.'.format(reaction1)) + # But leave it alone in case it's a DUPLICATE of some _other_ reaction. elif opposite_dir_match and not reaction1.reversible and not reaction2.reversible: # Irreversible reactions in opposite directions do not need to be marked duplicate in Chemkin - logging.warning('Marked reaction {0} as not duplicate because they are irreversible ' - 'in opposite directions for saving to Chemkin file.'.format(reaction1)) - reaction1.duplicate = False - reaction2.duplicate = False + logging.warning('Reaction {0} is marked as duplicate but for Chemkin file it ' + 'doesn\'t need to be because they are irreversible ' + 'in opposite directions.'.format(reaction1)) + # But leave it alone in case it's a DUPLICATE of some _other_ reaction. else: if (reaction1.kinetics.is_pressure_dependent() == reaction2.kinetics.is_pressure_dependent() and ((reaction1.reversible and reaction2.reversible) @@ -2150,7 +2150,7 @@ def save_chemkin_file(path, species, reactions, verbose=True, check_for_duplicat f.write('\n') f.write('END\n\n') f.close() - logging.info("Chemkin file contains {0} reactions.".format(_chemkin_reaction_count)) + logging.info("Chemkin surface file contains {0} reactions.".format(_chemkin_reaction_count)) _chemkin_reaction_count = None diff --git a/test/rmgpy/chemkinTest.py b/test/rmgpy/chemkinTest.py index 09099b865c..6b40561b9d 100644 --- a/test/rmgpy/chemkinTest.py +++ b/test/rmgpy/chemkinTest.py @@ -503,6 +503,21 @@ def test_mark_duplicate_reactions(self): assert duplicate_flags == expected_flags + @pytest.mark.skip(reason="WIP") + def test_unmark_duplicate_reactions(self): + """Test that we can properly REMOVE duplicate reaction flags for Chemkin.""" + + """ + We can't do this properly yet. + See https://github.com/ReactionMechanismGenerator/RMG-Py/pull/1856 + """ + s1 = Species().from_smiles('CC') + s2 = Species().from_smiles('[CH3]') + s3 = Species().from_smiles('[OH]') + s4 = Species().from_smiles('C[CH2]') + s5 = Species().from_smiles('O') + s6 = Species().from_smiles('[H]') + # Try initializing with duplicate=True reaction_list = [ Reaction(reactants=[s1], products=[s2, s2], duplicate=True, kinetics=Arrhenius()), @@ -549,6 +564,8 @@ def test_mark_duplicate_reactions(self): ), ] + expected_flags = [True, True, False, False, True, True, False, False] + mark_duplicate_reactions(reaction_list) duplicate_flags = [rxn.duplicate for rxn in reaction_list]