-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_state_densities.py
148 lines (114 loc) · 5.45 KB
/
test_state_densities.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/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
from .misc import expand_test_templates
from adcc.testdata.cache import cache
from pytest import approx
# The methods to test
basemethods = ["adc0", "adc1", "adc2", "adc2x", "adc3"]
methods = [m for bm in basemethods for m in [bm, "cvs_" + bm]]
@expand_test_templates(methods)
class Runners():
def base_test(self, *args, **kwargs):
raise NotImplementedError
def template_h2o_sto3g_singlet(self, method):
self.base_test("h2o_sto3g", method, "singlet")
def template_h2o_def2tzvp_singlet(self, method):
self.base_test("h2o_def2tzvp", method, "singlet")
def template_h2o_sto3g_triplet(self, method):
self.base_test("h2o_sto3g", method, "triplet")
def template_h2o_def2tzvp_triplet(self, method):
self.base_test("h2o_def2tzvp", method, "triplet")
def template_cn_sto3g(self, method):
self.base_test("cn_sto3g", method, "state")
def template_cn_ccpvdz(self, method):
self.base_test("cn_ccpvdz", method, "state")
def template_hf3_631g_spin_flip(self, method):
self.base_test("hf3_631g", method, "spin_flip")
#
# Other runners (to test that FC and FV work as they should)
#
def test_h2o_sto3g_fc_adc2_singlets(self):
self.base_test("h2o_sto3g", "fc_adc2", "singlet")
def test_h2o_sto3g_fv_adc2x_singlets(self):
self.base_test("h2o_sto3g", "fv_adc2x", "singlet")
def test_cn_sto3g_fc_adc2_states(self):
self.base_test("cn_sto3g", "fc_adc2", "state")
def test_cn_sto3g_fv_adc2x_states(self):
self.base_test("cn_sto3g", "fv_adc2x", "state")
def test_cn_sto3g_fv_cvs_adc2x_states(self):
self.base_test("cn_sto3g", "fv_cvs_adc2x", "state")
def test_h2s_sto3g_fc_cvs_adc2_singlets(self):
self.base_test("h2s_sto3g", "fc_cvs_adc2", "singlet")
def test_h2s_6311g_fc_adc2_singlets(self):
self.base_test("h2s_6311g", "fc_adc2", "singlet")
def test_h2s_6311g_fv_adc2_singlets(self):
self.base_test("h2s_6311g", "fv_adc2", "singlet")
def test_h2s_6311g_fc_cvs_adc2x_singlets(self):
self.base_test("h2s_6311g", "fc_cvs_adc2x", "singlet")
def test_h2s_6311g_fv_cvs_adc2x_singlets(self):
self.base_test("h2s_6311g", "fv_cvs_adc2x", "singlet")
# Return combinations not tested so far:
# The rationale is that cvs-spin-flip as a method do not make
# that much sense and probably the routines are anyway covered
# by the other testing we do.
delattr(Runners, "test_hf3_631g_spin_flip_cvs_adc0")
delattr(Runners, "test_hf3_631g_spin_flip_cvs_adc1")
delattr(Runners, "test_hf3_631g_spin_flip_cvs_adc2")
delattr(Runners, "test_hf3_631g_spin_flip_cvs_adc2x")
delattr(Runners, "test_hf3_631g_spin_flip_cvs_adc3")
class TestStateDiffDm(unittest.TestCase, Runners):
def base_test(self, system, method, kind):
method = method.replace("_", "-")
refdata = cache.reference_data[system]
state = cache.adc_states[system][method][kind]
refdens_a = refdata[method][kind]["state_diffdm_bb_a"]
refdens_b = refdata[method][kind]["state_diffdm_bb_b"]
refevals = refdata[method][kind]["eigenvalues"]
for i in range(len(state.excitation_vectors)):
# Check that we are talking about the same state when
# comparing reference and computed
assert state.excitation_energies[i] == refevals[i]
dm_ao_a, dm_ao_b = state.state_diffdms[i].to_ao_basis()
dm_ao_a = dm_ao_a.to_ndarray()
dm_ao_b = dm_ao_b.to_ndarray()
assert dm_ao_a == approx(refdens_a[i])
assert dm_ao_b == approx(refdens_b[i])
class TestStateGroundToExcitedTdm(unittest.TestCase, Runners):
def base_test(self, system, method, kind):
method = method.replace("_", "-")
refdata = cache.reference_data[system]
state = cache.adc_states[system][method][kind]
refdens_a = refdata[method][kind]["ground_to_excited_tdm_bb_a"]
refdens_b = refdata[method][kind]["ground_to_excited_tdm_bb_b"]
refevals = refdata[method][kind]["eigenvalues"]
for i in range(len(state.excitation_vectors)):
# Check that we are talking about the same state when
# comparing reference and computed
assert state.excitation_energies[i] == refevals[i]
tdms = state.transition_dms[i].to_ao_basis()
dm_ao_a, dm_ao_b = tdms
dm_ao_a = dm_ao_a.to_ndarray()
dm_ao_b = dm_ao_b.to_ndarray()
assert dm_ao_a == approx(refdens_a[i])
assert dm_ao_b == approx(refdens_b[i])