A UGMENTING G ENETIC A LGORITHMS WITH D EEP N EURAL N ETWORKS FOR E XPLORING THE C HEMICAL S PACE
A BSTRACT
Challenges in natural sciences can often be phrased as optimization problems.
Machine learning techniques have recently been applied to solve such problems.
One example in chemistry is the design of tailor-made organic materials and molecules, which requires efﬁcient methods to explore the chemical space.
We present a genetic algorithm (GA) that is enhanced with a neural network (DNN) based discriminator model to improve the diversity of generated molecules and at the same time steer the GA.
We show that our algorithm outperforms other generative models in optimization tasks.
We furthermore present a way to increase interpretability of genetic algorithms, which helped us to derive design principles.
Our open source implementation: https://github.com/aspuru-guzik-group/GA
I NTRODUCTION
The design of optimal structures under constraints is an important problem spanning multiple domains in the physical sciences.
Speciﬁcally, in chemistry, the design of tailor-made organic materials and molecules requires efﬁcient methods to explore the chemical space.
Purely experimental approaches are often time consuming and expensive.
Reliable computational tools can accelerate and guide experimental efforts to ﬁnd new materials faster.
We present a genetic algorithm (GA) (Davis, 1991; Devillers, 1996; Sheridan & Kearsley, 1995;
Parrill, 1996) for molecular design that is enhanced with two features:
A neural network based adaptive penalty.
This promotes exploratory behaviour of the GA and thus improve the diversity of generated molecules.
Exploiting the robustness of S ELFIES (Krenn et al., 2019), we do not need to incorporate any expert based mutation or cross-over rules.
Starting from only simple methane molecules, our algorithm outperforms other generative models in optimization tasks for molecular design.
By introducing machine learning (ML) techniques, the long term behaviour is not subject to stagnation, thus solving a signiﬁcant problem in genetic algorithms (Paszkowicz, 2009).
No domain knowledge is required; thus, our approach is not limited to chemistry-speciﬁc questions but can be applied to a wide range of optimization problems.
R ELATED W ORKS
Inverse design is the systematic development of structures with desired properties.
In chemistry (Sanchez-Lengeling & Aspuru-Guzik, 2018), the challenge of inverse design has been tackled as an optimization problem, among others in the form of variational autoencoders (VAEs), generative adversarial networks (GANs) and genetic algorithms.
Variational autoencoders and generative adversarial networks VAEs (Kingma & Welling, 2013) are a widely used method for direct generation of molecular string or graph representations (G´omezBombarelli et al., 2018).
They encode discrete representations into a continuous (latent) space.
Molecules resembling a known structure can be found by searching around the region of the encoded point.
Making using of the continuous latent representation, it is possible to search via gradients or Bayesian Optimization (BO).
However, the generation of semantically and syntactically valid molecules is a challenging task.
Thus, several follow up works to the VAE have been proposed for inverse design in chemistry.
Among them, CVAE (G´omez-Bombarelli et al., 2018), GVAE (Kusner et al., 2017) and SD-VAE (Dai et al., 2018) work directly on string molecular representations.
Alternatively, JT-VAE (Jin et al., 2018a) as well as CGVAE Liu et al.
(2018) work on molecular graphs.
Unlike latent space property optimization, the policy network (PN) based GCPN model
(You et al., 2018) proposes a reinforcement learning (RL)-based method for direct optimization on molecular graphs.
ORGAN (Guimaraes et al., 2017) demonstrate training string-based generative adversarial networks (GANs) (Goodfellow et al., 2014) via RL.
Another method based on adversarial training is
VJTNN (Jin et al., 2018b).
Segler et al.
(2017) ﬁrst introduced molecule generating models based on language models and reinforcement learning, where actions in an environment are taken to construct a molecule, receiving reward from an external scoring function.
This model has also shown strong performance in the GuacaMol benchmark (Brown et al.
In all the approaches mentioned above, generative models are trained to mimic the reference data set distributions, thus limiting the exploration ability of VAEs and GANs.
Genetic algorithms & related methods There exist several examples of GA based molecule optimization algorithms in literature (O’Boyle et al., 2011; Virshup et al., 2013; Rupakheti et al., 2015;
Jensen, 2019; Sheridan & Kearsley, 1995; Parrill, 1996)).
While some of these examples pre-deﬁne mutations on a SMILES level to ensure validity of the molecules, other approaches use fragmentbased assembly of molecules.
GAs are likely to get trapped in regions of local optima (Paszkowicz, 2009).
Thus, for selection of the best molecules, (Rupakheti et al., 2015; Jensen, 2019) report multiple restarts upon stagnation.
We include the aforementioned models as baselines for numerical comparison.
GA-D A RCHITECTURE 3. O VERVIEW
Our approach is illustrated in Figure 1.
Our generator is a genetic algorithm with a population of molecules m .
In each generation, the ﬁtness of all molecules is evaluated as a linear combination of molecular properties J ( m ) and the discriminator score D ( m ) :
[Equation]
Random mutations of high ﬁtness (best performing) molecules replace inferior members, while bestperforming molecules continue to a subsequent generation.
The probability of replacing a molecule is evaluated using a smooth logistic function based on a ranking of ﬁtness among the molecules of a generation.
At the end of each generation, a neural network based discriminator is trained jointly on molecules generated by the GA and a reference data set .
The ﬁtness evaluation accounts for the discriminator predictions for each molecule.
Therefore, the discriminator plays a role in the selection of the subsequent population.
3. M UTATION & C ROSS - OVER R ULES
Mutation of molecules to populate subsequent generations is an important element of the GA.
A low degree of mutation can lead to a slow exploration of the chemical space, causing stagnation of the ﬁtness function.
Robustness of S ELFIES allows us to do random mutations to molecular strings while preserving their validity.
Thus, our mutations only include 50% insertions or 50% replacements of single S ELFIES characters.
To accelerate the exploration of the GA, we add one domain-speciﬁc mutation rule – the direct addition of phenyl groups in approximately 4% of cases.
Character deletion is implicitly taken into account in S ELFIES mutations, and we do not use crossover rules.
decreasing discriminator predictions
Rank denotes the position of molecule in an increasing
3. R OLE OF THE D ISCRIMINATOR
The fundamental role of the discriminator is to increase molecular diversity by removing longsurviving molecules.
Consider the realistic scenario in which a GA has found a molecule close to a local optimum, where all mutations are lowering the ﬁtness.
As a result, this molecule survives for multiple generations while occupying a large fraction of the population.
During such periods, the GA has limited view of the chemical space as it repeatedly explores mutations of the same high-ﬁtness molecule.
A straightforward solution would be the addition of a linear penalty (Nanakorn & Meesomklin, 2001) in the ﬁtness function that accounts for the number of successive generations a molecule survives.
However, this method assigns independent scores to similar-looking molecules which again results in less variety.
Our solution is the addition of an adaptive penalty (in our case a neural network based discriminator), thus resolving the problem of stagnation.
Molecules with similar representation receive similar classiﬁcation scores.
Furthermore, long-surviving molecules are trained longer and receive weaker scores, resulting in decreasing ﬁtness - reducing the chance of long periods of stagnation (illustrated in Figure 2).
The task of the discriminator thus is to memorize families of high performing molecules and penalize their ﬁtness to force the GA to explore different regions in chemical space.
E XPERIMENTS
Comparing to the literature standard, we aim at maximizing the penalized logP objective J ( m ) proposed by (G´omez-Bombarelli et al., 2018).
For molecule m , the penalized logP function is deﬁned as
[Equation]
where logP indicates the water-octanol partition coefﬁcient, SA (Ertl & Schuffenhauer, 2009) represents the synthetic accessibility and prevents the formation of chemically unfeasible molecules, and RingPenalty linearly penalizes the presence of rings of size larger than 6.
Our reference data set consists of 250,000 commercially available molecules extracted from the ZINC database (Irwin et al., 2012).
All three quantities in the above equation are normalized based on this data set.
Models in the upper part are forced to optimize within the distributions of given reference data sets while the GA based approaches in the lower part can freely explore chemical space.
Direct comparisons need to take into account these different objectives and scopes.
The parameter β in our
GA can be used to balance exploration and exploitation (see Section 4.6)
[Table]
(G ´ omez-Bombarelli et al., 2018)4 . 85 ± 0 . VAE ORGAN (Guimaraes et al., 2017)3 .
52 ± 0 . GAN JT-VAE (Jin et al. , 2018a)4 .
90 ± 0 . VAE ChemTS (Yang et al., 2017) 5 .
6 ± 0 . RNN GCPN (You et al., 2018)7 . 87 ± 0 .
PN + GAN Random S ELFIES 6 . 19 ± 0 .
Random Search
E xp l o r a ti on GB-GA (Jensen, 2019)7 .
4 ± 0 .
GA
GB-GA (Jensen, 2019)15 .
76 ± 5 .
GA
GA (here) 12 .
61 ± 0 .
GA
GA + D (here) 13 .
31 ± 0 .
GA + DNN ( GA + D(t) (here)20 .
72 ± 3 . 14 )
GA + DNN
4. U NCONSTRAINED OPTIMIZATION AND COMPARISON WITH OTHER GENERATIVE MODELS
We deﬁne our ﬁtness function according to Eq. 1 and 2 with β = 0 and 10 .
The algorithm is run for 100 generations with a population size of 500.
All generated molecules are constrained to a canonical smile length of 81 characters (as in (Yang et al., 2017; Jensen, 2019)).
We train the discriminator (fully connected neural network with ReLU activation and sigmoid output layer, the input is a vector of chemical and geometrical properties characterizing the molecules) at the end of each generation for 10 epochs on 500 molecules proposed by the GA and 500 randomly drawn molecules from the ZINC data set.
We report maximum J ( m ) scores, averaged overindependent runs.
The highest J ( m ) achieved by our approach are 13 .
31 ± 0 .
63 ( β = 10 ) and
61 ± 0 .
81 ( β = 0 ), respectively, which is almost twice as high es the highest literature value of 7 . 87 ± 0 .
07 (See Table 1).
Furthermore, we compare to 50,000 random valid S ELFIES strings, which surprisingly outperforms some existing generative models.
The GA-D(t) results are explained in the next section.
4. L ONG TERM EXPERIMENT WITH A TIME - DEPENDENT ADAPTIVE PENALTY
In Figure 3, we show the results of runs where we use a time-dependent adaptive penalty.
During periods of saturation, the weight of the discriminator predictions is switched from 0 to 1000 until stagnation is overcome.
The genetic algorithm is hence forced to propose new families of molecules to increase J ( m ) .
As it can be observed in Figure 3, even after steep decreases in max J ( m ) , the scores recover and potentially reach values higher than in previous plateaus.
We observe that this approach signiﬁcantly outperforms all previous methods in maximizing the objective J ( m ) .
Visual inspection of the highest performing molecules shows that the GA is exploiting deﬁciencies of the (penalized) logP metric by generating chemically irrelevant motifs such as sulfur chains.
While being of limited relevance for application, this nonetheless shows the that the GA is very efﬁcient in exploring the chemical space and ﬁnding solutions for a given task.
Analysis of these solutions will help us to better understand and eventually improve objective functions.
At the same time, surprising solutions found by an unbiased algorithm can lead to unexpected discovery or boost human creativity (Lehman et al.
While exploitative tasks that follow some reference database are signiﬁcant for questions involving drug design, more explorative behaviour could be beneﬁcial in domains such as solar cell design (Yan et al.
(2018)), ﬂow battery design (Yang et al.
(2018)), and in particular for questions where datas sets are not available, such as design of targets in molecular beam interferometry (Fein et al.
4. A NALYSIS OF MOLECULE CLASSES EXPLORED BY THE GA
Figure 4 shows classes of molecules explored by the GA in a trajectory with 1000 generations and a generation size of 500 (see trajectories in Figure 3).
A K-means clustering analysis based in the
RDKit ﬁngerprint bit-vectors with 20 clusters was used to automatically generate labels for thebest performing molecules (in terms of their properties J ( m ) ) in each generation.
We ﬁnd that the algorithm starts with a class of relatively small molecules ( ≈ 40 generations, see class 10), after which the algorithm explores several different classes of large molecules with e.g. aromatic rings and conjugates carbon chains (see class 15) and long linear sulfur chains (see class 1).
Classincludes the molecules with the highest J ( m ) scores found in this work, exceeding values of 20.
The clustering analysis furthermore helps to analyze the large number of generated molecules.
This allows us to learn from the data and derive design rules to achieve high target properties.
In case of the penalized logP score, we ﬁnd that representative examples (short distance to the cluster center) of high performing classes contain aromatic rings, conjugated carbon chains and linear sulfur chains, which can act as design rules for molecules with high penalized logP scores.
Using these design rules to construct molecules of the maximally allowed length consisting of only sulfur chains, conjugated carbon chains and chains of benzene rings with sulfur bridges yields J ( m ) scores of 31.79, 8.58 and 10.02, respectively.
The J ( m ) score reached by the linear sulfur chain outperforms the best scores found by the GA and other generative models.
To visualize the explorative behaviour of the GA, we did a two-dimensional principal component analysis (PCA) of the molecular ﬁngerprint vectors of all molecules generated by the GA-D(t) in the trajectory shown in Figure 4.
Five snapshots of the trajectory are shown in Figure 5, colored according to their chemical family.
The property score J ( m ) of the trajectory is visualized in the images.
We ﬁnd that the GA sequentially explores different parts of the 2D projection of the chemical space, ﬁnding different families of high performing molecules, while the discriminator prevents the algorithm from searching in the same space repeatedly.
4. C ONSTRAINED OPTIMIZATION
In the previous sections, we aimed to maximize the penalized logP objective.
Here, we consider two different tasks: ﬁrstly, generating molecules of speciﬁc chemical interest and secondly, modifying existing molecules to increase penalized logP scores.
We used β = 0 throughout Section 4.4.
4.4. G ENERATING MOLECULES WITH SPECIFIC PROPERTIES
We run 250 instances of randomly selected sets of target properties (logP in the interval from -5 to 10, SA scores in the range from 1 to 5 and ring penalty for 0 to 3).
The ﬁtness function is modiﬁed to minimize the summed squared difference between the actual and desired properties.
We compute the number of experiments that successfully proposed molecules with a squared difference less than 1.0.
Each run is constrained to run for 100 generations with a maximum canonical SMILES length of 81 characters.
In 90.0% of the cases, our approach proposes the desired molecules. [Table]
4.4. I MPROVING PENALIZED LOG P SCORES OF SPECIFIC MOLECULES
In this experiment [Table] we follow the experimental setup proposed by You et al.
We optimize the penalized logP score of 800 low-scoring molecules from the ZINC data set.
Our genetic algorithm is initiated with a molecule from the data set [Table] and we run each experiment for 20 generations and a population size of 500 without the discriminator.
For each run, we report the molecule m that increases the penalized logP the greatest, while possessing a similarity sim ( m, m (cid:48) )
> δ with the respective reference molecules m (cid:48) .
We calculate molecular similarity based on Morgan Fingerprints of radius 2.
To ensure generation of molecules possessing a certain similarity, for molecule m we modify the ﬁtness to:
[Equation]
Here, SimilarityPenalty ( m ) is 0 if sim ( m, m (cid:48) )
> δ and − 10 6 otherwise.
In Table 2, we report the average improvement for each molecule.
Success is determined when the GA successfully improve upon the penalized logP score, while not violating the similarity constraint.
Figure S1 shows examples of improved molecular structures.
4. S IMULTANEOUS LOG P AND QED OPTIMIZATION
To show the performance of the GA on a drug-discovery task (Brown et al., 2019; Polykovskiy et al., 2018), we modiﬁed the objective function to include the drug-likeness score QED (Bickerton et al., 2012).
Solubility metric logP and drug-likeness cannot be maximized at the same time, which is shown in Figure 6 at the example of the ZINC and the GuacaMol data set (Brown et al., 2019).
The experiment shows that the GA is able to efﬁciently and densely sample the edge of the property distributions of both data sets.
Example molecules that simultaneously maximize logP and QED are shown in Figure 6c.
4. M ODIFICATION OF THE HYPERPARAMETER β
The deﬁnition of the ﬁtness function used in this work (see Equation 1) has a free parameter ( β ), that balances the relative importance of molecular target properties J ( m ) and discriminator score
D ( m ) .
Large values of β promote the generation of molecules that resemble the molecules from the reference data set, while small values of β let the GA explore molecules outside of the distribution of the reference data set.
To systematically explore this behaviour, we varied the β parameter and analyzed the resulting values of J ( m ) , D ( m ) as well as their distributions.
Figure 7 illustrates the results of this test, where each curve is obtained from averaging ﬁve independent runs with equal settings.
In Figure 7a, we show the average property score J ( m ) for 11 different values β and observe, as expected, that low values of β on average lead to higher J ( m ) score while very high values of β limit the algorithm to stay inside the reference data set distribution, which, per deﬁnition, has a mean
J ( m ) score of 0.
Figure 7b illustrates the low average discriminator scores encountered after a few generations in case of low values of β .
The curves shown in Figure 7a and b suggest that β allows us to interpolate between high and low J ( m ) and high and low resemblance with the reference data set.
However, as shown in Figure 7c, this is not the case.
At values of β ≈ 20 , there is a rather fast transition from molecules with high values of J ( m ) of approximately 12-13 to a J ( m ) distribution centered around 0 which is similar to the J ( m ) distribution of the reference data set.
The same abrupt change is visible in the distributions of the discriminator scores.
Only at β ≈ 18 , we ﬁnd a slightly wider distribution of intermediate J ( m ) values, which we assume is partially related to the fact that the β = 18 curve shown in Figure 7a is not converged yet.
Figure 7d shows examples of molecules generated with β =
(upper panel) and β = 50 (lower panel).
While in the ﬁrst case, the GA ﬁnds large molecules with many aromatic rings and long linear chains, that do not resemble the molecules in the reference data set, the latter case shows molecules with structures and properties resembling the reference data set.
In this case, the distribution of
J ( m ) is comparable to that of the data set (with 0 mean and unit standard deviation), while the discriminator encounters difﬁculty in correctly classiﬁcation of the GA molecules, indicated by a mean discriminator score varying around 0.5 across many generations.
C ONCLUSIONS AND F UTURE W ORK
We presented a hybrid GA and ML-based generative model and demonstrated its application in molecular design.
The model outperforms literature approaches in generating molecules with desired properties.
A detailed analysis of the data generated by the genetic algorithm allowed us to interpret the model and learn rules for the design of high performing molecules.
This human expert design inspired from GA molecules outperformed all molecules created by generative models.
For computationally more expensive property evaluations, we will extend our approach by the introduction of an on-the-ﬂy trained ML property evaluation method, which will open new ways of solving the inverse design challenge in chemistry and materials sciences.
Our approach is independent of domain knowledge, thus applicable to design questions in other scientiﬁc disciplines beyond chemistry.
We therefore plan to generalize the GA-D approach to make it a more general concept of generative modelling. A CKNOWLEDGMENTS
The authors thank Gabriel dos Passos Gomes & Andr´es Aguilar Granda for useful discussions.
A. A.-G. acknowledges generous support from the Canada 150 Research Chair Program, Tata Steel,
Anders G. Froseth and the Ofﬁce of Naval Research. M.K. acknowledges support from the Austrian Science Fund (FWF) through the Erwin Schr¨odinger fellowship No. J4309. P
F. has received funding from the European Union’s Horizon 2020 research and innovation programme under the Marie
Sklodowska-Curie grant agreement
No  S UPPLEMENTARY I NFORMATION Figure S1 shows examples of the molecules optimized in Section 4.4.
Figures S2-S4 show comparisons between the property distributions observed in molecule data sets such as the ZINC and the GuacaMol data set and property distributions of molecules generated using random S ELFIES (Figure S2), GA generated molecules with the penalized logP objective (Figure S3) and GA generated molecules with an objective function which includes logP and QED (Figure S4).
While the average logP scores of average S ELFIES are low, the tail of the distribution reaches to high values, explaining the surprisingly high penalized logP scores shown in Table 1.
The QED and weight distributions of molecules optimized using the penalized logP objective signiﬁcantly differ from the distributions of the ZINC and the GuacaMol data set (see Figure S3).
As soon as the
QED score is simultaneously optimized, the distributions of GA generated molecules and molecules from the reference data sets become more similar (see Figure S4).
Figure 6 shows that the GA can simultaneously optimize logP and QED.