RMG-Py icon indicating copy to clipboard operation
RMG-Py copied to clipboard

Calculate Reaction Degeneracy Fails in Intra_R_Add_Endocyclic Family

Open sevyharris opened this issue 2 years ago • 5 comments

Bug Description

RMG fails to calculate a reaction's degeneracy ( [CH2]C=CC=CC=C <=> [CH]1C=CC=CCC1 in reaction family Intra_R_Add_Endocyclic) while attempting to add_rules_from_training. This occurred while loading the database for an uncertainty calculation.

How To Reproduce

Try running the following code:

from rmgpy.data.rmg import RMGDatabase
from rmgpy import settings

database = RMGDatabase()
database.load(
    settings['database.directory'],
    thermo_libraries=[
        'BurkeH2O2',
        'CurranPentane',
        'FFCM1(-)',
        'primaryThermoLibrary',
        'thermo_DFT_CCSDTF12_BAC',
        'DFT_QCI_thermo',
        'CBS_QB3_1dHR',
    ],
    kinetics_families=[
        'Intra_R_Add_Endocyclic',
    ],
)

for familyLabel, family in database.kinetics.families.items():
    family.add_rules_from_training(thermo_database=database.thermo)


Expected Behavior

I expect the database to load without issue because it has in the recent past

Installation Information

Describe your installation method and system information.

  • OS: WSL: Ubuntu 20.04.1
  • Installation method: source
  • RMG version information:
    • RMG-Py: 3.0.0-938-g4377398cf
    • RMG-database: 3.0.0-539-g89564b633

Additional Context

Here's the error traceback:

Unable to calculate degeneracy for reaction [CH2]C=CC=CC=C <=> <Molecule "[CH]1C=CC=CCC1"> in reaction family Intra_R_Add_Endocyclic. Expected 1 reaction but generated 0
  File "/home/moon/rmg/RMG-Py/rmgpy/data/kinetics/family.py", line 1948, in calculate_degeneracy
    'but generated {2}').format(reaction, self.label, len(reactions)))
  File "/home/moon/rmg/RMG-Py/rmgpy/data/kinetics/family.py", line 1303, in add_rules_from_training
    new_degeneracy = self.calculate_degeneracy(item)
  File "/home/moon/rmg/my_examples/debug_degeneracy/min_err.py", line 22, in <module>
    family.add_rules_from_training(thermo_database=database.thermo)

sevyharris avatar Apr 12 '22 17:04 sevyharris

Same error saw here. https://github.com/ReactionMechanismGenerator/RMG-website/issues/241. But that issue seems to go away after the website was updated for unknown reason.

I looked at the hashes of your commits, and both RMG-Py and RMG-database are up to the latest main. Using the same version, I can replicate the issue. Looking into this now.

  • OS: MacOS 12.3.1

xiaoruiDong avatar Apr 12 '22 20:04 xiaoruiDong

Same error saw here. ReactionMechanismGenerator/RMG-website#241. But that issue seems to go away after the website was updated for unknown reason.

I looked at the hashes of your commits, and both RMG-Py and RMG-database are up to the latest main. Using the same version, I can replicate the issue. Looking into this now.

  • OS: MacOS 12.3.1

Thank you for looking into it!

sevyharris avatar Apr 12 '22 21:04 sevyharris

Part of the reason is that reactantNum and productNum are not defined in the groups.py of the family Intra_R_Add_Endocyclic.

After fixing this, I still got the same error. The problem is https://github.com/ReactionMechanismGenerator/RMG-Py/blob/4377398cf30eff9f28cf2ae65306cdd9dcb3d204/rmgpy/data/kinetics/family.py#L1302-L1303 at line 1302, the templated generated for this reaction is ['Root_N-1R!H-inRing']; but inside self.calculate_degeneracy(item) https://github.com/ReactionMechanismGenerator/RMG-Py/blob/4377398cf30eff9f28cf2ae65306cdd9dcb3d204/rmgpy/data/kinetics/family.py#L1932-L1938 at line 1933 generated 2 reactions but with different templates:

  • ['Root_N-1R!H-inRing_Ext-3R!H-R_Sp-4R!H-3R!H_Ext-1R!H-R_N-5R!H-inRing_Sp-5R!H-1R!H_N-2R!H->S_Ext-4R!H-R_N-Sp-6R!H-4R!H_Ext-5R!H-R_Int-7R!H-6R!H'].

The difference in template cause line 1937 raise an warning No reactions matched the specified template, frozenset({'Root_N-1R!H-inRing'}) and empty the reactions list.

The only modification in between is that ensure_independent_atom_ids(reactants, resonance=True)is called at line 1928. But it is not the cause, as _generate_reactions still yields the same super long template when feeding the same thing as in line 1302.

@mjohnson541 , do you know why different templates are matched here?


The two groups:

  • Root_N-1R!H-inRing
1 *2 C   u0 r0 {2,[D,T,B]}
2 *3 R!H u0 c0 {1,[D,T,B]}
3 *1 R!H u1
  • Root_N-1R!H-inRing_Ext-3R!H-R_Sp-4R!H-3R!H_Ext-1R!H-R_N-5R!H-inRing_Sp-5R!H-1R!H_N-2R!H->S_Ext-4R!H-R_N-Sp-6R!H-4R!H_Ext-5R!H-R_Int-7R!H-6R!H
1 *2 C u0 r0 {2,[D,T,B]} {5,S}
2 *3 C u0 c0 {1,[D,T,B]}
3 *1 C u1 {4,S}
4    C ux r0 {3,S} {6,D}
5    C ux r0 {1,S} {7,D}
6    C u0 r0 {4,D} {7,[S,D,T,B,Q]}
7    C u0 r0 {5,D} {6,[S,D,T,B,Q]}

xiaoruiDong avatar Apr 13 '22 03:04 xiaoruiDong

One thing really weird about the newly merged families are *labels are expected to be *1, *2, *3, but a few cases in the species dictionary have label index over 3 (*4, *5, *6, *7). Not sure if this is the case causing this issue.

xiaoruiDong avatar Apr 13 '22 15:04 xiaoruiDong

@sevyharris, the short answer is add_rules_from_training and fill_rules_by_averaging_up are not designed for ATG rate rules and shouldn't be called on ATG families.

However, this is a good catch helping us find multiple issues in both RMG-database and RMG-Py. https://github.com/ReactionMechanismGenerator/RMG-database/pull/576 https://github.com/ReactionMechanismGenerator/RMG-Py/pull/2297 https://github.com/ReactionMechanismGenerator/RMG-Py/pull/2299

Let me know if you have other questions. Otherwise, we will close the issue.

xiaoruiDong avatar Apr 13 '22 21:04 xiaoruiDong

This issue is being automatically marked as stale because it has not received any interaction in the last 90 days. Please leave a comment if this is still a relevant issue, otherwise it will automatically be closed in 30 days.

github-actions[bot] avatar Jun 21 '23 22:06 github-actions[bot]

From the penultimate comment above this issue spawned 3 PRs that have all been merged, and is now resolved.

rwest avatar Jun 22 '23 17:06 rwest