Package: janus-ga
JANUS: Parallel Tempered Genetic Algorithm Guided by Deep Neural Networks for Inverse Molecular DesignThis repository contains code for the paper:JANUS: Parallel Tempered Genetic Algorithm Guided by Deep Neural Networks for Inverse Molecular Design.Originally by: AkshatKumar Nigam, Robert Pollice, Alán Aspuru-GuzikUpdated by: Gary TomPrerequsites:UsePython 3.7 or up.You will need to separately installRDKitversion >= 2020.03.1. The easiest is to do this on conda.JANUS usesSELFIESversion 1.0.3. If you want to use a different version, pip install your desired version; this package will still be compatible. Note that you will have to change your input alphabets to work with other versions of SELFIES.Major changes:Support the use of any version of SELFIES (please check your installation).Improved multiprocessing. Fitness function is not parallelized, in the case that the function already spawns multiple processes.GPU acceleration of neural networks.Early stopping for classifier.Included SMILES filtering option.Additional hyperparameters for controlling JANUS. Defaults used in paper are given intestsdirectory.How to run:Install JANUS usingpipinstalljanus-gaExample script of how to use JANUS is found intests/example.py:fromjanusimportJANUS,utilsfromrdkitimportChem,RDLoggerfromrdkit.ChemimportAllChem,RDConfig,DescriptorsRDLogger.DisableLog("rdApp.*")importselfiesdeffitness_function(smi:str)->float:""" User-defined function that takes in individual smilesand outputs a fitness value."""# logP fitnessreturnDescriptors.MolLogP(Chem.MolFromSmiles(smi))defcustom_filter(smi:str):""" Function that takes in a smile and returns a boolean.True indicates the smiles PASSES the filter."""# smiles length filteriflen(smi)>81orlen(smi)==0:returnFalseelse:returnTrue# all parameters to be set, below are defaultsparams_dict={# Number of iterations that JANUS runs for"generations":200,# The number of molecules for which fitness calculations are done,# exploration and exploitation each have their own population"generation_size":5000,# Number of molecules that are exchanged between the exploration and exploitation"num_exchanges":5,# Callable filtering function (None defaults to no filtering)"custom_filter":custom_filter,# Fragments from starting population used to extend alphabet for mutations"use_fragments":True,# An option to use a classifier as selection bias"use_classifier":True,}# Set your SELFIES constraints (below used for manuscript)default_constraints=selfies.get_semantic_constraints()new_constraints=default_constraintsnew_constraints['S']=2new_constraints['P']=3selfies.set_semantic_constraints(new_constraints)# update constraints# Create JANUS object.agent=JANUS(work_dir='RESULTS',# where the results are savedfitness_function=fitness_function,# user-defined fitness for given smilesstart_population="./DATA/sample_start_smiles.txt",# file with starting smiles population**params_dict)# Alternatively, you can get hyperparameters from a yaml file# Descriptions for all parameters are found in default_params.ymlparams_dict=utils.from_yaml(work_dir='RESULTS',fitness_function=fitness_function,start_population="./DATA/sample_start_smiles.txt",yaml_file='default_params.yml',# default yaml file with parameters**params_dict# overwrite yaml parameters with dictionary)agent=JANUS(**params_dict)# Run according to parametersagent.run()# RUN IT!Within this file are examples for:A function for calculting property values (see functionfitness_function).Custom filtering of SMILES (see functioncustom_filter).Initializing JANUS from dictionary of parameters.Generating hyperparameters from provided yaml file (see functionjanus.utils.from_yaml).You can run the file with provided test filescdtests
python./example.pyImportant parameters the user should provide:work_dir: directory for outputting resultsfitness_function: fitness function defined for an input smiles that will be maximizedstart_population: path to text file of starting smiles one each new linegenerations: number if evolution iterations to performgeneration_size: number of molecules in the populations per generationcustom_filter: filter function checked after mutation and crossover, returnsTruefor accepted moleculesuse_fragments: toggle adding fragments from starting population to mutation alphabetuse_classifier: toggle using classifier for selection biasSeetests/default_params.ymlfor detailed description of adjustable parameters.Outputs:All results from running JANUS will be stored in specifiedwork_dir.The following files will be created:fitness_explore.txt:
Fitness values for all molecules from the exploration component of JANUS.fitness_local_search.txt:
Fitness values for all molecules from the exploitation component of JANUS.generation_all_best.txt:
Smiles and fitness value for the best molecule encountered in every generation (iteration).init_mols.txt:
List of molecules used to initialte JANUS.population_explore.txt:
SMILES for all molecules from the exploration component of JANUS.population_local_search.txt:
SMILES for all molecules from the exploitation component of JANUS.hparams.json:
Hyperparameters used for initializing JANUS.Paper Results/Reproducibility:Our code and results for each experiment in the paper can be found here:Experiment 4.1:https://drive.google.com/file/d/1rscIyzpTvtyiEkoP1WsF-XtSHJGQStUU/view?usp=sharingExperiment 4.3:https://drive.google.com/file/d/1tlIdfSWwzVeJ5kZ98l8G6osE9zf9wP1f/view?usp=sharingGuacaMol:https://drive.google.com/file/d/1FqetwNg6VVc-C3eiPoosGZ4-47WpYBAt/view?usp=sharingQuestions, problems?Make a github issue 😄. Please be as clear and descriptive as possible. Please feel free to reach
out in person: (akshat[DOT]nigam[AT]mail[DOT]utoronto[DOT]ca, rob[DOT]pollice[AT]utoronto[DOT]ca)LicenseApache License 2.0