Repository: Quantum-Accelerators/quacc
Pull request #2655 (2025-02-07 22:18:38)

Add automatic D4 parameters for r2SCAN

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/Quantum-Accelerators/quacc/pull/2655?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 97.42%. Comparing base [(`cd0b32a`)](https://app.codecov.io/gh/Quantum-Accelerators/quacc/commit/cd0b32ad850c499ac585d49f296ca636909ea1fd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators) to head [(`5cad344`)](https://app.codecov.io/gh/Quantum-Accelerators/quacc/commit/5cad34444d87d336a7befa8ae03335029d5ee7e0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main    #2655   +/-   ##
=======================================
  Coverage   97.42%   97.42%           
=======================================
  Files          90       90           
  Lines        3843     3846    +3     
=======================================
+ Hits         3744     3747    +3     
  Misses         99       99           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/Quantum-Accelerators/quacc/pull/2655?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Quantum-Accelerators).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7739722a..3af66abb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
 
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project generally adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [0.11.17]
+
+### Added
+
+- Added automatic r2SCAN D4 parameter settings for Vasp calculator
+
 ## [0.11.16]
 
 ### Changed
diff --git a/src/quacc/calculators/vasp/params.py b/src/quacc/calculators/vasp/params.py
index 0c52d8a0..58779fd3 100644
--- a/src/quacc/calculators/vasp/params.py
+++ b/src/quacc/calculators/vasp/params.py
@@ -235,6 +235,17 @@ def get_param_swaps(
         LOGGER.info("Recommending NPAR = 1 per the VASP manual.")
         calc.set(npar=1, ncore=None)
 
+    if (
+        calc.string_params["metagga"]
+        and calc.string_params["metagga"].lower() == "r2scan"
+        and not calc.float_params["vdw_s6"]
+        and not calc.float_params["vdw_s8"]
+        and not calc.float_params["vdw_a1"]
+        and not calc.float_params["vdw_a2"]
+    ):
+        LOGGER.info("Setting VDW_S6, VDW_S8, VDW_A1, VDW_A2 parameters for r2SCAN.")
+        calc.set(vdw_s6=1.0, vdw_s8=0.60187490, vdw_a1=0.51559235, vdw_a2=5.77342911)
+
     new_parameters = (
         calc.parameters
         if incar_copilot == "aggressive"


Test patch:
diff --git a/tests/core/calculators/vasp/test_vasp.py b/tests/core/calculators/vasp/test_vasp.py
index ca047a74..fc43ca63 100644
--- a/tests/core/calculators/vasp/test_vasp.py
+++ b/tests/core/calculators/vasp/test_vasp.py
@@ -693,6 +693,24 @@ def test_lorbit():
     assert calc.int_params["lorbit"] == 11
 
 
+def test_d4():
+    atoms = bulk("Cu")
+    calc = Vasp(atoms, xc="r2scan")
+    assert calc.float_params["vdw_s6"] == 1.0
+    assert calc.float_params["vdw_s8"] == 0.60187490
+    assert calc.float_params["vdw_a1"] == 0.51559235
+    assert calc.float_params["vdw_a2"] == 5.77342911
+
+    calc = Vasp(atoms, metagga="r2scan")
+    assert calc.float_params["vdw_s6"] == 1.0
+    assert calc.float_params["vdw_s8"] == 0.60187490
+    assert calc.float_params["vdw_a1"] == 0.51559235
+    assert calc.float_params["vdw_a2"] == 5.77342911
+
+    calc = Vasp(atoms, metagga="r2scan", vdw_s6=2.0)
+    assert calc.float_params["vdw_s6"] == 2.0
+
+
 def test_setups():
     atoms = bulk("Cu")
     calc = Vasp(atoms, preset="BulkSet")