libmolgrid: GPU Accelerated Molecular Gridding for Deep Learning Applications

Jocelyn Sunseri, David Ryan Koes

TL;DR

This paper introduces libmolgrid, a new open-source library designed to bridge the gap between molecular data and deep learning frameworks. It efficiently converts 3D molecular structures into multidimensional arrays (grids) suitable for machine learning, while also providing essential data preprocessing and augmentation tools, all accelerated by GPUs.

What Problem Does This Paper Address?

Representing molecules for machine learning is tricky. Traditional methods often lose crucial 3D spatial information like bond angles and torsions. While grid-based representations capture this 3D information, they require significant preprocessing and data handling that can be cumbersome and computationally expensive. Existing tools often lack the necessary functionalities for tasks like data augmentation, batch balancing, and seamless integration with popular deep learning frameworks (Caffe, PyTorch, Keras). This creates a bottleneck for researchers wanting to leverage deep learning for molecular modeling tasks.

Methods

libmolgrid tackles this by offering a comprehensive solution:

  • Molecular Gridding: It converts 3D molecular structures into multidimensional arrays (grids). This process is GPU-accelerated for speed.
  • Data Preprocessing & Augmentation: The library provides tools for:
  • Batch Composition: Creating batches of data suitable for ML workflows.
  • Data Augmentation: Introducing variations (like random rotations and translations) to the molecular data to improve model robustness.
  • Class Balancing & Stratification: Ensuring datasets are representative by balancing classes and stratifying examples based on specific criteria (e.g., regression variables).
  • Temporal/Spatial Recurrences: Support for handling sequential data, useful for molecular dynamics or recurrent neural networks.
  • Flexible Data Handling: It introduces ManagedGrids (which manage their own memory) and Grids (which act as views over existing memory buffers). This allows for efficient memory management and interoperability with other data structures like NumPy arrays and PyTorch tensors.
  • Framework Integration: Designed for seamless integration with Caffe, PyTorch, and Keras, minimizing the need for explicit conversions.

Datasets

The paper demonstrates the utility of libmolgrid using a toy dataset for binary classification of active vs. inactive binding. Specific details on the dataset's origin or size are not provided beyond this general description.

Key Insights and Ideas

  • Bridging the Representation Gap: libmolgrid effectively translates complex 3D molecular structures into a format that deep learning models can readily consume, preserving critical spatial information.
  • GPU Acceleration is Key: Leveraging GPUs for gridding significantly speeds up the computationally intensive parts of molecular data preparation.
  • Integrated Workflow: By combining gridding with essential data augmentation and batching functionalities, libmolgrid streamlines the entire ML pipeline for molecular data.
  • Memory Efficiency: The use of memory views (Grids) and managed buffers (ManagedGrids) optimizes memory usage, which is crucial for large molecular datasets.
  • Framework Agnosticism (with caveats): While designed for multiple frameworks, the paper highlights performance differences, particularly with TensorFlow, due to its data transfer mechanisms.

Key Results

The paper demonstrates successful training of a simple feed-forward network for binary classification using libmolgrid with Caffe, PyTorch, and Keras.

  • Performance: Using a GPU for gridding and training is significantly faster with Caffe and PyTorch compared to TensorFlow. This speedup is attributed to libmolgrid's direct access to data buffers with Caffe and PyTorch, avoiding costly data transfers.
  • Memory Utilization: TensorFlow shows less efficient memory utilization compared to Caffe and PyTorch.
  • Cartesian Reduction Example: A specific example shows libmolgrid's utility in converting voxelized grids back to Cartesian coordinates, achieving a root mean squared accuracy of 0.09Å.

Limitations and Future Work

  • TensorFlow Performance: The paper acknowledges that libmolgrid's performance with TensorFlow is currently limited by TensorFlow's data transfer mechanisms, which involve copying data between CPU and GPU. Future work aims to mitigate this by leveraging TensorFlow 2.0.
  • Grid Types: The authors plan to extend libmolgrid to support other grid types, such as spherical grids.
  • Documentation and Support: The paper points to the project's GitHub repository for source code, active support, documentation, tutorials, and installation instructions.

Summary updated

Abstract

There are many ways to represent a molecule as input to a machine learning model and each is associated with loss and retention of certain kinds of information. In the interest of preserving three-dimensional spatial information, including bond angles and torsions, we have developed libmolgrid, a general-purpose library for representing three-dimensional molecules using multidimensional arrays. This library also provides functionality for composing batches of data suited to machine learning workflows, including data augmentation, class balancing, and example stratification according to a regression variable or data subgroup, and it further supports temporal and spatial recurrences over that data to facilitate work with recurrent neural networks, dynamical data, and size extensive modeling. It was designed for seamless integration with popular deep learning frameworks, including Caffe, PyTorch, and Keras, providing good performance by leveraging graphical processing units (GPUs) for computationally-intensive tasks and efficient memory usage through the use of memory views over preallocated buffers. libmolgrid is a free and open source project that is actively supported, serving the growing need in the molecular modeling community for tools that streamline the process of data ingestion, representation construction, and principled machine learning model development.
BibTeX
@misc{sunseri2019libmolgrid,
  author = {Jocelyn Sunseri and David Ryan Koes},
  title = {{libmolgrid: GPU Accelerated Molecular Gridding for Deep Learning Applications}},
  year = {2019},
  eprint = {1912.04822},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1912.04822},
}
Figure