{"id":27036776,"url":"https://github.com/lab-cosmo/pet-mad","last_synced_at":"2025-08-21T15:34:59.701Z","repository":{"id":283087329,"uuid":"950517431","full_name":"lab-cosmo/pet-mad","owner":"lab-cosmo","description":"A universal interatomic potential for advanced materials modeling","archived":false,"fork":false,"pushed_at":"2025-08-14T13:40:51.000Z","size":327,"stargazers_count":64,"open_issues_count":7,"forks_count":4,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-08-14T15:29:48.182Z","etag":null,"topics":["machine-learned-interatomic-potentials","machine-learning","molecular-dynamics","universal-potential"],"latest_commit_sha":null,"homepage":"http://arxiv.org/abs/2503.14118","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lab-cosmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.bib","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-18T09:35:31.000Z","updated_at":"2025-07-18T15:45:32.000Z","dependencies_parsed_at":"2025-03-18T14:30:55.626Z","dependency_job_id":"d5037388-6c87-454c-9bc0-381b91138fd4","html_url":"https://github.com/lab-cosmo/pet-mad","commit_stats":null,"previous_names":["lab-cosmo/pet-mad"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lab-cosmo/pet-mad","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab-cosmo%2Fpet-mad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab-cosmo%2Fpet-mad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab-cosmo%2Fpet-mad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab-cosmo%2Fpet-mad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lab-cosmo","download_url":"https://codeload.github.com/lab-cosmo/pet-mad/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab-cosmo%2Fpet-mad/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271500436,"owners_count":24770391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["machine-learned-interatomic-potentials","machine-learning","molecular-dynamics","universal-potential"],"created_at":"2025-04-05T01:01:45.868Z","updated_at":"2025-08-21T15:34:59.691Z","avatar_url":"https://github.com/lab-cosmo.png","language":"Python","funding_links":[],"categories":["Universal Potentials"],"sub_categories":[],"readme":"\u003cdiv align=\"center\" width=\"600\"\u003e\n  \u003cpicture\u003e\n    \u003csource srcset=\"https://github.com/lab-cosmo/pet-mad/raw/refs/heads/main/docs/static/pet-mad-logo-with-text-dark.svg\" media=\"(prefers-color-scheme: dark)\"\u003e\n    \u003cimg src=\"https://github.com/lab-cosmo/pet-mad/raw/refs/heads/main/docs/static/pet-mad-logo-with-text.svg\" alt=\"Figure\"\u003e\n  \u003c/picture\u003e\n\u003c/div\u003e\n\n# PET-MAD: A Universal Interatomic Potential for Advanced Materials Modeling\n\nThis repository contains **PET-MAD** - a universal interatomic potential for\nadvanced materials modeling across the periodic table. This model is based on\nthe **Point Edge Transformer (PET)** model trained on the **Massive Atomic\nDiversity (MAD) Dataset** and is capable of predicting energies and forces in\ncomplex atomistic simulations.\n\n## Key Features\n\n- **Universality**: PET-MAD is a generally-applicable model that can be used for\n  a wide range of materials and molecules.\n- **Accuracy**: PET-MAD achieves high accuracy in various types of atomistic\n  simulations of organic and inorganic systems, comparable with system-specific\n  models, while being fast and efficient.\n- **Efficiency**: PET-MAD achieves high computational efficiency and low memory\n  usage, making it suitable for large-scale simulations.\n- **Infrastructure**: Various MD engines are available for diverse research and\n  application needs.\n- **HPC Compatibility**: Efficient in HPC environments for extensive simulations.\n\n## Table of Contents\n1. [Installation](#installation)\n2. [Pre-trained Models](#pre-trained-models)\n3. [Interfaces for Atomistic Simulations](#interfaces-for-atomistic-simulations)\n4. [Usage](#usage)\n    - [ASE Interface](#ase-interface)\n        - [Basic usage](#basic-usage)\n        - [Non-conservative (direct) forces and stresses prediction](#non-conservative-direct-forces-and-stresses-prediction)\n    - [Evaluating PET-MAD on a dataset](#evaluating-pet-mad-on-a-dataset)\n    - [Running PET-MAD with LAMMPS](#running-pet-mad-with-lammps)\n    - [Uncertainty Quantification](#uncertainty-quantification)\n    - [Running PET-MAD with empirical dispersion corrections](#running-pet-mad-with-empirical-dispersion-corrections)\n    - [Dataset visualization with the PET-MAD featurizer](#dataset-visualization-with-the-pet-mad-featurizer)\n5. [Examples](#examples)\n6. [Fine-tuning](#fine-tuning)\n7. [Documentation](#documentation)\n8. [Citing PET-MAD](#citing-pet-mad)\n\n## Installation\n\nYou can install PET-MAD using pip:\n\n```bash\npip install pet-mad\n```\n\nOr directly from the GitHub repository:\n\n```bash\npip install git+https://github.com/lab-cosmo/pet-mad.git\n```\n\nAlternatively, you can install PET-MAD using `conda` package manager, which is\nespecially important for running PET-MAD with **LAMMPS**.\n\n\u003e [!WARNING]\n\u003e We strongly recommend installing PET-MAD using\n\u003e [`Miniforge`](https://github.com/conda-forge/miniforge) as a base `conda`\n\u003e provider, because other `conda` providers (such as `Anaconda`) may yield\n\u003e undesired behavior when resolving dependencies and are usually slower than\n\u003e `Miniforge`. Smooth installation and use of PET-MAD is not guaranteed with\n\u003e other `conda` providers.\n\nTo install Miniforge on unix-like systems, run:\n\n```bash\nwget \"https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh\"\nbash Miniforge3-$(uname)-$(uname -m).sh\n```\n\nOnce Miniforge is installed, create a new conda environment and install PET-MAD\nwith:\n\n```bash\nconda create -n pet-mad\nconda activate pet-mad\nconda install -c metatensor -c conda-forge pet-mad\n```\n\n## Pre-trained Models\n\nCurrently, we provide the following pre-trained models:\n\n- **`v1.1.0`**: The dev version of the PET-MAD model with the non-conservative\n  forces and stresses. This version has notably worse performance on molecular\n  systems, and is not recommended for production use, as for now.\n- **`v1.0.2`**: Stable PET-MAD model trained on the MAD dataset, which contains 95,595\n  structures, including 3D and 2D inorganic crystals, surfaces, molecular\n  crystals, nanoclusters, and molecules. Use this version in the case you want\n  to repoduce the results from the [PET-MAD paper](https://arxiv.org/abs/2503.14118).\n\n## Interfaces for Atomistic Simulations\n\nPET-MAD integrates with the following atomistic simulation engines:\n\n- **Atomic Simulation Environment (ASE)**\n- **LAMMPS** (including the KOKKOS support)\n- **i-PI**\n- **OpenMM** (coming soon)\n- **GROMACS** (coming soon)\n\n## Usage\n\n### ASE Interface\n\n#### Basic usage\n\nYou can use the PET-MAD calculator, which is compatible with the Atomic\nSimulation Environment (ASE):\n\n```python\nfrom pet_mad.calculator import PETMADCalculator\nfrom ase.build import bulk\n\natoms = bulk(\"Si\", cubic=True, a=5.43, crystalstructure=\"diamond\")\npet_mad_calculator = PETMADCalculator(version=\"latest\", device=\"cpu\")\natoms.calc = pet_mad_calculator\nenergy = atoms.get_potential_energy()\nforces = atoms.get_forces()\n```\n\nThese ASE methods are ideal for single-structure evaluations, but they are\ninefficient for the evaluation on a large number of pre-defined structures. To\nperform efficient evaluation in that case, read [here](docs/README_BATCHED.md).\n\n#### Non-conservative (direct) forces and stresses prediction\n\nPET-MAD also supports the direct prediction of forces and stresses. In that case,\nthe forces and stresses are predicted as separate targets along with the energy\ntarget, i.e. not computed as derivatives of the energy using the PyTorch\nautomatic differentiation. This approach typically leads to 2-3x speedup in the\nevaluation time, since backward pass is disabled. However, as discussed in [this\npreprint](https://arxiv.org/abs/2412.11569) it requires additional care to avoid\ninstabilities during the molecular dynamics simulations.\n\nTo use the non-conservative forces and stresses, you need to set the `non_conservative` parameter to `True` when initializing the `PETMADCalculator` class.\n\n```python\nfrom pet_mad.calculator import PETMADCalculator\nfrom ase.build import bulk\n\natoms = bulk(\"Si\", cubic=True, a=5.43, crystalstructure=\"diamond\")\npet_mad_calculator = PETMADCalculator(version=\"latest\", device=\"cpu\", non_conservative=True)\natoms.calc = pet_mad_calculator\nenergy = atoms.get_potential_energy() # energy is computed as usual\nforces = atoms.get_forces() # forces now are predicted as a separate target\nstresses = atoms.get_stress() # stresses now are predicted as a separate target\n```\n\nMore details on how to make the direct forces MD simulations reliable are provided \nin the [Atomistic Cookbook](https://atomistic-cookbook.org/examples/pet-mad-nc/pet-mad-nc.html).\n\n### Evaluating PET-MAD on a dataset\n\nEfficient evaluation of PET-MAD on a desired dataset is also available from the\ncommand line via [`metatrain`](https://github.com/metatensor/metatrain), which\nis installed as a dependency of PET-MAD. To evaluate the model, you first need\nto fetch the PET-MAD model from the HuggingFace repository:\n\n```bash\nmtt export https://huggingface.co/lab-cosmo/pet-mad/resolve/v1.0.2/models/pet-mad-v1.0.2.ckpt -o pet-mad-latest.pt\n```\n\nAlternatively, you can also download the model from Python:\n\n```py\nimport pet_mad\n\n# Saving the latest version of PET-MAD to a TorchScript file\npet_mad.save_pet_mad(version=\"latest\", output=\"pet-mad-latest.pt\")\n\n# you can also get a metatomic AtomisticModel for advance usage\nmodel = pet_mad.get_pet_mad(version=\"latest\")\n```\n\nThis command will download the model and convert it to TorchScript format. Then\nyou need to create the `options.yaml` file and specify the dataset you want to\nevaluate the model on (where the dataset is stored in `extxyz` format):\n\n```yaml\nsystems: your-test-dataset.xyz\ntargets:\n  energy:\n    key: \"energy\"\n    unit: \"eV\"\n```\n\nThen, you can use the `mtt eval` command to evaluate the model on a dataset:\n\n```bash\nmtt eval pet-mad-latest.pt options.yaml --batch-size=16 --extensions-dir=extensions --output=predictions.xyz\n```\n\nThis will create a file called `predictions.xyz` with the predicted energies and\nforces for each structure in the dataset. More details on how to use `metatrain`\ncan be found in the [Metatrain documentation](https://metatensor.github.io/metatrain/latest/getting-started/usage.html#evaluation).\n\n### Uncertainty Quantification\n\nPET-MAD can also be used to calculate the uncertainty of the energy prediction.\nThis feature is particularly important if you are interested in probing the model\non the data that is far away from the training data. Another important use case\nis a propagation of the uncertainty of the energy prediction to other observables,\nlike phase transition temperatures, diffusion coefficients, etc.\n\nTo activate the uncertainty quantification, you need to set the\n`calculate_uncertainty` and / or`calculate_ensemble` parameters to `True` when\ninitializing the `PETMADCalculator` class. The first feature will calculate the\nuncertainty of the energy prediction, while the second one will calculate the\nensemble of the energy predictions based on the shallow ensemble of the last\nlayers of the model.\n\n```python\nfrom pet_mad.calculator import PETMADCalculator\nfrom ase.build import bulk\n\natoms = bulk(\"Si\", cubic=True, a=5.43, crystalstructure=\"diamond\")\npet_mad_calculator = PETMADCalculator(version=\"latest\", device=\"cpu\", calculate_uncertainty=True, calculate_ensemble=True)\natoms.calc = pet_mad_calculator\nenergy = atoms.get_potential_energy()\n\nenergy_uncertainty = atoms.calc.get_energy_uncertainty()\nenergy_ensemble = atoms.calc.get_energy_ensemble()\n```\n\nMore details on the uncertainty quantification and shallow\nensemble method can be found in [this](https://doi.org/10.1088/2632-2153/ad594a) and [this](https://doi.org/10.1088/2632-2153/ad805f) papers. \n\n\n\n## Running PET-MAD with LAMMPS\n\n### 1. Install LAMMPS with metatomic support\n\nTo use PET-MAD with LAMMPS, you need to first install PET-MAD from `conda` (see\nthe installation instructions above). Then, follow the instructions\n[here](https://docs.metatensor.org/metatomic/latest/engines/lammps.html#how-to-install-the-code) to install lammps-metatomic. We recomend you also use conda to install lammps.\n\n### 2. Run LAMMPS with PET-MAD\n\n#### 2.1. CPU version\n\nFetch the PET-MAD checkpoint from the HuggingFace repository:\n\n```bash\nmtt export https://huggingface.co/lab-cosmo/pet-mad/resolve/v1.0.2/models/pet-mad-v1.0.2.ckpt -o pet-mad-latest.pt\n```\n\nThis will download the model and convert it to TorchScript format compatible\nwith LAMMPS, using the `metatomic` and `metatrain` libraries, which PET-MAD is\nbased on.\n\nPrepare a lammps input file using `pair_style metatomic` and defining the\nmapping from LAMMPS types in the data file to elements PET-MAD can handle using\n`pair_coeff` syntax. Here we indicate that lammps atom type 1 is Silicon (atomic\nnumber 14).\n\n```\nunits metal\natom_style atomic\n\nread_data silicon.data\n\npair_style metatomic pet-mad-latest.pt device cpu # Change device to 'cuda' evaluate PET-MAD on GPU\npair_coeff * * 14\n\nneighbor 2.0 bin\ntimestep 0.001\n\ndump myDump all xyz 10 trajectory.xyz\ndump_modify myDump element Si\n\nthermo_style multi\nthermo 1\n\nvelocity all create 300 87287 mom yes rot yes\n\nfix 1 all nvt temp 300 300 0.10\n\nrun 100\n```\n\nCreate the **`silicon.data`** data file for a silicon system.\n\n```\n# LAMMPS data file for Silicon unit cell\n8 atoms\n1 atom types\n\n0.0  5.43  xlo xhi\n0.0  5.43  ylo yhi\n0.0  5.43  zlo zhi\n\nMasses\n\n1  28.084999992775295 # Si\n\nAtoms # atomic\n\n1   1   0   0   0\n2   1   1.3575   1.3575   1.3575\n3   1   0   2.715   2.715\n4   1   1.3575   4.0725   4.0725\n5   1   2.715   0   2.715\n6   1   4.0725   1.3575   4.0725\n7   1   2.715   2.715   0\n8   1   4.0725   4.0725   1.3575\n```\n\n```bash\nlmp -in lammps.in  # For serial version\nmpirun -np 1 lmp -in lammps.in  # For MPI version\n```\n\n#### 2.2. KOKKOS-enabled GPU version\n\nRunning LAMMPS with KOKKOS and GPU support is similar to the CPU version, but\nyou need to change the `lammps.in` slightly and run `lmp` binary with a few\nadditional flags.\n\nThe updated `lammps.in` file looks like this:\n\n```\npackage kokkos newton on neigh half\n\nunits metal\natom_style atomic/kk\n\nread_data silicon.data\n\npair_style metatensor/kk pet-mad-latest.pt # This will use the same device as the kokkos simulation\npair_coeff * * 14\n\nneighbor 2.0 bin\ntimestep 0.001\n\ndump myDump all xyz 10 trajectory.xyz\ndump_modify myDump element Si\n\nthermo_style multi\nthermo 1\n\nvelocity all create 300 87287 mom yes rot yes\n\nfix 1 all nvt temp 300 300 0.10\n\nrun_style verlet/kk\nrun 100\n```\n\nThe **silicon.data** file remains the same.\n\nTo run the KOKKOS-enabled version of LAMMPS, you need to run\n\n```bash\nlmp -in lammps.in -k on g 1 -sf kk # For serial version\nmpirun -np 1 lmp -in lammps.in -k on g 1 -sf kk # For MPI version\n```\n\nHere, the `-k on g 1 -sf kk` flags are used to activate the KOKKOS\nsubroutines. Specifically `g 1` is used to specify, how many GPUs are the\nsimulation is parallelized over, so if running the large systems on two or more\nGPUs, this number should be adjusted accordingly.\n\n\n### 3. Important Notes\n\n- For **CPU calculations**, use a single MPI task unless simulating large\n  systems (30+ Å box size). Multi-threading can be enabled via:\n\n  ```bash\n  export OMP_NUM_THREADS=4\n  ```\n\n- For **GPU calculations**, use **one MPI task per GPU**.\n\n## Running PET-MAD with empirical dispersion corrections\n\n### In **ASE**:\n\nYou can combine the PET-MAD calculator with the torch based implementation of\nthe D3 dispersion correction of `pfnet-research` - `torch-dftd`:\n\nWithin the PET-MAD environment you can install `torch-dftd` via:\n\n```bash\npip install torch-dftd\n```\n\nThen you can use the `D3Calculator` class to combine the two calculators:\n\n```python\nfrom torch_dftd.torch_dftd3_calculator import TorchDFTD3Calculator\nfrom pet_mad.calculator import PETMADCalculator\nfrom  ase.calculators.mixing import SumCalculator\n\ndevice = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n\ncalc_MAD = PETMADCalculator(version=\"latest\", device=device)\ndft_d3 = TorchDFTD3Calculator(device=device, xc=\"pbesol\", damping=\"bj\")\n\ncombined_calc = SumCalculator([calc_MAD, dft_d3])\n\n# assign the calculator to the atoms object\natoms.calc = combined_calc\n\n```\n\n## Dataset visualization with the PET-MAD featurizer\n \nYou can use PET-MAD last-layer features together with a pre-trained \nsketch-map dimensionality reduction to obtain 2D and 3D representations\nof a dataset, e.g. to identify structural or chemical motifs.\nThis can be used as a stand-alone feature builder, or combined with\nthe [chemiscope viewer](https://chemiscope.org) to generate an \ninteractive visualization. \n\n```python\nimport ase.io\nimport chemiscope\nfrom pet_mad.explore import PETMADFeaturizer\n\nfeaturizer = PETMADFeaturizer(version=\"latest\")\n\n# Load structures\nframes = ase.io.read(\"dataset.xyz\", \":\")\n\n# You can just compute features\nfeatures = featurizer(frames, None)\n\n# Or create an interactive visualization in a Jupyter notebook\nchemiscope.explore(\n    frames,\n    featurize=featurizer\n)\n```\n\n## Examples\n\nMore examples for **ASE, i-PI, and LAMMPS** are available in the [Atomistic\nCookbook](https://atomistic-cookbook.org/examples/pet-mad/pet-mad.html).\n\n## Fine-tuning\n\nPET-MAD can be fine-tuned using the\n[Metatrain](https://metatensor.github.io/metatrain/latest/advanced-concepts/fine-tuning.html)\nlibrary.\n\n## Documentation\n\nAdditional documentation can be found in the\n[metatensor](https://docs.metatensor.org),\n[metatomic](https://docs.metatensor.org/metatomic) and\n[metatrain](https://metatensor.github.io/metatrain/) repositories.\n\n- [Training a model](https://metatensor.github.io/metatrain/latest/getting-started/usage.html#training)\n- [Fine-tuning](https://metatensor.github.io/metatrain/latest/advanced-concepts/fine-tuning.html)\n- [LAMMPS interface](https://docs.metatensor.org/metatomic/latest/engines/lammps.html)\n- [i-PI interface](https://docs.metatensor.org/metatomic/latest/engines/ipi.html)\n\n## Citing PET-MAD\n\nIf you use PET-MAD in your research, please cite:\n\n```bibtex\n@misc{PET-MAD-2025,\n      title={PET-MAD, a universal interatomic potential for advanced materials modeling},\n      author={Arslan Mazitov and Filippo Bigi and Matthias Kellner and Paolo Pegolo and Davide Tisi and Guillaume Fraux and Sergey Pozdnyakov and Philip Loche and Michele Ceriotti},\n      year={2025},\n      eprint={2503.14118},\n      archivePrefix={arXiv},\n      primaryClass={cond-mat.mtrl-sci},\n      url={https://arxiv.org/abs/2503.14118}\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flab-cosmo%2Fpet-mad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flab-cosmo%2Fpet-mad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flab-cosmo%2Fpet-mad/lists"}