Skip to main content

Torch Autodiff Utility

Compatibility: Python Versions PyTorch Versions
Availability: Release PyPI Conda Version Apache-2.0
Status: Test Status Ubuntu Test Status macOS (ARM) Test Status Windows Build Status Documentation Status pre-commit.ci Status Coverage

This library is a collection of utility functions that are used in PyTorch (re-)implementations of projects from the Grimme group. In particular, the tad-mctc library provides:

  • autograd utilities (gradient checks, row-by-row Jacobians, checks for torch.func-transformed tensors)

  • atomic data (radii, EN, example molecules, ...)

  • batch utility (packing, masks, ...)

  • conversion functions (numpy, atomic symbols/numbers, ...)

  • coordination numbers (DFT-D3, DFT-D4, EEQ)

  • io (reading/writing coordinate files)

  • molecular properties (bond lengths/orders/angles, moment of inertia, ...)

  • safeops (autograd-safe implementations of common functions)

  • typing (base class for tensor-like behavior of arbitrary classes)

  • units

The name is inspired by the Fortran pendant "modular computation tool chain library" (mctc-lib).

Citation

If you use this software, please cite the following publication

  • M. Friede, C. Hölzer, S. Ehlert, S. Grimme, J. Chem. Phys., 2024, 161, 062501. DOI: 10.1063/5.0216715

Installation

pip PyPI Version PyPI Downloads

tad-mctc can easily be installed with pip.

pip install tad-mctc

conda Conda Version Conda Downloads

tad-mctc is also available from conda.

conda install tad-mctc

From source

This project is hosted on GitHub at tad-mctc/tad-mctc. Obtain the source by cloning the repository with

git clone https://github.com/tad-mctc/tad-mctc
cd tad-mctc

We recommend using a conda environment to install the package. You can setup the environment manager using a mambaforge installer. Install the required dependencies from the conda-forge channel.

mamba env create -n torch -f environment.yaml
mamba activate torch

Install this project with pip in the environment

pip install .

An optional, OpenMP-parallel C++ extension accelerates the CPU neighbour list for very large systems. By default it compiles lazily, on first use (no compiler needed just to install); set TAD_MCTC_BUILD_NATIVE=1 before pip install . to build it ahead of time instead, so the first real run never pays that one-off compile cost. The extension is built against the installed torch, so turn off pip's isolated build environment:

TAD_MCTC_BUILD_NATIVE=1 pip install --no-build-isolation .

The following dependencies are required

Compatibility

PyTorch \ Python 3.10 3.11 3.12 3.13 3.14
2.4.1 ✔️ ✔️ ✅ ❌ ❌
2.5.1 ✔️ ✔️ ✅ ❌ ❌
2.6.0 ✔️ ✔️ ✔️ ✅ ❌
2.7.1 ✔️ ✔️ ✔️ ✅ ❌
2.8.0 ✔️ ✔️ ✔️ ✅ ❌
2.9.1 ✔️ ✔️ ✔️ ✔️ ✅
2.10.0 ✔️ ✔️ ✔️ ✔️ ✅
2.11.0 ✔️ ✔️ ✔️ ✔️ ✅
2.12.1 ✔️ ✔️ ✔️ ✔️ ✅
2.13.0 ✔️ ✔️ ✔️ ✔️ ✅
2.14.0 ✅ ✅ ✅ ✅ ✅

✅ tested in CI    ✔️ supported, but not tested in CI (should still work)    ❌ not supported

Note that only the latest bug fix version is listed, but all preceding bug fix minor versions are supported. For example, although only version 2.4.1 is listed, version 2.4.0 is also supported.

Development

For development, additionally install the following tools in your environment.

mamba install black covdefaults mypy pre-commit pylint pytest pytest-cov pytest-xdist tox
pip install pytest-random-order

With pip, add the option -e for installing in development mode, and add [dev] for the development dependencies

pip install -e .[dev]

The pre-commit hooks are initialized by running the following command in the root of the repository.

pre-commit install

For testing all Python environments, simply run tox.

tox

Note that this randomizes the order of tests but skips "large" tests. To modify this behavior, tox has to skip the optional posargs.

tox -- test

Examples

The following example shows how to calculate the coordination number used in the EEQ model for a single structure.

import torch
import tad_mctc as mctc

numbers = mctc.convert.symbol_to_number(symbols="C C C C N C S H H H H H".split())

# coordinates in Bohr
positions = torch.tensor(
    [
        [-2.56745685564671, -0.02509985979910, 0.00000000000000],
        [-1.39177582455797, +2.27696188880014, 0.00000000000000],
        [+1.27784995624894, +2.45107479759386, 0.00000000000000],
        [+2.62801937615793, +0.25927727028120, 0.00000000000000],
        [+1.41097033661123, -1.99890996077412, 0.00000000000000],
        [-1.17186102298849, -2.34220576284180, 0.00000000000000],
        [-2.39505990368378, -5.22635838332362, 0.00000000000000],
        [+2.41961980455457, -3.62158019253045, 0.00000000000000],
        [-2.51744374846065, +3.98181713686746, 0.00000000000000],
        [+2.24269048384775, +4.24389473203647, 0.00000000000000],
        [+4.66488984573956, +0.17907568006409, 0.00000000000000],
        [-4.60044244782237, -0.17794734637413, 0.00000000000000],
    ]
)

# calculate EEQ coordination number
cn = mctc.ncoord.cn_eeq(numbers, positions)
torch.set_printoptions(precision=10)
print(cn)
# tensor([3.0519218445, 3.0177774429, 3.0132560730, 3.0197706223,
#         3.0779352188, 3.0095663071, 1.0991339684, 0.9968624115,
#         0.9943327904, 0.9947233200, 0.9945874214, 0.9945726395])

The next example shows the calculation of the coordination number used in DFT-D4 for a batch of structures.

import torch
import tad_mctc as mctc

# S22 system 4: formamide dimer
numbers = mctc.batch.pack((
    mctc.convert.symbol_to_number("C C N N H H H H H H O O".split()),
    mctc.convert.symbol_to_number("C O N H H H".split()),
))

# coordinates in Bohr
positions = mctc.batch.pack((
    torch.tensor([
        [-3.81469488143921, +0.09993441402912, 0.00000000000000],
        [+3.81469488143921, -0.09993441402912, 0.00000000000000],
        [-2.66030049324036, -2.15898251533508, 0.00000000000000],
        [+2.66030049324036, +2.15898251533508, 0.00000000000000],
        [-0.73178529739380, -2.28237795829773, 0.00000000000000],
        [-5.89039325714111, -0.02589114569128, 0.00000000000000],
        [-3.71254944801331, -3.73605775833130, 0.00000000000000],
        [+3.71254944801331, +3.73605775833130, 0.00000000000000],
        [+0.73178529739380, +2.28237795829773, 0.00000000000000],
        [+5.89039325714111, +0.02589114569128, 0.00000000000000],
        [-2.74426102638245, +2.16115570068359, 0.00000000000000],
        [+2.74426102638245, -2.16115570068359, 0.00000000000000],
    ]),
    torch.tensor([
        [-0.55569743203406, +1.09030425468557, 0.00000000000000],
        [+0.51473634678469, +3.15152550263611, 0.00000000000000],
        [+0.59869690244446, -1.16861263789477, 0.00000000000000],
        [-0.45355203669134, -2.74568780438064, 0.00000000000000],
        [+2.52721209544999, -1.29200800956867, 0.00000000000000],
        [-2.63139587595376, +0.96447869452240, 0.00000000000000],
    ]),
))

# calculate coordination number
cn = mctc.ncoord.cn_d4(numbers, positions)
torch.set_printoptions(precision=10)
print(cn)
# tensor([[2.6886456013, 2.6886456013, 2.6314170361, 2.6314167976,
#          0.8594539165, 0.9231414795, 0.8605306745, 0.8605306745,
#          0.8594539165, 0.9231414795, 0.8568341732, 0.8568341732],
#         [2.6886456013, 0.8568335176, 2.6314167976, 0.8605306745,
#          0.8594532013, 0.9231414795, 0.0000000000, 0.0000000000,
#          0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000]])

Contributing

This is a volunteer open source projects and contributions are always welcome. Please, take a moment to read the contributing guidelines.

License

This project is licensed under the Apache License, Version 2.0 (the "License"); you may not use this project's files except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Metadata

Release files for tad-mctc 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tad-mctc 0.9.0
File Size Uploaded
tad_mctc-0.9.0.tar.gz 8.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for tad-mctc 0.9.0
File Interpreter ABI Platform
tad_mctc-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 MB

Release files / tad_mctc-0.9.0.tar.gz

Download URL tad_mctc-0.9.0.tar.gz
Size 8.3 MB
Tags Source
SHA-256 checksum
How to use checksums
b881ad52be8fefad324d3ab8cebaefae5f39c5e03416cbd0b2486bf9dee100b7
BLAKE2b-256 checksum
How to use checksums
a85d1b175ead561b55e53b49116549c6db50c0e60044fd906c439dd9bb563c8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / tad_mctc-0.9.0-py3-none-any.whl

Download URL tad_mctc-0.9.0-py3-none-any.whl
Size 8.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c9530f7bfc9a720d6c19776038490131c34137e3dfe0bda992758eb46167f28e
BLAKE2b-256 checksum
How to use checksums
229ae973dac946e340a23b2fa8a501cece642ac1cb816c6852b3f8ffa94508ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page