-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSCF.py
More file actions
191 lines (131 loc) · 4.97 KB
/
SCF.py
File metadata and controls
191 lines (131 loc) · 4.97 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""
SCF.py is a module that contains all of the functions
for the HF SCF Procedure
"""
import numpy as np
import scipy as sp
def calc_nuclear_repulsion_energy(mol_):
"""
calc_nuclear_repulsion_energy - calculates the n-e repulsion energy of a
molecule
Arguments:
mol_: the PySCF molecule data structure created from Input
Returns:
Enuc: The n-e repulsion energy
"""
charges = mol_.atom_charges()
coords = mol_.atom_coords()
Enuc = 0
distance_matrix = np.zeros((3, 3), dtype=np.double)
"""
Replace with your implementation
Step 1. calcuate (3x3) distance matrix between all atoms
Step 2. Loop over atoms and calculate Enuc from formulat in Readme
"""
return Enuc
def calc_initial_density(mol_):
"""
calc_initial_density - Function to calculate the initial guess density
Arguments
mol_: the PySCF molecule data structure created from Input
Returns:
Duv: the (mol.nao x mol.nao) Guess Density Matrix
"""
num_aos = mol_.nao # Number of atomic orbitals, dimensions of the mats
Duv = np.zeros((num_aos, num_aos), dtype=np.double)
return Duv
def calc_hcore_matrix(Tuv_, Vuv_):
"""
calc_hcore_matrix - Computes the 1 electron core matrix
Arguments:
Tuv_: The Kinetic Energy 1e integral matrix
Vuv_: The Nuclear Repulsion 1e integrals matrix
Returns:
h_core: The one electron hamiltonian matrix
"""
"""
Replace with your implementation
Per the readme, this is a simple addition of the two matrices
"""
return h_core
def calc_fock_matrix(mol_, h_core_, er_ints_, Duv_):
"""
calc_fock_matrix - Calculates the Fock Matrix of the molecule
Arguments:
mol_: the PySCF molecule data structure created from Input
h_core_: the one electron hamiltonian matrix
er_ints_: the 2e electron repulsion integrals
Duv_: the density matrix
Returns:
Fuv: The fock matrix
"""
Fuv = h_core_.copy() # Takes care of the Huv part of the fock matrix
num_aos = mol_.nao # Number of atomic orbitals, dimension of the mats
"""
Replace with your implementation
Here you will do the summation of the last two terms in the Fock matrix
equation involving the two electron Integrals
Hint: You can do this with explicit loops over matrix indices, whichwill
have many for loops.
This can also be done with numpy aggregations, bonus points if you
implement this with only two loops.
For example, the first term can be implemented like the following:
(er_ints[mu,nu]*Duv).sum()
"""
return Fuv
def solve_Roothan_equations(Fuv_, Suv_):
"""
solve_Roothan_equations - Solves the matrix equations to determine
the MO coefficients
Arguments:
Fuv_: The Fock matrix
Suv_: The overlap matrix
Returns:
mo_energies: an array that contains eigenvalues of the solution
mo_coefficients: a matrix of the eigenvectors of the solution
"""
"""
Replace with your implementation
The Roothan Equations, which are of the form FC=SCe can be solved
directly from the proper use of scipy.linalg.eigh since this is a
symmetric hermitian matrix. Take a look at the documentation for that
function and you can implement this in one line.
"""
return mo_energies.real, mo_coeffs.real
def form_density_matrix(mol_, mo_coeffs_):
"""
form_dentsity_matrix - forms the density matrix from the eigenvectors
Note: the loops are over the number of electrons / 2, not all of the
atomic orbitals
Arguments:
mol_: the PySCF molecule data structure created from Input
mo_coefficients: a matrix of the eigenvectors of the solution
Returns:
Duv: the density matrix
"""
nelec = mol_.nelec[0] # Number of occupied orbitals
num_aos = mol_.nao # Number of atomic orbitals, dimensions of the mats
Duv = np.zeros(mol_.nao, mol_.nao, dtype=np.double)
"""
Replace with your implementation
This involves basically a computation of each density matrix element
that is a sum over the produces of the mo_coeffs.
"""
return Duv
def calc_total_energy(Fuv_, Huv_, Duv_, Enuc_):
"""
calc_total_energy - This function calculates the total energy of the
molecular system
Arguments:
Fuv_: the current Fock Matrix
Huv_: the core Hamiltonian Matrix
Duv_: the Density Matrix that corresponds to Fuv_
Enuc: the Nuclear Repulsion Energy
Returns:
Etot: the total energy of the molecule
"""
"""
Replace with your implementation
Should be able to implement this in one line with matrix arithmatic
"""
return Etot