C HEMICAL -R EACTION -A WARE M OLECULE R EPRESENTATION L EARNING
A BSTRACT
Molecule representation learning (MRL) methods aim to embed molecules into a real vector space.
However, existing SMILES-based (Simpliﬁed Molecular-Input
Line-Entry System)
or GNN-based (Graph Neural Networks)
MRL methods either take SMILES strings as input that have difﬁculty in encoding molecule structure information, or over-emphasize the importance of GNN architectures but neglect their generalization ability.
Here we propose using chemical reactions to assist learning molecule representation.
The key idea of our approach is to preserve the equivalence of molecules with respect to chemical reactions in the embedding space, i.e., forcing the sum of reactant embeddings and the sum of product embeddings to be equal for each chemical equation.
This constraint is proven effective to 1) keep the embedding space well-organized and 2) improve the generalization ability of molecule embeddings.
Moreover, our model can use any GNN as the molecule encoder and is thus agnostic to GNN architectures.
Experimental results demonstrate that our method achieves state-of-the-art performance in a variety of downstream tasks, e.g., reaction product prediction, molecule property prediction, reaction classiﬁcation, and graph-edit-distance prediction.
The code is available at https://github.com/hwwang55/MolR .
I NTRODUCTION
How to represent molecules is a fundamental and crucial problem in chemistry.
Chemists usually use IUPAC nomenclature, molecular formula, structural formula, skeletal formula, etc., to represent molecules in chemistry literature.
However, such representations are initially designed for human readers rather than computers.
To facilitate machine learning algorithms understanding and making use of molecules, molecule representation learning (MRL) is proposed to map molecules into a lowdimensional real space and represent them as dense vectors.
The learned vectors (a.k.a. embeddings) of molecules can beneﬁt a wide range of downstream tasks, such as chemical reaction prediction (Jin et al., 2017; Segler & Waller, 2017), molecule property prediction (Zhang et al., 2021), molecule generation (Mahmood et al., 2021), drug discovery (Rathi et al., 2019), retrosynthesis planning (Segler et al., 2018), chemical text mining (Krallinger et al., 2017), and chemical knowledge graph modeling (Bean et al., 2017).
Researchers have proposed a great many MRL methods.
A large portion of them, including MolBERT (Fabian et al., 2020), ChemBERTa (Chithrananda et al., 2020), SMILES-Transformer (Honda et al., 2019), SMILES-BERT (Wang et al., 2019), Molecule-Transformer (Shin et al., 2019), and SABiLSTM (Zheng et al., 2019b), take SMILES 2 strings as input and utilize natural language models, for example, Transformers (Vaswani et al., 2017) or BERT (Devlin et al., 2018), as their base model.
Despite the great power of such language models, they have difﬁculty dealing with SMILES input, OH OH OH OH because SMILES is 1D linearization of molecular structure, which makes it hard for language models to learn the original structural information of molecules simply based on “slender” strings (see
Section 4 for more discussion).
Another line of MRL methods, instead, use graph neural networks (GNNs) (Kipf & Welling, 2017) to process molecular graphs (Merkwirth & Lengauer, 2005; Jin et al., 2017; Gilmer et al., 2017; Ishida et al., 2021).
Though GNN-based methods are theoretically superior to SMILES-based methods in learning molecule structure, they are limited to designing fresh and delicate GNN architectures while ignoring the essence of MRL, which is generalization ability .
Actually, we will show later that, there is no speciﬁc GNN that performs universally best in all downstream tasks of MRL, which inspires us to explore beyond GNN architectures.
To address the limitations of existing work, in this paper, we propose using chemical reactions to assist learning molecule representations and improving their generalization ability.
A chemical reaction is usually represented as a chemical equation in the form of symbols and formulae, wherein the reactant entities are given on the left-hand side and the product entities on the right-hand side.
For example, the chemical equation of Fischer esteriﬁcation of acetic acid and ethanol can be written as CH 3 COOH + C 2 H 5 OH → CH 3 COOC 2 H 5 + H 2 O. A chemical reaction usually indicates a particular relation of equivalence between its reactants and products (e.g., in terms of conservation of mass and conservation of charge), and our idea is to preserve this equivalence in the molecule embedding space.
Speciﬁcally, given the chemical reaction of Fischer esteriﬁcation above, we hope that the equation h CH 3 COOH + h C 2 H 5 OH = h CH 3 COOC 2 H 5 + h H 2 O also holds, where h ( · ) repre- sents molecule embedding function.
This simple constraint endows molecule embeddings with very nice properties: (1) Molecule embeddings are composable with respect to chemical reactions, which make the embedding space well-organized (see Proposition 1); (2) More importantly, we will show later that, when the molecule encoder is a GNN with summation as the readout function, our model can automatically and implicitly learn reaction templates that summarize a group of chemical reactions within the same category (see Proposition 2).
The ability of learning reaction templates is the key to improving the generalization ability of molecule representation, since the model can easily generalize its learned knowledge to a molecule that is unseen but belongs to the same category as or shares the similar structure with a known molecule.
We show that the molecule embeddings learned by our proposed model, namely MolR (chemicalr eaction-aware mol ecule embeddings), is able to beneﬁt a variety of downstream tasks, which makes it signiﬁcantly distinct from all existing methods that are designed for only one downstream task.
For example, MolR achieves 17.4% absolute Hit@1 gain in reaction product prediction, 2.3% absolute
AUC gain on BBBP dataset in molecule property prediction, and 18.5% relative RMSE gain in graph-edit-distance prediction, respectively, over the best baseline method.
We also visualize the learned molecule embeddings and show that they are able to encode reaction templates as well as several key molecule attributes, e.g., molecule size and the number of smallest rings.
T HE P ROPOSED M ETHOD 2. S TRUCTURAL M OLECULE E NCODER
A molecular graph is represented as G =
( V, E ) , where V = { a 1 , · · · } is the set of non-hydrogen atoms and E = { b 1 , · · · } is the set of bonds.
Each atom a i has an initial feature vector x i encoding its properties.
In this work, we use four types of atom properties: element type , charge , whether the atom is an aromatic ring , and the count of attached hydrogen atom(s) .
Each type of atom properties is represented as a one-hot vector, and we add an additional “unknown” entry for each one-hot vector to handle unknown values during inference.
The four one-hot vectors are concatenated as the initial atom feature.
In addition, each bond b i has a bond type (e.g., single, double).
Since the bond type can usually be inferred by the features of its two associated atoms and does not consistently improve the model performance according to our experiments, we do not explicitly take bond type as input.
To learn structural representation of molecules, we choose GNNs, which utilize molecule structure and atom features to learn a representation vector for each atom and the entire molecule, as our base model.
Typical GNNs follow a neighborhood aggregation strategy, which iteratively updates the representation of an atom by aggregating representations of its neighbors and itself.
Formally, the k -th layer of a GNN is:
[Equation]
N
O
O ℎ !"
= AGGREGATE({ℎ #"$! }
#%!,’,(,) ) ℎ ’"
= ⋯
N
O
O ℎ *+,-./0 = READOUT({ℎ #1 } #%!2 )
For 𝑘 = 1,…,𝐾 : proline (a) GNN encoder
C C C
O
O propionic acid propanol
C O C C
C C C
O
O propionic acid water
C
O C C
R 1 C C
O
O
R 2 O C C
C C
O
O
O C C R
R
Reaction template: (
[Figure]
Reaction template
GNN encoder 𝑑 !!
𝑑 !"
𝑑 !
# 𝑑 !
$ 𝑑 "!
𝑑 "" 𝑑 "# 𝑑 "$ 𝑑 #! 𝑑 #" 𝑑 ## 𝑑 #$ 𝑑 $!
𝑑 $" 𝑑 $# 𝑑 $$
ℎ % !
ℎ % " ℎ %
# ℎ % $ ℎ & !
ℎ & " ℎ & # ℎ & $ reactants 𝑅 ’ products 𝑃 ’ … … … … … … … … … … … (
[Figure]
loss where h ki is atom a i ’s representation vector at the k -th layer ( h 0 i is initialized as a i ’s initial feature x i ), N ( i ) is the set of atoms directly connected to a i , and K is the number of GNN layers.
The choice of AGGREGATE function is essential to designing GNNs, and a number of GNN architectures have been proposed.
See Appendix A for a detailed introduction on GNN architectures.
Finally, a readout function is used to aggregate all node representations output by the last GNN layer to obtain the entire molecule’s representation h G :
[Equation]
The READOUT function can be a simple permutation invariant function such as summation and mean, or a more sophisticated graph-level pooling algorithm
(Ying et al., 2018; Zhang et al., 2018).
An illustrative example of GNN encoder is shown in Figure 1a.
2. P RESERVING C HEMICAL R EACTION E QUIVALENCE
A chemical reaction deﬁnes a particular relation “ → ” between reactant set R = { r 1 , r 2 , · · · } and product set P = { p 1 , p 2 , · · · } :
[Equation]
A chemical reaction usually represents a closed system where several physical quantities of the system retain constant before and after the reaction, such as mass, energy, charge, etc.
Therefore, it describes a certain kind of equivalence between its reactants and products in the chemical reaction space.
Our key idea is to preserve such equivalence in the molecule embedding space:
[Equation]
The above simple constraint is crucial to improving the quality of molecule embeddings.
We ﬁrst show, through the following proposition, that the chemical reaction relation “ → ” is an equivalence relation under the constraint of Eq.
Proposition 1 Let M be the set of molecules, R ⊆ M and P ⊆
M be the reactant set and product set of a chemical reaction, respectively.
If R → P ⇔ (cid:80) r ∈ R h r = (cid:80) p ∈
P h p for all chemical reactions, then “ → ” is an equivalence relation on 2 M that satisﬁes the following three properties:
(1) Reﬂexivity:
A → A , for all A ∈ 2 M ; (2) Symmetry:
A → B ⇔ B → A , for all A, B ∈ 2 M ; (3) Transitivity:
If A → B and B → C , then A → C , for all A, B, C ∈ 2 M .
The proof of Proposition 1 is in Appendix B. One important corollary of Proposition 1 is that, the set of all subsets of M , i.e. 2 M , is naturally split into equivalence classes based on the equivalence relation “ → ”.
For all molecule sets within one equivalent class, the sum of embeddings of all molecules they consist of should be equal.
For example, in organic synthesis, a target compound t may be made from three different sets of starting materials A , B , and C .
Then the sets A , B , C as well as { t } belong to one equivalence class, and we have (cid:80) m
∈
A h m = (cid:80) m
∈ B
h m = (cid:80) m
∈ C
h m = h t .
Note that the starting materials are usually small and basic molecules that frequently appear in a number of synthesis routes.
Therefore, Eq.
(4) forms a system of linear equations, wherein the chemical reaction equivalence imposes strong constraint on the embeddings of base molecules.
As a result, the feasible solutions of molecule embeddings will be more robust, and the whole embedding space will be more organized.
See the visualized result on molecule embedding space in Section 3. for more details.
We can further show that, the constraint in Eq.
(4) is also able to improve the generalization ability of molecule embeddings.
To see this, we ﬁrst deﬁne reaction center for a chemical reaction.
The reaction center of R → P is deﬁned as a subgraph of R consisting of atoms whose bonds have changed after reaction.
For example, for the reaction in the upper part of Figure 1b, its reaction center is the two oxygen atoms marked in dark orange, since they are the only two atoms whose bonds have changed.
Given the concept of reaction center, we have the following proposition:
Proposition 2 Let R → P be a chemical reaction where R is the reactant set and P is the product set, and C be its reaction center.
Suppose that we use the GNN (whose number of layers is K ) shown in Eqs.
(1) and (2) as the molecule encoder, and set the READOUT function in Eq.
(2) as summation.
Then for an arbitrary atom a in one of the reactant whose ﬁnal representation is h Ka , the residual term (cid:80)
r ∈ R h r − (cid:80)
p ∈
P h p is a function of h Ka if and only if the distance between atom a and reaction center C is less than K .
The proof of Proposition 2 is in Appendix C. Proposition 2 indicates that the residual between reactant embedding and product embedding will fully and only depend on atoms that are less than
K hops away from the reaction center.
For example, as shown in Figure 1b, suppose that we use a 3layer GNN to process Fischer esteriﬁcation of propionic acid and propanol, then the residual between reactant embedding and product embedding will totally depend on the reaction center (colored in orange) as well as atoms whose distance from the reaction center is 1 or 2 (colored in light orange).
This implies that, if the GNN encoder has been well-optimized on this chemical equation and outputs perfect embeddings, i.e., h CH [Equation] =
[Equation]
, then the equation h
[Equation]
[Equation] R 2 + h H 2 O will also hold for any functional group R 1 and R 2 , since the residual between the two sides of the equation does not depend on R 1 or R 2 that are more than 2 hops away from the reaction center.
The induced general chemical reaction R 1 -CH 2 COOH + R 2 -CH 2 CH 2 OH → R 1 -CH 2 COOCH 2 CH 2 -R
+ H 2 O is called a reaction template , which abstracts a group of chemical reactions within the same category.
The learned reaction templates are essential to improving the generalization ability of our model, as the model can easily apply this knowledge to reactions that are unseen in training data but comply with a known reaction template (e.g., acetic acid plus propanol, butyric acid plus butanol).
We will further show in Section 3.5 how reaction templates are encoded in molecule embeddings.
Remarks .
Below are some of our remarks to provide further understanding on the proposed model:
First, compared with (Jin et al., 2017) that also learns reaction templates, our model does not need a complicated network to calculate attention scores, nor requires additional atom mapping information between reactants and products as input.
Moreover, our model is theoretically able to learn a reaction template based on even only one reaction instance, which makes it particularly useful in few-shot learning (Wang et al., 2020) scenario.
See Section 3.1 for the experimental result.
Second, organic reactions are usually imbalanced and omit small and inorganic molecules to highlight the product of interest (e.g., H 2 O is usually omitted from Fischer esteriﬁcation).
Nonetheless, our model can still learn meaningful reaction templates as long as chemical reactions are written in a consistent manner (e.g., H 2 O is omitted for all Fischer esteriﬁcation).
Third, the number of GNN layers K can greatly impact the learned reaction templates according to
Proposition 2: A small K may not be enough to represent a meaningful reaction template (e.g., in
Fischer esteriﬁcation, the necessary carbonyl group “C=O” in carboxylic acid will not appear in the reaction template if K < 3 ), while a large K may include unnecessary atoms for a reaction template and thus reduces its coverage (e.g., the Fischer esteriﬁcation of formic acid HCOOH and methanol
CH 3 OH is not covered by the reaction template shown in Figure 1b).
The empirical impact of K is shown in Appendix D.
2. T RAINING THE M ODEL
According to Eq.
(4), a straightforward loss function for the proposed method is therefore L =|D| [Equation] R [Equation]
P
[Equation] ∈D [Equation] r ∈ R h r − (cid:80)
p ∈
P h p (cid:13)(cid:13) 2 , where R → P represents a chemical reaction in the training data D .
However, simply minimizing the above loss does not work, since the model will degenerate by outputting all-zero embeddings for all molecules.
Common solutions to this problem are introducing negative sampling strategy (Goldberg & Levy, 2014) or contrastive learning (Jaiswal et al., 2021).
Here we use a minibatch-based contrastive learning framework similar to (Radford et al., 2021) since it is more time- and memory-efﬁcient.
For a minibatch of data B = { R 1 → P 1 , R 2 → P 2 , · · · } ⊆ D , we ﬁrst use the GNN encoder to process all reactants R i and products P i in this minibatch and get their embeddings.
The matched reactant-product pairs ( R i , P i ) are treated as positive pairs, whose embedding discrepancy will be minimized, while the unmatched reactant-product pairs ( R i , P j )
( i (cid:54) =
j ) are treated as negative pairs, whose embedding discrepancy will be maximized.
To avoid the total loss being dominant by negative pairs, similar to (Bordes et al., 2013), we use a margin-based loss as follows (see Figure 1c for an illustrative example):
[Equation]
[Table]
where γ > 0 is a margin hyperparameter.
The whole model can thus be trained by minimizing the above loss using gradient-based optimization methods such as stochastic gradient descent (SGD).
Eq.
(5) can be seen as a special negative sampling strategy, which uses all unmatched products in a minibatch as negative samples for a given reactant.
Note, however, that it has two advantages over traditional negative sampling (Mikolov et al., 2013): (1) No extra memory is required to store negative samples; (2) Negative samples are automatically updated at the beginning of a new epoch since training instances are shufﬂed, which saves time of manually re-sampling negative samples.
E XPERIMENTS 3. R EACTION P RODUCT P REDICTION
Dataset .
We use reactions from USPTO granted patents collected by Lowe (2012) as the dataset, which is further cleaned by Zheng et al. (2019a).
The dataset contains 478,612 chemical reactions, and is split into training, validation, and test set of 408,673, 29,973, and 39,966 reactions, respectively, so we refer to this dataset as USPTO-479k .
Each reaction instance in USPTO-479k contains
SMILES strings of up to ﬁve reactant(s) and exactly one product.
Evaluation Protocol .
We formulate the task of reaction product prediction as a ranking problem.
In the inference stage, given the reactant set R of a chemical reaction, we treat all products in the test set as a candidate pool C (which contains 39,459 unique candidates), and rank all candidates based on the L2 distance between reactant embeddings h R and candidate product embeddings { h c } c ∈ C , i.e., d ( R, c ) = (cid:107) h R − h c (cid:107) 2 .
Then the ranking of the ground-truth product can be used to calculate
MRR (mean reciprocal rank), MR (mean rank), and Hit@1, 3, 5, 10 (hit ratio with cut-off values of 1, 3, 5, and 10).
Each experiment is repeated 3 times, and we report the result of mean and standard deviation on the test set when MRR on the validation set is maximized.
Baselines .
We use Mol2vec (Jaeger et al., 2018) and MolBERT (Fabian et al., 2020) as baselines.
For each baseline, we use the released pretrained model to output embeddings of reactants h R and candidate products { h c } c ∈ C , then rank all candidates based on their dot product: d ( R, c )
= − h (cid:62) R h c .
Since the pretrained models are not ﬁnetuned on USPTO-479k, we propose two ﬁnetuning strategies:
Mol2vec-FT1 and MolBERT-FT1 , which freeze their model parameters but train a diagonal matrix
K to rank candidates: d ( R, c ) = − h
(cid:62) R Kh c ; MolBERT-FT2 , which ﬁnetunes its model parameters by minimizing the contrastive loss function as shown in Eq.
(5) on USPTO-497k.
Note that Mol2vec is not an end-to-end model and thus cannot be ﬁnetuned using this strategy.
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure] [Figure]
[Table]
Hyperparameters Setting .
We use the following four GNNs as our molecule encoder: GCN (Kipf & Welling, 2017), GAT (Veli ˇ ckovi ´ c et al., 2018), SAGE (Hamilton et al., 2017), and TAG (Du et al., 2017), of which the details are introduced in Appendix A.
The number of layers for all GNNs is 2, the output dimension of all layers is 1,024, and the READOUT function is sum.
The margin γ is set to 4.
We train the model for 20 epochs with a batch size of 4,096, using Adam (Kingma & Ba, 2015) optimizer with a learning rate of 10 − 4 .
The result of hyperparameter sensitivity and ablation study are in Appendix D and E, respectively.
Result .
The result is reported in Table 1.
All the four variants of MolR signiﬁcantly outperform baseline methods.
For example, MolR-TAG achieves 14.2% absolute MRR gain and 17.4% absolute Hit@1 gain over the best baseline MolBERT-FT2.
In addition, we train MolR-TAG on only the ﬁrst 4,096 (1%) reaction instances in the training set (with a learning rate of 10 − 3 and 60 epochs while other hyperparameters remain the same), and the performance degrades quite slightly.
This justiﬁes our claim in Remark 1 in Section 2.2 that MolR works well in few-shot learning scenario.
To test the performance of MolR in realistic scenarios, we collect 16 multi-choice questions on product prediction from online resources of GRE Chemistry Test Practice Book etc.
Each question provides the reactants of a reaction and asks to select the correct product out of 4 or 5 choices.
These multi-choice questions are quite difﬁcult even for chemists, since the candidates are usually very similar to each other (see Appendix F for details).
The result is shown in Figure 2, which indicates that MolR surpasses baselines by a large margin.
Speciﬁcally, the Hit@1 (accuracy) of MolR-GCN is 0.625, which is twice as much as Mol2vec and MolBERT.
Moreover, we also conduct a case study on the ﬁrst 20 reactions in the test set of USPTO-479k.
Please refer to Appendix G for details.
3. M OLECULE P ROPERTY P REDICTION
Datasets .
We evaluate MolR on ﬁve datasets: BBBP , HIV , BACE , Tox21 , and ClinTox , proposed by Wu et al.
Each dataset contains thousands of molecule SMILES as well as binary labels indicating the property of interest (e.g., Tox21 measures the toxicity of compounds).
Baselines .
We compare our method with the following baselines: SMILES-Transformers (Honda et al., 2019), ECFP4 (Rogers & Hahn, 2010), GraphConv (Duvenaud et al., 2015),
Weave (Kearnes et al., 2016), ChemBERTa (Chithrananda et al., 2020), D-MPNN (Yang et al., 2019), CDDD (Winter
[Table]
Experimental Setup .
All datasets are split into training, validation, and test set by 8:1:1.
We use the model pretrained on USPTO-479k to process all datasets and output molecule embeddings, then feed embeddings and labels to a Logistic Regression model implemented in scikit-learn (Pedregosa et al., 2011), whose hyperparameters are as default except that solver=“liblinear”.
Each experiment is repeated 20 times, and we report the mean and the standard deviation of AUC on the test set.
Result .
The result of molecule property prediction is reported in Table 3.
As we can see, MolR performs the best on 4 out of 5 datasets.
We attribute the superior performance of MolR in molecule property prediction to that, MolR is pretrained on USPTO-479k, thus is sensitive to reaction centers according to Proposition 2.
Note that reaction centers usually consist of chemically active functional groups, which are essential to determine molecule property.
3. C HEMICAL R EACTION C LASSIFICATION
[Table]
Result of baselines is taken from (Probst et al., 2021).
Dataset, Baselines, and Experimental Setup .
The goal of chemical reaction classiﬁcation is to predict the reaction class that a chemical reaction belongs to (e.g., Nitro to amino).
We evaluate our model on USPTO-1k-TPL , which contains 400,604 training reactions and 44, test reactions, and the number of reaction classes is 1,000.
We use our pretrained models to calculate the sum of reactant embeddings and the sum of product embeddings in a reaction, then concatenate them as the feature of the reaction.
We use an MLP with two 2,048-unit hidden layers as the classiﬁer.
Each experiment is repeated 3 times, and we report the mean and standard deviation of Accuracy on the test set.
We compare our method with RXNFP (Schwaller et al., 2021), AP3- (Schneider et al., 2015), and DRFP (Probst et al., 2021).
Result .
The result of accuracy is reported in Table 4.
5NN and MLP represent a 5-Nearest-Neighbor and an MLP classiﬁer, respectively.
Note that even if these baselines are specially designed to learn reaction ﬁngerprint, our best method
MolR-TAG still surpasses AP3-256, and is close to DRFP and RXNFP.
This shows that our method can achieve on par performance with state-of-the-art reaction ﬁngerprint learning methods.
3. G RAPH -E DIT -D ISTANCE P REDICTION
Graph-edit-distance (GED) (Gao et al., 2010) is a measure of similarity between two graphs, which is deﬁned as the minimum number of graph edit operations to transform one graph to another.
Here we aim to predict the GED between two molecular graphs based on their embeddings.
The purpose
[Figure]
of this task is to show whether the learned molecule embeddings are able to preserve the structural similarity between molecules.
Moreover, since calculating the exact GED is NP-hard, the solution to this task can also be seen as an approximation algorithm for GED calculation
[Figure]
Dataset, Baselines, and Experimental Setup .
We randomly sample 10,000 molecule pairs from the ﬁrst 1,000 molecules in QM9 dataset (Wu et al., 2018), then calculate their ground-truth GEDs using NetworkX (Hagberg et al., 2008).
The dataset is split into training, validation
[Figure]
and test set by 8:1:
[Figure]
and we use our pretrained models to output embeddings for each molecule.
The embeddings of a pair of molecules are concatenated or subtracted as the features, and we use a Support Vector Regression model in scikit-learn with default hyperparameters to do the regression.
Each experiment is repeated 20 times, and we report the mean and the standard deviation of RMSE on the test set.
We use Mol2vec (Jaeger et al., 2018) and MolBERT (Fabian et al., 2020) as baselines.
Result .
The result of RMSE is reported in Table 2.
Our best MolR model reduces the RMSE by 18.5% and 12.8% in concat and subtract mode, respectively, compared with the best baseline.
Note that the interval of ground-truth GEDs is [1 , 14] , whose range is far larger than the RMSE of MolR.
The result indicates that MolR can serve as a strong approximation algorithm to calculate GED.
3. E MBEDDING V ISUALIZATION
To intuitively demonstrate the molecule embedding space, we use the pretrained MolR-GCN model to output embeddings of molecules in BBBP dataset, then visualize them using t-SNE (Van der
Maaten & Hinton, 2008) shown in Figure 4.
In Figure 4a, molecules are colored according to the property of permeability.
We ﬁnd two communities of non-permeable molecules, which demonstrates that MolR can capture molecule property of interest.
In Figure 4b, molecules are colored according to their GED to a randomly selected molecule (No. 1196) from BBBP dataset.
It is obvious that, molecules that are structurally similar with No. 1196 molecule (colored in orange) are also close to it in the embedding space, while molecules that are structurally dissimilar with No.molecule (colored in red) are also far from it in the embedding space.
The result indicates that MolR can well capture the structural similarity between molecules.
In Figure 4c, molecules are colored according to their size (i.e., the number of non-hydrogen atoms).
It is clear that the embedding space is perfectly segmented into small-molecule region (upper part) and large-molecule region (lower part).
In other words, the vertical axis of the 2D embedding space characterizes molecule size.
Last and surprisingly, we ﬁnd that the horizontal axis are actually related to the number of smallest rings (i.e., rings that do not contain another ring) in a molecule: As shown in Figure 4d, no-ring molecules (colored in blue) are only in the left cluster, one-ring molecules (colored in yellow) are only in the left and the middle clusters, two-ring molecules (colored in orange) are basically in the middle cluster, while the right cluster mainly consists of molecules with more than 2 rings (colored in red).
We also show that MolR encodes chemical reactions by taking alcohol oxidation and aldehyde oxidation as examples, whose chemical reaction templates are R-CH 2 OH + O 2 → R-CHO + H 2 O and
R-CHO + O 2 → R-COOH, respectively.
We ﬁrst use the pretrained MolR-GCN model to output embeddings for ethanol (CH 3 CH 2 OH), 1-octanol (CH 3 (CH 2 ) 7 OH), ethylene glycol ((CH 2 OH) 2 ), as well as their corresponding aldehyde and carboxylic acid, then visualize them using Principle
Component Analysis (PCA).
The result is visualized in Figure 3, which clearly demonstrates that h
[Table]
(red and orange arrows).
Note that the length of blue ar- row is about twice as much as the corresponding red or orange arrow, which is exactly because (CH 2 OH) 2 /(CH 2 CHO) 2 has two hydroxyl/aldehyde groups to be oxidized.
R ELATED W ORK
Existing MRL methods can be classiﬁed into two categories.
The ﬁrst is SMILES-based (Fabian et al., 2020; Chithrananda et al., 2020; Honda et al., 2019; Wang et al., 2019; Shin et al., 2019; Zheng et al., 2019b), which use language models to process SMILES strings.
For example, MolBERT (Fabian et al., 2020) uses BERT as the base model and designs three self-supervised tasks to learn molecule representation.
However, SMILES is 1D linearization of molecular structure and highly depends on the traverse order of molecule graphs.
This means that two atoms that are close in
SMILES may actually be far from each other and thus not correlated (e.g., the two oxygen atoms in “CC(CCCCCCO)O”), which will mislead language models that rely heavily on the relative position of tokens to provide self-supervision signal.
The second is structure-based methods, which can further be classiﬁed into traditional ﬁngerprintbased methods (Rogers & Hahn, 2010; Jaeger et al., 2018) and recent GNN-based methods (Jin et al., 2017; Gilmer et al., 2017; Ishida et al., 2021).
For example, Mol2vec (Jaeger et al., 2018) treats molecule substructures (ﬁngerprints) as words and molecules as sentences, then uses a Word2veclike method to calculate molecule embeddings.
However, they cannot identify the importance of different substructures, nor being trained in an end-to-end fashion.
GNN-based methods overcome their drawbacks, butt they usually require a large volume of training data due to their complicated architectures, which may limit their generalization ability when the data is sparse.
The idea of taking chemical reactions as prior knowledge is also applied to molecule generation task (Bradshaw et al., 2019; Nguyen & Tsuda, 2021).
Compared with these methods which focus on a particular task of molecule generation, the embeddings learned by our model are general-purpose and can beneﬁt a wide range of downstream tasks.
It is worth noticing that our model is also conceptually connected to methods in NLP where embeddings are composable (Bordes et al., 2013; Mikolov et al., 2013).
For example, TransE (Bordes et al., 2013) assumes that h + r ≈ t for a triplet ( head, relation, tail ) in knowledge graphs, and
Word2vec (Mikolov et al., 2013) learns word embeddings where simple vector addition can produce meaningful results, for example, vec(“Germany”)
+ vec(“capital”)
≈ vec(“Berlin”).
C ONCLUSION AND F UTURE W ORK
In this work, we use GNNs as the molecule encoder, and use chemical reactions to assist learning molecule representation by forcing the sum of reactant embeddings to be equal to the sum of product embeddings.
We prove that our model is able to learn reaction templates that are essential to improve the generalization ability.
Our model is shown to beneﬁt a wide range of downstream tasks, and the visualized results demonstrate that the learned embeddings are well-organized and reaction-aware.
We point out four directions as future work.
First, environmental condition is also a part of chemical reactions that we will consider to model.
Second, as discussed in Section 2.2, it is worth studying how to explicitly output learned reaction templates.
Third, it is interesting to investigate how to differentiate stereoisomers in the embedding space, since our model (as well as baselines) cannot handle stereoisomerism.
Last, including additional information (e.g., textual description of molecules) to assist learning molecule representation is also a promising direction.
A CKNOWLEDGEMENT
This research is based upon work supported by the Molecule Maker Lab Institute: an AI research institute program supported by NSF under award No. 2019897 and No. 2034562.
The views and conclusions contained herein are those of the authors and should not be interpreted as necessarily representing the ofﬁcial policies, either expressed or implied, of the U
S. Government.
The U S. Government is authorized to reproduce and distribute reprints for governmental purposes notwithstanding any copyright annotation therein A D ETAILED D ESCRIPTION OF GNN A RCHITECTURES
Before applying GNNs, we ﬁrst use pysmiles 3 to parse the SMILES strings of molecules to NetworkX graphs.
Then we use the following GNNs as our molecule encoder and investigate their performance in experiments.
The implementation of GNNs is based on Deep Graph Library (DGL) 4 .
For all GNNs, the number of layers is 2, and the output dimension of all layers is 1,024.
The activation function σ is identity for the last layer, and ReLU for all but the last layer.
We keep a bias term b for all the linear transformations below as it is the default setting in DGL, but our experiments show that the bias term can barely affect the result, so it is not shown in the following equations for clarity.
Graph Convolutional Networks (GCN) (Kipf & Welling, 2017).
In GCN, AGGREGATE is implemented as weighted average with respect to the inverse of square root of node degrees:
[Equation]
where W k is a learnable matrix, α ij = 1 / (cid:112)
|N
( i ) | · |N ( j ) | , and σ is activation function.
Graph Attention Networks (GAT) (Veli ˇ ckovi ´ c et al., 2018).
In GAT, AGGREGATE is implemented as multi-head self-attention:
[Equation]
where α k,sij =
LeakyReLU
[Equation]
w
[Equation]
k,s h kj (cid:3)(cid:17) is (unnormalized) attention weight, w is a learnable vector, (cid:102) denotes concatenate operation, and S is the number of attention heads.
In our experiments, S is set as 16 and the dimension of each attention head is set as 64, so that the total output dimension is still 1,024.
Graph Sample and Aggregate (GraphSAGE) (Hamilton et al., 2017).
In the pooling variant of
GraphSAGE, AGGREGATE is implemented as:
[Equation]
where h k N ( i ) =
MAX (cid:16)(cid:8) ReLU( W k
[Equation]
2 h k −
[Equation]
) (cid:9) j ∈N ( i ) (cid:17) is aggregated neighborhood representation, and MAX is an element-wise max-pooling function.
In addition to MAX, AGGREGATE can also be implemented as MEAN, GCN, and LSTM, but our experiments show that MAX achieves the best performance.
Topology Adaptive Graph Convolutional Networks (TAGCN) (Du et al., 2017).
In TAGCN, if we use H k to denote the representation matrix of all atoms in layer k , then AGGREGATE can be written as:
[Equation]
(9) where
˜ A
=
D − 1 / 2 AD − 1 / 2 is the normalized adjacency matrix, and L is the size of the local ﬁlter.
We set L to 2 in experiments.
It should be noted that, different from other GNNs, a single TAGCN layer can aggregate node information from neighbors up to L hops away.
Therefore, the actual number of layers for TAGCN is L K , which is 2 2 = 4 in our experiments.
B P ROOF OF P ROPOSITION
Proof.
To prove that “ → ” is an equivalence relation on 2 M , we need to prove that “ → ” satisﬁes reﬂexivity, symmetry, and transitivity:
Reﬂexivity .
For any A ∈ 2 M , it is clear that (cid:80) i ∈
A h i = (cid:80) i ∈
A h i .
Therefore, we have A → A .
Symmetry .
For any A, B ∈ 2 M , A → B ⇒ (cid:80) i ∈
A h i = (cid:80) i ∈
B h
i ⇒ B
→ A , and vice versa.
Therefore, we have A → B ⇔ B → A .
Transitivity .
If A → B and B → C , then we have (cid:80) i ∈
A h i = (cid:80) i ∈
B h i =
(cid:80) i ∈
C h i .
Therefore, we have A → C .
(cid:3)
C P ROOF OF P ROPOSITION
Proof.
Since the READOUT function is summation, the embedding of molecule G =
( V, E ) is the sum of ﬁnal embeddings of all atoms that G consists of: h G = (cid:80) a
i ∈ V h Ki .
Therefore, for the reaction R → P , we have (cid:80) r ∈ R h
[Equation]
− (cid:80)
[Equation]
=
[Equation]
h Kv − (cid:80) p ∈ P (cid:80) v ∈ p ˜
h
Kv , where h Kv is the representation vector of atom v calculated by a K -layer GNN on the reactant graph, and ˜ h
Kv is the representation vector of atom v calculated by the same K -layer GNN on the product graph.
If we treat all reactants R (all products P ) in a chemical reaction as one graph where each reactant (product) is a connected component of this graph, the above equation can be written as (cid:80) v ∈ R
h
Kv − (cid:80) v ∈ P ˜ h
Kv .
Denote C k as the set of atoms whose distance from the reaction center C is k
( C 0 = C ).
We can prove, by induction, that (cid:80)
[Equation]
Let’s ﬁrst consider the initial case where K = 1 .
Then the ﬁnal representation of an atom depends on the initial feature of itself as well as its one-hop neighbors.
Therefore, atoms whose ﬁnal representation differs from R to P must be those who have at least one bond changed from R to P , which are exactly the atoms in the reaction center C .
Representation of atoms that are not within the reaction center remains the same before and after reaction, and thus are eliminated.
Therefore, we have
[Equation]
Induction step.
Suppose we have (cid:80) v [Equation]
R h
Kv − [Equation] v ∈ P ˜ h
Kv =
(cid:80) [Equation] K [-− 1 k =
-][Equation]
[Equation] h Kv − [Equation] K[-− 1 k =
-]
[Equation]
[Equation] ˜ h
Kv for
K ≥ 1 .
This means that representation of atoms whose distance from the reaction center is no larger than K − 1 becomes different from R to P , while representation of atoms whose distance from the reaction center is larger than K − 1 remains the same.
Then for K + 1 , the number of GNN layers increases by one.
This means that atoms adjacent to the set ∪ K − 1 k =
C k are additionally inﬂuenced, and their representations are also changed.
It is clear that the set of atoms whose representation is changed is now ∪ Kk =
C k .
Therefore, we have (cid:80) v ∈ R
h K +1 v
[Equation]
(cid:80)[-v ∈∪ Kk =
 C k ˜ h-]
[Equation] for K + 1 .
Since (cid:80) r ∈ R h r − (cid:80) p ∈ P h p
=
(cid:80) v ∈∪ K − 1 k =
C k h Kv − (cid:80) v ∈∪ K − 1 k =
C k ˜ h
Kv , we can conclude that the residual term (cid:80) r ∈ R h r − (cid:80)
p
∈
P
h p is a function of h Ka if and only if a ∈ ∪ K − 1 k =0 , i.e., the distance between atom a and reaction center C is less than K .
[Equation]
D H YPERPARAMETER S ENSITIVITY
We investigate the sensitivity of MolR-GCN in the task of reaction product prediction to the following hyperparameters: the number of GCN layers K , the dimsension of embedding, the margin γ , the batch size, and the implementation of READOUT function.
Since the impact of the ﬁrst three hyperparameters are highly correlated, we report the result of MolR-GCN when jointly inﬂuenced by two hyperparameters.
Figure 5a shows the result of MolR-GCN when varying the number of GCN layers and the dimension of embedding.
It is clear that MolR-GCN does not perform well when K is too small ( K = 1 ) or too large ( K = 3 , 4 ), which empirically justiﬁes our claim in Remark 3 in Section 2.2 that the number of GNN layers K can greatly impact the learned reaction templates as well as the performance of our model.
Figure 5b demonstrates that the margin γ can greatly inﬂuence the model performance as well, and such inﬂuence is highly related to the dimension of embedding: When the embedding dimension increases from 128 to 2,048, the optimal γ also increases from 2 from 8.
This is because the expected
Euclidean distance between two vectors will increase proportionally to the square root of the vector length, which forces the optimal γ to move right accordingly.
[Figure] [Figure]
[Table]
Figure 5c shows that when batch size increases from 32 to 4,096, MRR also increases from 0.831 to 0.906.
This is because a larger batch size will introduce more unmatched reactant-product pairs as negative samples, which provides more supervision for model optimization.
In the extreme case of batch size = # training instances, all pairwise molecule distances will be calculated and optimized.
Moreover, as shown in Table 5, the time cost per epoch can also be signiﬁcantly reduced when increasing the batch size (run on an NVIDIA V100 GPU).
However, a larger batch size will also require more memory usage of a minibatch in GPU.
As shown in Table 5, when batch size increases fro 64 to 4,096, the required memory of MolR-GCN also increases from 5.3 GiB to 14.8 GiB.
This prevents us to further increase batch size since the memory of NVIDIA V100 GPU is 16 GiB.
Table 6 reports the result of MolR-GCN with different implementations of the READOUT function:
AvgPooling , which applies average pooling over the atoms in a molecule graph; MaxPooling , which applies max pooling over the atoms in a molecule graph; Attention , which uses an MLP to take the embedding of an atom as input and outputs its importance score, then averages all atom embeddings weighted by their importance scores to obtain the molecule embedding; SortPooling (Zhang et al., 2018), which sorts atom embeddings before calculating a molecule embedding; Set2set (Vinyals et al., 2016), which is also an attention-like method that iteratively calculates a query vector and uses the query vector to calculate the weighted average of atom embeddings; SetTransformer (Lee et al., 2019), which is another attention-based method that calculates the attention of atoms using
Transformer.
We also attach the result of SumPooling here, which is exactly what we use in our model.
The result shows that SumPooling signiﬁcantly outperforms all other pooling functions, even the ones that are really complicated.
This is because, as shown in Proposition 2, our model can learn reaction templates with SumPooling, which signiﬁcantly improves the generalization ability.
E A BLATION S TUDY
To demonstrate that introducing the constraint of chemical reaction equivalence can indeed beneﬁt downstream tasks, we conduct ablation study on MolR in the task of molecule property predic-
[Table] [Table]
tion, chemical reaction classiﬁcation, and graph-edit-distance prediction.
We directly train the four
GNNs, i.e., GCN, GAT, SAGE, and TAG, on these datasets, then report their results in Table 7.
For molecule property prediction task, our method can improve the AUC by 1% ∼ 5% compared with the GNN in most cases.
For chemical reaction classiﬁcation task, we observe a huge improvement of our models against GNNs ( 20% ∼ 28% ), of which the reason may be that our model is pretrained on USPTO dataset as well.
For GED prediction task, the improvement of our method is rather signiﬁcant when using SAGE as the encoder (around 18% ), and the improvement is around 1% for the rest three GNNs.
The result of the ablation study shows that the constraint of chemical reaction equivalence can effectively improve the quality of learned molecule embeddings in various downstream tasks.
F D ETAILS OF M ULTI - CHOICE Q UESTIONS ON P RODUCT P REDICTION
Our multi-choice questions on product prediction are collected from online resources of Oxford
University Press, 5 , 6 , mhpraticeplus.com 7 , and GRE Chemistry Test Practice Book 8 .
We ﬁlter out the questions 1) whose choices contain stereoisomers, since our model as well as baselines cannot handle stereoisomerism, and 2) that contain molecules that cannot be successfully parsed by our method or baselines.
We manually convert the ﬁgures of molecules into SMILES strings.
The ﬁrst ﬁve questions are listed below as examples (the correct answer is given after the question), while the complete SMILES version of these questions are included in the code repository.
Examples 1 ∼ 5:
CHO 1 .
CH 3 MgBr −−−−−−−−−→ 2 .
H 2 O , H +
Which of the following is the major product of the reaction shown above?
(D)
(A) O CH(B)
CHO H (C) OH HO CH(D)
OH CH5 https://global
oup
com/uk/orc/chemistry
okuyama
student
mcqs/ch19/https:/
chemistry
(E)
[Equation]
CH
[Equation]
LiAlH
[Equation]
(excess)
[Equation] [Equation]
3 O
[Equation]
Which of the following is the major organic product of the reaction shown above?
(D)
(A) CH 3 CH 2 CH 2 CH(OH)(B) CH 3 CH 2 CH 2 CHO (C) CH 3 CH 2 CH 2 CH
OH (D) CH 3 CH 2 CH 2 CH(E) CH 3 CH 2 C
[Equation]
CH 3.
[Equation]
Which of the following are the major products of the reaction shown above?
(D)
[Equation]
A
[Equation]
C
[Equation]
D
[Equation]
E
[Equation] [Equation]
Which of the following are the products of the reaction shown above?
(E)
[Equation]
A
[Equation]
B
[Equation]
C)
[Equation]
D
[Equation]
E
[Equation]
C HOH 1 .
NaOH −−−−−−−−−−−→ 2 .
Br
What is the product of the reaction shown above for para -cresol?
(A)
(A) C HO (B) C HONa (C) C HO (D)
C HO Br (E) ONa
G C ASE S TUDY ON USPTO-479 K D ATASET
The case study on USPTO-479k dataset is shown in Table 8.
To avoid cherry-picking, we select the ﬁrst 20 reaction instances (No.
∼ No. 19) in the test set for case study.
In Table 8, the ﬁrst column is the index of reactions, the second and the third column are the reactant(s) and the ground-truth product of this reaction, respectively, and the fourth to sixth column are the product predicted by
MolR-GCN, Mol2vec, and MolBERT, respectively.
Reactions whose product is correctly predicted by all the three methods are omitted for clarity.
The index below a predicted product indicates the actual reaction that this product comes from.
As shown in Table 8, MolR-GCN gives a wrong answer on only 2 reactions, while Mol2vec and
MolBERT make mistakes on 6 reactions.
Moreover, for the two reactions that MolR-GCN does not answer correctly (No. 5 and No. 10), Mol2vec and MolBERT give the exactly same wrong answers as well, which shows that the product of the two reactions are indeed very hard to predict.
Actually, for the No. 5 reaction, the predicted product (No. 32353) is identical to the reactant, which, technically speaking, cannot be seen as a wrong answer.
For the No. 10 reaction, the predicted product (No. 18889) is very similar to the ground-truth product and they only differ in one atom (N vs S).
Another two examples that are worth mentioning are: (1) The No. 6 reaction, where the ﬁrst reactant contains a triangle ring but it breaks up in the product.
MolR-GCN correctly predicts the product, but Mol2vec and MolBERT make mistakes by simply combining the two reactants together.
The
No. 17 reaction, where the nitro group (-NO 2 ) disappears after the reaction.
MolR-GCN predicts such chemical change successfully, but Mol2vec and MolBERT still retain the nitro group in their predicted products.
[Table]