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

Invalid SMARTS generated by MolToSmarts #4981

Closed
nielskm opened this issue Feb 3, 2022 · 2 comments
Closed

Invalid SMARTS generated by MolToSmarts #4981

nielskm opened this issue Feb 3, 2022 · 2 comments
Labels
Milestone

Comments

@nielskm
Copy link
Contributor

nielskm commented Feb 3, 2022

Describe the bug
Chem.MolToSmarts returns a SMARTS string which is invalid when converted back to a molecule using Chem.MolFromSmarts.

Original SMARTS: [NX3H2+0,NX4H3+;!$([N][!C]);!$([N]*~[#7,#8,#15,#16])]
RDKit SMARTS generated by Chem.MolToSmarts: [N&X3&H2&+0,N&X4&H3&+;!$(N!C);!$(N*~[#7,#8,#15,#16])]

The error is in the $(N!C) part. If I change back to $([N][!C]) the SMARTS become valid.

I have seen this bug with multiple different SMARTS strings, and all seem to involve a removal of square brackets around a !C (or other atoms).

To Reproduce

smarts = [NX3H2+0,NX4H3+;!$([N][!C]);!$([N]*~[#7,#8,#15,#16])]
mol = Chem.MolFromSmarts(smarts)
rdsmarts = Chem.MolToSmarts(mol)
mol2 = Chem.MolFromSmarts(rdsmarts)  # mol2 is None

Expected behavior
The SMARTS returned by Chem.MolToSmarts should be valid.

Configuration (please complete the following information):

  • RDKit version: 2021.09.4
  • OS: Ubuntu 20.04 on WSL2 (Windows 10)
  • Python version: 3.9.10
  • Are you using conda? Yes
  • If you are using conda, which channel did you install the rdkit from? conda-forge
@nielskm nielskm added the bug label Feb 3, 2022
@greglandrum
Copy link
Member

confirmed. Thanks for the bug report.

@greglandrum greglandrum added this to the 2021_09_5 milestone Feb 8, 2022
@greglandrum
Copy link
Member

And here's an even simpler simple reproducible:

In [6]: Chem.MolToSmarts(Chem.MolFromSmarts('[!C]'))
Out[6]: '!C'

greglandrum added a commit to greglandrum/rdkit that referenced this issue Feb 22, 2022
greglandrum added a commit that referenced this issue Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants