diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 02f531a..35035e1 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,3 +1,21 @@ +# This file is part of tad-multicharge. +# +# SPDX-Identifier: LGPL-3.0 +# Copyright (C) 2023 Marvin Friede +# +# tad-multicharge is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# tad-multicharge is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with tad-multicharge. If not, see . + # .readthedocs.yaml # Read the Docs configuration file # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details @@ -9,7 +27,7 @@ version: 2 build: os: ubuntu-22.04 tools: - python: "3.8" + python: "3.10" # Build documentation in the docs/ directory with Sphinx sphinx: diff --git a/.vscode/settings.json b/.vscode/settings.json index 22782e4..92158e0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,11 +7,10 @@ "editor.insertSpaces": true, "editor.tabSize": 4 }, - "pylint.args": ["--indent-string=' '"], "python.analysis.diagnosticSeverityOverrides": { "reportPrivateImportUsage": "information" }, - "python.defaultInterpreterPath": "${env:CONDA_PREFIX}/envs/dxtb/bin/python", + "python.defaultInterpreterPath": "${env:CONDA_PREFIX}/envs/torch/bin/python", "python.testing.pytestArgs": [], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true diff --git a/README.rst b/README.rst index 9763534..a2f610e 100644 --- a/README.rst +++ b/README.rst @@ -5,8 +5,8 @@ Torch Autodiff Multicharge :target: https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11-blue.svg :alt: Python Versions -.. image:: https://img.shields.io/github/v/release/tad-mctc/tad-mctc - :target: https://github.com/tad-mctc/tad-mctc/releases/latest +.. image:: https://img.shields.io/github/v/release/tad-mctc/tad-multicharge + :target: https://github.com/tad-mctc/tad-multicharge/releases/latest :alt: Release .. image:: https://img.shields.io/pypi/v/tad-mctc @@ -17,20 +17,20 @@ Torch Autodiff Multicharge :target: https://www.gnu.org/licenses/lgpl-3.0 :alt: LGPL-3.0 -.. image:: https://github.com/tad-mctc/tad-mctc/actions/workflows/python.yaml/badge.svg - :target: https://github.com/tad-mctc/tad-mctc/actions/workflows/python.yaml +.. image:: https://github.com/tad-mctc/tad-multicharge/actions/workflows/python.yaml/badge.svg + :target: https://github.com/tad-mctc/tad-multicharge/actions/workflows/python.yaml :alt: CI .. image:: https://readthedocs.org/projects/tad-mctc/badge/?version=latest :target: https://tad-mctc.readthedocs.io :alt: Documentation Status -.. image:: https://codecov.io/gh/tad-mctc/tad-mctc/branch/main/graph/badge.svg?token=OGJJnZ6t4G - :target: https://codecov.io/gh/tad-mctc/tad-mctc +.. image:: https://codecov.io/gh/tad-mctc/tad-multicharge/branch/main/graph/badge.svg?token=OGJJnZ6t4G + :target: https://codecov.io/gh/tad-mctc/tad-multicharge :alt: Coverage -.. image:: https://results.pre-commit.ci/badge/github/tad-mctc/tad-mctc/main.svg - :target: https://results.pre-commit.ci/latest/github/tad-mctc/tad-mctc/main +.. image:: https://results.pre-commit.ci/badge/github/tad-mctc/tad-multicharge/main.svg + :target: https://results.pre-commit.ci/latest/github/tad-mctc/tad-multicharge/main :alt: pre-commit.ci status PyTorch implementation of the electronegativity equilibration (EEQ) model for atomic partial charges. diff --git a/docs/index.rst b/docs/index.rst index 7d138cb..6a37867 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,8 +5,8 @@ Torch Autodiff Multicharge :target: https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11-blue.svg :alt: Python Versions -.. image:: https://img.shields.io/github/v/release/tad-mctc/tad-mctc - :target: https://github.com/tad-mctc/tad-mctc/releases/latest +.. image:: https://img.shields.io/github/v/release/tad-mctc/tad-multicharge + :target: https://github.com/tad-mctc/tad-multicharge/releases/latest :alt: Release .. image:: https://img.shields.io/pypi/v/tad-mctc @@ -17,22 +17,23 @@ Torch Autodiff Multicharge :target: https://www.gnu.org/licenses/lgpl-3.0 :alt: LGPL-3.0 -.. image:: https://github.com/tad-mctc/tad-mctc/actions/workflows/python.yaml/badge.svg - :target: https://github.com/tad-mctc/tad-mctc/actions/workflows/python.yaml +.. image:: https://github.com/tad-mctc/tad-multicharge/actions/workflows/python.yaml/badge.svg + :target: https://github.com/tad-mctc/tad-multicharge/actions/workflows/python.yaml :alt: CI .. image:: https://readthedocs.org/projects/tad-mctc/badge/?version=latest :target: https://tad-mctc.readthedocs.io :alt: Documentation Status -.. image:: https://codecov.io/gh/tad-mctc/tad-mctc/branch/main/graph/badge.svg?token=OGJJnZ6t4G - :target: https://codecov.io/gh/tad-mctc/tad-mctc +.. image:: https://codecov.io/gh/tad-mctc/tad-multicharge/branch/main/graph/badge.svg?token=OGJJnZ6t4G + :target: https://codecov.io/gh/tad-mctc/tad-multicharge :alt: Coverage -.. image:: https://results.pre-commit.ci/badge/github/tad-mctc/tad-mctc/main.svg - :target: https://results.pre-commit.ci/latest/github/tad-mctc/tad-mctc/main +.. image:: https://results.pre-commit.ci/badge/github/tad-mctc/tad-multicharge/main.svg + :target: https://results.pre-commit.ci/latest/github/tad-mctc/tad-multicharge/main :alt: pre-commit.ci status + PyTorch implementation of the electronegativity equilibration (EEQ) model for atomic partial charges. This module allows to process a single structure or a batch of structures for the calculation of atom-resolved dispersion energies. diff --git a/environment.yaml b/environment.yaml index 7c9e9b3..d742e5b 100644 --- a/environment.yaml +++ b/environment.yaml @@ -21,7 +21,7 @@ channels: - conda-forge - pytorch dependencies: - - numpy - - pytorch + - python>=3.8 + - pytorch>=1.11.0 - pip: - - tad-mctc + - tad-mctc>=0.0.2 diff --git a/src/tad_multicharge/__init__.py b/src/tad_multicharge/__init__.py index 6050c84..8e5a8dc 100644 --- a/src/tad_multicharge/__init__.py +++ b/src/tad_multicharge/__init__.py @@ -72,6 +72,7 @@ >>> >>> # calculate dispersion energy in Hartree >>> energy = torch.sum(d4.dftd4(numbers, positions, charge, param), -1) +>>> >>> torch.set_printoptions(precision=10) >>> print(energy) tensor([-0.0088341432, -0.0027013607]) @@ -83,3 +84,4 @@ from . import eeq, model from .__version__ import __version__ from .eeq import get_charges as get_eeq_charges +from .eeq import get_eeq diff --git a/test/test_grad/test_dedr.py b/test/test_grad/test_dedr.py index 6ce96d6..01d0ba1 100644 --- a/test/test_grad/test_dedr.py +++ b/test/test_grad/test_dedr.py @@ -24,6 +24,7 @@ import torch from tad_mctc.autograd import dgradcheck, dgradgradcheck, jac from tad_mctc.batch import pack +from tad_mctc.convert import tensor_to_numpy from tad_mctc.typing import DD, Callable, Tensor from tad_multicharge import eeq @@ -174,6 +175,7 @@ def run_autograd(dtype: torch.dtype, name: str) -> None: (grad,) = torch.autograd.grad(energy.sum(), positions) positions.detach_() + grad.detach_() assert pytest.approx(numgrad.cpu(), abs=tol * 10) == grad.cpu() @@ -271,8 +273,9 @@ def run_jacobian(dtype: torch.dtype, name: str, atol: float) -> None: jacobian: Tensor = fjac(numbers, positions, charge) # type: ignore positions.detach_() + jac_np = tensor_to_numpy(jacobian) - assert pytest.approx(numgrad.cpu(), abs=atol) == jacobian.cpu() + assert pytest.approx(numgrad.cpu(), abs=atol) == jac_np @pytest.mark.grad diff --git a/test/test_grad/test_dqdr.py b/test/test_grad/test_dqdr.py index c50f1da..9abf527 100644 --- a/test/test_grad/test_dqdr.py +++ b/test/test_grad/test_dqdr.py @@ -24,7 +24,7 @@ import torch from tad_mctc.autograd import dgradcheck, dgradgradcheck, jac from tad_mctc.batch import pack -from tad_mctc.convert import reshape_fortran +from tad_mctc.convert import reshape_fortran, tensor_to_numpy from tad_mctc.typing import DD, Callable, Tensor from tad_multicharge import eeq @@ -150,12 +150,9 @@ def test_gradgradcheck_batch(dtype: torch.dtype, name1: str, name2: str) -> None assert dgradgradcheck(func, diffvars, atol=tol, fast_mode=FAST_MODE) -sample_list = sample_list[:-1] - - @pytest.mark.grad @pytest.mark.parametrize("dtype", [torch.double]) -@pytest.mark.parametrize("name", sample_list) +@pytest.mark.parametrize("name", sample_list[:-1]) def test_jacobian(dtype: torch.dtype, name: str) -> None: """Compare with reference values from tblite.""" dd: DD = {"device": DEVICE, "dtype": dtype} @@ -185,12 +182,13 @@ def test_jacobian(dtype: torch.dtype, name: str) -> None: jacobian: Tensor = fjac(numbers, positions, charge) # type: ignore positions.detach_() + jac_np = tensor_to_numpy(jacobian) # 1 / 768 element in MB16_43_01 is slightly off - assert pytest.approx(ref.cpu(), abs=tol * 10.5) == jacobian.cpu() + assert pytest.approx(ref.cpu(), abs=tol * 10.5) == jac_np assert pytest.approx(ref.cpu(), abs=tol * 10) == numgrad.cpu() - assert pytest.approx(numgrad.cpu(), abs=tol) == jacobian.cpu() + assert pytest.approx(numgrad.cpu(), abs=tol) == jac_np def calc_numgrad(numbers: Tensor, positions: Tensor, charge: Tensor) -> Tensor: