{"id":8720,"library":"torch-dftd","title":"Torch-DFTD","description":"torch-dftd is a Python library providing a PyTorch implementation of the DFT-D2 and DFT-D3 dispersion correction models for quantum chemistry calculations. It leverages PyTorch's automatic differentiation capabilities to efficiently compute energies, forces, and virials. The library is currently at version 0.5.3, released on March 11, 2026. While it has seen recent updates, its GitHub repository indicates that it is \"not actively maintained\".","status":"maintenance","version":"0.5.3","language":"en","source_language":"en","source_url":"https://github.com/pfnet-research/torch-dftd","tags":["pytorch","dftd","quantum chemistry","dispersion correction","ase","computational chemistry","autodiff"],"install":[{"cmd":"pip install torch-dftd","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core deep learning framework for tensor operations and autodifferentiation.","package":"torch","optional":false},{"reason":"Atomic Simulation Environment, used for creating and manipulating atomic structures (e.g., `ase.build.molecule`, `ase.Atoms`). Required for common use cases.","package":"ase","optional":false},{"reason":"Required for accelerating 3-body terms on specific CUDA versions for GPU computation. Only needed if using 3-body terms and a compatible CUDA setup.","package":"cupy-cuda12x","optional":true}],"imports":[{"symbol":"TorchDFTD3Calculator","correct":"from torch_dftd.torch_dftd3_calculator import TorchDFTD3Calculator"},{"note":"For DFT-D2 calculations, use TorchDFTD2Calculator instead of TorchDFTD3Calculator.","symbol":"TorchDFTD2Calculator","correct":"from torch_dftd.torch_dftd2_calculator import TorchDFTD2Calculator"}],"quickstart":{"code":"import torch\nimport ase.build\nfrom torch_dftd.torch_dftd3_calculator import TorchDFTD3Calculator\n\n# Create an ASE Atoms object for methanol\natoms = ase.build.molecule(\"CH3OH\")\n\n# Determine device for computation\ndevice = \"cuda:0\" if torch.cuda.is_available() else \"cpu\"\nprint(f\"Using device: {device}\")\n\n# Initialize the DFTD3 calculator with the atoms object and device\n# Common damping functions are 'zero', 'bj', 's6'\ncalc = TorchDFTD3Calculator(atoms=atoms, device=device, damping=\"bj\")\n\n# Attach the calculator to the atoms object\natoms.set_calculator(calc)\n\n# Get potential energy and forces\nenergy = atoms.get_potential_energy()\nforces = atoms.get_forces()\n\nprint(f\"Total DFT-D3 energy: {energy:.4f} eV\")\nprint(f\"Forces (first atom):\n{forces[0]}\")","lang":"python","description":"This quickstart demonstrates how to set up a DFT-D3 calculation for a methanol molecule using `torch-dftd` with `ase`. It initializes an `ase.Atoms` object, creates a `TorchDFTD3Calculator`, attaches it to the atoms, and then computes the potential energy and atomic forces. It dynamically selects between CUDA (GPU) and CPU for computation."},"warnings":[{"fix":"Be aware that long-term support may be minimal. Consider forking the repository if deep customization or active maintenance is critical for your project.","message":"The official GitHub repository for torch-dftd explicitly states that the project is 'not actively maintained'. While releases might still occur, active development, bug fixes for new issues, or compatibility updates for future PyTorch/Python versions may be limited.","severity":"maintenance","affected_versions":"All versions"},{"fix":"Refer to the project's `README.md` or `pyproject.toml` for the exact tested environment. It's recommended to use a Python version compatible with PyTorch < 3.11 for older PyTorch versions on macOS/Windows.","message":"The library is tested against specific Python (3.10) and CUDA (12.2) versions, and specific torch (2.0.1) and ase (3.22.1) versions. Using significantly different versions may lead to unexpected behavior or incompatibilities.","severity":"gotcha","affected_versions":"<=0.5.3"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install ASE via pip: `pip install ase`","cause":"The Atomic Simulation Environment (ASE) library, a core dependency for creating and manipulating atomic structures used by torch-dftd's examples and common workflows, is not installed.","error":"ModuleNotFoundError: No module named 'ase'"},{"fix":"Ensure all relevant tensors (e.g., atomic positions if handled manually) and the `TorchDFTD3Calculator` instance are explicitly moved to the same device (e.g., `device='cuda:0'` for the calculator and `tensor.to(device)` for tensors). The quickstart handles this for the calculator.","cause":"This is a common PyTorch error indicating that tensors involved in a computation are on different devices (e.g., one on CPU, another on GPU). The `TorchDFTD3Calculator` can be initialized with a device, but input data or other tensors might not be moved accordingly.","error":"RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0!"},{"fix":"Ensure `atoms.set_calculator(calc)` is called after initializing `TorchDFTD3Calculator` and before attempting to retrieve energies or forces from the `atoms` object.","cause":"The `get_potential_energy()` or `get_forces()` methods are called on an `ase.Atoms` object before a calculator (like `TorchDFTD3Calculator`) has been attached to it using `atoms.set_calculator(calc)`.","error":"AttributeError: 'Atoms' object has no attribute 'get_potential_energy'"}]}