Does the SMILE (or Simplified Molecular Input Line Entry System) code have an EBNF definition ? https://en.wikipedia.org/wiki/Simplified_Molecular_Input_Lin... Claims there is a context free grammar.
Parsing Chemistry
21–30 of 30 posts
Re: Parsing Chemistry
#22Earlier quoted context omitted.
I'd be really interested to know of anybody making money with those topics (and doesn't already have their own domain-specific practice for the problem)
Cheminformatics is such an example. Heavily used in computational drug discovery.
Re: Parsing Chemistry
#23Earlier quoted context omitted.
SMILES and SELFIES are molecular graph representations and aren't meant to solve the "parse this sum formula" problem. SELFIES are for genAI. If you ask a VAE to generate SMILES, it will spit out some strings that are invalid - can't happen with SELFIES, that is the one application where they are robust.
It's still being argued if you really need SELFIES, or if SMILES autoencoders can be trained to only generate valid molecules, or if generating invalid molecules is useful (I'm in camp SELFIES, but I also want better ways to represent and learn on graphical chemical structures, ratehr than serialized strings).
Re: Parsing Chemistry
#24Earlier quoted context omitted.
It's still being argued if you really need SELFIES, or if SMILES autoencoders can be trained to only generate valid molecules, or if generating invalid molecules is useful (I'm in camp SELFIES, but I also want better ways to represent and learn on graphical chemical structures, ratehr than serialized strings).
can you guys explain what makes SELFIES robust? I'd only heard of SMILES until this thread, but I have been out of this space for 10 years.
The VAE is trained with a very large number of valid SMILES strings, typically tokenized at the character level (so "C" is a token, and "Br" is "B" then "r"). I and others have observed that VAEs trained like this produce large number of embedding vectors that do not decode to valid SMILES strings- they have syntax errors, or perform chemical alchemy (personally, I saw the training set had Br (bromine) and Ca (Calcium), and the output molecules sometimes were Ba (barium) even though that's not in the original dataset at all.
There are other reasons why the tokenizer produces bad results- only about 1-10% of vectors decode to valid molecules. Invalid SMILES are mostly useless- they don't correspond to actual structures.
To respond to this, the SELFIES format makes a few changes so that it is effectively impossible to produce invalid SELFIES stringes when decoding a VAE. Among other things, tokenization matches the actual elements and so the model will only ever output valid elements.
I believe this is the SMILES paper that my own experiments were based on: https://arxiv.org/pdf/1610.02415 (see https://github.com/maxhodak/keras-molecules for an open source attempt at implementation)
And this is the paper introducing SELFIES: https://arxiv.org/abs/1905.13741 (open source packages for working with SELFIES, and some example training scripts https://github.com/aspuru-guzik-group/selfies see "Validity of Latent Space in VAE SMILES vs. SELFIES for more detail on the robustness).
BTW, as a side note: even though we put a bunch of effort into duplicating the original SMILES VAE, it was extremely slow to train and not very useful. Now you can just ask Gemini to write a full SELFIES VAE and train it in less than a day on a conventional GPU (thanks pytorch transformers!) to get a decent basic set of embeddings useful for exploring chemical space.
Re: Parsing Chemistry
#25Earlier quoted context omitted.
can you guys explain what makes SELFIES robust? I'd only heard of SMILES until this thread, but I have been out of this space for 10 years.
Let me start with an example- some time ago I worked on a VAE that encoded and decoded SMILES strings. The idea is that you should be able to encode a SMILES into an embedding space, do all the normal things you would do in that space, and then convert the resulting embedding vector back to a valid molecule. The VAE is trained with a very large number of valid SMILES strings, typically tokenized at the character leve…
Re: Parsing Chemistry
#26Earlier quoted context omitted.
Let me start with an example- some time ago I worked on a VAE that encoded and decoded SMILES strings. The idea is that you should be able to encode a SMILES into an embedding space, do all the normal things you would do in that space, and then convert the resulting embedding vector back to a valid molecule. The VAE is trained with a very large number of valid SMILES strings, typically tokenized at the character leve…
Thanks, that's very interesting! Naive question, but why couldn't you force a specific tokenization scheme on SMILES? Specifically, just one token per element? I understand SELFIES does more, but your example of Ba/Br made me wonder.
Re: Parsing Chemistry
#27Does the SMILE (or Simplified Molecular Input Line Entry System) code have an EBNF definition ? https://en.wikipedia.org/wiki/Simplified_Molecular_Input_Lin... Claims there is a context free grammar.
I wrote a very simple SMILES parser using pyparsing https://github.com/dakoner/smilesparser/tree/master I wouldn't say it's intended for production work, but it has been useful in situations where I didn't want to pull in rdkit.
You also define Chain as:
Chain
I believe this means your grammar allows the invalid SMILES C=.NRe: Parsing Chemistry
#28Does the SMILE (or Simplified Molecular Input Line Entry System) code have an EBNF definition ? https://en.wikipedia.org/wiki/Simplified_Molecular_Input_Lin... Claims there is a context free grammar.
That's "SMILES". Yes. Here is the yacc grammar for the SMILES parser in the RDKit. https://github.com/rdkit/rdkit/blob/master/Code/GraphMol/Smi... There's also one from OpenSMILES at http://opensmiles.org/opensmiles.html#_grammar . It has a shift/reduce error (as I recall) that I was not competent enough to fix. I prefer to parser almost completely in the lexer, with a small amount of lexer state to handle balanced p…
The lexer: https://hg.sr.ht/~dalke/smiview/browse/smiview.py?rev=tip#L3...
The lexer state transitions: https://hg.sr.ht/~dalke/smiview/browse/smiview.py?rev=tip#L3...
Re: Parsing Chemistry
#29Earlier quoted context omitted.
Thanks, that's very interesting! Naive question, but why couldn't you force a specific tokenization scheme on SMILES? Specifically, just one token per element? I understand SELFIES does more, but your example of Ba/Br made me wonder.
I asked the authors of the original SMILES paper and they didn't have a good answer. I wrote a parser for SMILES so I could tokenize that way but never followed up, and eventually SELFIES was announced.
Re: Parsing Chemistry
#30Earlier quoted context omitted.
I'd be really interested to know of anybody making money with those topics (and doesn't already have their own domain-specific practice for the problem)
Cheminformatics is such an example. Heavily used in computational drug discovery.