No description, website, or topics provided.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Author: Lukas Turcani
Please note that results in the paper were calculated using the
Anaconda distribution of Python 3.6.3 downloaded from
I noticed that even switching to a different version of Python 3.6,
such as 3.6.6, introduced some very slight, and completely negligible,
differences in some of the numbers reported in the paper.
While this should be of no consequence, it is pretty annoying.


This repo contains the code used for the paper "Machine Learning for Organic Cage Property Prediction". In order to replicate the results shown in the paper, go through the following steps:

  1. Download the file cage_prediction.db from This is a SQL database holding the cage properties which are modelled in the paper.

  2. Train the desired models using the files in train_scripts. Note that every training script has a usage statement which can be seen by running:

    python --help

    for example:

    python train_scripts/collapse_prediction/ --help

    Also note that in the commands below path/to/cage_prediction.db should be replaced by the path to the file cage_prediction.db on your computer.


The script collapse_prediction/ can be used to regenerate the results from Table 2 in the paper:

python train_scripts/collapse_prediction/ path/to/cage_prediction.db -r 1 2 3 4 5 6 -t 1

The numbers after -r and -t indicate which reactions and topologies you wish to see the results for. By adding or removing numbers you can see the results for different rows of Table 2. To see which number corresponds to which reaction or topology run:

python train_scripts/collapse_prediction/ --help

The script collapse_prediction/ is also used to calculate the results for the cross-topology model with:

python train_scripts/collapse_prediction/ path/to/cage_prediction.db -r 1 2 8 9 10 11 12 -t 1 2 3 4 5 --join


The script collapse_prediction/ is used to get the results shown in Tables 3 and 4. To get the results for Table 3:

python train_scripts/collapse_prediction/ path/to/cage_prediction.db train 1 2 3 4 5 6

and for Table 4:

python train_scripts/collapse_prediction/ path/to/cage_prediction.db test 1 2 3 4 5 6


The script regression/ can be used to make Table 5 and 6 and Table 2 in the SI. For example:

python train_scripts/regression/ path/to/cage_prediction.db cage_property

where cage_property can be either window_diff, window_std or cavity_size. Note that this script prints the results in a Latex syntax.

regression/ and regression/

The scripts regression/ and regression/ can be used to get the results for individual rows of Tables 5, 6 and Table 2 in the SI:

python train_scripts/regression/ path/to/cage_prediction.db cage_property -r 1 2 3 -t 1
python train_scripts/regression/ path/to/cage_prediction.db cage_property 1 2 3 4 5

Note that these scripts are run exactly like the collapse_prediction/ and collapse_prediction/ with the exception that window_diff, window_std or cavity_size must be specified after path/to/cage_prediction.db. For example, to get the results of the cross-topology model for cavity sizes:

python train_scripts/regression/ path/to/cage_prediction.db cavity_size -r 1 2 8 9 10 11 12 -t 1 2 3 4 5 --join

Doing everything from scratch.

We provide the SQL database and optimized cage structures used in the paper in However, if you wish to regenerate the results, starting only from the SMILES of the building blocks and linkers, go through the following steps:

For complete reporduciblity, use the fork of pywindow from

commit hash: 1625d1111e1e0ae0e61964794f726af8a2154eee

and stk commit hash: 292a13e4c6278e49988bac4bb2c0175bd1321d04.

Although for best results, using the most up-to-date versions of the libraries is reccomended.

Installing rdkit and stk.

Make sure you are using the Anaconda distribution of Python. This is necessary because stk depends on rdkit, which requires the conda package manager. rdkit can be installed without the Anaconda distribution but it is a significantly more complicated process. If you wish to do it anyway, refer to the rdkit documentation,, for help. If have Anaconda Python installed, just type the following commands into your terminal:

  1. conda install -c rdkit rdkit
  2. pip install stk

Generating the SQL database.

To generate the database from the SMILES strings go through the follow steps 1 to 4. If you want to skip remaking the cage molecules and re-optimizing them, you can download the .json holding the optimized cages from and go straight to step 4. This will use the optimized cages and recalculate their properties.

  1. Generate the structures of the building blocks and linkers:

  2. Assemble the unoptimized cages using stk:

    python 1 2 3 5 6 7 8 11 18 19 26 27
  3. Optimize the structures of the cages, requires a MACROMODEL license. The repository has a script called, which can easily optimize molecules in a stk population file. This can make the optimization step significantly easier. Note that this step can take multiple days. For example, to optimize the structures of the cages with in the amine2aldehyde3.json file with

    python amine2amine2aldehyde3.json amine2aldehyde3_opt.json /opt/schrodinger2017-4


    python --help

    for an explanation of the command line arguments. It may also help to read the docstring within the file.

  4. Store the cage properties in a SQL database. The SQL database can be remade by running:

    ./make_database.bash dirpath

    where dirpath is the path to the cages folder extracted from cages.tar.gz, which is downloaded from make_database.bash if found in the database folder of this repository.


The files used for this are held in the following folders: database, train_scripts, trained_models and website. The database folder contains code which is used to create the SQL database holding the properties of organic cages used in this study. The train_scripts folder contains scripts which use the SQL database to train random forest models for cage property prediction. trained_models contains pickled scikit-learn random forest estimators which have been trained. These are the models which the website,, uses. The website folder contains the code to make the aforementioned website.