A unified framework for machine learning collective variables for enhanced sampling simulations: <tt>mlcolvar</tt>

Luigi Bonati, Enrico Trizio, Andrea Rizzi, Michele Parrinello

Abstract

Identifying a reduced set of collective variables is critical for understanding atomistic simulations and accelerating them through enhanced sampling techniques. Recently, several methods have been proposed to learn these variables directly from atomistic data. Depending on the type of data available, the learning process can be framed as dimensionality reduction, classification of metastable states or identification of slow modes. Here we present mlcolvar, a Python library that simplifies the construction of these variables and their use in the context of enhanced sampling through a contributed interface to the PLUMED software. The library is organized modularly to facilitate the extension and cross-contamination of these methodologies. In this spirit, we developed a general multi-task learning framework in which multiple objective functions and data from different simulations can be combined to improve the collective variables. The library's versatility is demonstrated through simple examples that are prototypical of realistic scenarios.

Introduction

Molecular Dynamics (MD) simulations serve as a "computational microscope" for chemistry and biology, yet they are often limited by a significant timescale gap. Rare events, such as protein folding or chemical reactions, occur on timescales far exceeding the reach of standard simulations. To overcome this, researchers employ enhanced sampling techniques, which apply a bias to the system to facilitate transitions out of local energy minima.

The effectiveness of these techniques hinges on the identification of Collective Variables (CVs)—low-dimensional projections of the system's high-dimensional atomic coordinates. Traditionally, CVs were hand-crafted based on physical intuition. However, selecting an inappropriate CV can lead to poor convergence and failure to capture the relevant physics. While machine learning (ML) has emerged as a powerful tool for learning CVs from data, the field has remained fragmented, with implementations often limited to one-off scripts that are difficult to integrate into production MD environments.

The mlcolvar Framework

The mlcolvar library, built on PyTorch and PyTorch Lightning, addresses these challenges by providing a unified and modular framework for CV design. It categorizes CV learning into three primary data-driven paradigms based on the available data:

  1. Unsupervised Learning: Utilizes unlabeled MD snapshots to identify structural patterns through methods like Principal Component Analysis (PCA) or Autoencoders.
  2. Supervised Learning: Employs labeled data (e.g., distinguishing "State A" from "State B") to find variables that maximize the discrimination between metastable states using techniques like Linear Discriminant Analysis (LDA) or Deep-TDA.
  3. Time-Informed Learning: Leverages time-lagged data to extract the system's "slowest" modes, which typically correspond to the most physically significant transitions (e.g., TICA, Deep-TICA).
Data-driven approaches for learning collective variables: unsupervised (unlabeled), supervised (labeled), and time-informed (time-lagged).

A core innovation of the library is its multi-task learning framework. This allows for the simultaneous optimization of a single CV model using multiple objective functions. For instance, a model can be trained to preserve global structural information (reconstruction loss) while simultaneously maximizing the separation between specific states (discrimination loss).

Library Architecture and Deployment

mlcolvar is designed with modularity at its core. By standardizing components such as normalization layers, neural network architectures, and statistical transforms, it enables researchers to easily "cross-contaminate" different methodologies. This modularity facilitates the creation of hybrid models, such as adding a time-lagged objective to a standard Autoencoder.

The `mlcolvar` workflow: from MD data processing to model training and deployment in enhanced sampling simulations via PLUMED.

A significant hurdle in applying ML to MD is the computational overhead during production runs. mlcolvar overcomes this by utilizing TorchScript to export trained models. These compiled models can be executed directly by the C++-based PLUMED software, ensuring that the ML-based CV calculation does not become a bottleneck for the physics engine.

Results and Applications

The library's capabilities were demonstrated using a three-state 2D toy model based on a modified Muller-Brown potential. Key results include:

  • Unsupervised Discovery: An Autoencoder-based CV successfully guided the system to discover previously unsampled metastable states.
  • Efficient Sampling: A supervised Deep-TDA CV enabled multiple transitions between all states, allowing for the calculation of a converged free energy surface.
  • Correcting Suboptimal CVs: In cases where a naive CV (e.g., a single coordinate) failed, a time-informed Deep-TICA model correctly identified the slow mode, leading to efficient sampling.
  • Semi-Supervised Multi-Tasking: Combining reconstruction and discrimination losses allowed the model to more accurately follow the minimum free energy path compared to single-objective models.

Conclusion and Future Directions

While mlcolvar significantly simplifies the design and deployment of ML-based CVs, the choice of input descriptors remains a critical factor. Future work will focus on expanding the library with specialized architectures for diverse physical systems, improving the interpretability of learned CVs, and fostering a community-driven repository of CV methodologies. By bridging the gap between deep learning and molecular dynamics, mlcolvar provides a robust platform for accelerating the discovery of complex molecular processes.

Summary updated

Abstract

Identifying a reduced set of collective variables is critical for understanding atomistic simulations and accelerating them through enhanced sampling techniques. Recently, several methods have been proposed to learn these variables directly from atomistic data. Depending on the type of data available, the learning process can be framed as dimensionality reduction, classification of metastable states, or identification of slow modes. Here, we present mlcolvar, a Python library that simplifies the construction of these variables and their use in the context of enhanced sampling through a contributed interface to the PLUMED software. The library is organized modularly to facilitate the extension and cross-contamination of these methodologies. In this spirit, we developed a general multi-task learning framework in which multiple objective functions and data from different simulations can be combined to improve the collective variables. The library's versatility is demonstrated through simple examples that are prototypical of realistic scenarios.
BibTeX
@article{bonati2023unified,
  author = {Luigi Bonati and Enrico Trizio and Andrea Rizzi and Michele Parrinello},
  title = {{A unified framework for machine learning collective variables for enhanced sampling simulations: <tt>mlcolvar</tt>}},
  journal = {The Journal of Chemical Physics},
  year = {2023},
  doi = {10.1063/5.0156343},
}
Figure