-
Notifications
You must be signed in to change notification settings - Fork 437
/
test_mp2.py
127 lines (111 loc) · 4.67 KB
/
test_mp2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import numpy as np
import pytest
from utils import *
import psi4
pytestmark = [pytest.mark.psi, pytest.mark.api, pytest.mark.quick, pytest.mark.mp2]
_ref_h2o_ccpvdz = {
"df": {
"HF TOTAL ENERGY": -76.0167614256151865,
"MP2 SAME-SPIN CORRELATION ENERGY": -0.0527406422061238,
"MP2 OPPOSITE-SPIN CORRELATION ENERGY": -0.1562926850310142,
"MP2 CORRELATION ENERGY": -0.2090333272371381,
"MP2 TOTAL ENERGY": -76.2257947528523232,
"SCS-MP2 CORRELATION ENERGY": -0.2051314361059251,
"SCS-MP2 TOTAL ENERGY": -76.2218928617211162,
},
"conv": {
"HF TOTAL ENERGY": -76.01678947133706,
"MP2 SAME-SPIN CORRELATION ENERGY": -0.05268120425816,
"MP2 OPPOSITE-SPIN CORRELATION ENERGY": -0.15637564436589,
"MP2 CORRELATION ENERGY": -0.20905684862405,
"MP2 TOTAL ENERGY": -76.22584631996111,
"SCS-MP2 CORRELATION ENERGY": -0.20521117465845,
"SCS-MP2 TOTAL ENERGY": -76.22200064599551,
},
} # yapf: disable
for mp2type in ["df", "conv"]:
_ref_h2o_ccpvdz[mp2type]["SCF TOTAL ENERGY"] = _ref_h2o_ccpvdz[mp2type]["HF TOTAL ENERGY"]
_ref_h2o_ccpvdz[mp2type]["CURRENT REFERENCE ENERGY"] = _ref_h2o_ccpvdz[mp2type]["HF TOTAL ENERGY"]
_ref_h2o_ccpvdz[mp2type]["5050SCS-MP2 CORRELATION ENERGY"] = 0.5 * (
_ref_h2o_ccpvdz[mp2type]["MP2 SAME-SPIN CORRELATION ENERGY"]
+ _ref_h2o_ccpvdz[mp2type]["MP2 OPPOSITE-SPIN CORRELATION ENERGY"]
)
_ref_h2o_ccpvdz[mp2type]["5050SCS-MP2 TOTAL ENERGY"] = (
_ref_h2o_ccpvdz[mp2type]["5050SCS-MP2 CORRELATION ENERGY"] + _ref_h2o_ccpvdz[mp2type]["HF TOTAL ENERGY"]
)
@pytest.mark.parametrize(
"inp",
[
pytest.param({"name": "Mp2", "custom": "SCS-MP2", "options": {"mp2_type": "df"}}, id="mp2 (df)"),
pytest.param({"name": "Mp2", "custom": "MP2", "options": {"mp2_type": "conv"}}, id="mp2 (conv)"),
pytest.param(
{
"name": "Mp2",
"custom": "SCS-MP2",
"options": {"mp2_type": "df", "mp2_os_scale": 1.2, "mp2_ss_scale": 0.33333333},
},
id="explicit scs mp2 (df)",
),
pytest.param(
{
"name": "Mp2",
"custom": "SCS-MP2",
"options": {"mp2_type": "conv", "os_scale": 1.2, "ss_scale": 0.33333333},
},
id="explicit scs mp2 (conv)",
),
pytest.param(
{
"name": "Mp2",
"custom": "5050SCS-MP2",
"options": {"mp2_type": "df", "mp2_os_scale": 0.5, "mp2_ss_scale": 0.5},
},
id="user-def scs mp2 (df)",
),
pytest.param(
{"name": "Mp2", "custom": "5050SCS-MP2", "options": {"mp2_type": "conv", "os_scale": 0.5, "ss_scale": 0.5}},
id="user-def scs mp2 (conv)",
),
],
)
def test_scsmp2(inp):
"""Formerly known as dfmp2-4"""
h2o = psi4.geometry(
"""
O
H 1 1.0
H 1 1.0 2 90.0
"""
)
psi4.set_options({"basis": "cc-pvdz"})
psi4.set_options(inp["options"])
ene, wfn = psi4.energy(inp["name"], return_wfn=True)
ref_block = _ref_h2o_ccpvdz[inp["options"]["mp2_type"]]
# ref_corl = ref_block[inp['pv'] + ' CORRELATION ENERGY']
# ref_tot = ref_block[inp['pv'] + ' TOTAL ENERGY']
ref_corl = ref_block["MP2 CORRELATION ENERGY"]
ref_tot = ref_block["MP2 TOTAL ENERGY"]
ref_custom_corl = ref_block[inp["custom"] + " CORRELATION ENERGY"]
ref_custom_tot = ref_block[inp["custom"] + " TOTAL ENERGY"]
for obj in [psi4.core, wfn]:
for pv in [
"HF TOTAL ENERGY",
"SCF TOTAL ENERGY",
"MP2 SAME-SPIN CORRELATION ENERGY",
"MP2 OPPOSITE-SPIN CORRELATION ENERGY",
"MP2 CORRELATION ENERGY",
"MP2 TOTAL ENERGY",
"SCS-MP2 CORRELATION ENERGY",
"SCS-MP2 TOTAL ENERGY",
"CURRENT REFERENCE ENERGY",
]:
assert compare_values(ref_block[pv], obj.variable(pv), 5, pv)
if any((x in inp["options"] for x in ["os_scale", "ss_scale", "mp2_os_scale", "mp2_ss_scale"])):
assert compare_values(
ref_custom_corl, obj.variable("CUSTOM SCS-MP2 CORRELATION ENERGY"), 5, "custom scsmp2 corl"
)
assert compare_values(ref_custom_tot, obj.variable("CUSTOM SCS-MP2 TOTAL ENERGY"), 5, "custom scsmp2 ")
assert compare_values(ref_corl, obj.variable("CURRENT CORRELATION ENERGY"), 5, "current corl")
assert compare_values(ref_tot, obj.variable("CURRENT ENERGY"), 5, "current")
assert compare_values(ref_tot, ene, 5, "return")
assert compare_values(ref_tot, wfn.energy(), 5, "wfn")