/
test_properties.py
87 lines (71 loc) · 3.27 KB
/
test_properties.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
#!/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
from .misc import assert_allclose_signfix
from .test_state_densities import Runners
from numpy.testing import assert_allclose
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]]
class TestTransitionDipoleMoments(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]
res_tdms = state.transition_dipole_moments
ref_tdms = refdata[method][kind]["transition_dipole_moments"]
refevals = refdata[method][kind]["eigenvalues"]
n_ref = len(state.excitation_vectors)
for i in range(n_ref):
res_tdm = res_tdms[i]
ref_tdm = ref_tdms[i]
assert state.excitation_energies[i] == refevals[i]
res_tdm_norm = np.sum(res_tdm * res_tdm)
ref_tdm_norm = np.sum(ref_tdm * ref_tdm)
assert res_tdm_norm == approx(ref_tdm_norm, abs=1e-5)
assert_allclose_signfix(res_tdm, ref_tdm, atol=1e-5)
class TestOscillatorStrengths(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]
res_oscs = state.oscillator_strengths
ref_tdms = refdata[method][kind]["transition_dipole_moments"]
refevals = refdata[method][kind]["eigenvalues"]
n_ref = len(state.excitation_vectors)
for i in range(n_ref):
assert state.excitation_energies[i] == refevals[i]
ref_tdm_norm = np.sum(ref_tdms[i] * ref_tdms[i])
assert res_oscs[i] == approx(2. / 3. * ref_tdm_norm * refevals[i])
class TestStateDipoleMoments(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]
res_dms = state.state_dipole_moments
ref = refdata[method][kind]
n_ref = len(state.excitation_vectors)
assert_allclose(res_dms, ref["state_dipole_moments"][:n_ref], atol=1e-4)