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

SmilesWidget: Canonicalize SMILES code #507

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

danielhollas
Copy link
Contributor

@danielhollas danielhollas commented Aug 31, 2023

Canonicalize user-provided SMILES using RDKit. If the canonical name is different from the input SMILES, we print the canonical SMILES.

Test plan:

  1. Input SMILES C=CC1=C(C2=CC=C(C3=CC=CC=C3)C=C2)C=C(C=C)C(C4=CC=C(C(C=C5)=CC=C5C(C=C6C=C)=C(C=C)C=C6C7=CC=C(C(C=C8)=CC=C8C(C=C9C=C)=C(C=C)C=C9C%10=CC=CC=C%10)C=C7)C=C4)=C1

should give you
C=Cc1cc(-c2ccc(-c3ccc(-c4cc(C=C)c(-c5ccc(-c6ccc(-c7cc(C=C)c(-c8ccc(-c9ccccc9)cc8)cc7C=C)cc6)cc5)cc4C=C)cc3)cc2)c(C=C)cc1-c1ccccc1

and should not fail.

I also add a missing error check that caused uncaught exception in #505

Closes #505. Closes #331

@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Patch coverage: 80.00% and project coverage change: +0.02% 🎉

Comparison is base (5038966) 79.42% compared to head (94679cd) 79.44%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #507      +/-   ##
==========================================
+ Coverage   79.42%   79.44%   +0.02%     
==========================================
  Files          27       27              
  Lines        3757     3785      +28     
==========================================
+ Hits         2984     3007      +23     
- Misses        773      778       +5     
Flag Coverage Δ
python-3.10 79.44% <80.00%> (+0.02%) ⬆️
python-3.8 79.48% <80.00%> (+0.01%) ⬆️
python-3.9 79.48% <80.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
aiidalab_widgets_base/structures.py 74.96% <71.42%> (-0.19%) ⬇️
tests/test_structures.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danielhollas danielhollas marked this pull request as ready for review September 4, 2023 00:46
Copy link
Member

@cpignedoli cpignedoli left a comment

Choose a reason for hiding this comment

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

I tested in on my local instance and it works. It does not fix an open problem I have with a SMILE, that I never reported:
CC1=C(C)C(C2=C3C=CC4=C(C5=C(C)C(C)=C(C6=C(C=CC=C7)C7=CC8=C6C=CC=C8)C(C)=C5C)C9=CC=C%10N9[Fe]%11(N%12C(C=CC%12=C(C%13=C(C)C(C)=C(C%14=C(C=CC=C%15)C%15=CC%16=C%14C=CC=C%16)C(C)=C%13C)C%17=CC=C2N%17%11)=C%10C%18=C(C)C(C)=C(C%19=C(C=CC=C%20)C%20=CC%21=C%19C=CC=C%21)C(C)=C%18C)N43)=C(C)C(C)=C1C%22=C(C=CC=C%23)C%23=CC%24=C%22C=CC=C%24

image

@danielhollas
Copy link
Contributor Author

@cpignedoli thanks for taking a look. Can you please open a new issue for this new SMILES?

Interestingly, in my application that generates multiple conformers it works. It looks like passing useRandomCoordinates into EmbedMolecule fixes the issue. But let's deal with that in a separate PR.

@cpignedoli cpignedoli mentioned this pull request Sep 5, 2023
Copy link
Member

@yakutovicha yakutovicha left a comment

Choose a reason for hiding this comment

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

The code looks good to me. Provided that @cpignedoli tested it, I approve 👍

@danielhollas danielhollas added the enhancement New feature or request label Sep 6, 2023
@danielhollas danielhollas self-assigned this Sep 6, 2023
@danielhollas danielhollas merged commit 96d589d into aiidalab:master Sep 6, 2023
7 checks passed
@danielhollas danielhollas deleted the canonical-smiles branch September 6, 2023 14:03
danielhollas added a commit that referenced this pull request Sep 6, 2023
Use RdKit to canonicalize the SMILES code given from the user.
When the canonical SMILES differs from the input, print it.
Apparently, some SMILES failed to generate conformer when they were not canonicalized. 
Closes #505 and #331
unkcpz added a commit to unkcpz/aiidalab-widgets-base that referenced this pull request Nov 16, 2023
* fix pseudodojo in report and load_panel_value
* Refactoring of pseudo selector widget, renamed the protocol name.
* add test for pseudodojo

---------

Co-authored-by: Jusong Yu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG in Smiles Widget SmilesWidget: Canonicalize input SMILES string
3 participants