MolVoxel:Easy-to-Use Molecular Voxelization Tool
Project description
MolVoxel: Molecular Voxelization Tool
MolVoxel is an Easy-to-Use Molecular Voxelization Tool implemented in Python.
It requires minimal dependencies, so it's very simple to install and use. If you want to use numba version, just install numba additionally.
If there's a feature you need, let me know! I'll do my best to add it.
Dependencies
- Required
- Numpy, SciPy
- Optional
- Numba
- PyTorch, CUDA Available
- RDKit, pymol-open-source
Citation
@article{seo2024pharmaconet,
title={PharmacoNet: deep learning-guided pharmacophore modeling for ultra-large-scale virtual screening},
author={Seo, Seonghwan and Kim, Woo Youn},
journal={Chemical Science},
year={2024},
publisher={Royal Society of Chemistry}
}
Quick Start
Installation
pip install molvoxel
pip install molvoxel[numba, torch, rdkit] # Optional Dependencies
Configuring Voxelizer Object
import molvoxel
# Default (Resolution: 0.5, dimension: 64, density_type: gaussian, sigma: 0.5, library='numpy')
voxelizer = molvoxel.create_voxelizer()
# Set gaussian sigma = 1.0, spatial dimension = (48, 48, 48) with numba library
voxelizer = molvoxel.create_voxelizer(dimension=48, density_type='gaussian', sigma=1.0, library='numba')
# Set binary density with torch library
voxelizer = molvoxel.create_voxelizer(density_type='binary', library='torch')
# CUDA
voxelizer = molvoxel.create_voxelizer(library='torch', device='cuda')
Voxelization
Numpy, Numba
from rdkit import Chem # rdkit is not required packages
import numpy as np
def get_atom_features(atom):
symbol, aromatic = atom.GetSymbol(), atom.GetIsAromatic()
return [symbol == 'C', symbol == 'N', symbol == 'O', symbol == 'S', aromatic]
mol = Chem.SDMolSupplier('./test/10gs/10gs_ligand.sdf')[0]
channels = {'C': 0, 'N': 1, 'O': 2, 'S': 3}
coords = mol.GetConformer().GetPositions() # (V, 3)
center = coords.mean(axis=0) # (3,)
atom_types = np.array([channels[atom.GetSymbol()] for atom in mol.GetAtoms()]) # (V,)
atom_features = np.array([get_atom_features(atom) for atom in mol.GetAtoms()]) # (V, 5)
atom_radius = 1.0 # scalar
image = voxelizer.forward_single(coords, center, atom_radius) # (1, 64, 64, 64)
image = voxelizer.forward_types(coords, center, atom_types, atom_radius) # (4, 64, 64, 64)
image = voxelizer.forward_features(coords, center, atom_features, atom_radius) # (5, 64, 64, 64)
PyTorch - Cuda Available
# PyTorch is required
import torch
device = 'cuda' # or 'cpu'
coords = torch.FloatTensor(coords).to(device) # (V, 3)
center = torch.FloatTensor(center).to(device) # (3,)
atom_types = torch.LongTensor(atom_types).to(device) # (V,)
atom_features = torch.FloatTensor(atom_features).to(device) # (V, 5)
image = voxelizer.forward_single(coords, center, atom_radius) # (1, 64, 64, 64)
image = voxelizer.forward_types(coords, center, atom_types, atom_radius) # (4, 32, 32, 32)
image = voxelizer.forward_features(coords, center, atom_features, atom_radius) # (5, 32, 32, 32)
Voxelization
Input
- $X \in \mathbb{R}^{N\times3}$ : Coordinates of $N$ atoms
- $R \in \mathbb{R}^N$ : Radii of $N$ atoms
- $F \in \mathbb{R}^{N\times C}$ : Atomic Features of $N$ atoms - $C$ channels.
Kernel
$d$: distance, $r$: atom radius
Gaussian Kernel
$\sigma$: gaussian sigma (default=0.5)
$$ f(d, r, \sigma) = \begin{cases} \exp \left( -0.5(\frac{d/r}{\sigma})^2 \right) & \text{if}~d \leq r \ 0 & \text{else} \end{cases} $$
Binary Kernel
$$ f(d, r) = \begin{cases} 1 & \text{if}~d \leq r \ 0 & \text{else} \end{cases} $$
Output
- $I \in \mathbb{R}^{D \times H \times W \times C}$ : Output Image with $C$ channels.
- $G \in \mathbb{R}^{D\times H\times W \times 3}$ : 3D Grid of $I$.
$$ I_{d,h,w,:} = \sum_{n}^{N} F_n \times f(||X_n - G_{d,h,w}||,R_n,\sigma) $$
RDKit Wrapper
# RDKit is required
from molvoxel.rdkit import AtomTypeGetter, BondTypeGetter, MolPointCloudMaker, MolWrapper
atom_getter = AtomTypeGetter(['C', 'N', 'O', 'S'])
bond_getter = BondTypeGetter.default() # (SINGLE, DOUBLE, TRIPLE, AROMATIC)
pointcloudmaker = MolPointCloudMaker(atom_getter, bond_getter, channel_type='types')
wrapper = MolWrapper(pointcloudmaker, voxelizer, visualizer)
image = wrapper.run(rdmol, center, radii=1.0)
Project details
Release history Release notifications | RSS feed
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 molvoxel-0.2.0.tar.gz.
File metadata
- Download URL: molvoxel-0.2.0.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97c9837241f99791f5c08760c1782ad1bd9a568bfbb80e4dc7a671487c515329
|
|
| MD5 |
daa0fad3b53edeb276c74ea935b55765
|
|
| BLAKE2b-256 |
bf9e623bce33c467bf7d188f9997d10265dd0f06b48b756912968a9b9974cd7a
|
File details
Details for the file molvoxel-0.2.0-py3-none-any.whl.
File metadata
- Download URL: molvoxel-0.2.0-py3-none-any.whl
- Upload date:
- Size: 36.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa51350e235ac582a8dd60df799bcae161423de631d1e09d9c00a9fa35225a0d
|
|
| MD5 |
512cb5538625198b0e020ebc50240a24
|
|
| BLAKE2b-256 |
9165a43079adb84ae21b25be39b459c2d3faab17d76527465f073ec628c660e4
|