- Combining semi-empirical quantum chemistry with machine learning in PyTorch -
The xTB methods (GFNn-xTB) are a series of semi-empirical quantum chemical methods that provide a good balance between accuracy and computational cost.
With dxtb, we provide a re-implementation of the xTB methods in PyTorch, which allows for automatic differentiation and seamless integration into machine learning frameworks.
NOTE: If you encounter any bugs or have questions on how to use dxtb, feel free to open an issue.
dxtb can easily be installed with pip.
pip install dxtb[libcint]Installing the libcint interface is recommended, as it is faster than the pure PyTorch implementation on the CPU. The pure PyTorch integral driver provides the overlap, dipole and quadrupole integrals (and thereby GFN2-xTB) with derivatives of any order, on CPU and CUDA. However, the interface is currently only available on Linux.
dxtb is also available on conda from the conda-forge channel.
mamba install dxtbThe optional libcint interface (not on conda) can be installed via pip install tad-libcint.
For Windows, dxtb is not available via conda, because PyTorch itself is not registered in the conda-forge channel.
For more options, see the installation guide in the documentation.
The following example demonstrates how to compute the energy and forces using GFN1-xTB.
import torch
import dxtb
dd = {"dtype": torch.double, "device": torch.device("cpu")}
# LiH
numbers = torch.tensor([3, 1], device=dd["device"])
positions = torch.tensor([[0.0, 0.0, 0.0], [0.0, 0.0, 1.5]], **dd)
# instantiate a calculator
calc = dxtb.calculators.GFN1Calculator(numbers, **dd)
# compute the energy
pos = positions.clone().requires_grad_(True)
energy = calc.get_energy(pos)
# obtain gradient (dE/dR) via autograd
(g,) = torch.autograd.grad(energy, pos)
# Alternatively, forces can directly be requested from the calculator.
# (Don't forget to manually reset the calculator when the inputs are identical.)
calc.reset()
pos = positions.clone().requires_grad_(True)
forces = calc.get_forces(pos)
assert torch.equal(forces, -g)All quantities are in atomic units.
For more examples and details, check out the documentation.
| PyTorch \ Python | 3.10 | 3.11 | 3.12 | 3.13 | 3.14 |
|---|---|---|---|---|---|
| 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.1 | ✅ | ✅ | ✅ | ✅ | ✅ |
✅ 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.5.1 is listed, version 2.5.0 is also supported.
The libcint interface is not available for macOS and Windows. Correspondingly, the pure PyTorch integral driver is used there, which is slower than libcint on the CPU for large systems (see the documentation for the available integral algorithms). While macOS support may be considered in the future, native Windows support is not possible, because the underlying libcint library does not work under Windows.
If you use dxtb in your research, please cite the following paper:
- M. Friede, C. Hölzer, S. Ehlert, S. Grimme, dxtb -- An Efficient and Fully Differentiable Framework for Extended Tight-Binding, J. Chem. Phys., 2024, 161, 062501. (DOI)
The Supporting Information can be found here.
For details on the xTB methods, see
- C. Bannwarth, E. Caldeweyher, S. Ehlert, A. Hansen, P. Pracht, J. Seibert, S. Spicher, S. Grimme, WIREs Comput. Mol. Sci., 2020, 11, e01493. (DOI)
- C. Bannwarth, S. Ehlert, S. Grimme, J. Chem. Theory Comput., 2019, 15, 1652-1671. (DOI)
- S. Grimme, C. Bannwarth, P. Shushkov, J. Chem. Theory Comput., 2017, 13, 1989-2009. (DOI)
This is a volunteer open source projects and contributions are always welcome. Please, take a moment to read the contributing guidelines.
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.
