ReactionMechanismGenerator / RMG-Py

Python version of the amazing Reaction Mechanism Generator (RMG).
http://reactionmechanismgenerator.github.io/RMG-Py/
Other
400 stars 228 forks source link

Make surface molecules from smiles using Argon workaround #2607

Open sevyharris opened 9 months ago

sevyharris commented 9 months ago

Motivation or Problem

The issue is described here, https://github.com/ReactionMechanismGenerator/RMG-Py/issues/2603, but basically RDKit complains when you try to make a surface molecule using smiles.

Description of Changes

This PR adds a workaround where you initialize the molecule using Ar as a replacement for X to get the adjacency list and then remove the extra pairs of electrons and change Ar back to X to get the originally intended molecule.

Testing

Run this code to test out instantiating all the species in the Surface family training reactions: NOTE TO SELF -- DON'T FORGET TO REBUILD!

import os
import glob
import rmgpy
import rmgpy.chemkin
import rmgpy.molecule

# Get all of the surface training reactions
search_str = os.path.join(rmgpy.settings['database.directory'], 'kinetics', 'families', 'Surface_*', 'training', 'dictionary.txt')
species_dict_files = glob.glob(search_str)

# Test on all the species in surface training reactions
for dict_file in species_dict_files:
    species_dict = rmgpy.chemkin.load_species_dictionary(dict_file)
    for key in species_dict.keys():
        sp = species_dict[key]

        test_smiles = sp.smiles.replace('Pt', 'X')
        test_sp = rmgpy.molecule.Molecule(smiles=test_smiles)

        assert(test_sp.is_isomorphic(sp.molecule[0]))    
github-actions[bot] commented 5 months ago

This pull request 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 pull request, otherwise it will automatically be closed in 30 days.

github-actions[bot] commented 2 months ago

This pull request 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 pull request, otherwise it will automatically be closed in 30 days.

sevyharris commented 1 month ago

This is working with the test code described above, so now I just need to put that into an actual unit test and it'll be ready to go.

sevyharris commented 1 month ago

Unit tests added, but don't work yet because the SMILES string from the rdkit translator's to_smiles() uses 'Pt' instead of 'X'. Need to figure out where is the most appropriate place to make this final translation, but then it should be ready

sevyharris commented 1 month ago

Some mission creep: RMG molecule had no way to distinguish between specific Pt atom and more general surface X atom.

I wanted rmgpy.molecule.Molecule(smiles="[Pt]").to_smiles() to return '[Pt]' and rmgpy.molecule.Molecule(smiles="[X]").to_smiles() to return '[X]', but there was no good way to do this since the internal RMG molecule adjacency list always converted Pt to X and then converted all X's back to Pt in the to_smiles() function.

So, I added a specific Pt atom type with the intention of being able to add other metals later on.

It passes my simple test cases, but now I need to clean up the PR and look for other places this might cause problems for RMG-cat.

sevyharris commented 1 month ago

Richard's working on a related PR: https://github.com/ReactionMechanismGenerator/RMG-Py/pull/2701. The rdkit * might be a more elegant way of doing this than the Ar workaround