Skip to content

Edit save_training_reactions in family.py to allow use for R_Recombination family#2922

Open
Nora-Khalil wants to merge 1 commit intomainfrom
atomlabels_in_save_training_reactions
Open

Edit save_training_reactions in family.py to allow use for R_Recombination family#2922
Nora-Khalil wants to merge 1 commit intomainfrom
atomlabels_in_save_training_reactions

Conversation

@Nora-Khalil
Copy link
Copy Markdown
Contributor

@Nora-Khalil Nora-Khalil commented Apr 10, 2026

In save_training_reactions in family.py, this commit allows for training reactions to be added to families that have multiple atoms with the same atom label. Only implemented for R_Recombination as of right now, where two atoms in the product are both labeled as '*' since it is the simple recombination of two radicals and we don't need them individually numbered. I'm not sure if there are other families that do this too. If so, the assert statement in the new code introduced here would just have to be edited.

Motivation or Problem

It's easy to use the ipython/kinetics_library_to_training.ipynb script to add new training reactions to a pre-existing kinetic family. However, if the family has a top-level group definition/recipe that labels multiple atoms in a reactant or product with the same label (i.e. R_Recombination), an error is encountered when we run family.save_training_reactions() to save new training reactions to this family's existing depository.

To see if a new training reaction involves a species that already exists in the training dictionary.txt, the save_training_data function will 1) see if the formula of the species in the new reaction matches any already in the dictionary and 2) if it finds a match, then retrieves the atom labeling for both the matched existing species and the species in the new reaction. However, in the python dict() that is returned from get_all_labeled_atoms, we will get something like this : {'*', [Atom F, Atom C]} in the case of the R_Recomb family (if we're getting the labeling of the product generated from the recombination). For the function to work properly, it's instead expecting something like this {'*': Atom F} or {'*1': Atom H}, so we get an error when the value of the dict() is a list.

Description of Changes

  • If the function encounters a value in the atom labeling dict() that is a list, set a flag to True and propose two different mappings (one of which should pass the isomorphism check performed later if the species does indeed already exist in the dictionary).
  • Run the isomorphism check on all the mappings if we have multiple, or proceed as normal if not.

Testing

To test, I added my new training reactions to R_Recombination via the ipython/kinetics_library_to_training.ipynb notebook (which successfully ran with out errors after these changes were introduced).

To confirm that everything looked good, I loaded the database in a separate script and ran something like:

training_depo_for_R_recomb = database.kinetics.families['R_Recombination'].get_training_depository()
species_in_depo = database.kinetics.families['R_Recombination'].get_species(<path to R_Recomb training dictionary.txt>)

for tr in training_depo_for_R_recomb.entries.values(): 
    if <str unique to my new training reactions> in tr.long_desc:
        display(tr.item)
        print(tr.label)
        
        edited_label_line = tr.label.replace(' <=>', '').replace(' +', '').replace('\n','')
        
        species_involved = edited_label_line.split(' ')

        for spec in species_involved: 
            print(species_in_depo[spec].to_adjacency_list())

To get a bunch of outputs like this:
Screenshot 2026-04-10 at 2 04 14 PM

I then visually confirmed that the atom labeling of the species involved in the new training reactions looks how it should.

Reviewer Tips

just do your best

…ing reactions to be added to families that have multiple atoms with the same atom label. Only implemented for R_Recombination as of right now, where multiple atoms in the products are labeled as '*'.
@Nora-Khalil Nora-Khalil requested a review from rwest April 10, 2026 18:11
@Nora-Khalil
Copy link
Copy Markdown
Contributor Author

Related to 8a057a4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant