D ATA -E FFICIENT G RAPH G RAMMAR L EARNING FOR M OLECULAR G ENERATION
A BSTRACT
The problem of molecular generation has received signiﬁcant attention recently.
Existing methods are typically based on deep neural networks and require training on large datasets with tens of thousands of samples.
In practice, however, the size of class-speciﬁc chemical datasets is usually limited (e.g., dozens of samples) due to labor-intensive experimentation and data collection.
This presents a considerable challenge for the deep learning generative models to comprehensively describe the molecular design space.
Another major challenge is to generate only physically synthesizable molecules.
This is a non-trivial task for neural network-based generative models since the relevant chemical knowledge can only be extracted and generalized from the limited training data.
In this work, we propose a data-efﬁcient generative model that can be learned from datasets with orders of magnitude smaller sizes than common benchmarks.
At the heart of this method is a learnable graph grammar that generates molecules from a sequence of production rules.
Without any human assistance, these production rules are automatically constructed from training data.
Furthermore, additional chemical knowledge can be incorporated in the model by further grammar optimization.
Our learned graph grammar yields state-of-the-art results on generating high-quality molecules for three monomer datasets that contain only ∼samples each.
Our approach also achieves remarkable performance in a challenging polymer generation task with only 117 training samples and is competitive against existing methods using 81 k data points.
Code is available at https://github.com/gmh14/data_efficient_grammar .
I NTRODUCTION
The rise of computational approaches has started to have a signiﬁcant impact on the discovery of materials and drugs.
Recent advances in machine learning, especially deep learning (DL), have driven rapid development on generating novel molecular structures (Maziarka et al., 2020; Xu et al., 2019;
Hoffman et al., 2022).Various forms of generative models including generative adversarial networks (De Cao & Kipf, 2018; Maziarka et al., 2020), variational autoencoders (VAEs) (Jin et al., 2018; 2020; Liu et al., 2018; Sattarov et al., 2019), and reinforcement learning (You et al., 2018) have been exploited to represent the complicated molecular design space and generate new molecules.
They typically formulate molecular generation as a problem of distribution learning, where the generative model ﬁrst learns to reproduce the distribution of a training set before generating new molecular structures.
Generative models have also managed to integrate certain chemical constraints (e.g., valency restrictions)
(Jin et al., 2018; Liu et al., 2018) and shown promising results on the common benchmarks (Irwin et al., 2012; Ramakrishnan et al., 2014).
However, DL-based generative models face a serious limitation: they require large amounts of training data to achieve reasonable performance.
In practice, molecule data is not always abundant (Stanley et al., 2021; Altae-Tran et al., 2017;
Subramanian et al., 2016); for instance, the focus may be on a speciﬁc type of molecules fulﬁlling certain ingredient requirements.
Particularly in the context of polymers, large amounts of training data are not available, and therefore DL models use manually constructed or generated data (St. John et al., 2019; Jin et al., 2020; Ma & Luo, 2020).
Real data sets, as used in one of the state-of-the-art papers on polyurethane property prediction, have as little as 20 samples (Menon et al., 2019).
In such scenarios, designing a pure DL-based model is challenging.
N CO
N CO
OC N N CO … …
N CO OC N N CO
N CO
OC N N CO
N CO …
Bottom-upSearch
GrammarProduction
Evaluation
Training Data
Graph Grammar
Generated Samples
[Figure]
Recent renewed interest in formal grammars (Kajino, 2019; Krenn et al., 2019; Nigam et al., 2021;
Guo et al., 2021) provides an alternative to pure DL methods.
In formal language theory, a grammar is a set of production rules describing how to generate valid strings according to the language’s syntax.
A chemical grammar may thus be considered as an interpretable and compact design model that simultaneously serves as a molecular representation and a generative model; even domain-speciﬁc constraints can be explicitly incorporated into the rules.
Recent examples range from string-based (Krenn et al., 2019; Nigam et al., 2021) to hypergraph-based (Kajino, 2019) and polymer-speciﬁc grammars (Guo et al., 2021).
Grammar-based generative models do not rely on large training datasets and easily extrapolate to generate molecules outside the distribution of training samples.
Yet, they have two major drawbacks.
First, current approaches require that chemical grammars are manually designed by human experts (Krenn et al., 2019; Nigam et al., 2021; Dai et al., 2018).
This is a tedious process that heavily relies on expertise in chemistry.
Moreover, the existing grammars are also very ﬁne-grained (i.e., rules are mostly attaching atoms) in order to cover the syntax of general molecules instead of a speciﬁc dataset.
Hence, it is not straightforward how to incorporate the bias of given data (e.g., certain molecular substructures) into such grammars.
The second drawback is that it remains challenging to integrate chemistry knowledge beyond simple constraints (e.g., valency restrictions) into the grammar.
Current grammar construction approaches fail to capture more abstract or complex aspects such as the diversity or synthesizabilty of the generated molecules, which constrains their practicality.
Solutions such as Kajino (2019) resort to costly optimization on the level of molecules (or their latent representation) after the grammar is built or learned.
For a more detailed delimitation of related work, see Sec. 2.
In this paper, we propose a generative model combining complex graph grammar construction with a relatively simple and effective learning technique.
In particular, our grammar incorporates substructures of varying sizes (i.e., above atom level) and the construction process directly optimizes various chemical metrics (e.g., distribution statistics and synthesizability) while satisfying speciﬁc chemical constraints (e.g., valency restrictions).
Moreover, we have the beneﬁts of symbolic knowledge representation: explainability and data efﬁciency.
Our evaluation focuses on polymers, particularly their monomer building blocks.
Thus, we curate new, realistic polymer datasets gathered from literature that represent speciﬁc classes of monomers.
Note that our model works for arbitrary molecules.
Framework.
Figure 1 outlines our approach.
Given molecules and domain-speciﬁc metrics to be optimized, we iteratively construct and evaluate a graph grammar as our generative model.
We consider the construction as a minimum spanning forest problem and combine it with optimization of the metrics, via a learnable function F θ determining which rules to construct.
Results.
Our model successfully deals with extreme settings – from a DL perspective – learning meaningful production rules based on only ∼ 10 samples (e.g., of a speciﬁc class); this is of significant importance in a practical setting (Stanley et al., 2021; Altae-Tran et al., 2017) but has been ignored so far.
In particular, our model is able to generate members of a speciﬁc monomer class with a decent success rate.
No previous state-of-the-art system achieves similar performance in our experiments.
Generally, our approach works on training data that is orders of magnitude smaller than the amount needed by DL-based systems to produce meaningful results.
Given ∼ 100 samples, we achieve performance comparable to state-of-the-art systems trained on 81 k samples, across a wide range of common and new evaluation metrics.
Besides, our grammar optimization method can adjust to any user-deﬁned domain-speciﬁc metrics.
The learned grammars can capture domainspeciﬁc knowledge explicitly, e.g., the characteristic functional groups of a given class of polymers can be extracted from the production rules.
R ELATED W ORK
Generative Models for Molecules.
Existing models can be categorized based on their molecule representation.
It is common to use SMILES strings (Weininger, 1988).
Yang et al.
(2017), Olivecrona et al.
(2017), Chenthamarakshan et al.
(2020), Schiff et al.
and Gómez-Bombarelli et al.
(2018) use recurrent neural networks to generate the strings in a sequential manner.
For instance, Gómez-Bombarelli et al.
(2018) propose a VAE based on sequence-to-sequence encoders and decoders.
Guimaraes et al.
(2017), Sanchez-Lengeling et al.
(2017), and Dai et al.
(2018) additionally apply optimization objectives to enforce similarity or semantic correctness to generate valid SMILES.
Alternatively, molecules can be treated as graphs.
Simonovsky & Komodakis (2018), Ma et al.
(2018), and De Cao & Kipf (2018) generate the graphs in a single step, directly outputting adjacency matrices and node labels.
GraphNVP (Madhawa et al., 2019) uses two steps to generate the node labels based on the adjacency matrix; it exploits a model to encode molecules and uses the same model whose layers are reversed to generate new molecules.
You et al.
; Li et al.
(2018); Samanta et al.
; Liu et al.
; Liao et al.
; Jin et al.
(2018; 2020) build molecule graphs iteratively based on either atom nodes or substructures.
For example, JT-VAE (Jin et al., 2018)
ﬁrst generates a tree and then expands some of its nodes by attaching substructures based on a vocabulary mined from given molecules; Similarly, HierVAE (Jin et al., 2020) also uses a vocabulary, but improves upon the combinatorial attachment process by directly applying a multiresolution representation, allowing for generating much larger and diverse molecules.
All these methods depend on DL and require large training datasets.
Moreover, the resulting models are usually not interpretable.
Our approach alleviates this obstacle and can deal with practically common setting of only dozens of available data points.
Generative Models using Graph Grammars.
Our approach belongs to the class of models generating new graphs based on the production rules of a graph grammar.
These models are non-parametric, interpretable, and can incorporate meaningful graph properties into the rules.
One option is to use grammars that are manually designed by human experts (Dai et al., 2018; Nigam et al., 2021).
For instance, STONED (Nigam et al., 2021) generates new molecules based on a string-based representation of given molecules by replacing tokens (representing atoms) in accordance with the SELFIES grammar (Krenn et al., 2019).
While the simplicity of this approach is attractive, the generated molecules are not necessary reasonable from a chemical perspective (e.g., they might not be synthesizable).
This problem can be overcome by mining the grammar from real data.
Recently, several automatic techniques that explicitly construct a graph grammar have been proposed in the context of large-scale graphs to facilitate understanding and analysis (Sikdar et al., 2019; Aguinaga et al., 2018; Hibshman et al., 2019).
These works are domain-independent and do not allow specialization of the constructed grammar to reﬂect domain-speciﬁc knowledge.
Closest to our method is MHG (Kajino, 2019), a framework that constructs a molecular hyperedge-replacement grammar based on
Aguinaga et al.
From the given data, MHG learns a ﬁne-grained grammar where the rules iteratively attach single atoms and therefore incorporates hard chemical constraints (e.g., valency restrictions).
MHG then applies a VAE conditioned on the grammar to the molecules’ tree decompositions in order to also learn soft constraints (e.g., stability).
Finally, it uses Bayesian optimization to guide molecule generation.
The ﬁne-grained rules in MHG allows for rich diversity.
However, our experiments show that these rules make it hard to capture distribution-speciﬁc properties, e.g., characteristic substructures of a speciﬁc molecular class.
Such a drawback limits the practical use of
MHG.
In contrast, our approach focuses on subgraphs instead of individual atoms only.
It directly incorporates domain-speciﬁc knowledge into grammar construction and therefore avoids complicated post-processing to achieve high generation performance.
P RELIMINARIES
Molecular Hypergraph.
Molecules can naturally be represented as graphs by taking the atoms as nodes and the bonds as edges.
We particularly use a hypergraph representation.
Given a molecule
M , the hypergraph H M
=
( V, E H ) consists of a set of nodes V and a set of hyperedges E H ; a hyperedge can join more than two nodes.
Given a regular molecular graph, we construct a hypergraph by including all nodes and adding hyperedges as follows: a hyperedge is added for each bond that joins only two nodes, and for each individual ring (including aromatic ones) that joins all nodes (more than 2) in the ring.
Consider Figure 2(a) where we add two hyperedges of the latter kind, one for each ring. [Figure]
[Figure]
SingleBond
AromaticBond OxygenAtomNode CarbonAtomNode NitrogenAtomNode
Anchors
[Figure]
Formal Grammar.
A grammar G = ( N , Σ , P , X ) has a ﬁnite set N of non-terminal symbols, an initial symbol X , and a ﬁnite set of terminal symbols Σ .
It describes how to build strings from a language’s alphabet using a set of production rules P = { p i | i
= 1 , ..., k } of form p
i : LHS → RHS , where LHS is short for left-hand side and RHS for right-hand side.
Based on such a grammar, a string (of terminal symbols) is generated starting at X , by iteratively selecting rules whose lefthand side matches a non-terminal symbol inside the current string and replacing that with the rule’s right-hand side, until the string does not contain any non-terminals.
Minimum Spanning Forest (MSF).
A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices, without any cycles and with the minimum possible total edge weight.
Minimum spanning forest is the union of MSTs for a set of unconnected edge-weighted undirected graphs.
G RAPH G RAMMAR L EARNING WITH D OMAIN -S PECIFIC O PTIMIZATION
Graph Grammar.
We focus on a formal grammar over molecule graphs instead of strings, a graph grammar .
As shown in Figure 2(b), both left and right-hand side of each production rule are graphs.
These graphs contain non-terminal nodes (shadowed squares) and terminal nodes (colored circles), representing atoms.
The white nodes are anchor nodes , which do not change from the left to the right-hand side.
Molecule graph generation based on a graph grammar is analogous to the one with string-based grammars described in Sec.
3 (see also Figure 2(c)).
To determine if a production rule p i is applicable at each step, we use subgraph matching (Gentner, 1983) to test whether the current graph contains a subgraph that is isomorphic to the rule’s left-hand side.
Since the subgraphs are usually small in scale, the matching process is efﬁcient in practice.
Overall Pipeline.
As shown in Figure 1, the input to our algorithm consists of a set of molecular structures and a set of evaluation metrics (e.g., diversity and synthesizablity).
The goal is to learn a graph grammar which can be used for molecule generation.
To this end, we ﬁrst consider each molecule as a hypergraph.
The grammar construction is a bottom-up procedure, which iteratively creates production rules by contracting hyperedges (shown in Figure 3).
The hyperedges to contract are determined by a parameterized function F θ , implemented as a neural network.
We simultaneously perform multiple randomized searches to obtain multiple grammars which are evaluated with respect to the input metrics.
This approach learns how to create a grammar that samples molecules maximizing the input metrics.
Hence, domain-speciﬁc knowledge can be incorporated to the grammar-based generative model.
The grammar construction and learning process are described in detail in the following Sec. 4.1 and 4.2.
The ﬁnal molecule generation is detailed in Appendix A.
[Figure]
4. B OTTOM - UP G RAMMAR C ONSTRUCTION
We describe at a high-level our grammar construction approach (shown in Figure 3).
A bottom-up search builds up production rules from the ﬁnest-grained level that comprises individual hyperedges in the molecular hypergraph.
We construct a grammar by iteratively sampling a set of hyperedges and contracting them into an individual node.
The sampling algorithm is described in more detail in
Sec. 4.2.
For each contraction step, a production rule is constructed and added to the grammar and we obtain a new hypergraph with fewer nodes and edges.
We simultaneously perform the hyperedge selection and rule construction for all input molecules until all hyperedges are contracted.
Without the loss of generality, we describe the construction process for a single molecule.
At iteration t , we consider the current graph H M,t
=
( V, E H ) and sample m hyperedges E ∗ t
=
e ( i )
t ∈
E H
| i = 1 , ..., m } .
Let V ∗ t = { v ( i ) t ∈ V | i = 1 , ..., n } be the nodes joined by these hyperedges.
We then extract all connected components with respect to these hyperedges.
Next, we convert each connected component H ( i ) sub,t
=
( V ( i ) sub,t , E ( i ) sub,t ) into a production rule.
The anchor nodes are those nodes from V that are connected to nodes from H ( i ) sub,t in the original graph H M
but that do not occur in H ( i ) sub,t themselves.
We also provide notation for the relevant edges:
[Equation]
t
[Equation]
Then we construct the production rule p i : LHS → RHS with non-terminal node R ∗ on the left:
[Equation]
When all connected components have been converted into production rules, we update the original hypergraph to H M,t +1 by replacing each connected component with the non-terminal node R ∗ .
The above process continues until the hypergraph only consists of one single non-terminal node.
For this ﬁnally constructed rule, we use the initial node X instead of R ∗ on the left-hand side.
Our proposal has several properties: (1) As a generative model, the grammar can reproduce all input molecules.
(2) Since the production rules are constructed from subgraphs of real molecules, valency conditions are naturally obeyed and all generated molecules are thus valid.
The generation not only interpolates the training data but also extrapolates to generate molecular structures outside the distribution of previously seen examples.
The constructed grammar roughly follows Chomsky normal form (Chomsky, 1959) and hence is easy to parse and can serve for explanation.
4. O PTIMIZING G RAMMAR C ONSTRUCTION
So far, we have left open a critical question: how to optimize the grammar for the input metrics?
Since the grammar construction is completely determined by the sequence of hyperedge sets selected, we can convert the optimization of the grammar into the optimization of the hyperedge selection sequence; in particular, note that there are no hyperparameters in addition.
Thus, the variable of the optimization problem is the selection sequence with objective to maximize the input metrics.
We formulate the search for a sequence of hyperedge sets as an MSF problem.
The bottom-up grammar construction process can be considered as search for a spanning forest for all input graphs.
Note that instead of the structure of MSF itself, we focus on the order of hyperedges added to the
MSF.
The order of hyperedges is determined by an edge-weight function F : E H → R mapping each hyperedge in every considered molecule hypergraphs to a scalar value.
Optimizing the hyperedge selection is equivalent to optimizing the edge weight function.
Note that this kind of function is similar to the concept of potential function in the ﬁeld of graphical models (Barber, 2012).
Our goal here is to learn a potential function F ( · ) that maximizes the given evaluation metrics.
We deﬁne our edge weight function as a parameterized function of hyperedge features as F ( e ; θ ) =
F θ ( f ( e )) , where f ( · ) is a feature extractor function for individual hyperedges e , and θ are the parameters of F ( · ) to be optimized.
There is no speciﬁc restriction on the choice of f ( · ) so we use a pretrained neural network in our experiments.
Our optimization objective is max θ (cid:80) i λ i M i , where M i is the value of the i -th input grammar metric, and λ i is the weight of the i -th metric.
Since most grammar metrics can only be obtained by evaluating a set of molecules generated by the grammar, it is impossible to get the gradient of M i with respect to the parameters θ via the chain rule.
We address this problem by formulating the process of MSF construction as Monte Carlo (MC) sampling.
To obtain the gradient of non-differentiable evaluation metrics, we draw inspiration from task-based learning (Donti et al., 2017; Chen et al., 2019) and reinforcement learning, by using
REINFORCE (Williams, 1992) to optimize the potential function.
Speciﬁcally, we deﬁne a random variable X : Ω → { 0 , 1 } on each hyperedge, where X =
( X = 0 ) means the hyperedge is (not) selected.
In each iteration of grammar construction, X follows a Bernoulli distribution, based on the probability φ ( e ; θ ) to sample e :
[Equation]
where σ ( · ) is the sigmoid function.
For φ ( e ; θ ) , the larger the weight of edge e , the lower the probability of e being sampled in the current iteration, which matches the target of MSF.
We sample X for each hyperedge and construct grammar production rules iteratively as described in Sec. 4.1.
Suppose that the constructed grammar is G .
Since G is determined by the sampled order of hyperedges, we have p
[Equation]
G )
= p
[Equation]
X
[Equation]
φ
[Equation]
e
[Equation]
θ
[Equation]
1 − X
[Equation]
j
[Equation]
t , where C ( · ) is grammar construction process, e ( j ) t is the j -th hyperedge selected in the t -th iteration, and X is the concatenation of selected hyperedges along all iterations.
The optimization objective is:
[Equation]
We estimate the expectation with MC sampling and REINFORCE, approximating the gradient with respect to θ as:
[Equation]
We then apply gradient ascent in order to maximize the objective.
Note that M i ( X ) is normalized to zero mean for each sampling batch to reduce variance in training.
The grammar construction, evaluation, and optimization process is repeated until θ converges or the iteration number exceeds a preset limit.
Our approach reduces the complexity of the optimization variable space from being combinatorial (all possible orderings of selected hyperedges) to the dimension of the parameter θ .
Such complexity is also much lower than other deep neural network generative models that are directly trained on the molecule dataset.
E VALUATION
Our evaluation investigates the following ﬁve questions:
• How do SOTA models for molecule generation perform on realistic small monomer datasets ?
• Is our approach effective in generating speciﬁc types of monomers that are synthesizable ?
• How do the models perform on larger monomer datasets ?
• Can our approach learn to weigh and optimize different metrics according to user needs ?
Can our grammar’s explainability support applications , such as functional group extraction?
5. E XPERIMENT S ETUP
Data.
We use three small datasets, each representing a speciﬁc class of monomers, which we curate manually from the literature: Acrylates, Chain Extenders, and Isocyanates, containing only 32, 11, and 11 samples, respectively (printed in Appendix G).
For comparison and for pretraining baselines, we also use a large collection of 81k monomers from St. John et al.
and Jin et al.
Evaluation Metrics.
We consider commonly used metrics in the literature (Polykovskiy et al., 2020) and new ones for assessing both individual sample quality and distribution similarity:
• Validity/Uniqueness/Novelty: Percentage of chemically valid/unique/novel molecules.
• Diversity: Average pairwise molecular distance among generated molecules, where the molecular distance is deﬁned as the Tanimoto distance over Morgan ﬁngerprints (
Rogers
Hahn,
• Chamfer Distance (Fan et al., 2017):
Distance between two sets of molecules, wherein the usual pairwise Euclidean distance is replaced by the Tanimoto distance.
• Retro ∗ Score (RS): Success rate of the Retro ∗ model (Chen et al., 2020) which was trained to ﬁnd a retrosynthesis path to build a molecule from a list of commercially available ones 2 .
• Membership : Percentage of molecules belonging to the training data’s monomer class.
We propose the last three as new metrics.
We deﬁne the Chamfer Distance for molecules to account for “external” diversity between generated data and training data as quantitative indicator of the generative model’s extrapolation ability.
Ideally, generated molecules should not be too close to any training molecule.
Hence, a larger distance is more desired.
Note that the commonly used metrics of existing distances only focus on similarity to the training data.
Furthermore, we include the Retro ∗ Score as a metric estimating sample synthesizability since the commonly used SA Score (Ertl & Schuffenhauer, 2009) does not adequately assess more recent molecules (Polykovskiy et al., 2020).
For our small datasets, we check class membership as well.
Since a polymer’s class is usually determined by its monomer types, it is essential that a generative model can generate class members.
Baselines.
We compare to various approaches: GraphNVP, JT-VAE, HierVAE, MHG, and
STONED; for descriptions see Sec.
We call our method DEG, short for Data-Efﬁcient Graph
Grammar.
Appendix B provides the implementation details.
5. R ESULTS ON S MALL , C LASS -S PECIFIC P OLYMER D ATA
Results.
Table 1 shows the results on the Isocyanate data; due to lack of space the other two tables are in Appendix C.1.
Observe that GraphNVP has a rather poor performance.
The VAEs and existing grammar-based systems perform reasonably well on some metrics, but have low scores on the RS and Membership metrics.
In contrast, our method signiﬁcantly outperforms the other methods in terms of Membership and Retro ∗ Score on all three datasets.
It also achieves the best or comparable performance on all other metrics.
Discussion.
Our evaluation shows that learning on monomer datasets, especially when the dataset size is small, is much more challenging than larger datasets as used in the related work (Irwin et al., 2012; Ramakrishnan et al., 2014).
GraphNVP shows poor performance since it uses molecular graph adjacency matrix as model input, which is extremely sparse for our relatively large monomer structures.
The vocabulary-based JT-VAE and HierVAE perform reasonably well.
However, when
We
[Table]
the dataset is small, JT-VAE is not able to mine a vocabulary that would allow it to generate many unique molecules.
The more diverse vocabulary of HierVAE clearly solves this shortcoming
[Table]
but the low Membership score shows that it does not capture monomer class speciﬁcs.
In general, grammar-based methods can better capture class-speciﬁc molecule characteristics than DL-based methods and have higher Membership scores.
However, they perform poorly on RS.
Speciﬁcally,
MHG has ﬁne-grained rules that simply attaches atoms.
This leads to high diversity but the rules hardly capture domain-speciﬁc characteristics.
The STONED method iteratively replaces atoms based on the SELFIES grammar and only performs interpolation and exploration based on training data, making it hard to embed build-in domain-speciﬁc knowledge in the generative model.
The overall results show that: 1) Our learned, substructure-based grammar successfully captures class speciﬁcs – a critical evaluation criterion which has been ignored so far.
Other critical, domainspeciﬁc metrics such as RS can successfully be optimized during grammar learning.
Our score is ≥ 5 × higher than the others.
More importantly, the optimization is done in-situ during grammar construction, and hence it avoids post-processing.
Our method is the only one that constantly achieves stable performance.
Altogether, these results clearly differentiate us from the others.
5. R ESULTS ON L ARGE P OLYMER D ATASET
Our method is developed to model speciﬁc classes of complex molecules (e.g., classes of different monomers or polymers) and is expected to deal with most practical scenarios with only a few dozen samples for training.
However, as mentioned above, monomer data itself is different from the molecules used in related works.
Therefore, we also investigate how our method performs on large monomer datasets comparing with existing methods.
4 Since our approach is relatively complex, but more data-efﬁcient, we apply it to a 0 .
15% subset.
Details are provided in Appendix B.
Results.
Table 3 in the appendix shows the results.
In summary, some SOTA systems such as
SMILESVAE and GraphNVP fail to capture any distribution speciﬁcs and mostly generate invalid molecules.
JT-VAE and grammar-based baselines (MHG, STONED) perform poorly with respect to the former but their sample quality is reasonable.
HierVAE performs extremely well on all metrics except Chamfer distance.
Our approach can generally compete with the latter (only trained on 0 .
15% data) and achieves better sample quality, especially Chamfer distance is twice as high.
Discussion.
Monomer data turns out to be much more challenging compared to the common datasets.
Generally, DL-based methods achieve better performance in terms of distribution statistics, while grammar-based models (including ours) have better sample quality.
It is reasonable since DLbased methods are all based on distribution learning while grammar-based methods are more focused on modeling chemical rules.
Our approach is the only grammar-based system performing well on distribution statistics, which highlights the importance of grammar construction.
Fine-grained grammars that either iteratively attaches single atoms (MHG), or only performs input data interpolation (STONED) cannot ﬁt training data more speciﬁcally.
Our sample quality is among the best.
Fur-
[Figure]
O C N N C O O
[Figure]
C
[Figure]
O C N
[Figure]
C
[Figure]
O O
[Figure]
C
[Figure]
thermore of the
5. A NALYSIS
Optimizing for Speciﬁc Metrics, Balance Factor λ .
We study the effect of λ weighing the importance of metrics according to user needs.
We choose 9 different combinations for two optimization objectives: Diversity and RS.
λ 1 ranges from 0 to 2 with 0 .
25 as interval, while λ 2 ranges from 4 to 0 with 0 .
5 as interval.
Figure 4 depicts results for Isocyanates and Acrylates.
We see that λ fulﬁlls its purpose, as the performance of the two objectives can be well controlled.
In our study, we use λ 1 = 1 , λ 2 = 2 for a balanced trade-off between Diversity and RS.
Explainability Supports Applications, Functional Group Extraction.
In Appendix F, we show production rules of three graph grammars learned from three small polymer datasets.
For each grammar, there is clearly a rule capturing the functional group that characterizes the dataset’s corresponding monomer class.
For example, p 3 is the relevant production rule for Isocyanates.
Since functional groups must be present in all monomers of this type, the relevant rule is easily obtained by selecting the rule shared by all inputs.
Generated Examples.
Figure 4 also shows examples generated using our grammars learned on
Isocyanates and Acrylates.
Though we have only 32 and 11 training samples respectively, our graph grammar can be used to generate novel and complex molecules.
For example, cyclooctane is not contained in the training data but our grammar can generate it by sequentially applying two partial ring formation rules.
For more generated examples on the other datasets, see Appendix C.2.
C ONCLUSIONS
We propose a data-efﬁcient generative model combining graph grammar construction with domainspeciﬁc optimization.
Our grammar incorporates substructures of varying size and the construction directly optimizes various chemical metrics.
Extensive experiments on three small size polymer datasets and a large polymer dataset demonstrate the effectiveness of our method.
Our system is the only one that is capable of generating monomers in a speciﬁc class with a high success rate.
It will be useful to incorporate property prediction models with our graph grammar for generating superior molecular candidates for practical use.
A CKNOWLEDGEMENT
This work is supported by the MIT-IBM Watson AI Lab and its member company, Evonik.
A D ETAILS ON THE M OLECULE G ENERATION
Given a learned grammar, we condition the generation strategy based on (non)terminal symbols in the rules: during molecule generation, we exponentially increase the probability of those production rules without non-terminal symbol on the right-hand side based on the iteration number.
Formally, the probability to select a certain production rule r at iteration t is p ( r ) =
Z − 1 exp( αtx r ) , where x r is a binary value indicating whether rule r contains only terminal symbols on the right-hand side, and Z is a normalization factor.
We used α = 0 .
5 in our experiments, since it reduces the generation time sufﬁciently while maintaining satisfactory diversity.
Note that we initially experimented with uniform random sampling of rules during testing.
However, the possibility of generating arbitrarily large molecules (i.e., by choosing production rules with a non-terminal symbol on the right-hand side more likely) sometimes resulted in a never-ending generation process, a problem in practice.
B D ETAILS ON THE I MPLEMENTATION
Evaluation Metrics.
For the large polymer dataset, we consider 4 additional evaluation metrics, measuring distribution statistcs of the generated molecules, which are commonly used in DL-based methods.
The metrics are:
• Octanol-Water Partition Coefﬁcient (logP) :
A ratio of a chemical’s concentration in the octanol phase to its concentration in the aqueous phase of a two-phase octanol/water system.
• Synthetic Accessibility Score (SA) Estimate of how hard or easy it is to synthesize a given molecule based on the molecule’s fragments (Ertl & Schuffenhauer, 2009).
• Quantitative Estimation of Drug-likeness (QED) :
Estimate of how likely a molecule is to be a viable drug candidate, meant to capture aesthetics in medicinal chemistry (Bickerton et al., 2012).
• Molecular Weight (MW) :
Sum of atomic weights in a molecule.
Differences in the histograms for the generated and real data may reveal bias towards generating lighter or heavier molecules.
Note that, while SA Score and QED are not considered useful sample quality heuristics for more recent molecules, they are still useful as distribution statistics (Polykovskiy et al., 2020; Shultz, 2018).
Baselines.
For STONED, as suggested by the authors, we ﬁrst generate the chemical space for each sample in the dataset 5 .Then
we take all samples scoring higher than 0 .
8 and randomly sample the remaining ones to obtain our 10k samples.
For MHG, we learn a hypergraph grammar on the dataset following the paper’s implementation and generate molecules by randomly sampling and deploying production rules.
For other baselines we mainly use the settings suggested in the original papers.
For the experiments on the small datasets, SMILESVAE, GraphNVP and HierVAE are pretrained on the large dataset and thereafter ﬁne-tuned on speciﬁc small dataset; the other baseline implementations do not support pretraining, hence we train them from scratch on the small datasets.
Our System.
For our approach, we choose a pretrained graph neural network (Hu et al., 2019) as our feature extractor f ( · ) .
Note that we do not ﬁnetune its parameters during training and it can be replaced by any plug-and-play feature extractors.
For the potential function F θ , we use a two-layer fully connected network with size 300 and 128 .
For the optimization objectives, we consider two metrics: diversity and RS.
For hyperparameters, we set MC sampling size as 5 .
We use the Adam optimizer to train the two-layer network with learning rate 0 .
We trained for 20 epochs.
We train the model and construct grammar on each dataset separately from scratch.
For the large polymer dataset, we only use 117 training samples to optimize the grammar.
This is motivated by the fact that only 436 different motifs exist in the training dataset as stated in Jin et al.
We can then construct a subset consisting of 436 molecules that can cover these 436 motifs by random sampling.
We then sample from this subset to get the training set for our method.
For the basic setting of our method, we sample 117 training molecules.
We also consider the scenario with more data, where we extend the former set to 239 samples.
After training, we generated 10 k samples per dataset for evaluation.
For the large polymer dataset, besides the naively generated 10 k samples, we further construct another set of generated molecules
[Table]
and SMILESVAE did not allow for reasonable evaluation on some metrics (–).
Our method DEG was trained on 0 .
15% and 0 .
3% of the train data.
DEG (ﬁtting) is evaluated using the selected 10 k samples via the ﬁtting process described in Appendix B.
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
to have a fair comparison with DL-based methods on distribution statistics.
We perform a ﬁtting process selecting 10 k data points from 100 k generated samples using the same learned grammar in order to get a better performance on distribution statistics.
Speciﬁcally, we calculate the four evaluation metrics of distribution statistics for both the training dataset and the 100 k generated samples; each data point can have a corresponding 4 -dimensional vector.
We perform k -means clustering of all the vectors of the training dataset with k = 10 , 000 .
Then we partition the 4 -dimensional space into k regions using Voronoi diagram and treat each region ‘equal mass’.
For each region, we sample one data point from our generated samples that lie in the region.
Thus, we construct a set of 10 k generated samples and evaluate it the same way as the other methods.
C A DDITIONAL R ESULTS C. Q UANTITATIVE RESULTS
We report the results on the Acrylate and Chain Extender datasets in Table 2.
Since SMILESVAE cannot achieve reasonable validity for all three small datasets, we omit it in the tables.
Our method signiﬁcantly outperforms the others in terms of Retro ∗ Score and Membership, while achieving best or comparable performance across all other metrics.
The results for the large polymer dataset are reported in Table 3.
As common practice (Jin et al., 2020; Polykovskiy et al., 2020), we compute Frechet distance between property distributions of molecules in the generated and test sets for distribution statistics.
All but our two new evaluation metrics are computed using MOSES (Polykovskiy et al., 2020).
Since the building blocks of polymer data in this dataset are from a special database (St. John et al., 2019), which differs signiﬁcantly from the emolecule database Retro ∗ is trained on, we do not report RS as it is less meaningful.
Our method achieves remarkable performances across all evaluation metrics.
Note that we only usedata points while the others are fully trained on the whole dataset.
C. E XAMPLES OF GENERATED RESULTS
O S S N O
O
O O
O S S
O
N
F
O HN N
N
O O
HN
S
O O
O O
S
F
O
O O
N
O
S
O O
O
O HO
NH
OH
H 2 N
NH
O
OH
NH
O
O O O
H
[Figure]
D S WITCHING THE F EATURE E XTRACTOR
In order to demonstrate the plug-and-play capability of our system’s feature extractor, we provide experimental results where we use most embeddings from the deepchem package 6 .
As it can be seen in Figure 6, this simple feature extractor yields higher performance than the pretrained GNN at the start of the optimization, but cannot improve further through the whole learning process.
In order to obtain a reasonable optimized grammar, an ideal feature extractor should capture both the local and the global information of the hyperedges in the hypergraph.
Hence, the GNN ﬁts better our purpose of grammar construction.
[Figure]
E D EMONSTRATION OF S TABILITY OF REINFORCE
Since REINFORCE is known to have large variance
[Figure]
we provide results on the stability of our proposed DEG.
We run our algorithm with three random seeds on the Isocyanates data.
The experimental results are shown in Figure 7.
The diversity scores are relatively stable across the three random seeds.
The RS scores vary more but all three experiments converge to a similar value around the end of optimization.
We also show convergence curves for the other three datasets in Figure
[Figure] [Figure]
[Figure]
G O UR D ATASETS G. I SOCYANATES
MDI O=C=
NC1=CC=CC(CC2=CC=C(C=
C2N=C=
O)CC3=CC=C(C
=
C3)N
=C=O)=C
MDI O=C
=
NC1=
CC(CC2=C(C=C(C=
C2)CC3=CC=C(C
=
C3N=
C
=O)CC4=
CC=C (C=C4)N=C
=O)N=
C=O)=CC=
C
MDI O=C=
NC1=CC=C(C
=
C1)CC2=CC=C(C=
C2N=C=
O)CC
=C(C =C(C
=
C3)CC4=
C
C=C(C=
C4N=
C
=O)CC5=
CC=C(C
=
C5)N=C=O)N=
C=
O
HDI O=C=NCCCCCCN
=
C
=
O
HDI O=C=NCCCCCCCCCCCCN=
C
=
O
HDI O=C=NCCCCCCCCCCCCCCCCCCN=
C
=
O
HDI O=C=NCCCCCCCCCCCCCCCCCCCCCCCCN=
C
=
O
IPDI CC1(CC(CC(CN=
C=O)(C1)C)N=
C=O)C
TDI CC1=C(C
=C(C=
C1)CN=C=O)N=
C=
O
HMDI O=C
=NC1CCC(CC2CCC(CC2)N=
C=
O)CC
LDI CCOC(C(N=
C=O)CCCCN=
C=O)=O
G. A CRYLATES Benzyl
Acrylate C=CC(=O)OCC1=
CC=CC=C
Phenyl Acrylate C=CC(=O)OC1=CC=CC=C
Phenyl Methacrylate CC(=C)C(=O)OC1=CC=CC=C 2-Phenylethyl Acrylate C=
CC(=O)OCCC1=CC=CC=C n-Octyl Methacrylate CCCCCCCCOC(=O)C(=C)C
Sec-Butyl Acrylate CCC(C)OC(=O)C
=
C
Benzyl Methacrylate CC(=C)C(=O)OCC1=CC=CC=C
Pentaﬂuorophenyl acrylate C=CC(=O)OC1=
C(C(=C(C(=C1F)F)F)F)F iso-Butyl methacrylate CC(C)COC(=O)C(=C)C n-Dodecyl methacrylate CCCCCCCCCCCCOC(=O)C(=C)C sec-Butyl methacrylate CCC(C)OC(=O)C(=C)C n-Propyl methacrylate CCCOC(=O)C(=C)C 3,3,5-Trimethylcyclohexyl methacrylate CC1CC(CC(C1)(C)C)OC(=O)C(=C)C iso-Decyl acrylate CC(C)CCCCCCCOC(=O)C=
C n-Propyl acrylate CCCOC(=O)C=
C 2-Methoxyethyl acrylate COCCOC(=O)C=C 2-Phenoxyethyl methacrylate CC(=C)C(=O)OCCOC1=CC=CC=C n-Hexyl acrylate CCCCCCOC(=O)C=
C 2-n-Butoxyethyl methacrylate CCCCOCCOC(=O)C(=C)C
Methyl Methacrylate CC(=C)C(=O)OC
Methyl Acrylate COC(=O)C=C
Butyl Arylate CCCCOC(=O)C=C 2-Ethoxyethyl methacrylate CCOCCOC(=O)C(=C)C
Isobornyl methacrylate CC(=C)C(=O)OC1CC2CCC1(C2(C)C)C 2-Ethylhexyl methacrylate CCCCC(CC)COC(=O)C(=C)C
Neopentyl glycol propoxylate diacrylate CC(C)(COCCCOC(=O)C=
C)COCCCOC(=O)C=C 1,6-Hexanediol diacrylate C=CC(=O)OCCCCCCOC(=O)C=
C
Pentaerythritol triacrylate C=CC(=O)OCC(CO)(COC(=O)C=
C)COC(=O)C=C
Trimethylolpropane propoxylate triacrylate
CCC(COCCCOC(=O)C=C)(COCCCOC(=O)C=
C)COCCCOC(=O)C=C
Di(trimethylolpropane) tetraacrylate
CCC(COCC(CC)(COC(=O)C=C)COC(=O)C=
C)(COC(=O)C=
C)COC(=O)C=C
Dipentaerythritol pentaacrylate
C=CC(=O)OCC(CO)(COCC(COC(=O)C
=
C)(COC(=O)C=C)COC(=O)C=C)COC(=O)C=
C
Dipentaerythritol hexaacrylate
C=CC(=O)OCC(COCC(COC(=O)C=
C)(COC(=O)C=C)COC(=O)C=C) (COC(=O)C=C)COC(=O)C
=
C
G.
C HAIN E XTENDERS EG
[Table]
AE-H-AE OCCNC(=O)NCCCCCCNC(=O)NCCO AE-L-AE OCCN1C(=O)NC(C1(=O))CCCCNC(=O)NCCO D-E-D Oc1ccc(cc1)CCC(=O)OCCOC(=O)CCc1ccc(cc1)O LYS OC(=O)C(N)CCCCN L-Orn OC(=O)C(N)CCCN
Pip N1CCNCC
AFD Nc1ccc(cc1)
SSc2ccc(cc2)N
MDA Nc1ccc(cc1)Cc2ccc(cc2)N