Repository: Quantum-Accelerators/quacc
Pull request #2657 (2025-02-08 13:51:43)

Fix r2SCAN D4


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a3da444b..6ed0fc28 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.19]
+
+### Fixed
+
+- Fixed automatic setting of D4 parameters for r2SCAN
+
 ## [0.11.18]
 
 ### Changed
diff --git a/src/quacc/calculators/vasp/params.py b/src/quacc/calculators/vasp/params.py
index 58779fd3..c10f1ea8 100644
--- a/src/quacc/calculators/vasp/params.py
+++ b/src/quacc/calculators/vasp/params.py
@@ -238,6 +238,7 @@ def get_param_swaps(
     if (
         calc.string_params["metagga"]
         and calc.string_params["metagga"].lower() == "r2scan"
+        and calc.int_params["ivdw"] == 13
         and not calc.float_params["vdw_s6"]
         and not calc.float_params["vdw_s8"]
         and not calc.float_params["vdw_a1"]


Test patch:
diff --git a/tests/core/calculators/vasp/test_vasp.py b/tests/core/calculators/vasp/test_vasp.py
index fc43ca63..0199e5e0 100644
--- a/tests/core/calculators/vasp/test_vasp.py
+++ b/tests/core/calculators/vasp/test_vasp.py
@@ -695,13 +695,13 @@ def test_lorbit():
 
 def test_d4():
     atoms = bulk("Cu")
-    calc = Vasp(atoms, xc="r2scan")
+    calc = Vasp(atoms, xc="r2scan", ivdw=13)
     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")
+    calc = Vasp(atoms, metagga="r2scan", ivdw=13)
     assert calc.float_params["vdw_s6"] == 1.0
     assert calc.float_params["vdw_s8"] == 0.60187490
     assert calc.float_params["vdw_a1"] == 0.51559235
@@ -710,6 +710,9 @@ def test_d4():
     calc = Vasp(atoms, metagga="r2scan", vdw_s6=2.0)
     assert calc.float_params["vdw_s6"] == 2.0
 
+    calc = Vasp(atoms, metagga="r2scan")
+    assert calc.float_params["vdw_s6"] is None
+
 
 def test_setups():
     atoms = bulk("Cu")
diff --git a/tests/core/schemas/test_vasp_schema.py b/tests/core/schemas/test_vasp_schema.py
index c9bf0eda..7240550a 100644
--- a/tests/core/schemas/test_vasp_schema.py
+++ b/tests/core/schemas/test_vasp_schema.py
@@ -228,7 +228,9 @@ def test_no_bader(tmp_path, monkeypatch, run1, caplog):
     copytree(run1, p)
     atoms = read(p / "OUTCAR.gz")
     with caplog.at_level(WARNING):
-        results = VaspSummarize(directory=p, run_bader=True, run_chargemol=False).run(atoms)
+        results = VaspSummarize(directory=p, run_bader=True, run_chargemol=False).run(
+            atoms
+        )
     assert "bader" not in results
 
 
@@ -238,5 +240,7 @@ def test_no_chargemol(tmp_path, monkeypatch, run1, caplog):
     copytree(run1, p)
     atoms = read(p / "OUTCAR.gz")
     with caplog.at_level(WARNING):
-        results = VaspSummarize(directory=p, run_bader=False, run_chargemol=True).run(atoms)
+        results = VaspSummarize(directory=p, run_bader=False, run_chargemol=True).run(
+            atoms
+        )
     assert "chargemol" not in results