Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from dftd4:main #106

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/fortran-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
compiler: gnu
version: 8

- os: macos-latest
- os: macos-13
build: cmake
build-type: debug
compiler: gnu
Expand All @@ -36,7 +36,7 @@ jobs:
compiler: gnu
version: 9

- os: macos-latest
- os: macos-13
build: meson
build-type: debug
compiler: gnu
Expand Down Expand Up @@ -267,6 +267,11 @@ jobs:
create-args: >-
python=${{ matrix.python_v }}

- name: Install ase<3.23 for Python 3.7
if: matrix.python_v == '3.7'
run: |
micromamba install -y -c conda-forge "ase<3.23"

- name: Install GCC (OSX)
if: ${{ contains(matrix.os, 'macos') }}
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: wheel

on: [push, workflow_dispatch]

env:
# https://github.com/actions/checkout/issues/1809
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:
sdist:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -69,7 +73,7 @@ jobs:
auditwheel show dftd4-*/dist/*.whl
auditwheel repair -w . dftd4-*/dist/*.whl --plat ${{ env.plat }}
env:
plat: manylinux${{ matrix.python == '3.6' && '2010' || '_2_12' }}_x86_64
plat: manylinux2014_x86_64
- uses: actions/upload-artifact@v3
with:
name: dftd4-python-${{ matrix.python }}
Expand Down
9 changes: 5 additions & 4 deletions python/dftd4/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@

from typing import List, Optional

from .interface import DispersionModel, DampingParam
from ase.atoms import Atoms
from ase.calculators.calculator import (
CalculationFailed,
Calculator,
InputError,
CalculationFailed,
all_changes,
)
from ase.calculators.mixing import SumCalculator
from ase.atoms import Atoms
from ase.units import Hartree, Bohr
from ase.units import Bohr, Hartree

from .interface import DampingParam, DispersionModel


class DFTD4(Calculator):
Expand Down
4 changes: 3 additions & 1 deletion python/dftd4/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# along with dftd4. If not, see <https://www.gnu.org/licenses/>.

from math import sqrt

import numpy as np

try:
from os.path import join, dirname
from os.path import dirname, join

from ase.collections import Collection

# using a collection will remove the data, but we get at least the structures
Expand Down
2 changes: 1 addition & 1 deletion python/dftd4/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"""

from typing import Optional
import numpy as np

import numpy as np

from . import library

Expand Down
2 changes: 1 addition & 1 deletion python/dftd4/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the Lesser GNU General Public License
# along with dftd4. If not, see <https://www.gnu.org/licenses/>.

from os.path import join, dirname, exists
from os.path import dirname, exists, join
from typing import Optional

# We prefer tomli and tomlkit here, because they are 1.0.0 compliant, while toml is not yet
Expand Down
8 changes: 4 additions & 4 deletions python/dftd4/pyscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
except ModuleNotFoundError:
raise ModuleNotFoundError("This submodule requires pyscf installed")

import numpy as np
from typing import Tuple

from .interface import DispersionModel, DampingParam
import numpy as np

from .interface import DampingParam, DispersionModel

GradientsBase = getattr(rhf_grad, "GradientsBase", rhf_grad.Gradients)

Expand Down Expand Up @@ -101,7 +101,7 @@ def kernel(self) -> Tuple[float, np.ndarray]:
mol = self.mol

disp = DispersionModel(
mol.atom_charges(),
np.asarray([gto.charge(sym) for sym in mol.elements]),
mol.atom_coords(),
mol.charge,
)
Expand Down Expand Up @@ -177,8 +177,8 @@ def energy(mf):
-110.917424528592
"""

from pyscf.scf import hf
from pyscf.mcscf import casci
from pyscf.scf import hf

if not isinstance(mf, (hf.SCF, casci.CASCI)):
raise TypeError("mf must be an instance of SCF or CASCI")
Expand Down
5 changes: 3 additions & 2 deletions python/dftd4/qcschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@
"""

from typing import Union
from .interface import DispersionModel, DampingParam
from .library import get_api_version

import numpy as np
import qcelemental as qcel

from .interface import DampingParam, DispersionModel
from .library import get_api_version

_supported_drivers = [
"energy",
Expand Down
24 changes: 18 additions & 6 deletions python/dftd4/test_ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# You should have received a copy of the Lesser GNU General Public License
# along with dftd4. If not, see <https://www.gnu.org/licenses/>.

from dftd4.ase import DFTD4
import numpy as np
from ase.build import molecule
from ase.calculators.emt import EMT
from dftd4.ase import DFTD4
from pytest import approx
import numpy as np


def test_ase_scand4():
def test_ase_scand4() -> None:
thr = 1.0e-6

forces = np.array(
Expand All @@ -47,11 +47,17 @@ def test_ase_scand4():

atoms.calc = DFTD4(method="SCAN").add_calculator(EMT())
assert approx(atoms.get_potential_energy(), abs=thr) == 3.6624398683434225
energies = [calc.get_potential_energy() for calc in atoms.calc.calcs]

if hasattr(atoms.calc, "calcs"):
calcs = atoms.calc.calcs
else:
calcs = atoms.calc.mixer.calcs

energies = [calc.get_potential_energy() for calc in calcs]
assert approx(energies, abs=thr) == [-0.021665446836610563, 3.684105315180033]


def test_ase_tpssd4():
def test_ase_tpssd4() -> None:
thr = 1.0e-6

forces = np.array(
Expand Down Expand Up @@ -79,5 +85,11 @@ def test_ase_tpssd4():

atoms.calc = DFTD4(method="TPSS").add_calculator(EMT())
assert approx(atoms.get_potential_energy(), abs=thr) == 4.864016486351274
energies = [calc.get_potential_energy() for calc in atoms.calc.calcs]

if hasattr(atoms.calc, 'calcs'):
calcs = atoms.calc.calcs
else:
calcs = atoms.calc.mixer.calcs

energies = [calc.get_potential_energy() for calc in calcs]
assert approx(energies, abs=thr) == [-0.24206732765720396, 5.106083814008478]
18 changes: 9 additions & 9 deletions python/dftd4/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
# You should have received a copy of the Lesser GNU General Public License
# along with dftd4. If not, see <https://www.gnu.org/licenses/>.

from dftd4.interface import Structure, DampingParam, DispersionModel
from pytest import approx, raises
import numpy as np
from dftd4.interface import DampingParam, DispersionModel, Structure
from pytest import approx, raises


def test_rational_damping_noargs():
def test_rational_damping_noargs() -> None:
"""Check constructor of damping parameters for insufficient arguments"""

with raises(TypeError):
Expand All @@ -38,7 +38,7 @@ def test_rational_damping_noargs():
DampingParam(s8=1.0, a1=0.4, a2=5.0, method="abc")


def test_structure():
def test_structure() -> None:
"""check if the molecular structure data is working as expected."""

numbers = np.array(
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_structure():
mol.update(np.zeros((24, 3)))


def test_blypd4():
def test_blypd4() -> None:
"""Use BLYP-D4 for a mindless molecule"""
thr = 1.0e-7

Expand Down Expand Up @@ -157,7 +157,7 @@ def test_blypd4():
assert approx(res.get("energy"), abs=thr) == -0.06991716314879085


def test_pbed4():
def test_pbed4() -> None:
"""Use PBE-D4 for a mindless molecule"""
thr = 1.0e-7

Expand Down Expand Up @@ -213,7 +213,7 @@ def test_pbed4():
assert approx(res.get("energy"), abs=thr) == -0.028415184156428127


def test_r2scan3c():
def test_r2scan3c() -> None:
"""Use r2SCAN-3c for a mindless molecule"""
thr = 1.0e-8

Expand Down Expand Up @@ -273,7 +273,7 @@ def test_r2scan3c():
assert approx(res.get("energy"), abs=thr) == -0.008016697276824889


def test_pair_resolved():
def test_pair_resolved() -> None:
"""Calculate pairwise resolved dispersion energy for a molecule"""
thr = 1.0e-8

Expand Down Expand Up @@ -469,7 +469,7 @@ def test_pair_resolved():
assert approx(res.get("non-additive pairwise energy"), abs=thr) == pair_disp3


def test_properties():
def test_properties() -> None:
"""Calculate dispersion related properties for a molecule"""
thr = 1.0e-7

Expand Down
5 changes: 3 additions & 2 deletions python/dftd4/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# along with dftd4. If not, see <https://www.gnu.org/licenses/>.


from dftd4.library import get_api_version
from pkg_resources import parse_version

from dftd4 import __version__
from dftd4.library import get_api_version


def test_api_version():
def test_api_version() -> None:
"""Ensure that the API version is compatible."""

assert parse_version(get_api_version()) == parse_version(__version__)
13 changes: 7 additions & 6 deletions python/dftd4/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
# along with dftd4. If not, see <https://www.gnu.org/licenses/>.


from dftd4.parameters import get_all_damping_params, get_damping_param
from pytest import approx
from dftd4.parameters import get_damping_param, get_all_damping_params


def get_data_file_name() -> str:
"""Make sure we can still test without installing"""
from os.path import join, dirname, exists
from os.path import dirname, exists, join

from dftd4.parameters import get_data_file_name as _get_data_file_name

data_file = join(dirname(__file__), "..", "..", "assets", "parameters.toml")
return data_file if exists(data_file) else _get_data_file_name()


def test_get_b3lyp():
def test_get_b3lyp() -> None:
expected = {
"s6": 1.0,
"s9": 1.0,
Expand All @@ -43,7 +44,7 @@ def test_get_b3lyp():
assert approx(actual[key]) == expected[key]


def test_get_b2plyp():
def test_get_b2plyp() -> None:
expected = {
"s6": 0.64,
"s9": 1.0,
Expand All @@ -58,7 +59,7 @@ def test_get_b2plyp():
assert approx(actual[key]) == expected[key]


def test_get_pw6b95():
def test_get_pw6b95() -> None:
expected = {
"s6": 1.0,
"s9": 1.0,
Expand All @@ -75,7 +76,7 @@ def test_get_pw6b95():
assert approx(actual[key]) == expected[key]


def test_all_parameters():
def test_all_parameters() -> None:
params = get_all_damping_params()

assert "b3lyp" in params
Expand Down
Loading
Loading