RetCL: A Selection-based Approach for Retrosynthesis via Contrastive Learning

Retrosynthesis , of which the goal is to find a set of reactants for synthesizing a target product , is an emerging research area of deep learning . While the existing approaches have shown promising results , they currently lack the ability to consider availability ( e.g. , stability or purchasability ) of the reactants or generalize to unseen reaction templates ( i.e. , chemical reaction rules ) . In this paper , we propose a new approach that mitigates the issues by reformulating retrosynthesis into a selection problem of reactants from a candidate set of commercially available molecules . To this end , we design an efficient reactant selection framework , named RETCL ( retrosynthesis via contrastive learning ) , for enumerating all of the candidate molecules based on selection scores computed by graph neural networks . For learning the score functions , we also propose a novel contrastive training scheme with hard negative mining . Extensive experiments demonstrate the benefits of the proposed selection-based approach . For example , when all 671k reactants in the USPTO database are given as candidates , our RETCL achieves top-1 exact match accuracy of 71.3 % for the USPTO-50k benchmark , while a recent transformer-based approach achieves 59.6 % . We also demonstrate that RETCL generalizes well to unseen templates in various settings in contrast to template-based approaches . The code will be released . 1 INTRODUCTION . Retrosynthesis ( Corey , 1991 ) , finding a synthetic route starting from commercially available reactants to synthesize a target product ( see Figure 1a ) , is at the center of focus for discovering new materials in both academia and industry . It plays an essential role in practical applications by finding a new synthetic path , which can be more cost-effective or avoid patent infringement . However , retrosynthesis is a challenging task that requires searching over a vast number of molecules and chemical reactions , which is intractable to enumerate . Nevertheless , due to its utter importance , researchers have developed computer-aided frameworks to automate the process of retrosynthesis for more than three decades ( Corey et al. , 1985 ) . The computer-aided approaches for retrosynthesis mainly fall into two categories depending on their reliance on the reaction templates , i.e. , sub-graph patterns describing how the chemical reaction occurs among reactants ( see Figure 1b ) . The template-based approaches ( Coley et al. , 2017b ; Segler & Waller , 2017 ; Dai et al. , 2019 ) first enumerate known reaction templates and then apply a wellmatched template into the target product to obtain reactants . Although they can provide chemically interpretable predictions , they limit the search space to known templates and can not discover novel synthetic routes . In contrast , template-free approaches ( Liu et al. , 2017 ; Karpov et al. , 2019 ; Zheng et al. , 2019 ; Shi et al. , 2020 ) generate the reactants from scratch to avoid relying on the reaction templates . However , they require to search the entire molecular space , and their predictions could be either unstable or commercially unavailable . We emphasize that retrosynthesis methods are often required to consider the availability of reactants and generalize to unseen templates in real-world scenarios . For example , when a predicted reactant is not available ( e.g. , not purchasable ) for a chemist or a laboratory , the synthetic path starting from the predicted reactant can not be instantly used in practice . Moreover , chemists often require retrosynthetic analysis based on unknown reaction rules . This is especially significant due to our incomplete knowledge of chemical reactions ; e.g. , 29 million reactions were regularly recorded between 2009 and 2019 in Reaxys1 ( Mutton & Ridley , 2019 ) . Contribution . In this paper , we propose a new selection-based approach , which allows considering the commercial availability of reactants . To this end , we reformulate the task of retrosynthesis as a problem where reactants are selected from a candidate set of available molecules . This approach has two benefits over the existing ones : ( a ) it guarantees the commercial availability of the selected reactants , which allows chemists proceeding to practical procedures such as lab-scale experiments or optimization of reaction conditions ; ( b ) it can generalize to unseen reaction templates and find novel synthetic routes . For the selection-based retrosynthesis , we propose an efficient selection framework , named RETCL ( retrosynthesis via contrastive learning ) . To this end , we design two effective selection scores in synthetic and retrosynthetic manners . To be specific , we use the cosine similarity between molecular embeddings of the product and the reactants computed by graph neural networks . For training the score functions , we also propose a novel contrastive learning scheme ( Sohn , 2016 ; He et al. , 2019 ; Chen et al. , 2020b ) with hard negative mining ( Harwood et al. , 2017 ) to overcome a scalability issue while handling a large-scale candidate set . To demonstrate the effectiveness of our RETCL , we conduct various experiments based on the USPTO database ( Lowe , 2012 ) containing 1.8M chemical reactions in the US patent literature . Thanks to our prior knowledge on the candidate reactants , our method achieves 71.3 % test accuracy and significantly outperforms the baselines without such prior knowledge . Furthermore , our algorithm demonstrates its superiority even when enhancing the baselines with candidate reactants , e.g. , our algorithm improves upon the existing template-free approach ( Chen et al. , 2019 ) by 11.7 % . We also evaluate the generalization ability of RETCL by testing USPTO-50k-trained models on the USPTOfull dataset ; we obtain 39.9 % test accuracy while the state-of-the-art template-based approach ( Dai et al. , 2019 ) achieves 26.7 % . Finally , we demonstrate how our RETCL can improve multi-step retrosynthetic analysis where intermediate reactants are not in our candidate set . We believe our scheme has the potential to improve further in the future , by utilizing ( a ) additional chemical knowledge such as atom-mapping or leaving groups ( Shi et al. , 2020 ; Somnath et al. , 2020 ) ; ( b ) various constrastive learning techniques in other domains , e.g. , computer vision ( He et al. , 2019 ; Chen et al. , 2020b ; Hénaff et al. , 2019 ; Tian et al. , 2019 ) , audio processing ( Oord et al. , 2018 ) , and reinforcement learning ( Srinivas et al. , 2020 ) . 2 SELECTION-BASED RETROSYNTHESIS VIA CONTRASTIVE LEARNING . 2.1 OVERVIEW OF RETCL . In this section , we propose a selection framework for retrosynthesis via contrastive learning , coined RETCL . Our framework is based on solving the retrosynthesis task as a selection problem over a candidate set of commercially available reactants given the target product . Especially , we design a selection procedure based on molecular embeddings computed by graph neural networks and train the networks via contrastive learning . To this end , we define a chemical reactionR → P as a synthetic process of converting a reactant-set R = { R1 , . . . , Rn } , i.e. , a set of reactant molecules , to a product molecule P ( see Figure 1a ) . We 1A chemical database , https : //www.reaxys.com aim to solve the problem of retrosynthesis by finding the reactant-setR from a candidate set C which can be synthesized to the target product P . Especially , we consider the case when the candidate set C consists of commercially available molecules . Throughout this paper , we say that the synthetic direction ( fromR to P ) is forward and the retrosynthetic direction ( from P toR ) is backward . Note that our framework stands out from the existing works in terms of the candidate set C. To be specific , ( a ) template-free approaches ( Lin et al. , 2019 ; Karpov et al. , 2019 ; Shi et al. , 2020 ) choose C as the whole space of ( possibly unavailable ) molecules ; and ( b ) template-based approaches ( Coley et al. , 2017b ; Segler & Waller , 2017 ; Dai et al. , 2019 ) choose C as possible reactants extracted from the known reaction templates . In comparison , our framework neither requires ( a ) search over the entire space of molecules , or ( b ) domain knowledge to extract the reaction templates . We now briefly outline the RETCL framework . Our framework first searches the most likely reactantsetsR1 , . . . , RT ⊂ C in a sequential manner based on a backward selection score ψ ( R|P , Rgiven ) , and then ranks the reactant-sets using ψ ( R|P , Rgiven ) and another forward score φ ( P |R ) . For learning the score functions , we propose a novel contrastive learning scheme with hard negative mining for improving the selection qualities . We next provide detailed descriptions of the search procedure and the training scheme in Section 2.2 and 2.3 , respectively . 2.2 SEARCH PROCEDURE WITH GRAPH NEURAL NETWORKS . We first introduce the search procedure of RETCL in detail . To find a reactant-setR = { R1 , . . . , Rn } , we select each elementRi sequentially from the candidate set C based on the backward ( retrosynthetic ) selection score ψ ( R|P , Rgiven ) . It represents a selection score of a reactant R given a target product P and a set of previously selected reactantsRgiven ⊂ C. Note that the score function is also capable of selecting a special reactant Rhalt to stop updating the reactant-set . Using beam search , we choose top T likely reactant-setsR1 , . . . , RT . Furthermore , we rank the chosen reactant-setsR1 , . . . , RT based on the backward selection score ψ ( R|P , Rgiven ) and the forward ( synthetic ) score φ ( P |R ) . The latter represents the synthesizability ofR for P . Note that ψ ( R|P , Rgiven ) and φ ( P |R ) correspond to backward and forward directions of a chemical reaction R → P , respectively ( see Section 2.1 and Figure 1a ) . Using both score functions , we define an overall score on a chemical reactionR → P as follows : score ( P , R ) = 1 n+ 2 ( max π∈Π n+1∑ i=1 ψ ( Rπ ( i ) |P , { Rπ ( 1 ) , . . . , Rπ ( i−1 ) } ) + φ ( P |R ) ) , ( 1 ) whereRn+1 = Rhalt and Π is the space of permutations defined on the integers 1 , . . . , n+1 satisfying π ( n+1 ) = n+1 . Based on score ( P , R ) , we decide the rankings of R1 , . . . , RT for synthesizing the target product P . We note that the maxπ∈Π operator and the 1n+2 term make the overall score ( equation 1 ) be independent of order and number of reactants , respectively . Figure 2 illustrates this search procedure of our framework . Score design . We next elaborate our design choices for the score functions ψ and φ . We first observe that the molecular graph of the product P can be decomposed into subgraphs from each reactant of the reactant-set R , as illustrated in Figure 1a . Moreover , when selecting reactants sequentially , the structural information of the previously selected reactants Rgiven should be ignored to avoid duplicated selections . From these observations , we design the scores ψθ ( R|P , Rgiven ) and φ ( P |R ) as follows : ψ ( R|P , Rgiven ) = CosSim ( fθ ( P ) − ∑ S∈Rgiven gθ ( S ) , hθ ( R ) ) , φ ( P |R ) = CosSim ( ∑ R∈R gθ ( R ) , hθ ( P ) ) , where CosSim is the cosine similarity and fθ , gθ , hθ are embedding functions from a molecule to a fixed-sized vector with parameters θ . Note that one could think that fθ and gθ are query functions for a product and a reactant , respectively , while hθ is a key function for a molecule . Such a query-key separation allows the search procedure to be processed as an efficient matrix-vector multiplication . This computational efficiency is important in our selection-based setting because the number of candidates is often very large , e.g. , |C| ≈ 6× 105 for the USPTO dataset . To parameterize the embedding functions fθ , gθ and hθ , we use the recently proposed graph neural network ( GNN ) architecture , structure2vec ( Dai et al. , 2016 ; 2019 ) . The implementation details of the architecture is described in Section 3.1 . Incorporating reaction types . A human expert could have some prior information about a reaction type , e.g. , carbon-carbon bond formation , for the target product P . To utilize this prior knowledge , we add trainable embedding bias vectors u ( t ) and v ( t ) for each reaction type t into the query embeddings of ψ and φ , respectively . For example , φ ( P |R ) becomes CosSim ( ∑ R∈R gθ ( R ) + v ( t ) , hθ ( P ) ) . The bias vectors are initialized by zero at beginning of training .

Summary: RETCL enumerates all of the candidate molecules (all US patent dataset, all 671k) based on selection scores computed by graph neural networks. The cosine similarity between products and reactants are used to design scores, which is later used for training. The way of ‘cosine similarity to bridge reactants to products are interesting.