From 69f0a8b5995a040f3a80c062e8370818819516e1 Mon Sep 17 00:00:00 2001 From: ifilot Date: Sun, 12 Jul 2026 15:56:08 +0200 Subject: [PATCH] Fixed SVWN5 parameters --- docs/electronic_structure_calculations.rst | 56 +++++++++++----------- pydft/xcfunctionals.py | 12 ++--- pyproject.toml | 2 +- tests/test_custom_basisset.py | 2 +- tests/test_dft.py | 20 ++++---- tests/test_finite_difference_grid.py | 2 +- tests/test_xc.py | 4 +- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/docs/electronic_structure_calculations.rst b/docs/electronic_structure_calculations.rst index 856bfc5..ac0e96a 100755 --- a/docs/electronic_structure_calculations.rst +++ b/docs/electronic_structure_calculations.rst @@ -20,7 +20,7 @@ the :meth:`pydft.DFT.scf` routine to start the self-consistent field calculation Performing this calculation shows that the total electronic energy for this system corresponds to:: - Total electronic energy: -111.130470 Ht + Total electronic energy: -110.854614 Ht Result dictionary ----------------- @@ -112,17 +112,17 @@ electron-electron repulsion and exchange-correlation energy. The above script yields the following output:: - Total electronic energy: -111.130470 Ht + Total electronic energy: -110.854614 Ht - Kinetic energy: 110.217226 Ht - Nuclear attraction: -304.930911 Ht - Electron-electron repulsion: 75.612987 Ht - Exchange energy: -12.055233 Ht - Correlation energy: -1.232632 Ht - Exchange-correlation energy: -13.287865 Ht + Kinetic energy: 110.215413 Ht + Nuclear attraction: -304.926853 Ht + Electron-electron repulsion: 75.610445 Ht + Exchange energy: -12.054947 Ht + Correlation energy: -0.956764 Ht + Exchange-correlation energy: -13.011711 Ht Nucleus-nucleus repulsion: 21.258092 Ht - Sum: -111.130470 Ht + Sum: -110.854614 Ht Self-consistent field matrices ------------------------------ @@ -154,23 +154,23 @@ Executing the script above yields output like the following. The timings depend on the machine and runtime environment:: 001 | E = -179.237419 | dE = 0.0000e+00 | 0.0010 s - 002 | E = -106.662588 | dE = 0.0000e+00 | 1.2765 s - 003 | E = -117.641796 | dE = 7.2575e+01 | 0.0172 s - 004 | E = -107.190988 | dE = 1.0979e+01 | 0.0201 s - 005 | E = -117.376118 | dE = 1.0451e+01 | 0.0203 s - 006 | E = -117.085797 | dE = 1.0185e+01 | 0.0160 s - 007 | E = -108.013652 | dE = 2.9032e-01 | 0.0149 s - 008 | E = -107.421366 | dE = 9.0721e+00 | 0.0143 s - 009 | E = -110.457951 | dE = 5.9229e-01 | 0.0151 s - 010 | E = -110.419024 | dE = 3.0366e+00 | 0.0176 s - 011 | E = -109.548780 | dE = 3.8927e-02 | 0.0159 s - 012 | E = -111.008079 | dE = 8.7024e-01 | 0.0159 s - 013 | E = -111.118875 | dE = 1.4593e+00 | 0.0163 s - 014 | E = -111.130700 | dE = 1.1080e-01 | 0.0162 s - 015 | E = -111.130454 | dE = 1.1825e-02 | 0.0210 s - 016 | E = -111.130470 | dE = 2.4610e-04 | 0.0258 s - 017 | E = -111.130470 | dE = 1.6288e-05 | 0.0188 s - 018 | E = -111.130470 | dE = 9.2335e-08 | 0.0158 s + 002 | E = -106.382130 | dE = 0.0000e+00 | 0.5628 s + 003 | E = -117.367416 | dE = 7.2855e+01 | 0.0187 s + 004 | E = -106.912634 | dE = 1.0985e+01 | 0.0157 s + 005 | E = -117.101972 | dE = 1.0455e+01 | 0.0153 s + 006 | E = -116.811360 | dE = 1.0189e+01 | 0.0157 s + 007 | E = -107.735924 | dE = 2.9061e-01 | 0.0177 s + 008 | E = -107.142887 | dE = 9.0754e+00 | 0.0206 s + 009 | E = -110.184408 | dE = 5.9304e-01 | 0.0153 s + 010 | E = -110.142428 | dE = 3.0415e+00 | 0.0180 s + 011 | E = -109.287578 | dE = 4.1979e-02 | 0.0226 s + 012 | E = -110.733835 | dE = 8.5485e-01 | 0.0187 s + 013 | E = -110.843185 | dE = 1.4463e+00 | 0.0231 s + 014 | E = -110.854814 | dE = 1.0935e-01 | 0.0183 s + 015 | E = -110.854598 | dE = 1.1628e-02 | 0.0193 s + 016 | E = -110.854614 | dE = 2.1610e-04 | 0.0159 s + 017 | E = -110.854614 | dE = 1.6018e-05 | 0.0182 s + 018 | E = -110.854614 | dE = 9.5061e-08 | 0.0175 s Stopping SCF cycle, convergence reached. Each line corresponds to one update of the density matrix. Internally, PyDFT @@ -193,8 +193,8 @@ argument when constructing the :class:`pydft.DFT` object: which yields the following total electronic energies for the :code:`SVWN5` and :code:`PBE` :cite:p:`pbe:1996` exchange-correlation functions:: - SVWN: -111.13047044798054 Ht - PBE: -111.64036457334683 Ht + SVWN: -110.85461362334834 Ht + PBE: -111.64036457334686 Ht Tuning the numerical accuracy ----------------------------- diff --git a/pydft/xcfunctionals.py b/pydft/xcfunctionals.py index e4eea41..95afb3f 100644 --- a/pydft/xcfunctionals.py +++ b/pydft/xcfunctionals.py @@ -144,9 +144,9 @@ def __vwn5(self, dens): # but is correct in the original paper of Vosko, Wilk and Nusair # https://cdnsciencepub.com/doi/pdf/10.1139/p80-159 A = 0.0621814 - x0 = -0.409286 - b = 13.0720 - c = 42.7198 + x0 = -0.10498 + b = 3.72744 + c = 12.9352 rs = (3. / 4. / np.pi / dens)**(1./3.) @@ -163,9 +163,9 @@ def __vwn5_deriv(self, dens): Derivative of the VWN5 correlation functional towards the density """ A = 0.0621814 - x0 = -0.409286 - b = 13.0720 - c = 42.7198 + x0 = -0.10498 + b = 3.72744 + c = 12.9352 X0 = x0**2 + b * x0 + c Q = (4 * c - b**2)**(1/2) diff --git a/pyproject.toml b/pyproject.toml index 9e63b6d..1b1ac09 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pydft" -version = "0.8.0" +version = "0.9.0" authors = [ { name="Ivo Filot", email="ivo@ivofilot.nl" } ] diff --git a/tests/test_custom_basisset.py b/tests/test_custom_basisset.py index fb30c01..a8ad6a9 100755 --- a/tests/test_custom_basisset.py +++ b/tests/test_custom_basisset.py @@ -27,7 +27,7 @@ def test_h2(self): dft = DFT(mol, basis=cgfs) res = dft.scf() - answer = -1.1562627795279132 + answer = -1.1204764001484104 np.testing.assert_almost_equal(res['energy'], answer, 4) if __name__ == '__main__': diff --git a/tests/test_dft.py b/tests/test_dft.py index 5c482f0..3e3516d 100755 --- a/tests/test_dft.py +++ b/tests/test_dft.py @@ -16,7 +16,7 @@ def test_helium(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -2.8081735181814724 + answer = -2.7704595622068138 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_h2o(self): @@ -30,7 +30,7 @@ def test_h2o(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -74.92583960745394 + answer = -74.72985279614994 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_co(self): @@ -44,7 +44,7 @@ def test_co(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -111.1305117481223 + answer = -110.85461362334834 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_bf3(self): @@ -58,7 +58,7 @@ def test_bf3(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -318.19442532820096 + answer = -317.55352572879667 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_ch4(self): @@ -72,7 +72,7 @@ def test_ch4(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -39.790602071993334 + answer = -39.60074741004088 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_co2(self): @@ -86,7 +86,7 @@ def test_co2(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -184.97691522055553 + answer = -184.5409746994328 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_ethylene(self): @@ -100,7 +100,7 @@ def test_ethylene(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -77.13648424441982 + answer = -76.82946120370394 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_h2(self): @@ -114,7 +114,7 @@ def test_h2(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -1.1562627795279132 + answer = -1.1204764001484104 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_lih(self): @@ -128,7 +128,7 @@ def test_lih(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -7.862755794011036 + answer = -7.789199497213202 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_benzene(self): @@ -142,7 +142,7 @@ def test_benzene(self): dft = DFT(mol, basis='sto3g') res = dft.scf() - answer = -227.9563844056453 + answer = -227.14299165089105 np.testing.assert_almost_equal(res['energy'], answer, 4) if __name__ == '__main__': diff --git a/tests/test_finite_difference_grid.py b/tests/test_finite_difference_grid.py index a73d3c6..45f5395 100755 --- a/tests/test_finite_difference_grid.py +++ b/tests/test_finite_difference_grid.py @@ -14,7 +14,7 @@ def test_co(self): mol_builder = MoleculeBuilder() mol = mol_builder.from_name('CO') - answers = [-110.8427, -111.1378, -111.1305, -111.1437, -111.1475, -111.1348] + answers = [-110.5669, -110.8619, -110.8546, -110.8678, -110.8716, -110.8589] res = [] for fdpts in [3,5,7,9,11,13]: diff --git a/tests/test_xc.py b/tests/test_xc.py index e6e03ee..9724eb6 100755 --- a/tests/test_xc.py +++ b/tests/test_xc.py @@ -16,7 +16,7 @@ def test_svwn5(self): dft = DFT(mol, basis='sto3g', functional='svwn5') res = dft.scf() - answer = -2.8081735181814724 + answer = -2.7704595622068138 np.testing.assert_almost_equal(res['energy'], answer, 4) def test_pbe(self): @@ -31,4 +31,4 @@ def test_pbe(self): res = dft.scf() answer = -2.8287483384734955 - np.testing.assert_almost_equal(res['energy'], answer, 4) \ No newline at end of file + np.testing.assert_almost_equal(res['energy'], answer, 4)