/
test_properties_consistency.py
90 lines (72 loc) · 3.25 KB
/
test_properties_consistency.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
#!/usr/bin/env python3
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
## ---------------------------------------------------------------------
##
## Copyright (C) 2020 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 numpy.testing import assert_allclose
from adcc.testdata.cache import cache
from .misc import expand_test_templates
from pytest import approx
basemethods = ["adc0", "adc1", "adc2", "adc2x", "adc3"]
methods = [m for bm in basemethods for m in [bm, "cvs_" + bm]]
@expand_test_templates(methods)
class RunnersConsistency:
def base_test(self, *args, **kwargs):
raise NotImplementedError
def template_methox_sto3g_singlet(self, method):
self.base_test("methox_sto3g", method, "singlet")
class TestMagneticTransitionDipoleMoments(unittest.TestCase, RunnersConsistency):
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.transition_magnetic_dipole_moment
ref = refdata[method][kind]
n_ref = len(state.excitation_vector)
assert_allclose(
res_dms, ref["transition_magnetic_dipole_moments"][:n_ref], atol=1e-4
)
class TestTransitionDipoleMomentsVelocity(unittest.TestCase, RunnersConsistency):
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.transition_dipole_moment_velocity
ref = refdata[method][kind]
n_ref = len(state.excitation_vector)
assert_allclose(
res_dms, ref["transition_dipole_moments_velocity"][:n_ref], atol=1e-4
)
class TestRotatoryStrengths(unittest.TestCase, RunnersConsistency):
def base_test(self, system, method, kind):
method = method.replace("_", "-")
refdata = cache.reference_data[system]
state = cache.adc_states[system][method][kind]
res_rots = state.rotatory_strength
ref_tmdm = refdata[method][kind]["transition_magnetic_dipole_moments"]
ref_tdmvel = refdata[method][kind]["transition_dipole_moments_velocity"]
refevals = refdata[method][kind]["eigenvalues"]
n_ref = len(state.excitation_vector)
for i in range(n_ref):
assert state.excitation_energy[i] == refevals[i]
ref_dot = np.dot(ref_tmdm[i], ref_tdmvel[i])
assert res_rots[i] == approx(ref_dot / refevals[i])