Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
January 18, 2018 12:16
January 18, 2018 12:16
September 3, 2019 10:38
January 16, 2018 04:23

chemical VAE

This repository contains the framework and code for constructing a variational autoencoder (VAE) for use with molecular SMILES, as described in doi:10.1021/acscentsci.7b00572, with preprint at

In short, molecular SMILES are encoded into a code vector representation, and can be decoded from the code representation back to molecular SMILES. The autoencoder may also be jointly trained with property prediction to help shape the latent space. The new latent space can then be optimized upon to find the molecules with the most optimized properties of interest.

In our example, we perform encoding/decoding with the ZINC dataset, and shape the latent space on prediction on logP, QED, and SAS properties.

Upcoming updates:

  • Updated Docker environment
  • Improved tutorial

Questions, problems?

Make a github issue 😄. Please be as clear and descriptive as possible.

How to install


An Anaconda python environment is recommend. Check the environment.yml file, but primarily:

  • Python >= 3.5
  • Keras >= 2.0.0 && <= 2.0.7
  • Tensorflow == 1.1
  • RDKit
  • Numpy

Jupyter notebook is required to run the ipynb examples. Make sure that the Keras backend is set to use Tensorflow

Create a conda enviroment:

conda env create -f environment.yml
source activate chemvae
python install

via pip

Assuming you have all the requirements:

pip install git+

Example: ZINC dataset

This repository contains an example of how to run the autoencoder on the zinc dataset.

First, take a look at the zinc directory. Parameters are set in the following jsons

  • exp.json - Sets parameters for location of data, global experimental parameters number of epochs to run, properties to predict etc.

For a full description of all the parameters, see ; parameters set in exp.json will overwrite parameters in, and parameters set in params.json will overwrite parameters in both exp.json and

Once you have set the parameters, run the autoencoder using the command from directory with exp.json:

python -m chemvae.train_vae

(Make sure you copy examples directories to not overwrite the trained weights (*.h5))

Components : main script for training variational autoencoder Accepts arguments -d ... Example of how to run (with example directory here)

  • - Library of models, contains the encoder, decoder and property prediction models.
  • - Custom keras layer containing custom teacher forcing/sampling
  • - Custom rnn function for, written in tensorflow backend.
  • - Some default parameter settings for the autoencoder
  • - library for parsing SMILES into one-hot encoding and vice versa
  • - library containing callbacks used by
    • Includes Weight_Annealer callback, which is used to update the weight of the KL loss component
  • - utility functions for an autoencoder object, used post processing.


This software is written by Jennifer Wei, Benjamin Sanchez-Lengeling, Dennis Sheberla, Rafael Gomez-Bomberelli, and Alan Aspuru-Guzik ( It is based on the work published in by

Feel free to reach out to us with any questions!

Funding acknowledgements

"This work was supported by the Computational Chemical Sciences Program funded by the U.S.Department of Energy, Office of Science, Basic Energy Sciences, under Award #DE- FG02-17ER16362"


Code for 10.1021/acscentsci.7b00572, now running on Keras 2.0 and Tensorflow







No releases published


No packages published