GRAIL is an open-source tool for drug metabolism prediction, based on graph neural networks and SMARTS reaction rules.
Project description
GRAIL: Graph Neural Networks and Rule-based Approach in Drug Metabolism Prediction
GRAIL is an open-source tool for drug metabolism prediction, combining SMARTS reaction rules with Graph Neural Networks (GNNs). It is designed for researchers and developers working in cheminformatics, drug discovery, and computational biology.
Key Features
- Rule-based Predictions: Leverages SMARTS reaction rules for accurate metabolic predictions.
- Graph Neural Networks: Utilizes cutting-edge GNN architectures for enhanced learning from molecular graphs.
- Flexible Data Handling: Supports data input from multiple formats, including pandas DataFrames, dictionaries, and SDF files.
- Customizable Models: Includes modular components (
Filter,Generator, and others) for flexible model creation and training. - Hyperparameter Optimization: Built-in support for Optuna for efficient hyperparameter tuning.
Table of Contents
1. Installation
1.1 From Source with Poetry
Run the following command in the directory containing the pyproject.toml file:
poetry install
1.2 From PyPI
Install the library directly from PyPI:
pip install grail_metabolism
IMPORTANT: If you plan to run GRAIL with CUDA, execute the install.py script post-installation to set up the appropriate torch-geometric, torch-scatter, and torch-sparse versions:
python install.py
2. Data Availability
The dataset can be downloaded from Zenodo.
Note: This dataset is still in draft form and is subject to updates.
3. Quick Start
IMPORTANT: Due to RXNMapper incompatibility with newer Python versions, use Python 3.9 or lower when creating new transformation rules.
For a quick demonstration of the library's capabilities, refer to the notebooks/Unit_Tests.ipynb file.
4. Modules Overview
4.1 MolFrame
The MolFrame class handles data preparation and is essential for working with metabolic maps and molecular data. It supports:
- Initialization:
- From
pandas.DataFrame - From dictionaries with metabolic maps
- From SDF files
- From
- File Loading:
- Use the
MolFrame.from_filemethod to load data. - Pre-process triples (substrate, metabolite, real_or_not) using
MolFrame.read_triples.
- Use the
4.2 Models
The model module contains key components:
- Filter: Implements GNN-based filters for molecular graphs.
- Generator: Handles the generation of reaction rules and transformations.
4.3 Utilities
- Preparation: Prepares and standardizes molecular data for training and evaluation.
- OptunaWrapper: Facilitates hyperparameter optimization using the Optuna library.
- Transform: Here you can transform molecular data into graphs
- ReactionMapper: Make your own set of reaction rules via RXNMapper
Graphs' base characteristics:
There are two types of molecular graphs in this library: singlegraphs (just common molecular graphs) and pairgraphs, in which two molecular graphs (substrate and product) are merged by those maximum common substructure.
Node-edge dimensions:
- 16 and 18 in singlegraphs (
from_rdmol) - 10 and 6 in PCAed singlegraphs
- 17 and 18 in pairgraphs (
from_pair) - 12 and 6 in PCAed pairgraphs
There are also SMARTS reaction graphs (merged by atom mapping) from_rule
Reaction mapper
combine_reactionto process reaction into SMARTS patternprocessto process the MolFrame bycombine_reaction
5. Usage Examples
Example 1: Loading Data with MolFrame
from grail_metabolism.utils.preparation import MolFrame
# Process triples
# (substrate_index, metabolite_index, real_or_not)
triples = MolFrame.read_triples('triples.txt')
# Initialize from file
mol_frame = MolFrame.from_file('data.sdf', triples)
Example 2: Training filter part
from grail_metabolism.model.filter import Filter
from grail_metabolism.utils.preparation import MolFrame
# Setting hyperparameters
in_channels = ...
edge_dim = ...
arg_vec = [...] # len = 6
# Set up the data
train = MolFrame(...)
test = MolFrame(...)
model = Filter(in_channels, edge_dim, arg_vec, mode=...) # mode: pair or single
model.fit(train)
# Or
train.train_pairs(model, # or train_singles
test,
lr=...,
eps=...,
decay=...,
verbose=...)
sub = ...
met = ...
model.predict(sub, met)
Example 3: Training the Generator
from grail_metabolism.model.generator import Generator
from grail_metabolism.utils.preparation import MolFrame
from grail_metabolism.utils.transform import from_rule
from rdkit import Chem
# Setting rule dict
rules = [...]
rule_dict = {rule: from_rule(rule) for rule in rules}
in_channels = ...
edge_dim = ...
# Set up the data
train = MolFrame(...)
model = Generator(rule_dict, in_channels, edge_dim)
model.fit(train)
model.generate(...)
Example 4: Training a Complete Model
from grail_metabolism.utils.preparation import MolFrame
from grail_metabolism.model.grail import summon_the_grail
# Initialize model and datasets
rules = ...
model = summon_the_grail(rules, (..., ...), (..., ...))
train_set = MolFrame(...)
test_set = MolFrame(...)
# Train the model
trained_model = model.fit(train_set)
model.generate(...)
Example 4: Hyperparameter Optimization
from grail_metabolism.utils.optuna import OptunaWrapper
# Initialize OptunaWrapper
wrapper = OptunaWrapper(None, mode='pair')
# Or use OptunaWrapper.from_pickle for the ready Optuna study
# Run optimization
wrapper.make_study(train_set, test_set)
# Train optimal model
wrapper.train_on(train_set, test_set)
6. Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grail_metabolism-0.1.3.tar.gz.
File metadata
- Download URL: grail_metabolism-0.1.3.tar.gz
- Upload date:
- Size: 101.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95f74ff4ad5f8ef452aa64c2725b1430a5bf49cb9b94d5b88c7d4bd9e6abb35c
|
|
| MD5 |
0abe5564ac96754b4940cafb63b71626
|
|
| BLAKE2b-256 |
97ef7fb794db9b09e55e282894bc3937e7b7c61187da653d7c2dcd960f1992ff
|
File details
Details for the file grail_metabolism-0.1.3-py3-none-any.whl.
File metadata
- Download URL: grail_metabolism-0.1.3-py3-none-any.whl
- Upload date:
- Size: 62.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b39034add2872bc1e051aee8fffbcca2c1a1b8e585261adb570c9848e0396f28
|
|
| MD5 |
58c2ace293b3500e70eb9638e7703266
|
|
| BLAKE2b-256 |
1fc8ea63a9b36224e8ce2497a6548dfc9219a76cff6439d11d99cdd254e15be0
|