Skip to content

Commit

Permalink
make gab-independent functionals not depend on gab; closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Jul 12, 2020
1 parent d24236f commit c7fdb3a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ vwn3_a_b
vwn5_n
vwn5_a_b
pbex_n_gnn
pbex_a_b_gaa_gab_gbb
pbex_a_b_gaa_gbb
pbec_n_gnn
pbec_a_b_gaa_gab_gbb
b88_n_gnn
b88_a_b_gaa_gab_gbb
b88_a_b_gaa_gbb
lyp_n_gnn
lyp_a_b_gaa_gab_gbb
```
Expand Down
56 changes: 25 additions & 31 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
vwn5_n,
vwn5_a_b,
pbex_n_gnn,
pbex_a_b_gaa_gab_gbb,
pbex_a_b_gaa_gbb,
pbec_n_gnn,
pbec_a_b_gaa_gab_gbb,
b88_n_gnn,
b88_a_b_gaa_gab_gbb,
b88_a_b_gaa_gbb,
lyp_n_gnn,
lyp_a_b_gaa_gab_gbb,
)
Expand Down Expand Up @@ -127,26 +127,23 @@ def test_pbec_unpolarized():


def test_pbex_polarized():
fun = pbex_a_b_gaa_gab_gbb
fun = pbex_a_b_gaa_gbb
a = 0.02
b = 0.05
gaa = 0.02
gab = 0.03
gbb = 0.04

d_00000 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 0, 0, 0])
d_10000 = derv(fun, [a, b, gaa, gab, gbb], [1, 0, 0, 0, 0])
d_01000 = derv(fun, [a, b, gaa, gab, gbb], [0, 1, 0, 0, 0])
d_00100 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 1, 0, 0])
d_00010 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 0, 1, 0])
d_00001 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 0, 0, 1])
d_0000 = derv(fun, [a, b, gaa, gbb], [0, 0, 0, 0])
d_1000 = derv(fun, [a, b, gaa, gbb], [1, 0, 0, 0])
d_0100 = derv(fun, [a, b, gaa, gbb], [0, 1, 0, 0])
d_0010 = derv(fun, [a, b, gaa, gbb], [0, 0, 1, 0])
d_0001 = derv(fun, [a, b, gaa, gbb], [0, 0, 0, 1])

assert d_00000 == pytest.approx(-0.030022232676348133)
assert d_10000 == pytest.approx(-0.4399544626404114)
assert d_01000 == pytest.approx(-0.4179516165421625)
assert d_00100 == pytest.approx(-0.037768955504833064)
assert d_00010 == pytest.approx(0.0)
assert d_00001 == pytest.approx(-0.07798714870271929)
assert d_0000 == pytest.approx(-0.030022232676348133)
assert d_1000 == pytest.approx(-0.4399544626404114)
assert d_0100 == pytest.approx(-0.4179516165421625)
assert d_0010 == pytest.approx(-0.037768955504833064)
assert d_0001 == pytest.approx(-0.07798714870271929)


def test_pbec_polarized():
Expand Down Expand Up @@ -187,26 +184,23 @@ def test_b88_unpolarized():


def test_b88_polarized():
fun = b88_a_b_gaa_gab_gbb
fun = b88_a_b_gaa_gbb
a = 0.02
b = 0.05
gaa = 0.02
gab = 0.03
gbb = 0.04

d_00000 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 0, 0, 0])
d_10000 = derv(fun, [a, b, gaa, gab, gbb], [1, 0, 0, 0, 0])
d_01000 = derv(fun, [a, b, gaa, gab, gbb], [0, 1, 0, 0, 0])
d_00100 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 1, 0, 0])
d_00010 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 0, 1, 0])
d_00001 = derv(fun, [a, b, gaa, gab, gbb], [0, 0, 0, 0, 1])

assert d_00000 == pytest.approx(-0.03144503226070762)
assert d_10000 == pytest.approx(-0.3093251926971783)
assert d_01000 == pytest.approx(-0.4049705102105752)
assert d_00100 == pytest.approx(-0.11788498562531187)
assert d_00010 == pytest.approx(0.0)
assert d_00001 == pytest.approx(-0.08629201015426126)
d_0000 = derv(fun, [a, b, gaa, gbb], [0, 0, 0, 0])
d_1000 = derv(fun, [a, b, gaa, gbb], [1, 0, 0, 0])
d_0100 = derv(fun, [a, b, gaa, gbb], [0, 1, 0, 0])
d_0010 = derv(fun, [a, b, gaa, gbb], [0, 0, 1, 0])
d_0001 = derv(fun, [a, b, gaa, gbb], [0, 0, 0, 1])

assert d_0000 == pytest.approx(-0.03144503226070762)
assert d_1000 == pytest.approx(-0.3093251926971783)
assert d_0100 == pytest.approx(-0.4049705102105752)
assert d_0010 == pytest.approx(-0.11788498562531187)
assert d_0001 == pytest.approx(-0.08629201015426126)


def test_lyp_unpolarized():
Expand Down
4 changes: 2 additions & 2 deletions xcauto/functionals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from .vwn import vwn3_n, vwn3_a_b, vwn5_n, vwn5_a_b

from .pbe import pbex_n_gnn, pbex_a_b_gaa_gab_gbb, pbec_n_gnn, pbec_a_b_gaa_gab_gbb
from .pbe import pbex_n_gnn, pbex_a_b_gaa_gbb, pbec_n_gnn, pbec_a_b_gaa_gab_gbb

from .becke import b88_n_gnn, b88_a_b_gaa_gab_gbb
from .becke import b88_n_gnn, b88_a_b_gaa_gbb

from .lyp import lyp_n_gnn, lyp_a_b_gaa_gab_gbb
6 changes: 2 additions & 4 deletions xcauto/functionals/becke.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ def _b88_a_gaa(a, gaa):
return slaterx_a(a) + b88


def b88_a_b_gaa_gab_gbb(a, b, gaa, gab, gbb):
# gab not used
def b88_a_b_gaa_gbb(a, b, gaa, gbb):
return _b88_a_gaa(a, gaa) + _b88_a_gaa(b, gbb)


def b88_n_gnn(n, gnn):
a = 0.5 * n
b = 0.5 * n
gaa = 0.25 * gnn
gab = None
gbb = gaa
return b88_a_b_gaa_gab_gbb(a, b, gaa, gab, gbb)
return b88_a_b_gaa_gbb(a, b, gaa, gbb)
3 changes: 1 addition & 2 deletions xcauto/functionals/pbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def pbex_n_gnn(n, gnn):
return pbex_a_gaa(a, gaa) + pbex_a_gaa(b, gbb)


def pbex_a_b_gaa_gab_gbb(a, b, gaa, gab, gbb):
# gab not used
def pbex_a_b_gaa_gbb(a, b, gaa, gbb):
return pbex_a_gaa(a, gaa) + pbex_a_gaa(b, gbb)


Expand Down

0 comments on commit c7fdb3a

Please sign in to comment.