Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make surface molecules from smiles using Argon workaround #2607

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sevyharris
Copy link
Contributor

@sevyharris sevyharris commented Feb 7, 2024

Motivation or Problem

The issue is described here, #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]))    

@sevyharris sevyharris self-assigned this Feb 7, 2024
@sevyharris sevyharris linked an issue Feb 7, 2024 that may be closed by this pull request
Copy link
Member

@rwest rwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Could we have a couple unit tests? I think there are some templates to copy. Can we do a round-trip (i.e. generate SMILES-like strings with X in, that reproduce the original molecule on import)?

Copy link

github-actions bot commented Jun 7, 2024

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 github-actions bot added the stale stale issue/PR as determined by actions bot label Jun 7, 2024
@sevyharris sevyharris removed the stale stale issue/PR as determined by actions bot label Jun 7, 2024
Copy link

github-actions bot commented Sep 6, 2024

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 github-actions bot added the stale stale issue/PR as determined by actions bot label Sep 6, 2024
@sevyharris sevyharris removed the stale stale issue/PR as determined by actions bot label Sep 6, 2024
@sevyharris
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

Richard's working on a related PR: #2701. The rdkit * might be a more elegant way of doing this than the Ar workaround

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

Successfully merging this pull request may close these issues.

Can't construct surface rmgpy.molecule.Molecule()
2 participants