Molecular grammar is a new chemical representation designed to provide faultless generation of organic structures
pip install git+https://github.com/sergsb/LegoGram.git
from legogram import LegoGram, pretrained
model = LegoGram(load=pretrained.M_250k)
mol = 'COC(=O)Cc1csc(NC(=O)Cc2coc3cc(C)ccc23)n1'
encoded = model.encode(mol)`
model.decode(encoded) == "COC(=O)Cc1csc(NC(=O)Cc2coc3cc(C)ccc23)n1" #It's a toy example. In production compare by InChI
>>True
mol = 'COC(=O)Cc1csc(NC(=O)Cc2coc3cc(C)ccc23)n1'
noncompressed = model.encode(mol)
compressed = model.encode(mol,optimize=True)
print("SMILES len = {}, uncomressed grammar = {}, comressed grammar = {}".format(len(mol),len(noncompressed),len(compressed))
>> SMILES len = 40, uncomressed grammar = 26, comressed grammar = 14
model = legogram.LegoGram(smiles="legogram/data/250k_rndm_zinc_drugs_clean.smi", optimize_limit=100)
Check source code for documentation: "legogram.py" for base interface, "apps/" for usage plugins.
This library was described in my PhD Thesis (Chapter 6). Sosnin, Sergey (2021): Exploration of Chemical Space by Machine Learning. figshare. Thesis. https://doi.org/10.6084/m9.figshare.14160683.v1