Skip to content

Commit

Permalink
Merge pull request #1 from tad-mctc/fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
marvinfriede authored Dec 20, 2023
2 parents e2412a3 + 2037be9 commit cdf7495
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 30 deletions.
20 changes: 19 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
17 changes: 9 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/tad_multicharge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
5 changes: 4 additions & 1 deletion test/test_grad/test_dedr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions test/test_grad/test_dqdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit cdf7495

Please sign in to comment.