Ersilia Book
Search…
Antibiotic activity prediction
In this case example, we show how to run predictions based on the AI/ML model developed in the paper A Deep Learning Approach to Antibiotic Drug Discovery, by Stokes et al. Cell (2020). In this study, a deep learning model was trained using the excellent Chemprop tool. Halicin, a drug originally researched for the treatment of diabetes, was predicted to have broad antibacterial activity.

Command-line interface

We provide a command-line interface (CLI) to interact with the Ersilia Model Hub. To check the available commands, simply type:
1
# list available commands
2
ersilia --help
Copied!

Browse the model catalog

You can explore our catalog of models. The following will return a list of models currently available in our remote repositories.
1
# catalog of models
2
ersilia catalog
Copied!
The Ersilia Model Hub is growing continuously to fulfil the needs of the community. Please do not hesitate to request new models! Just reach out to us, we will be happy to assist: [email protected]
In the Ersilia Model Hub, the antibiotic activity prediction model has the identifier eos4e40 and the slug chemprop-antibiotic. You can use either one to refer to this model all of the commands below. For example, you can get more information through the model card:
1
# display model card using slug...
2
ersilia card chemprop-antibiotic
3
# ... or using ersilia identifier
4
ersilia card eos4e40
Copied!

Fetch model and install it locally

The first step is to download the model to your local device and install it along with its dependencies. By default, a ~/eos directory (for Ersilia Open Source) will be created in your HOME. This folder will contain all fetched models along with additional files to manage the AI/ML content available locally.
To download and install the antibiotic activity prediction model, simply use the fetch command:
1
# fetch model from remote repository
2
ersilia fetch chemprop-antibiotic
Copied!
This model weighs 850 MB, so fetching will take a while. In order to provide robust predictions, the original paper released an ensemble of 20 individual models. We do not want to compromise the accuracy of the model, this is why the full ensemble is downloaded. Our team is currently developing a lightning library that will provide lighter versions of the models for easier testing and deployment.
We do our best to keep the user away from the dependency hell. Models are automatically installed with the necessary degree of isolation from the system. While some models have no dependencies at all and can be run using the system Python installation, others need to be containerized using Docker.

Serve model

Once the model has been fetched, it should be ready to be used. A model in the Ersilia Model Hub can be thought of as a set of APIs. You can serve the model like this:
1
# serve model
2
ersilia serve chemprop-antibiotic
Copied!
A URL will be prompted as well as a process id (PID). These can be relevant if you are an advanced user and want to have low-level control of the tool. The most important is, however, the list of available APIs. In this case, we want to infer antibiotic activity through the predict API.
The predict API is obviously one of the most ubiquitous throughout our catalog of models. Other common APIs are transform and interpret.

Make predictions

The antibiotic activity prediction model takes chemical structures as input and provides an activity score (ranging from 0 to 1) under a cutoff of E.coli growth inhibition of 50 uM.
Ideally, in the chemistry models, the input molecules are specified as SMILES strings. SMILES strings can be easily found online. For instance, we can find Halicin in PubChem and then predict its antimicrobial activity as follows:
1
# Halicin
2
ersilia api predict -i "C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]"
Copied!
It is also possible to use InChIKey or even molecule name (through the Chemical Identifier Resolver) instead of SMILES. Ersilia will take care of this automatically. However, please take into account that this requires an internet connection and will slow down the process, as requests to external tools are necessary.
You can make multiple predictions in batch mode. This is typically much faster than running predictions one by one in a loop. For instance, we can predict the antimicrobial activity of Halicin and Ibuprofen. We don't expect Ibuprofen to be active.
1
# Halicin and Ibuprofen
2
ersilia api predict -i "['C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]','CC(C)CC1=CC=C(C=C1)C(C)C(=O)O']"
Copied!
This can become impractical and perhaps you prefer to provide an input file instead. Let's name this file input.csv.
input.csv
1
C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]
2
CC(C)CC1=CC=C(C=C1)C(C)C(=O)O
Copied!
The terminal command now becomes much cleaner:
1
# predict using an input file
2
ersilia api predict -i input.csv
Copied!
By default, predictions are returned in the standard output of the terminal. We favour the widely used JSON format because it offers great flexibility and interoperability. However, many of the model APIs return an output that can be naturally expressed in tabular format, for example, in a CSV file. If this is what you want, simply specify an output file with the .csv extension.
1
# save output in a CSV file
2
ersilia api predict -i input.csv -o output.csv
Copied!
At the moment, the available formats are JSON (.json), CSV (.csv), TSV (.tsv) and HDF5 (.h5). The latter is appropriate for large-scale numerical data and is relevant for the lake of pre-computed predictions available in the Isaura resource.

Close model

Once you are done with predictions, it is advised to stop the model server:
1
# close model
2
ersilia close
Copied!

Delete model

If you are sure you don't want to use a model anymore, you may want to remove it from your computer. This includes deleting all model files and specific dependencies:
1
# delete model
2
ersilia delete chemprop-antibiotic
Copied!

As a Python package

Models can be fetched from the Ersilia Model Hub, served, and run as a Python package. The main class is called ErsiliaModel:
1
# import main class
2
from ersilia import ErsiliaModel
3
# instantiate the model
4
mdl = ErsiliaModel("chemprop-antibiotic")
Copied!
Then, you can perform the same actions as in the CLI. To serve:
1
# serve model
2
mdl.serve()
Copied!
To make predictions for Halicin and Ibuprofen:
1
# Halicin and Ibuprofen
2
input = [
3
"C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]",
4
"CC(C)CC1=CC=C(C=C1)C(C)C(=O)O"
5
]
6
# predict
7
mdl.predict(input)
Copied!
To close the model:
1
# close model
2
mdl.close()
Copied!

Using the 'with' statement

A more concise way to run prediction would be to use the with clause:
1
# use with statement
2
with ErsiliaModel("chemprop-antibiotic") as mdl:
3
mdl.predict(input)
Copied!