Skip to main content

TorchMD-NET provides state-of-the-art neural networks potentials for biomolecular systems

Project description

Code style: black CI Documentation Status

TorchMD-NET

TorchMD-NET provides state-of-the-art neural networks potentials (NNPs) and a mechanism to train them. It offers efficient and fast implementations if several NNPs and it is integrated in GPU-accelerated molecular dynamics code like ACEMD, OpenMM and TorchMD. TorchMD-NET exposes its NNPs as PyTorch modules.

Documentation

Documentation is available at https://torchmd-net.readthedocs.io

Available architectures

Installation

TorchMD-Net is available as a pip installable wheel as well as in conda-forge

TorchMD-Net provides builds for CPU-only, CUDA 11.8 and CUDA 12.4. CPU versions are only provided as reference, as the performance will be extremely limited. Depending on which variant you wish to install, you can install it with one of the following commands:

# The following will install the CUDA 12.4 version by default
pip install torchmd-net 
# The following will install the CUDA 11.8 version
pip install torchmd-net --extra-index-url https://download.pytorch.org/whl/cu118 --extra-index-url https://us-central1-python.pkg.dev/pypi-packages-455608/cu118/simple
# The following will install the CUDA 12.4 version
pip install torchmd-net --extra-index-url https://download.pytorch.org/whl/cu124 --extra-index-url https://us-central1-python.pkg.dev/pypi-packages-455608/cu124/simple
# The following will install the CPU only version (not recommended)
pip install torchmd-net --extra-index-url https://download.pytorch.org/whl/cpu --extra-index-url https://us-central1-python.pkg.dev/pypi-packages-455608/cpu/simple   

Alternatively it can be installed with conda or mamba with one of the following commands. We recommend using Miniforge instead of anaconda.

mamba install torchmd-net cuda-version=11.8
mamba install torchmd-net cuda-version=12.4

Install from source

TorchMD-Net is installed using pip, but you will need to install some dependencies before. Check this documentation page.

Usage

Specifying training arguments can either be done via a configuration yaml file or through command line arguments directly. Several examples of architectural and training specifications for some models and datasets can be found in examples/. Note that if a parameter is present both in the yaml file and the command line, the command line version takes precedence. GPUs can be selected by setting the CUDA_VISIBLE_DEVICES environment variable. Otherwise, the argument --ngpus can be used to select the number of GPUs to train on (-1, the default, uses all available GPUs or the ones specified in CUDA_VISIBLE_DEVICES). Keep in mind that the GPU ID reported by nvidia-smi might not be the same as the one CUDA_VISIBLE_DEVICES uses.
For example, to train the Equivariant Transformer on the QM9 dataset with the architectural and training hyperparameters described in the paper, one can run:

mkdir output
CUDA_VISIBLE_DEVICES=0 torchmd-train --conf torchmd-net/examples/ET-QM9.yaml --log-dir output/

Run torchmd-train --help to see all available options and their descriptions.

Pretrained models

See here for instructions on how to load pretrained models.

Creating a new dataset

If you want to train on custom data, first have a look at torchmdnet.datasets.Custom, which provides functionalities for loading a NumPy dataset consisting of atom types and coordinates, as well as energies, forces or both as the labels. Alternatively, you can implement a custom class according to the torch-geometric way of implementing a dataset. That is, derive the Dataset or InMemoryDataset class and implement the necessary functions (more info here). The dataset must return torch-geometric Data objects, containing at least the keys z (atom types) and pos (atomic coordinates), as well as y (label), neg_dy (negative derivative of the label w.r.t atom coordinates) or both.

Custom prior models

In addition to implementing a custom dataset class, it is also possible to add a custom prior model to the model. This can be done by implementing a new prior model class in torchmdnet.priors and adding the argument --prior-model <PriorModelName>. As an example, have a look at torchmdnet.priors.Atomref.

Multi-Node Training

In order to train models on multiple nodes some environment variables have to be set, which provide all necessary information to PyTorch Lightning. In the following we provide an example bash script to start training on two machines with two GPUs each. The script has to be started once on each node. Once torchmd-train is started on all nodes, a network connection between the nodes will be established using NCCL.

In addition to the environment variables the argument --num-nodes has to be specified with the number of nodes involved during training.

export NODE_RANK=0
export MASTER_ADDR=hostname1
export MASTER_PORT=12910

mkdir -p output
CUDA_VISIBLE_DEVICES=0,1 torchmd-train --conf torchmd-net/examples/ET-QM9.yaml.yaml --num-nodes 2 --log-dir output/
  • NODE_RANK : Integer indicating the node index. Must be 0 for the main node and incremented by one for each additional node.
  • MASTER_ADDR : Hostname or IP address of the main node. The same for all involved nodes.
  • MASTER_PORT : A free network port for communication between nodes. PyTorch Lightning suggests port 12910 as a default.

Known Limitations

  • Due to the way PyTorch Lightning calculates the number of required DDP processes, all nodes must use the same number of GPUs. Otherwise training will not start or crash.
  • We observe a 50x decrease in performance when mixing nodes with different GPU architectures (tested with RTX 2080 Ti and RTX 3090).
  • Some CUDA systems might hang during a multi-GPU parallel training. Try export NCCL_P2P_DISABLE=1, which disables direct peer to peer GPU communication.

Cite

If you use TorchMD-NET in your research, please cite the following papers:

Main reference

@misc{pelaez2024torchmdnet,
title={TorchMD-Net 2.0: Fast Neural Network Potentials for Molecular Simulations}, 
author={Raul P. Pelaez and Guillem Simeon and Raimondas Galvelis and Antonio Mirarchi and Peter Eastman and Stefan Doerr and Philipp Thölke and Thomas E. Markland and Gianni De Fabritiis},
year={2024},
eprint={2402.17660},
archivePrefix={arXiv},
primaryClass={cs.LG}
}

TensorNet

@inproceedings{simeon2023tensornet,
title={TensorNet: Cartesian Tensor Representations for Efficient Learning of Molecular Potentials},
author={Guillem Simeon and Gianni De Fabritiis},
booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
year={2023},
url={https://openreview.net/forum?id=BEHlPdBZ2e}
}

Equivariant Transformer

@inproceedings{
tholke2021equivariant,
title={Equivariant Transformers for Neural Network based Molecular Potentials},
author={Philipp Th{\"o}lke and Gianni De Fabritiis},
booktitle={International Conference on Learning Representations},
year={2022},
url={https://openreview.net/forum?id=zNHzqZ9wrRB}
}

Graph Network

@article{Majewski2023,
  title = {Machine learning coarse-grained potentials of protein thermodynamics},
  volume = {14},
  ISSN = {2041-1723},
  url = {http://dx.doi.org/10.1038/s41467-023-41343-1},
  DOI = {10.1038/s41467-023-41343-1},
  number = {1},
  journal = {Nature Communications},
  publisher = {Springer Science and Business Media LLC},
  author = {Majewski,  Maciej and Pérez,  Adrià and Th\"{o}lke,  Philipp and Doerr,  Stefan and Charron,  Nicholas E. and Giorgino,  Toni and Husic,  Brooke E. and Clementi,  Cecilia and Noé,  Frank and De Fabritiis,  Gianni},
  year = {2023},
  month = sep 
}

Developer guide

Implementing a new architecture

To implement a new architecture, you need to follow these steps:
1. Create a new class in torchmdnet.models that inherits from torch.nn.Model. Follow TorchMD_ET as a template. This is a minimum implementation of a model:

class MyModule(nn.Module):
  def __init__(self, parameter1, parameter2):
	super(MyModule, self).__init__()
	# Define your model here
	self.layer1 = nn.Linear(10, 10)
	...
	# Initialize your model parameters here
	self.reset_parameters()

    def reset_parameters(self):
      # Initialize your model parameters here
	  nn.init.xavier_uniform_(self.layer1.weight)
	...
	
  def forward(self,
        z: Tensor, # Atomic numbers, shape (n_atoms, 1)
        pos: Tensor, # Atomic positions, shape (n_atoms, 3)
        batch: Tensor, # Batch vector, shape (n_atoms, 1). All atoms in the same molecule have the same value and are contiguous.
        q: Optional[Tensor] = None, # Atomic charges, shape (n_atoms, 1)
        s: Optional[Tensor] = None, # Atomic spins, shape (n_atoms, 1)
    ) -> Tuple[Tensor, Tensor, Tensor, Tensor, Tensor]:
	# Define your forward pass here
	scalar_features = ...
	vector_features = ...
	# Return the scalar and vector features, as well as the atomic numbers, positions and batch vector
	return scalar_features, vector_features, z, pos, batch

2. Add the model to the __all__ list in torchmdnet.models.__init__.py. This will make the tests pick your model up.
3. Tell models.model.create_model how to initialize your module by adding a new entry, for instance:

    elif args["model"] == "mymodule":
       from torchmdnet.models.torchmd_mymodule import MyModule
       is_equivariant = False # Set to True if your model is equivariant
       representation_model = MyModule(
           parameter1=args["parameter1"],
           parameter2=args["parameter2"],
           **shared_args, # Arguments typically shared by all models
       )

4. Add any new parameters required to initialize your module to scripts.train.get_args. For instance:

  parser.add_argument('--parameter1', type=int, default=32, help='Parameter1 required by MyModule')
  ...

5. Add an example configuration file to torchmd-net/examples that uses your model.
6. Make tests use your configuration file by adding a case to tests.utils.load_example_args. For instance:

if model_name == "mymodule":
       config_file = join(dirname(dirname(__file__)), "examples", "MyModule-QM9.yaml")

At this point, if your module is missing some feature the tests will let you know, and you can add it. If you add a new feature to the package, please add a test for it.

Code style

We use black. Please run black on your modified files before committing.

Testing

To run the tests, install the package and run pytest in the root directory of the repository. Tests are a good source of knowledge on how to use the different components of the package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

torchmd_net-2.4.10-cp313-cp313-win_amd64.whl (681.8 kB view details)

Uploaded CPython 3.13Windows x86-64

torchmd_net-2.4.10-cp313-cp313-manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp312-cp312-win_amd64.whl (682.2 kB view details)

Uploaded CPython 3.12Windows x86-64

torchmd_net-2.4.10-cp312-cp312-manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp311-cp311-win_amd64.whl (680.8 kB view details)

Uploaded CPython 3.11Windows x86-64

torchmd_net-2.4.10-cp311-cp311-manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp310-cp310-win_amd64.whl (680.4 kB view details)

Uploaded CPython 3.10Windows x86-64

torchmd_net-2.4.10-cp310-cp310-manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp39-cp39-win_amd64.whl (680.4 kB view details)

Uploaded CPython 3.9Windows x86-64

torchmd_net-2.4.10-cp39-cp39-manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

torchmd_net-2.4.10-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file torchmd_net-2.4.10-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 525d4fdd334d0f169b986606b97251f1ee11ddfceebdd113629b5623f44451bb
MD5 7b4d3fa995e933dba8c35278b72f9aeb
BLAKE2b-256 0975b11cb501985e00644d1001d13665264a761334935b86ecf7bf001613dbb4

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e43ada16220bee81af935c730a857fd009807534fd5c1e14648dbba5173ff80c
MD5 5d88707694c63c2a8653d3ea9b520501
BLAKE2b-256 6f33e12c75c258947e942203097a0265d8c7f2d3592f29d8568505d18be0c756

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 233a4e125b76bde3ccbc9f302a31b420fdf6c9ea9e29650a58493ac7ad96f4f1
MD5 d7279a2411092d96ecb0601ae07244c2
BLAKE2b-256 13e74ab86cd1acbb44b5fddb88e33475b7e2e363e51e6fcc1c5b5e957aab5fa8

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2107c702330d7f0a88b628caa9c885675a4b6e62df7997f435ad2cdb26b77a1d
MD5 ff68f98f81dd1b27d65852923441ac7a
BLAKE2b-256 115c81f1e29b36a070b6499804524c2b7adfde1106fa18e50b907633c6d6de8a

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6861508671e708064ea00a31621a17ac674c0f322d43221ad4eb5a0d9b012c1d
MD5 34bfb03085050f024581fa52a1ba76c5
BLAKE2b-256 a028ccda65f20c96957824958244ce35925a9f3f4462c0ee60b470fecccda709

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e5c968d749af4086d1d87e54a457706a4912b8106471da6313ce4679d341602
MD5 d5f2c5ac484aa626c681a4cc2dc401fe
BLAKE2b-256 f70376994bb39947f9730dedcbc382483a455afb46f55efd0e3cb7deaf5b1460

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c97f1d2aea735cedf22a452eb1af76309ea811f85658e450f8843a068355bdda
MD5 1dff7de7c75d0dc361627d65271b0075
BLAKE2b-256 5e82f8ba39d952bc531a637c43f3b1602f9258431076c48b4fa0c0747ed1111f

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2a674eb41ad886a39599e86054dd66c5cd64ec60515790e3e20e40ea0fa90447
MD5 9b6e9e81b580faa95e16566e9c3562b6
BLAKE2b-256 e81f8bd2c3bb1641a1f9cc9307394243b20767a574ce19b16fe2901811ba5651

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9e2ba944685ad56631ae777e3ba344caaf448107532eca1e8c278a76160d6875
MD5 312ebff31c9e3acd3ec5424f960a6fe7
BLAKE2b-256 11e379fca04120e02145761e8d149e67066ddfcea524e2af730e09a9bc7aeb92

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 36c6f9f6d90f5ff0191420e47b1b9211650bdecd5ed3bf885cb6ed81de1d4d57
MD5 5e90323afde1813c15c11d45a29ffb54
BLAKE2b-256 f4d671b016a4b160359f68c960c145778f425dd9cde2ec469dc648dcd6bd218f

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 12fd72be834d2da3ca7ce5f8835a30bd0d6cd4de0e591b1b4a042b92bbd5811f
MD5 b87b4607ea5276ff7a2ef962a3d3dc5b
BLAKE2b-256 1bc8dcd105730e9e4440f050881d80b872510678b3150921735c8e18ce57fbe7

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ebc32234bb2d20803839ab26dad13b10cb9f6774198556c8c0de017eb516a6a4
MD5 03d58c949b32c514854eb80ae60e162d
BLAKE2b-256 f7f9a0223ca010838281cb3c5719c473fede805528028702ae039edc4d68529c

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: torchmd_net-2.4.10-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 680.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for torchmd_net-2.4.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6521be3bff48837c97e4bd6dcf89e7f7d1ee348cae9a26699c7d71f33e8bd342
MD5 00937cd2a626694730be1a2458424514
BLAKE2b-256 9dd1af2304f6aeb15f962512cd6ccf75726335483ce7f1f18f8164606730dafb

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c20bffa614754b6ff79c764d4fd1bab2fc23d56796fa1d7cc51e6d118fc578c8
MD5 85157b161827824b651d901a9bb7f09c
BLAKE2b-256 143a37b82617d1b88493f90d1c0dea816642bd64c2030316ea01032370cf00ce

See more details on using hashes here.

File details

Details for the file torchmd_net-2.4.10-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for torchmd_net-2.4.10-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4b3efc80fa8d67c540f45c4cb70bcf881d9299542814c0c4685f45879a309c0f
MD5 af44df4ffedc4ae410300c535afe8737
BLAKE2b-256 230509291d964587827be291997df8307f999fb223ce938248d29794e9e38420

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page