Package: safe-mol
:safety_vest: SAFESequentialAttachment-basedFragmentEmbedding (SAFE) is a novel molecular line notation that represents molecules as an unordered sequence of fragment blocks to improve molecule design using generative models.Paper|Docs|🤗 Model|🤗 Training DatasetOverview of SAFESAFEis thedeep learning molecular representation. It's an encoding leveraging a peculiarity in the decoding schemes of SMILES, to allow representation of molecules as a contiguous sequence of connected fragments. SAFE strings are valid SMILES strings, and thus are able to preserve the same amount of information. The intuitive representation of molecules as an ordered sequence of connected fragments greatly simplifies the following tasks often encountered in molecular design:de novodesignsuperstructure generationscaffold decorationmotif extensionlinker generationscaffold morphing.The construction of a SAFE strings requires defining a molecular fragmentation algorithm. By default, we use [BRICS], but any other fragmentation algorithm can be used. The image below illustrates the process of building a SAFE string. The resulting string is a valid SMILES that can be read bydatamolorRDKit.News2024/01/15@IanAWatsonhas a C++ implementation of SAFE inLillyMolthat is quite fast and use a custom fragmentation algorithm. Follow the installation instruction on the repo and checkout the docs of the CLI here:docs/Molecule_Tools/SAFE.mdInstallationYou can installsafeusing pip:pipinstallsafe-molYou can use conda/mamba:mambainstall-cconda-forgesafe-molDatasets and ModelsTypeNameInfosSizeCommentModeldatamol-io/safe-gpt87M params350MDefault modelTraining Datasetdatamol-io/safe-gpt1.1B rows250GBTraining datasetDrug Benchmark Datasetdatamol-io/safe-drugs26 rows20 kBBenchmarking datasetUsagePlease refer to thedocumentation, which contains tutorials for getting started withsafeand detailed descriptions of the functions provided, as well as an example of how to get started with SAFE-GPT.APIWe summarize some key functions provided by thesafepackage below.FunctionDescriptionsafe.encodeTranslates a SMILES string into its corresponding SAFE string.safe.decodeTranslates a SAFE string into its corresponding SMILES string. The SAFE decoder just augment RDKit'sChem.MolFromSmileswith an optional correction argument to take care of missing hydrogen bonds.safe.splitTokenizes a SAFE string to build a generative model.ExamplesTranslation between SAFE and SMILES representationsimportsafeibuprofen="CC(Cc1ccc(cc1)C(C(=O)O)C)C"# SMILES -> SAFE -> SMILES translationtry:ibuprofen_sf=safe.encode(ibuprofen)# c12ccc3cc1.C3(C)C(=O)O.CC(C)C2ibuprofen_smi=safe.decode(ibuprofen_sf,canonical=True)# CC(C)Cc1ccc(C(C)C(=O)O)cc1exceptsafe.EncoderError:passexceptsafe.DecoderError:passibuprofen_tokens=list(safe.split(ibuprofen_sf))Training/Finetuning a (new) modelA command line interface is available to train a new model, please runsafe-train --help. You can also provide an existing checkpoint to continue training or finetune on you own dataset.For example:safe-train--config<pathtoconfig>\--model-path<pathtomodel>\--tokenizer<pathtotokenizer>\--dataset<pathtodataset>\--num_labels9\--torch_compileTrue\--optim"adamw_torch"\--learning_rate1e-5\--prop_loss_coeff1e-3\--gradient_accumulation_steps1\--output_dir"<path to outputdir>"\--max_steps5ReferencesIf you use this repository, please cite the following relatedpaper:@misc{noutahi2023gotta,title={Gotta be SAFE: A New Framework for Molecular Design},author={Emmanuel Noutahi and Cristian Gabellini and Michael Craig and Jonathan S. C Lim and Prudencio Tossou},year={2023},eprint={2310.10773},archivePrefix={arXiv},primaryClass={cs.LG}}LicenseNote that all data and model weights ofSAFEare exclusively licensed for research purposes. The accompanying dataset is licensed under CC BY 4.0, which permits solely non-commercial usage. SeeDATA_LICENSEfor details.This code base is licensed under the Apache-2.0 license. SeeLICENSEfor details.Development lifecycleSetup dev environmentmambacreate-nsafe-fenv.yml
mambaactivatesafe

pipinstall--no-deps-e.TestsYou can run tests locally with:pytest