Repository navigation
Expand file tree
/
Copy pathdfadc.py
More file actions
150 lines (112 loc) · 4.55 KB
/
Copy pathdfadc.py
File metadata and controls
150 lines (112 loc) · 4.55 KB
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
149
150
#!/usr/bin/env python
# Copyright 2014-2022 The PySCF Developers. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: Abdelrahman Ahmed <>
# Samragni Banerjee <samragnibanerjee4@gmail.com>
# James Serna <jamcar456@gmail.com>
# Terrence Stahl <>
# Alexander Sokolov <alexander.y.sokolov@gmail.com>
#
import numpy as np
def get_ovvv_df(myadc, Lov, Lvv, p, chnk_size):
''' Returns approximate ovvv integrals used in restricted implementation'''
nvir = myadc._nvir
naux = myadc.with_df.get_naoaux()
if myadc.if_naf:
naux = myadc.naux
Lvv = Lvv.reshape(naux,nvir*nvir)
nocc = Lov.size//(naux*nvir)
Lov = Lov.reshape(naux,nocc,nvir)
if chnk_size < nocc:
Lov_temp = np.ascontiguousarray(Lov.transpose(1,2,0)[p:p+chnk_size].reshape(-1,naux))
else:
Lov_temp = np.ascontiguousarray(Lov.transpose(1,2,0).reshape(-1,naux))
ovvv = np.dot(Lov_temp, Lvv)
ovvv = ovvv.reshape(-1, nvir, nvir, nvir)
return ovvv
def get_ovvv_spin_df(myadc, Lov, Lvv, p, chnk_size):
''' Returns approximate ovvv integrals (different spin cases) used in unrestricted implementation '''
nocc = Lov.shape[1]
nvir_1 = Lov.shape[2]
nvir_2 = Lvv.shape[1]
naux = myadc.with_df.get_naoaux()
if myadc.if_naf:
naux = myadc.naux
Lvv = Lvv.reshape(naux,nvir_2*nvir_2)
Lov = Lov.reshape(naux,nocc,nvir_1)
if chnk_size < nocc:
#Lov_temp = np.ascontiguousarray(Lov.T[:,p:p+chnk_size,:].reshape(-1,naux))
Lov_temp = np.ascontiguousarray(Lov.transpose(1,2,0)[p:p+chnk_size].reshape(-1,naux))
else:
Lov_temp = np.ascontiguousarray(Lov.transpose(1,2,0).reshape(-1,naux))
ovvv = np.dot(Lov_temp, Lvv)
ovvv = ovvv.reshape(-1, nvir_1, nvir_2, nvir_2)
#vvvv = np.ascontiguousarray(vvvv.transpose(0,2,1,3)).reshape(-1, nvir, nvir * nvir)
return ovvv
def get_vvvv_df(myadc, Lvv, p, chnk_size):
''' Returns approximate vvvv integrals used in restricted implementation'''
nvir = myadc._nvir
naux = myadc.with_df.get_naoaux()
if myadc.if_naf:
naux = myadc.naux
Lvv = Lvv.reshape(naux,nvir,nvir)
if chnk_size < nvir:
Lvv_temp = np.ascontiguousarray(Lvv.T[p:p+chnk_size].reshape(-1,naux))
else:
Lvv_temp = np.ascontiguousarray(Lvv.T.reshape(-1,naux))
Lvv = Lvv.reshape(naux,nvir*nvir)
vvvv = np.dot(Lvv_temp, Lvv)
vvvv = vvvv.reshape(-1, nvir, nvir, nvir)
vvvv = vvvv.transpose(0,2,1,3).reshape(-1, nvir, nvir, nvir)
vvvv = np.ascontiguousarray(vvvv)
return vvvv
def get_vvvv_antisym_df(myadc, Lvv, p, chnk_size, pack = True):
''' Returns approximate antisymmetrized vvvv integrals (alpha/beta spin) used in unrestricted implementation'''
naux = myadc.with_df.get_naoaux()
if myadc.if_naf:
naux = myadc.naux
nvir = Lvv.shape[1]
ind_vv_g = np.tril_indices(nvir, k=-1)
if chnk_size < nvir:
Lvv_temp = np.ascontiguousarray(Lvv.T[p:p+chnk_size].reshape(-1,naux))
else:
Lvv_temp = np.ascontiguousarray(Lvv.T.reshape(-1,naux))
Lvv = Lvv.reshape(naux,nvir*nvir)
vvvv = np.dot(Lvv_temp, Lvv)
vvvv = vvvv.reshape(-1, nvir, nvir, nvir)
vvvv = vvvv.transpose(0,2,1,3)
vvvv -= vvvv.transpose(0,1,3,2)
if pack:
vvvv = np.ascontiguousarray(vvvv[:, :, ind_vv_g[0], ind_vv_g[1]])
else:
vvvv = np.ascontiguousarray(vvvv)
return vvvv
def get_vVvV_df(myadc, Lvv, LVV, p, chnk_size):
''' Returns approximate vvvv integrals (mixed spin) used in unrestricted implementation'''
naux = myadc.with_df.get_naoaux()
if myadc.if_naf:
naux = myadc.naux
nvir_1 = Lvv.shape[1]
nvir_2 = LVV.shape[1]
if chnk_size < nvir_1:
Lvv_temp = np.ascontiguousarray(Lvv.T[p:p+chnk_size].reshape(-1,naux))
else:
Lvv_temp = np.ascontiguousarray(Lvv.T.reshape(-1,naux))
LVV = LVV.reshape(naux,nvir_2*nvir_2)
vvvv = np.dot(Lvv_temp, LVV)
vvvv = vvvv.reshape(-1,nvir_1,nvir_2,nvir_2)
vvvv = vvvv.transpose(0,2,1,3)
vvvv = np.ascontiguousarray(vvvv)
return vvvv