TS09 and D4 corrections with ASE

TS09 and D4 are atomic-charge dependent dispersion corrections (see TS09 PRL paper and D4 homepage for the refs). The D4 code is available at github. According to GPAW documentation, TS09 and D4 show for the S26 test set smaller mean deviation than vdW-DF. Herewith, D4 correction does not depend on the actual calculation as it is added to the calculated energy.

Here is how D4 correction can be added with ASE (see Readme):

from ase.build import molecule 
from ase.calculators.mixing import SumCalculator 
from ase.optimize import BFGS
from dftd4.ase import DFTD4 
from gpaw import GPAW 

atoms = molecule('H2O') 
atoms.center(vacuum=4)

gpaw = GPAW(txt='H2O.txt',xc='PBE') 
atoms.calc = SumCalculator([DFTD4(method='PBE'), gpaw])

#atoms.get_potential_energy()

opt = BFGS(atoms)
opt.run(fmax=0.05)

Let me stress that before choosing TS09 or D4 one should consider all pro and contra. TS09 method used Hirshfeld charges while D4 uses the electronegativity equilibration method to obtain charges. The former naturally accounts for the interfacial charge transfer while the latter does not. TS09 requires vdW radii and is implemented for a limited set on functionals (see ASE code), like PBE, RPBE, and BLYP. D4 supports much more functionals (see parameters). Regarding the vdW radii values for TS09 bare in mind that there are four sources – one in GPAW, two in ASE and one more in ASE.

Here is how TS09 correction can be added with ASE and GPAW:

from ase.build import molecule
from ase.calculators.vdwcorrection import vdWTkatchenko09prl
from ase.data.vdw_alvarez import vdw_radii
from ase.optimize import BFGS
from gpaw.analyse.hirshfeld import HirshfeldPartitioning
from gpaw.analyse.vdwradii import vdWradii
from gpaw import GPAW

atoms = molecule('H2O')
atoms.center(vacuum=4)

gpaw = GPAW(txt='H2O.txt',xc='PBE')
atoms.calc = vdWTkatchenko09prl(HirshfeldPartitioning(gpaw), vdWradii(atoms.get_chemical_symbols(), 'PBE'))

#atoms.get_potential_energy()
opt = BFGS(atoms)
opt.run(fmax=0.05)

P.S. Note that the TS09 and D4 energies are no outputted to the H2O.txt.