MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度技术分析:TorchANI 2.0

TorchANI 2.0 是一个开源库,专为原子间的神经网络势函数(ANI-style neural network interatomic potentials)的训练、开发和研究提供支持。该项目由 Roitberg 团队原创并维护,致力于解决分子动力学和化学计算领域中的关键问题。

项目背景与痛点

在分子动力学模拟中,传统的势函数计算高度依赖于预定义的物理和化学知识。然而,这种计算模式存在诸多限制,例如无法准确处理新出现的化学组合或复杂体系中的多重相互作用。TorchANI 通过引入深度学习技术解决这些问题,能够自适应地学习原子间的复杂交互,尤其在处理大规模分子体系时表现出色。

技术核心揭秘

技术架构

TorchANI 的设计思想集中在将深度学习方法与传统的物理建模相结合。它利用 PyTorch 作为计算平台,结合分子势函数的特异性来优化深度学习模型。模型通过训练大量化学结构数据,能够预测分子中原子间相互作用的势能,从而高效地进行动力学模拟。

graph TD A[用户输入数据] --> B{"数据预处理"} B -->|"数据清洗" | C[特征提取] C --> D[构建深度模型] D --> E{"模型训练"} E -->|"损失函数优化"| F[模型验证] E -->|"调优完成"| G[模型导出] F --> H{"模型评估"} H -->|"性能达标"| G H -->|"性能不达标"| E

技术难点

  1. 大规模数据处理:原子间的相互作用数据量庞大,如何进行高效的数据预处理和特征提取是一个难点。
  2. 模型复杂性:深度学习模型的复杂性决定了其在大规模分子上训练和预测的难点。TorchANI 必须在模型性能与计算成本之间取得平衡。
  3. 物理建模的融合:将深度学习模型与实际的物理约束融合起来,实现自适应的学习过程,同时保持化学意义上的准确性。

功能亮点与差异

相比其他同类工具,TorchANI 在原子间相互作用的精确建模方面表现出众。其特有的深度学习模型训练和优化机制能够处理复杂的原子间关系,尤其擅长在多样化分子结构中的精确模拟。

此外,TorchANI 的 PyTorch 平台集成提供丰富的灵活性,使得高级用户能够轻松定制和扩展模型,针对特定化学问题进行优化。

应用场景与落地建议

TorchANI 适用于需要精细的分子水平动力学模拟的场景,如药物设计、材料发现和化学反应机理研究。在生产环境中,需特别注意以下几点:

  1. 数据清洗:确保训练数据的质量,剔除异常值。
  2. 模型验证:针对具体应用场景进行充分的模型验证。
  3. 计算资源:为训练和预测过程提供足够的计算资源。

综合评价

优点

  1. 高效的计算能力:借助 PyTorch,能够处理大规模的分子动力学计算任务。
  2. 灵活性高:用户可自定义模型,适应各种化学研究需求。

缺点

  1. 计算资源密集:高性能计算需求较高,成本可能成为严苛条件下的限制因素。
  2. 模型复杂性:高级深度学习模型的调试和优化工作量大。

关于

GitHub 原始描述(英文)

TorchANI 2.0 is an open-source library that supports training, development, and research of ANI-style neural network interatomic potentials. It was originally developed and is currently maintained by the Roitberg group.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
868
价值分
383
活跃状态
活跃

语言占比

C++
CMake
Cuda
Dockerfile
Jinja
Python
Shell

Release

README

TorchANI 2 logo

License: MIT PyPI PyPI - Downloads CI Code style: black

TorchANI 2.0 is an open-source library that supports training, development, and research of ANI-style neural network interatomic potentials. It was originally developed and is currently maintained by the Roitberg group. For information and examples, please see the comprehensive documentation.

⚠️ Important: If you were using a previous version of TorchANI and your code does not work with TorchANI 2.0 check out the migration guide, there are very few breaking changes, most code should work with minimal modifications. If you can’t figure something out please open a GitHub issue, we are here to help! In the meantime, you can pin torchani to version 2.2.4 (pip install ‘torchani==2.2.4’), which does not have breaking changes. If you require the old state dicts of ANI models you can access them by calling .legacy_state_dict() instead of .state_dict()

If you find a bug in TorchANI 2.0, or have some feature request, also feel free to open a GitHub issue. TorchANI 2.0 is currently tested against PyTorch 2.13 and CUDA 13.0

If you find this work useful please cite the following articles:

To run molecular dynamics (full ML or ML/MM) with Amber (sander or pmemd) check out the TorchANI-Amber interface, and the relevant publications:

Installation

We recommend installing torchani inside a conda|mamba environment, or a venv.

⚠️ Important: Please install torchani with pip if you want the latest version, even if using a conda env since the torchani conda package is currently not maintained.

We also recommended you first install a specific torch version, with a specific CUDA toolkit backend, for example:

pip install torch==2.13 --index-url https://download.pytorch.org/whl/cu130

for the version with CUDA 13.0. This is not strictly required, but is easier if you want to control these versions. Note that TorchANI 2 requires PyTorch >= 2.0.

Afterwards:

pip install torchani

TorchANI 2.0 provides C++ and CUDA extensions for accelerated computation of descriptors and network inference. In order to build the extensions, first install the CUDA Toolkit appropriate for your PyTorch version. You can follow the instructions in the official documentation for your system. Alternatively, if you are using a conda environment, you can install the toolkit with conda install nvidia::cuda-toolkit=13.0

After this, run:

ani build-extensions

By default the extensions are built for all detected SMs. If you want to build the extensions for specific SMs run for instance:

ani build-extensions --sm 8.0 --sm 8.9 

From source (GitHub repo)

To build and install TorchANI directly from the GitHub repo do the following:

# Clone the repo and cd to the directory
git clone https://github.com/aiqm/torchani.git
cd ./torchani

# Create a conda (or mamba) environment
# Note that environment.yaml contains many optional dependencies needed to
# build the compiled extensions, build the documentation, and run tests and tools
# You can comment these out if you are not planning to do that
conda env create -f ./environment.yaml

Instead of using a conda environment you can use a python venv, and install the torchani optional dependencies running pip install -r dev_requirements.txt.

pip install --no-deps -v -e .

Afterwards you can install the extensions with:

ani build-extensions

After this you can perform some optional steps if you installed the required dev dependencies:

# Download files needed for testing and building the docs (optional)
bash ./download-dev-data.sh

# Build the documentation (optional)
sphinx-build docs/src docs/build

# Manually run unit tests (optional)
cd ./tests
pytest -v .

This process works for most use cases, for more details regarding building the CUDA and C++ extensions refer to TorchANI CSRC.

From source in macOS

There is no CUDA support on macOS and TorchANI is untested with Apple Metal Performance Shaders (MPS). The environment.yaml file needs slight modifications if installing on macOS. Please consult the corresponding file and modify it before creating the conda environment.

GPU support

TorchANI 2.0 can be run in CUDA-enabled GPUs. This is highly recommended unless doing simple debugging or tests. If you don’t run TorchANI on a GPU, expect degraded performance. TorchANI is untested with AMD GPUs (ROCm | HIP).

Command Line Interface

TorchANI 2.0 provides an executable script, ani, with some utilities. Check usage by calling torchani --help.

Building the TorchANI conda package (for developers)

The conda package can be built locally using the recipe in ./recipe, by running:

cd ./torchani_sandbox
conda install conda-build conda-verify
mkdir ./conda-pkgs/  # This dir must exist before running conda-build
conda build \
    -c pytorch -c nvidia -c conda-forge \
    --no-anaconda-upload \
    --output-folder ./conda-pkgs/ \
    ./recipe

The meta.yaml in the recipe assumes that the extensions are built using the system’s CUDA Toolkit, located in /usr/local/cuda. If this is not possible, add the following dependencies to the host environment:

  • nvidia::cuda-libraries-dev={{ cuda }}
  • nvidia::cuda-nvcc={{ cuda }}
  • nvidia::cuda-cccl={{ cuda }}

and remove cuda_home=/usr/local/cuda from the build script. Note that doing this may significantly increase build time.

The CI (GitHub Actions Workflow) that tests that the conda pkg builds correctly runs only:

  • on pull requests that contain the string conda in the branch name.

The workflow that deploys the conda pkg to the internal server runs only:

  • on the default branch, at 00:00:00 every day
  • on pull requests that contain both the strings conda and release in the branch name

评论

暂无评论