-
Notifications
You must be signed in to change notification settings - Fork 19
/
LazyMp.py
94 lines (85 loc) · 3.35 KB
/
LazyMp.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
#!/usr/bin/env python3
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
## ---------------------------------------------------------------------
##
## Copyright (C) 2019 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 Lesser 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 Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with adcc. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------
import numpy as np
import libadcc
from .misc import cached_property
from .ReferenceState import ReferenceState
from .caching_policy import DefaultCachingPolicy
from .OneParticleOperator import OneParticleOperator, product_trace
class LazyMp(libadcc.LazyMp):
def __init__(self, hf, caching_policy=DefaultCachingPolicy()):
"""
Initialise the class dealing with the M/oller-Plesset ground state.
"""
if isinstance(hf, libadcc.LazyMp):
# Copy-Constructor, needed from C++ side
super().__init__(hf)
return
if isinstance(hf, libadcc.HartreeFockSolution_i):
hf = ReferenceState(hf)
if not isinstance(hf, ReferenceState):
raise TypeError("hf needs to be a ReferenceState "
"or a HartreeFockSolution_i")
super().__init__(hf, caching_policy)
@property
def mp2_diffdm(self):
"""
Return the MP2 differensce density in the MO basis.
"""
ret = OneParticleOperator.from_cpp(super().mp2_diffdm)
ret.reference_state = self.reference_state
return ret
def density(self, level=2):
"""
Return the MP density in the MO basis with all corrections
up to the specified order of perturbation theory
"""
if level == 1:
return self.reference_state.density
elif level == 2:
return self.reference_state.density + self.mp2_diffdm
else:
raise NotImplementedError("Only densities for level 1 and 2"
" are implemented.")
def dipole_moment(self, level=2):
"""
Return the MP dipole moment at the specified level of
perturbation theory.
"""
if level == 1:
return self.reference_state.dipole_moment
elif level == 2:
return self.mp2_dipole_moment
else:
raise NotImplementedError("Only dipole moments for level 1 and 2"
" are implemented.")
@property
def mp2_density(self):
return self.density(2)
@cached_property
def mp2_dipole_moment(self):
refstate = self.reference_state
dipole_integrals = refstate.operators.electric_dipole
mp2corr = -np.array([product_trace(comp, self.mp2_diffdm)
for comp in dipole_integrals])
return refstate.dipole_moment + mp2corr