Skip to content
Snippets Groups Projects
Commit b74277c0 authored by moritz.buchhorn's avatar moritz.buchhorn
Browse files

Small changes

parent b780462b
No related branches found
No related tags found
1 merge request!2Week2
%% Cell type:markdown id: tags:
# B.CTC: SCF
In diesem Notebook werden wir einen auf das Nötigste reduzierten SCF-Code verwenden, um einen Einblick in die einzelnen Iterationen zu gewinnen.
%% Cell type:code id: tags:
``` python
import scf
import numpy as np
from pyscf import gto
import plotly.graph_objects as go
```
%% Cell type:code id: tags:
``` python
# To build such a molecule object, specific information is required, which is defined in the following code line. (In this oversimplified case, only the molecular coordinates and the basis set are used.) With this information, PySCF can now calculate the individual system-dependent parameters.
coordinates='''
C 0.00 0.00 0.00
O 0.00 1.54 0.00
O 0.00 -1.54 0.00
'''
# To build such a molecule object, specific information is required, which is defined in the following code line. (In this oversimplified case, only the molecular coordinates and the basis set are used.) With this information, PySCF can now calculate the individual system-dependent parameters.
mol = gto.M(atom=coordinates, basis='sto-3g')
# nuclei-nuclei potential
E_nuc = mol.energy_nuc()
# number of atomic orbitals
NAO = mol.nao
# number of electrons
NEL = mol.nelectron
# overlap integrals
S= mol.intor('int1e_ovlp')
S = mol.intor('int1e_ovlp')
# kinetic energy integrals
T_e = mol.intor('int1e_kin')
# electrons-nuclei potential energy integrals
V_ne = mol.intor('int1e_nuc')
# two electron Coulomb integrals
J = mol.intor('int2e')
Hc = scf.build_hc(T_e, V_ne)
X = scf.build_ortho_mat(S)
finished_scf = scf.scf(Hc,X,J, E_nuc, NAO, NEL)
```
%% Cell type:code id: tags:
``` python
fig = go.Figure()
fig.add_trace(go.Scatter(
x = list(range(finished_scf["iterations"])),
y = finished_scf["tot_energies"],
))
fig.show()
```
%% Cell type:code id: tags:
``` python
fig = go.Figure()
orb_eigenvalues = finished_scf["orb_eigenvalues"].T
for i in range(len(orb_eigenvalues)):
fig.add_trace(go.Scatter(
x = list(range(finished_scf["iterations"])),
y = orb_eigenvalues[i],
))
fig.show()
```
%% Cell type:code id: tags:
``` python
np.set_printoptions(suppress=True, precision=2)
[print(("{:6.2f}"*len(line)).format(*line)) for line in finished_scf["coefficients"][-1].T]
# finished_scf["coefficients"][70].T
```
......
#!/usr/bin/env python
# coding: utf-8
from pyscf import gto
import numpy as np
......@@ -89,6 +88,8 @@ def scf(Hc: np.array, X: np.array, J: np.array, E_nuc: float, NAO: int, NEL: int
this_scf = {
"tot_energies": [E_tot_0],
"orb_eigenvalues": [e_0],
"coefficients": [C_0],
"iterations": 0
}
# SCF loop
......@@ -101,13 +102,14 @@ def scf(Hc: np.array, X: np.array, J: np.array, E_nuc: float, NAO: int, NEL: int
e, C = solve_eigenvalue(Fp, X)
P = build_density(C, NAO, NEL)
E_el = electronic_energy(P, Hc, F, NAO)
E_tot = E_el + E_nuc
this_scf["tot_energies"].append(E_tot)
this_scf["orb_eigenvalues"].append(e)
this_scf["coefficients"].append(C)
if np.abs(E_el-E_el_0)<delta_E:
print("E_el converged after: "+str(i)+" Iterations.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment