Package: rxn-biocatalysis-tools
:leaves: Biocatalysis ModelBiocatalysed Synthesis Planning using Data-driven LearningTable of ContentsAbstractDataECREACTData SourcesUsing the Pre-trained ModelTraining your own ModelSetup EnvironmentData Pre-processingTraining using OpenNMT-pyEvaluationAbstractEnzyme catalysts are an integral part of green chemistry strategies towards a more sustainable and resource-efficient chemical synthesis. However, the use of biocatalysed reactions in retrosynthetic planning clashes with the difficulties in predicting the enzymatic activity on unreported substrates and enzyme-specific stereo- and regioselectivity. As of now, only rule-based systems support retrosynthetic planning using biocatalysis, while initial data-driven approaches are limited to forward predictions. Here, we extend the data-driven forward reaction as well as retrosynthetic pathway prediction models based on the Molecular Transformer architecture to biocatalysis. The enzymatic knowledge is learned from an extensive data set of publicly available biochemical reactions with the aid of a new class token scheme based on the enzyme commission classification number, which captures catalysis patterns among different enzymes belonging to the same hierarchy. The forward reaction prediction model (top-1 accuracy of 49.6%), the retrosynthetic pathway (top-1 single-step round-trip accuracy of 39.6%) and the curated data set are made publicly available to facilitate the adoption of enzymatic catalysis in the design of greener chemistry processes.DataEnzymatic reactions and the accompanying EC numbers were extracted from four databases, namely Rhea, BRENDA, PathBank, and MetaNetX and merged into a new data set, named ECREACT, containing enzyme-catalysed reactions with the respective EC number.ECREACTThe ECREACT data set contains samples of all 7 EC classes (1: Oxidoreductases, 2: Transferases, 3: Hydrolases, 4: Lyases, 5: Isomerases, 6: Ligases, 7: Translocases) distributed as shown in (a). The distributions of the substrates and products are shown in the TMAPS (b) and (c) respectively.The data set is available as a.csvfile in the following format:rxn_smiles,ec,source
CC=O.O.O=O|1.2.3.1>>CC(=O)[O-],1.2.3.1,brenda_reaction_smiles
CC(N)=O.O|3.5.1.4>>CC(=O)O,3.5.1.4,brenda_reaction_smiles
...The fieldrxn_smilesis a reaction SMILES extended with the EC number on the reactant side. The reactants and the EC number are separated by a pipe|. The fieldecis the EC number. Be aware that they can also contain entries such as1.20.1.M1or1.14.-.-. The fieldsourcedescribes the source database of the reaction information.Download ECREACT 1.0Data SourcesECREACT is composed of data from four publicly accessible databases:Rhea, an expert-curated knowledgebase of chemical and transport reactions of biological interest - and the standard for enzyme and transporter annotation in UniProtKB.:file_cabinet:BRENDA, an information system representing one of the most comprehensive enzyme repositories.:file_cabinet:PathBank, an interactive, visual database containing more than 100 000 machine-readable pathways found in model organisms such as humans, mice, E. coli, yeast, and Arabidopsis thaliana.:file_cabinet:MetaNetX, an online platform for accessing, analyzing and manipulating genome-scale metabolic networks (GSM) as well as biochemical pathways.:file_cabinet:The contributions by EC class from each of the data sources is shown in the plot below.Using the Pre-trained ModelWe provide a model for retrosynthetic pathway prediction pre-trained on ECREACT as part of theIBM RXN for Chemistryplatform. This model can also be used through thePython wrapperfor the IBM RXN for Chemistry API. You can get a free API keyhere.api_key='API_KEY'fromrxn4chemistryimportRXN4ChemistryWrapperrxn4chemistry_wrapper=RXN4ChemistryWrapper(api_key=api_key)# NOTE: you can create a project or set an esiting one using:# rxn4chemistry_wrapper.set_project('PROJECT_ID')rxn4chemistry_wrapper.create_project('test_wrapper')print(rxn4chemistry_wrapper.project_id)response=rxn4chemistry_wrapper.predict_automatic_retrosynthesis('OC1C(O)C=C(Br)C=C1',ai_model='enzymatic-2021-04-16')results=rxn4chemistry_wrapper.get_predict_automatic_retrosynthesis_results(response['prediction_id'])print(results['status'])# NOTE: upon 'SUCCESS' you can inspect the predicted retrosynthetic paths.print(results['retrosynthetic_paths'][0])Training your own ModelSetup EnvironmentAs not all dependencies are available from PyPI for all platforms, we suggest you create a conda environment from the suppliedconda.yml:condaenvcreate-fconda.yml
condaactivaterxn-biocatalysis-toolsAlternatively, :leaves: RXN Biocatalysis Tools are available as a PyPI package and can be installed usining pip; however, not all dependencies will be installed depending on your platform.pipinstallrxn_biocatalysis_toolsData Pre-processingThe :leaves: RXN Biocatalysis Tools Python package installs a script that can be used to preprocess reaction data. Reaction data can be combined, filtered, or augmented as explained in the usage documentation below. After these initial steps, the data is tokenized and split into training, validation, and testingsrc(reactants + EC) andtgt(product/s) files. The output data structure generated by the script is the following, depending on the options set..
└──experiments├──1│├──combined.txt│├──src-test.txt│├──src-train.txt│├──src-valid.txt│├──tgt-test.txt│├──tgt-train.txt│└──tgt-valid.txt├──2│├──combined.txt│├──src-test.txt│├──src-train.txt│├──src-valid.txt│├──tgt-test.txt│├──tgt-train.txt│└──tgt-valid.txt└──3├──combined.txt├──src-test.txt├──src-train.txt├──src-valid.txt├──tgt-test.txt├──tgt-train.txt└──tgt-valid.txtUsage of the script:rbt-preprocessINPUT_FILE...OUTPUT_DIRECTORY[--remove-patterns=FILE_PATH][--remove-molecules=FILE_PATH][--ec-level=LEVEL;default=3][-max-products=MAX_PRODUCTS;default=1][--min-atom-count=MIN_ATOM_COUNT;default=4][--bi-directional][--split-products]Argument / OptionExampleDescriptionDefaultINPUT_FILE ...file1.csv file2.csvFile(s) containing enzymatic reaction SMILES1OUTPUT_DIRECTORY/output/directory/The directory to which output files will be written--remove-patternspatterns.txtSMARTS patterns for molecules to be removed2--remove-moleculesmolecules.txtMolecule SMILES to be removed3--ec-level--ec-level 1 --ec-level 2The number of EC levels to be exported, can be repreated3--max-products--max-products 1The max number of products (rxns with more are dropped)1--min-atom-count--min-atom-count 4The min atom count (smaller molecules are removed)4--bi-directional--bi-directionalWhether to create the inverse of every reaction4--split-products--split-productsWhether to split reactions with multiple prodcuts51Example of an enzymatic reaction SMILES:CC(N)=O.O|3.5.1.4>>CC(=O)O2Seepatterns.txtfor an example3Seemolecules.txtfor an example4Example: For the reactionCC(N)=O.O|3.5.1.4>>CC(=O)O, the reactionCC(=O)O|3.5.1.4>>CC(N)=O.Owill be added5Example: The reactionA|3.5.1.4>>B.Cis split into reactionsA|3.5.1.4>>BandA|3.5.1.4>>CTraining using OpenNMT-pyThe first step in the OpenNMT is to runonmt_preprocessfor both the forward and backward models. In the examples below, the data with 3 EC-levels is used. You will probably have to adapt the paths, depending on your directory structure and platform.The pre-processed USPTO files can be foundhere.DATASET=data/uspto_datasetDATASET_TRANSFER=experiments/3# forwardonmt_preprocess-train_src"${DATASET}/src-train.txt""${DATASET_TRANSFER}/src-train.txt"\-train_tgt"${DATASET}/tgt-train.txt""${DATASET_TRANSFER}/tgt-train.txt"-train_idsusptotransfer\-valid_src"${DATASET}/src-valid.txt"-valid_tgt"${DATASET_TRANSFER}/tgt-valid.txt"\-save_data"preprocessing/multitask_forward"\-src_seq_length3000-tgt_seq_length3000\-src_vocab_size3000-tgt_vocab_size3000\-share_vocab# backwardonmt_preprocess-train_src"${DATASET}/tgt-train.txt""${DATASET_TRANSFER}/tgt-train.txt"\-train_tgt"${DATASET}/src-train.txt""${DATASET_TRANSFER}/src-train.txt"-train_idsusptotransfer\-valid_src"${DATASET}/tgt-valid.txt"-valid_tgt"${DATASET_TRANSFER}/src-valid.txt"\-save_data"preprocessing/multitask_backward"\-src_seq_length3000-tgt_seq_length3000\-src_vocab_size3000-tgt_vocab_size3000\-share_vocabOnce the OpenNMT pre-preprocessing has finished, the actual training can be started:# if forwardDATASET="preprocessing/multitask_forward"OUTDIR="/model/multitask_forward"LOGDIR="/logs/forward"# end if# if backwardDATASET="preprocessing/multitask_backward"OUTDIR="model/multitask_backward"LOGDIR="logs/backward"# end ifW1=9W2=1onmt_train-data${DATASET}\-save_model${OUTDIR}\-data_idsusptotransfer--data_weights${W1}${W2}\-seed42-gpu_ranks0\-train_steps250000-param_init0\-param_init_glorot-max_generator_batches32\-batch_size6144-batch_typetokens\-normalizationtokens-max_grad_norm0-accum_count4\-optimadam-adam_beta10.9-adam_beta20.998-decay_methodnoam\-warmup_steps8000-learning_rate2-label_smoothing0.0\-layers4-rnn_size384-word_vec_size384\-encoder_typetransformer-decoder_typetransformer\-dropout0.1-position_encoding-share_embeddings\-global_attentiongeneral-global_attention_functionsoftmax\-self_attn_typescaled-dot-heads8-transformer_ff2048\--tensorboard--tensorboard_log_dir${LOGDIR}EvaluationThe test set is evaluated usingonmt_translate. Three new files are generated:tgt-pred.txt(forward prediction)src-pred.txt(backward prediction)tgt-pred-rtrp.txt(roundtriip prediction, a backward prediction followed by a forward prediction)Before the roundtrip prediction, the SMILES insrc-pred.txtshould be standardized using the scriptrbt-preprocess. The script does not edit the file in place, so good practise is to renamesrc-pred.txttosrc-pred-noncanon.txtand then run:rbt-canonicalizesrc-pred-noncanon.txtsrc-pred.txtExample evaluation scripts:# forward predictionDATASET_TRANSFER="experiments/3"# Get the newest file from the model directoryMODEL=$(lsmodel/multitask_forward*.pt-t|head-1)onmt_translate-model"${MODEL}"\-src"${DATASET_TRANSFER}/src-test.txt"\-output"${DATASET_TRANSFER}/tgt-pred.txt"\-n_best10-beam_size10-max_length300-batch_size64\-gpu0# backward predictionDATASET_TRANSFER="experiments/3"# Get the newest file from the model directoryMODEL=$(lsmodel/multitask_backward*.pt-t|head-1)onmt_translate-model"${MODEL}"\-src"${DATASET_TRANSFER}/tgt-test.txt"\-output"${DATASET_TRANSFER}/src-pred.txt"\-n_best10-beam_size10-max_length300-batch_size64\-gpu0# roundtrip predictionDATASET_TRANSFER="experiments/3"# Get the newest file from the model directoryMODEL=$(lsmodel/multitask_forward*.pt-t|head-1)onmt_translate-model"${MODEL}"\-src"${DATASET_TRANSFER}/src-pred.txt"\-output"${DATASET_TRANSFER}/tgt-pred-rtrp.txt"\-n_best1-beam_size5-max_length300-batch_size64\-gpu0The :leaves: RXN Biocatalysis Tools PyPI package contains an evaluation script that calculates accuracies from the files produced above. For these examples, theINPUT_FOLDERis the same asDATASET_TRANSFER,--n-best-fw,--top-n-fw,--top-n-bw,--top-n-rtrare all set to10.rbt-evaluateINPUT_FOLDER--name=NAME[--n-best-fw=N_BEST_FW;default=5][--n-best-bw=N_BEST_BW;default=10][--n-best-rtr=N_BEST_RTR;default=1][--top-n-fw=TOP_N_FW;default=1][--top-n-fw=TOP_N_FW;default=1][--top-n-bw=TOP_N_BW;default=1][--top-n-rtr=TOP_N_RTR;default=1][--top-n-range][--isomeric-smiles|--no-isomeric-smiles;default:--isomeric-smiles]Argument / OptionExampleDescriptionDefaultINPUT_FOLDER/input/directory/The folder containing the src and tgt files--nameexperiment-3The name of the output evaluation csv file--n-best-fw--n-best-fw 10The number of calculated tgt predictions per src5--n-best-bw--n-best-bw 10The number of calculated src predictions per tgt10--n-best-rtr--n-best-rtr 1The number of calculated (roundtrip) tgt predictions per predicted src1--top-n-fw--top-n-fw 10The number of forward predictions to consider in the evaluation1--top-n-bw--top-n-bw 10The number of backward predictions to consider in the evaluation1--top-n-rtr--top-n-rtr 10The number of roundtrip predictions to consider in the evaluation1--top-n-range--top-n-rangeWhether to consider the forward, backward, and roundtrip predictionsup tothe respective top-n numbers in the evaluation--isomeric-smiles--isomeric-smilesDonotignore stereochemistry during the evaluation--no-isomeric-smiles--no-isomeric-smilesIgnore stereochemistry during the evaluationThe evaluation will produce multiple new files inINPUT_FOLDER: A.csvfile with the fieldsmetric,type,top,ec, andvalue; and multiple files containing correct and incorrect forward, backward, and roundtrip predictions for each top-n. In addition, the accuracy ofonlypredicting the EC number is calculated and the respective files written out as well.