psi4 / psi4numpy

Combining Psi4 and Numpy for education and development.
BSD 3-Clause "New" or "Revised" License
330 stars 151 forks source link

Correct nalpha/nbeta mixup #114

Closed JonathonMisiewicz closed 3 years ago

JonathonMisiewicz commented 3 years ago

Description

Closes #113, a correctness bug in the SOUHF implementation. Alpha and beta orbitals are now treated consistently.

Status

JonathonMisiewicz commented 3 years ago

I give the iterations for the default molecule below. The tl:dr version is that the old and new code agree about the final energy to 13 decimals. My interpretation is that because the alpha and beta orbitals had been swapped everywhere, all quantities labeled alpha were actually beta, and vice versa. For example:

Ca, Da = diag_H(H, nbeta)
Cb, Db = diag_H(H, nalpha)

That code saves the beta orbitals and density to Ca, Da, so the next code passes the correct beta orbitals and also the correct alpha orbitals to the JK object

J, K = scf_helper.compute_jk(jk, [Ca[:, :nbeta], Cb[:, :nalpha]])

Iterations Pre-Change:

SCF Iteration   1: Energy = -140.1011012598234515   dE = -1.40101E+02   dRMS = 8.41852E-02
SCF Iteration   2: Energy = -136.6373083541924984   dE =  3.46379E+00   dRMS = 8.24159E-02
SCF Iteration   3: Energy = -149.2687286507880060   dE = -1.26314E+01   dRMS = 1.98253E-02
SCF Iteration   4: Energy = -149.6214174921378230   dE = -3.52689E-01   dRMS = 4.26925E-03
SCF Iteration   5: Energy = -149.6420068413705167   dE = -2.05893E-02   dRMS = 8.18715E-04
Micro Iteration  1: Rel. RMS = 4.40025e-01 (a: 4.26e-01, b: 4.54e-01)
Micro Iteration  2: Rel. RMS = 1.38885e-01 (a: 1.36e-01, b: 1.42e-01)
Micro Iteration  3: Rel. RMS = 5.68683e-02 (a: 5.80e-02, b: 5.57e-02)
Micro Iteration  4: Rel. RMS = 3.09422e-02 (a: 2.94e-02, b: 3.24e-02)
SCF Iteration   6: Energy = -149.6432314200488918   dE = -1.22458E-03   dRMS = 5.66405E-06
Micro Iteration  1: Rel. RMS = 1.02526e-01 (a: 2.49e-01, b: 2.96e-01)
Micro Iteration  2: Rel. RMS = 6.30125e-02 (a: 1.48e-01, b: 1.89e-01)
Micro Iteration  3: Rel. RMS = 2.62997e-02 (a: 5.85e-02, b: 8.30e-02)
SCF Iteration   7: Energy = -149.6432314819751355   dE = -6.19262E-08   dRMS = 2.58127E-08
Micro Iteration  1: Rel. RMS = 7.42264e-03 (a: 3.21e-01, b: 2.57e-01)
SCF Iteration   8: Energy = -149.6432314819761586   dE = -1.02318E-12   dRMS = 2.11731E-09
Total time for SCF iterations: 0.157 seconds 

Spin Contamination Metric: 4.55302E-02

Final SCF energy: -149.64323148 hartree
    SCF Energy............................................................................PASSED

Iterations Post-Change:

SCF Iteration   1: Energy = -140.1011012598234515   dE = -1.40101E+02   dRMS = 8.41852E-02
SCF Iteration   2: Energy = -136.6373083541924984   dE =  3.46379E+00   dRMS = 8.24159E-02
SCF Iteration   3: Energy = -149.2687286507879776   dE = -1.26314E+01   dRMS = 1.98253E-02
SCF Iteration   4: Energy = -149.6214174921378230   dE = -3.52689E-01   dRMS = 4.26925E-03
SCF Iteration   5: Energy = -149.6420068413705167   dE = -2.05893E-02   dRMS = 8.18715E-04
Micro Iteration  1: Rel. RMS = 4.40025e-01 (a: 4.54e-01, b: 4.26e-01)
Micro Iteration  2: Rel. RMS = 1.38885e-01 (a: 1.42e-01, b: 1.36e-01)
Micro Iteration  3: Rel. RMS = 5.68683e-02 (a: 5.57e-02, b: 5.80e-02)
Micro Iteration  4: Rel. RMS = 3.09422e-02 (a: 3.24e-02, b: 2.94e-02)
SCF Iteration   6: Energy = -149.6432314200488918   dE = -1.22458E-03   dRMS = 5.66405E-06
Micro Iteration  1: Rel. RMS = 1.02526e-01 (a: 2.96e-01, b: 2.49e-01)
Micro Iteration  2: Rel. RMS = 6.30125e-02 (a: 1.89e-01, b: 1.48e-01)
Micro Iteration  3: Rel. RMS = 2.62997e-02 (a: 8.30e-02, b: 5.85e-02)
SCF Iteration   7: Energy = -149.6432314819751923   dE = -6.19263E-08   dRMS = 2.58127E-08
Micro Iteration  1: Rel. RMS = 7.42264e-03 (a: 2.57e-01, b: 3.21e-01)
SCF Iteration   8: Energy = -149.6432314819761871   dE = -9.94760E-13   dRMS = 2.11731E-09
Total time for SCF iterations: 0.165 seconds 

Spin Contamination Metric: 4.55302E-02

Final SCF energy: -149.64323148 hartree
    SCF Energy............................................................................PASSED
dgasmith commented 3 years ago

Well, at least I screwed up consistently.

Thanks again for cleaning this up!