import hsfcf
import numpy as np
def SCF (r = 1.4632, Z=[1,1], b1 = hsfcf.GTO["H"], b2 = hsfcf.GTO["H"], b = 3):
R = [0, r] # ΠΠ°Π΄Π°Π΅ΠΌ ΡΠ΅Π½ΡΡΡ Π°ΡΠΎΠΌΠΎΠ²
s_scf = hsfcf.S(R, b1, b2, b) # ΠΠ΅Π½Π΅ΡΠ°ΡΠΈΡ ΠΌΠ°ΡΡΠΈΡΡ ΠΏΠ΅ΡΠ΅ΠΊΡΡΠ²Π°Π½ΠΈΡ S
h_scf = hsfcf.H(R, Z, b1, b2, b) # ΠΠ΅Π½Π΅ΡΠ°ΡΠΈΡ Π³Π°ΠΌΠΈΠ»ΡΡΠΎΠ½ΠΈΠ°Π½Π° H Π΄Π»Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΎΡΠ° Π€ΠΎΠΊΠ° (core-Hamiltonian operator)
X = hsfcf.diagon(m=s_scf) # ΠΠΈΠ°Π³ΠΎΠ½Π°Π»ΠΈΠ·ΠΈΡΠΎΠ²Π°Π½Π½Π°Ρ ΠΌΠ°ΡΡΠΈΡΡ S
Xa = X.getH() # ΡΡΠ°Π½ΡΠΏΠΎΠ½ΠΈΡΠΎΠ²Π°Π½Π½Π°Ρ ΠΌΠ°ΡΡΠΈΡΠ°
p_scf = np.matrix([[0,0],[0,0]], dtype=np.float64) # ΠΌΠ°ΡΡΠΈΡΠ° ΠΏΠ»ΠΎΡΠ½ΠΎΡΡΠΈ P
for iteracion in range(50): # ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° ΡΡ
ΠΎΠ΄ΠΈΠΌΠΎΡΡΠΈ SCF ΠΈΡΠ΅ΡΠ°ΡΠΈΡΠΌΠΈ (Π·Π°ΠΏΠΎΠ»Π½ΡΠ΅ΠΌ ΠΌΠ°ΡΡΠΈΡΡ F, Π΄ΠΈΠ°Π³ΠΎΠ½Π°Π»ΠΈΠ·ΠΈΡΡΠ΅ΠΌ, ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ ΡΠ°Π·Π½ΠΈΡΡ)
# Π Π°ΡΡΠ΅Ρ Π΄Π²ΡΡ
ΡΠ»Π΅ΠΊΡΡΠΎΠ½Π½ΠΎΠΉ ΡΠ°ΡΡΠΈ ΠΌΠ°ΡΡΠΈΡΡ Π€ΠΎΠΊΠ° (G)
# ΠΠ΅Π½Π΅ΡΠ°ΡΠΈΡ ΠΌΠ°ΡΡΠΈΡΡ Π€ΠΎΠΊΠ°: F = H + G
g_scf = hsfcf.G(r, p_scf, b1, b2, b)
f_scf = h_scf + g_scf
# Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΌΠ°ΡΡΠΈΡΡ F' = X_adj * F * X
f_tra = Xa * f_scf * X
# ΠΠΈΠ°Π³ΠΎΠ½Π°Π»ΠΈΠ·Π°ΡΠΈΡ F' ΠΈ Π³Π΅Π½Π΅ΡΠ°ΡΠΈΡ C'
c_tra = hsfcf.diagon2(m=f_tra)
# ΠΠΎΡΡΡΠΎΠ΅Π½ΠΈΠ΅ ΠΌΠ°ΡΡΠΈΡΡ ΠΊΠΎΡΡΡΠΈΡΠΈΠ΅Π½ΡΠΎΠ² C C = X * C'
c_scf = X * c_tra
# ΠΠ· ΠΌΠ°ΡΡΠΈΡΡ C ΡΡΡΠΎΠΈΠΌ ΠΌΠ°ΡΡΠΈΡΡ Π ΠΈ ΠΏΠ΅ΡΠ΅ΡΡΠΈΡΡΠ²Π°Π΅ΠΌ ΠΌΠ°ΡΡΠΈΡΡ ΠΏΠ»ΠΎΡΠ½ΠΎΡΡΠΈ P
p_temp = hsfcf.P(C=c_scf)
print("ΠΠΊΠΎΠ½ΡΠ΅Π½Π° " + str(iteracion + 1) + " ΠΈΡΠ΅ΡΠ°ΡΠΈΡ.\n")
# ΠΡΠΎΠ²Π΅ΡΠΊΠ° ΡΡ
ΠΎΠ΄ΠΈΠΌΠΎΡΡΠΈ
if np.linalg.norm(p_temp - p_scf) < 1E-4:
print("SCF ΡΠΎΡΠ»ΠΎΡΡ! Π£ΡΠ°!")
return {"S":s_scf,"H":h_scf,"X": X,"F":f_scf,"C":c_scf,"P":p_temp}
else:
p_scf = p_temp
print("SCF Π½Π΅ ΡΠΎΡΠ»ΠΎΡΡ. Π£ΠΏΡ...")
return {"S":s_scf,"H":h_scf,"X": X,"F":f_scf,"C":c_scf,"P":p_temp}