Skip to content

Commit 3e16f9f

Browse files
authored
Allow to add DFTD4 to other ASE calculators (#97)
- bump version number to 3.2.0
1 parent 9b70ca8 commit 3e16f9f

10 files changed

Lines changed: 62 additions & 11 deletions

File tree

fpm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "dftd4"
2-
version = "3.1.0"
2+
version = "3.2.0"
33
license = "LGPL-3.0-or-later"
44
maintainer = ["@awvwgk"]
55
author = ["Eike Caldeweyher", "Sebastian Ehlert", "Stefan Grimme"]

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
project(
1818
'dftd4',
1919
'fortran',
20-
version: '3.1.0',
20+
version: '3.2.0',
2121
license: 'LGPL-3.0-or-later',
2222
meson_version: '>=0.53',
2323
default_options: [

python/README.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ To use the ``DFTD4`` calculator as dispersion correction the calculator can be c
125125
>>> atoms = molecule('H2O')
126126
>>> atoms.calc = SumCalculator([DFTD4(method="PBE"), NWChem(xc="PBE")])
127127
128+
For convenience ``DFTD4`` allows to combine itself with another calculator by using the ``add_calculator`` method which returns a SumCalculator:
129+
130+
.. code:: python
131+
132+
>>> from ase.build import molecule
133+
>>> from ase.calculators.emt import EMT
134+
>>> from dftd4.ase import DFTD4
135+
>>> atoms = molecule("C60")
136+
>>> atoms.calc = DFTD4(method="pbe").add_calculator(EMT())
137+
>>> atoms.get_potential_energy()
138+
6.348142387048062
139+
>>> [calc.get_potential_energy() for calc in atoms.calc.calcs]
140+
[-6.015477436263984, 12.363619823312046]
141+
142+
The individual contributions are available by iterating over the list of calculators in ``calc.calcs``.
143+
Note that ``DFTD4`` will always place itself as first calculator in the list.
144+
128145

129146
Installing
130147
~~~~~~~~~~
@@ -154,7 +171,7 @@ Now you are ready to use ``dftd4``, check if you can import it with
154171
>>> import dftd4
155172
>>> from dftd4.libdftd4 import get_api_version
156173
>>> get_api_version()
157-
'3.0.0'
174+
'3.2.0'
158175
159176
160177
Building the extension module

python/dftd4/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# make sure we have a CFFI available
1919
import cffi
2020

21-
__version__ = "3.1.0"
21+
__version__ = "3.2.0"

python/dftd4/ase.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,30 @@
3434
Keyword Default Description
3535
======================== ============ ============================================
3636
method None Method to calculate dispersion for
37+
params_tweaks None Optional dict with the damping parameters
3738
cache_api True Reuse generate API objects (recommended)
3839
======================== ============ ============================================
3940
41+
The params_tweaks dict contains the damping parameters, at least s8, a1 and a2
42+
must be provided
43+
44+
======================== =========== ============================================
45+
Tweakable parameter Default Description
46+
======================== =========== ============================================
47+
s6 1.0 Scaling of the dipole-dipole dispersion
48+
s8 None Scaling of the dipole-quadrupole dispersion
49+
s9 1.0 Scaling of the three-body dispersion energy
50+
a1 None Scaling of the critical radii
51+
a2 None Offset of the critical radii
52+
alp 16.0 Exponent of the zero damping (ATM only)
53+
======================== =========== ============================================
54+
55+
Either method or s8, a1 and a2 must be provided, s9 can be used to overwrite
56+
the ATM scaling if the method is provided in the model.
57+
Disabling the three-body dispersion (s9=0.0) changes the internal selection rules
58+
for damping parameters of a given method and prefers special two-body only
59+
damping parameters if available!
60+
4061
Example
4162
-------
4263
>>> from ase.build import molecule
@@ -69,6 +90,7 @@
6990
CalculationFailed,
7091
all_changes,
7192
)
93+
from ase.calculators.mixing import SumCalculator
7294
from ase.atoms import Atoms
7395
from ase.units import Hartree, Bohr
7496

@@ -102,6 +124,9 @@ def __init__(
102124

103125
Calculator.__init__(self, atoms=atoms, **kwargs)
104126

127+
def add_calculator(self, other: Calculator) -> Calculator:
128+
return SumCalculator([self, other])
129+
105130
def set(self, **kwargs) -> dict:
106131
"""Set new parameters to dftd4"""
107132

python/dftd4/libdftd4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
-------
2626
>>> from dftd4.libdftd4 import get_api_version
2727
>>> get_api_version()
28-
'3.0.0'
28+
'3.2.0'
2929
"""
3030

3131
try:

python/dftd4/test_ase.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from dftd4.ase import DFTD4
1818
from ase.build import molecule
19+
from ase.calculators.emt import EMT
1920
from pytest import approx, raises
2021
import numpy as np
2122

@@ -41,10 +42,14 @@ def test_ase_scand4():
4142
atoms = molecule("methylenecyclopropane")
4243
atoms.calc = DFTD4(method="SCAN")
4344

44-
print(atoms.get_forces())
4545
assert approx(atoms.get_potential_energy(), abs=thr) == -0.021665446836610567
4646
assert approx(atoms.get_forces(), abs=thr) == forces
4747

48+
atoms.calc = DFTD4(method="SCAN").add_calculator(EMT())
49+
assert approx(atoms.get_potential_energy(), abs=thr) == 3.6624398683434225
50+
energies = [calc.get_potential_energy() for calc in atoms.calc.calcs]
51+
assert approx(energies, abs=thr) == [-0.021665446836610563, 3.684105315180033]
52+
4853

4954
def test_ase_tpssd4():
5055
thr = 1.0e-6
@@ -69,6 +74,10 @@ def test_ase_tpssd4():
6974
atoms = molecule("C2H6CHOH")
7075
atoms.calc = DFTD4(method="TPSS")
7176

72-
print(atoms.get_forces())
7377
assert approx(atoms.get_potential_energy(), abs=thr) == -0.24206732765720423
7478
assert approx(atoms.get_forces(), abs=thr) == forces
79+
80+
atoms.calc = DFTD4(method="TPSS").add_calculator(EMT())
81+
assert approx(atoms.get_potential_energy(), abs=thr) == 4.864016486351274
82+
energies = [calc.get_potential_energy() for calc in atoms.calc.calcs]
83+
assert approx(energies, abs=thr) == [-0.24206732765720396, 5.106083814008478]

python/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ project(
2727
)
2828
install = true
2929

30-
dftd4_dep = dependency('dftd4', version: '>=3.1.0')
30+
dftd4_dep = dependency('dftd4', version: '>=3.2.0')
3131
dftd4_header = files('..'/'include'/'dftd4.h')
3232

3333
subdir('dftd4')

python/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = dftd4-python
3-
version = 3.1.0
3+
version = 3.2.0
44
desciption = Python API of the DFT-D4 project
55
long_desciption = file: README.rst
66
long_description_content_type = text/x-rst

src/dftd4/version.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ module dftd4_version
2424

2525

2626
!> String representation of the dftd4 version
27-
character(len=*), parameter :: dftd4_version_string = "3.1.0"
27+
character(len=*), parameter :: dftd4_version_string = "3.2.0"
2828

2929
!> Numeric representation of the dftd4 version
30-
integer, parameter :: dftd4_version_compact(3) = [3, 1, 0]
30+
integer, parameter :: dftd4_version_compact(3) = [3, 2, 0]
3131

3232

3333
contains

0 commit comments

Comments
 (0)