-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_psi4.py
129 lines (104 loc) · 4.48 KB
/
test_psi4.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
128
129
#!/usr/bin/env python3
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
## ---------------------------------------------------------------------
##
## Copyright (C) 2018 by the adcc authors
##
## This file is part of adcc.
##
## adcc is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## adcc is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with adcc. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------
import unittest
import numpy as np
import adcc
import adcc.backends
from ..misc import expand_test_templates
from .testing import (eri_asymm_construction_test, eri_chem_permutations,
operator_import_test)
from numpy.testing import assert_almost_equal
from adcc.backends import have_backend
from adcc.testdata import geometry
import pytest
if have_backend("psi4"):
import psi4
basissets = ["sto3g", "ccpvdz"]
@expand_test_templates(basissets)
@pytest.mark.skipif(not have_backend("psi4"), reason="psi4 not found.")
class TestPsi4(unittest.TestCase):
def base_test(self, wfn):
hfdata = adcc.backends.import_scf_results(wfn)
assert hfdata.backend == "psi4"
n_orbs = 2 * wfn.nmo()
assert hfdata.spin_multiplicity != 0
assert hfdata.n_orbs_alpha == hfdata.n_orbs_beta
if hfdata.restricted:
assert np.all(hfdata.orben_f[:hfdata.n_orbs_alpha]
== hfdata.orben_f[hfdata.n_orbs_alpha:])
assert hfdata.energy_scf == wfn.energy()
assert hfdata.spin_multiplicity == wfn.molecule().multiplicity()
# occupation_f
assert_almost_equal(hfdata.occupation_f, np.hstack((
np.asarray(wfn.occupation_a()), np.asarray(wfn.occupation_b())
)))
# orben_f
assert_almost_equal(hfdata.orben_f,
np.hstack((wfn.epsilon_a(), wfn.epsilon_b())))
# orbcoeff_fb
assert_almost_equal(hfdata.orbcoeff_fb, np.transpose(np.hstack((
np.asarray(wfn.Ca()),
np.asarray(wfn.Cb()))
)))
# Fock matrix fock_ff
fock_alpha_bb = np.asarray(wfn.Fa())
fock_beta_bb = np.asarray(wfn.Fb())
if hfdata.restricted:
assert_almost_equal(fock_alpha_bb, fock_beta_bb)
fock_ff = np.zeros((n_orbs, n_orbs))
fock_alpha = np.einsum('ui,vj,uv', np.asarray(wfn.Ca()),
np.asarray(wfn.Ca()), fock_alpha_bb)
fock_ff[:hfdata.n_orbs_alpha, :hfdata.n_orbs_alpha] = fock_alpha
fock_beta = np.einsum('ui,vj,uv', np.asarray(wfn.Cb()),
np.asarray(wfn.Cb()), fock_beta_bb)
fock_ff[hfdata.n_orbs_alpha:, hfdata.n_orbs_alpha:] = fock_beta
assert_almost_equal(hfdata.fock_ff, fock_ff)
# test symmetry of the ERI tensor
eri = np.empty((hfdata.n_orbs, hfdata.n_orbs,
hfdata.n_orbs, hfdata.n_orbs))
sfull = slice(0, hfdata.n_orbs)
hfdata.fill_eri_ffff((sfull, sfull, sfull, sfull), eri)
for perm in eri_chem_permutations:
eri_perm = np.transpose(eri, perm)
assert_almost_equal(eri_perm, eri)
def template_rhf_h2o(self, basis):
wfn = adcc.backends.run_hf("psi4", geometry.xyz["h2o"], basis)
self.base_test(wfn)
# Test ERI
eri_asymm_construction_test(wfn)
eri_asymm_construction_test(wfn, core_orbitals=1)
# Test dipole
mints = psi4.core.MintsHelper(wfn.basisset())
ao_dip = [np.array(comp) for comp in mints.ao_dipole()]
operator_import_test(wfn, ao_dip)
def template_uhf_ch2nh2(self, basis):
wfn = adcc.backends.run_hf("psi4", geometry.xyz["ch2nh2"], basis,
multiplicity=2)
self.base_test(wfn)
# Test ERI
eri_asymm_construction_test(wfn)
eri_asymm_construction_test(wfn, core_orbitals=1)
# Test dipole
mints = psi4.core.MintsHelper(wfn.basisset())
ao_dip = [np.array(comp) for comp in mints.ao_dipole()]
operator_import_test(wfn, ao_dip)