3939======================== ============ ============================================
4040 method None Method to calculate dispersion for
4141 damping None Damping function to use
42- params_tweaks None Optional dict with the damping parameters
42+ params_tweaks {} Optional dict with the damping parameters
43+ realspace_cutoff {} Optional dict to override cutoff values
4344 cache_api True Reuse generate API objects (recommended)
4445======================== ============ ============================================
4546
6364for damping parameters of a given method and prefers special two-body only
6465damping parameters if available!
6566
67+ The realspace cutoff parameters allow adjusting the distance values for which
68+ interactions are considered
69+
70+ ================== =========== ==========================================
71+ Realspace cutoff Default Description
72+ ================== =========== ==========================================
73+ disp2 60 * Bohr Pairwise dispersion interactions
74+ disp3 40 * Bohr Triple dispersion interactions
75+ cn 40 * Bohr Coordination number counting
76+ ================== =========== ==========================================
77+
78+ Values provided in the dict are expected to be in Angstrom. When providing values
79+ in Bohr multiply the inputs by the `ase.units.Bohr` constant.
80+
6681Example
6782-------
6883>>> from ase.build import molecule
@@ -146,6 +161,7 @@ class DFTD3(Calculator):
146161 "method" : None ,
147162 "damping" : None ,
148163 "params_tweaks" : {},
164+ "realspace_cutoff" : {},
149165 "cache_api" : True ,
150166 }
151167
@@ -237,20 +253,33 @@ def _create_api_calculator(self) -> DispersionModel:
237253 _periodic ,
238254 )
239255
240- except RuntimeError :
241- raise InputError ("Cannot construct dispersion model for dftd3" )
256+ except RuntimeError as e :
257+ raise InputError ("Cannot construct dispersion model for dftd3" ) from e
242258
243259 return disp
244260
261+ def _apply_realspace_cutoff (self , disp : DispersionModel ) -> None :
262+ """Apply realspace cutoff parameters to dispersion model"""
263+
264+ try :
265+ if self .parameters .realspace_cutoff :
266+ disp2 = self .parameters .realspace_cutoff .get ("disp2" , 60.0 * Bohr ) / Bohr
267+ disp3 = self .parameters .realspace_cutoff .get ("disp3" , 40.0 * Bohr ) / Bohr
268+ cn = self .parameters .realspace_cutoff .get ("cn" , 40.0 * Bohr ) / Bohr
269+
270+ disp .set_realspace_cutoff (disp2 = disp2 , disp3 = disp3 , cn = cn )
271+ except RuntimeError as e :
272+ raise InputError ("Cannot update realspace cutoff for dftd3" ) from e
273+
245274 def _create_damping_param (self ) -> DampingParam :
246275 """Create a new API damping parameter object"""
247276
248277 try :
249278 params_tweaks = self .parameters .params_tweaks if self .parameters .params_tweaks else {"method" : self .parameters .get ("method" )}
250279 dpar = _damping_param [self .parameters .get ("damping" )](** params_tweaks )
251280
252- except RuntimeError :
253- raise InputError ("Cannot construct damping parameter for dftd3" )
281+ except RuntimeError as e :
282+ raise InputError ("Cannot construct damping parameter for dftd3" ) from e
254283
255284 return dpar
256285
@@ -271,12 +300,15 @@ def calculate(
271300 if self ._disp is None :
272301 self ._disp = self ._create_api_calculator ()
273302
303+ # Apply realspace cutoff before evaluation (works with cached calculator)
304+ self ._apply_realspace_cutoff (self ._disp )
305+
274306 _dpar = self ._create_damping_param ()
275307
276308 try :
277309 _res = self ._disp .get_dispersion (param = _dpar , grad = True )
278- except RuntimeError :
279- raise CalculationFailed ("dftd3 could not evaluate input" )
310+ except RuntimeError as e :
311+ raise CalculationFailed ("dftd3 could not evaluate input" ) from e
280312
281313 # These properties are garanteed to exist for all implemented calculators
282314 self .results ["energy" ] = _res .get ("energy" ) * Hartree
0 commit comments