1
1
import sys
2
+ import warnings
2
3
import numpy
3
4
import scipy
4
5
import pyscf
7
8
8
9
def hcore (mol , * _ ):
9
10
"""Uses the diagonalization of the core to compute the guess Hamiltonian.
10
-
11
+
11
12
Args:
12
13
mol (pyscf Mole): pyscf Mole object.
13
-
14
+
14
15
Returns:
15
16
A numpy ndarray containing the computed approximate Hamiltonian.
16
17
"""
@@ -19,14 +20,14 @@ def hcore(mol, *_):
19
20
return h
20
21
21
22
def GWH (mol , * _ ):
22
- """Uses the generalized Wolfsberg-Helmholtz to compute the guess Hamiltonian.
23
-
24
- Args:
25
- mol (pyscf Mole): pyscf Mole object.
26
-
27
- Returns:
28
- A numpy ndarray containing the computed approximate Hamiltonian.
29
- """
23
+ """Uses the generalized Wolfsberg-Helmholtz to compute the guess Hamiltonian.
24
+
25
+ Args:
26
+ mol (pyscf Mole): pyscf Mole object.
27
+
28
+ Returns:
29
+ A numpy ndarray containing the computed approximate Hamiltonian.
30
+ """
30
31
h = hcore (mol )
31
32
S = mol .intor_symmetric ('int1e_ovlp' )
32
33
K = 1.75 # See J. Chem. Phys. 1952, 20, 837
@@ -41,11 +42,11 @@ def GWH(mol, *_):
41
42
42
43
def SAD (mol , func ):
43
44
"""Uses the superposition of atomic densities to compute the guess Hamiltonian.
44
-
45
+
45
46
Args:
46
47
mol (pyscf Mole): pyscf Mole object.
47
48
func (str): Exchange-correlation functional.
48
-
49
+
49
50
Returns:
50
51
A numpy ndarray containing the computed approximate Hamiltonian.
51
52
"""
@@ -59,10 +60,10 @@ def SAD(mol, func):
59
60
60
61
def SAP (mol , * _ ):
61
62
"""Uses the superposition of atomic potentials to compute the guess Hamiltonian.
62
-
63
+
63
64
Args:
64
65
mol (pyscf Mole): pyscf Mole object.
65
-
66
+
66
67
Returns:
67
68
A numpy ndarray containing the computed approximate Hamiltonian.
68
69
"""
@@ -74,29 +75,29 @@ def SAP(mol, *_):
74
75
75
76
def LB (mol , * _ ):
76
77
"""Uses the Laikov-Briling model with HF-based parameters to compute the guess Hamiltonian.
77
-
78
+
78
79
Args:
79
80
mol (pyscf Mole): pyscf Mole object.
80
-
81
+
81
82
Returns:
82
83
A numpy ndarray containing the computed approximate Hamiltonian.
83
84
"""
84
85
return LB20 (parameters = 'HF' ).Heff (mol )
85
86
86
87
def LB_HFS (mol , * _ ):
87
88
""" Laikov-Briling using HFS-based parameters
88
-
89
+
89
90
Args:
90
91
mol (pyscf Mole): pyscf Mole object.
91
-
92
+
92
93
Returns:
93
94
A numpy ndarray containing the computed approximate Hamiltonian.
94
95
"""
95
96
return LB20 (parameters = 'HFS' ).Heff (mol )
96
97
97
98
def solveF (mol , fock ):
98
99
"""Computes the eigenvalues and eigenvectors corresponding to the given Hamiltonian.
99
-
100
+
100
101
Args:
101
102
mol (pyscf Mole): pyscf Mole object.
102
103
fock (numpy ndarray): Approximate Hamiltonian.
@@ -106,10 +107,10 @@ def solveF(mol, fock):
106
107
107
108
def get_guess (arg ):
108
109
"""Returns the function of the method selected to compute the approximate hamiltoninan
109
-
110
+
110
111
Args:
111
112
arg (str): Approximate Hamiltonian
112
-
113
+
113
114
Returns:
114
115
The function of the selected method.
115
116
"""
@@ -120,17 +121,29 @@ def get_guess(arg):
120
121
exit (1 )
121
122
return guesses [arg ]
122
123
124
+
125
+ def check_nelec (nelec , nao ):
126
+ """ Checks if there is enough orbitals
127
+ for the electrons"""
128
+ if numpy .any (numpy .array (nelec ) > nao ):
129
+ raise RuntimeError (f'Too many electrons ({ nelec } ) for { nao } orbitals' )
130
+ elif numpy .any (numpy .array (nelec ) == nao ):
131
+ msg = f'{ nelec } electrons for { nao } orbitals. Is the input intended to have a complete shell?'
132
+ warnings .warn (msg )
133
+
134
+
123
135
def get_occ (e , nelec , spin ):
124
- """Computes the occupancy.
125
-
136
+ """Returns the occupied subset of e
137
+
126
138
Args:
127
139
e (numpy ndarray): Energy eigenvalues.
128
140
nelec(tuple): Number of alpha and beta electrons.
129
141
spin(int): Spin.
130
-
142
+
131
143
Returns:
132
- A numpy ndarray containing the occupancy .
144
+ A numpy ndarray containing the occupied eigenvalues .
133
145
"""
146
+ check_nelec (nelec , e .shape [0 ])
134
147
if spin == None :
135
148
nocc = nelec [0 ]
136
149
return e [:nocc ,...]
@@ -141,17 +154,20 @@ def get_occ(e, nelec, spin):
141
154
e1 [1 ,:nocc [1 ],...] = e [:nocc [1 ],...]
142
155
return e1
143
156
157
+
144
158
def get_dm (v , nelec , spin ):
145
159
"""Computes the density matrix.
146
-
160
+
147
161
Args:
148
162
v (numpy ndarray): Eigenvectors of a previously solve Hamiltoinan.
149
163
nelec(tuple): Number of alpha and beta electrons.
150
164
spin(int): Spin.
151
-
165
+
152
166
Return:
153
167
A numpy ndarray containing the density matrix computed using the guess Hamiltonian.
154
168
"""
169
+
170
+ check_nelec (nelec , len (v ))
155
171
if spin == None :
156
172
nocc = nelec [0 ]
157
173
dm = v [:,:nocc ] @ v [:,:nocc ].T
0 commit comments