/
AdcMethod.py
99 lines (84 loc) · 3.19 KB
/
AdcMethod.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
#!/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/>.
##
## ---------------------------------------------------------------------
def get_valid_methods():
valid_prefixes = ["cvs"]
valid_bases = ["adc0", "adc1", "adc2", "adc2x", "adc3"]
ret = valid_bases + [p + "-" + m for p in valid_prefixes
for m in valid_bases]
return ret
class AdcMethod:
available_methods = get_valid_methods()
def __init__(self, method):
if method not in self.available_methods:
raise ValueError("Invalid method " + str(method) + ". Only "
+ ",".join(self.available_methods) + " are known.")
split = method.split("-")
self.__base_method = split[-1]
split = split[:-1]
self.is_core_valence_separated = "cvs" in split
try:
if self.__base_method == "adc2x":
self.level = 2
else:
self.level = int(self.__base_method[-1])
except ValueError:
raise ValueError("Not a valid base method: " + self.__base_method)
def at_level(self, newlevel):
"""
Return an equivalent method, where only the level is changed
(e.g. calling this on a CVS method returns a CVS method)
"""
if self.is_core_valence_separated:
return AdcMethod("cvs-adc" + str(newlevel))
else:
return AdcMethod("adc" + str(newlevel))
@property
def name(self):
if self.is_core_valence_separated:
return "cvs-" + self.__base_method
else:
return self.__base_method
@property
def property_method(self):
"""
The name of the canonical method to use for computing properties
for this ADC method. This only differs from the name property
for the ADC(2)-x family of methods.
"""
if self.__base_method == "adc2x":
return AdcMethod(self.name.replace("adc2x", "adc2")).name
else:
return self.name
@property
def base_method(self):
"""
The base (full) method, i.e. with all approximations such as
CVS stripped off.
"""
return AdcMethod(self.__base_method)
def __eq__(self, other):
return self.name == other.name
def __ne__(self, other):
return self.name != other.name
def __repr__(self):
return "Method(name={})".format(self.name)