Skip to content

Conversation

@edinvay
Copy link
Contributor

@edinvay edinvay commented Jan 9, 2026

DO NOT MERGE!

Currently, Mrchem is completely missing necessary infrastructure for a possibility of encoding non-SCF algorithms.
Therefore, the branch cannot be merged.

@gitpeterwind gitpeterwind added the WIP Work in progress label Jan 10, 2026
@ilfreddy
Copy link
Contributor

Please change the content of the comments, especially those containing unacceptable language, or remove this pull request. And add a meaningful explanation about what this pull request is doing.

This commit consolidates the development of real-valued L2 and H1 inner
products for OrbitalVector objects, implements gradient and preconditioning
machinery, and resolves discrepancies caused by differing Laplacian
conventions between MRCPP and MRChem.

no control over SCF?

I am about to modify the code

added euclidian gradient

added calculation of grad_E

comments and small fixes

grad can be computed now

set convention R(- \Delta, \lambda) = (- \Delta - \lambda)^(-1)

different conventions give the difference norm(grad_E - grad_E1) equaled approximately 10^(-6)

removed some printing and added check of the convergence of A to 4 Fock matrix

implemented preconditioning (without projection yet), TODO: project preconditioned grad_E
…t descent direction, skip preconditioning and then polak_ribiere momentum
… too low!?

===========================================================================
                                 Molecule
---------------------------------------------------------------------------
 Charge                  :                                               0
 Multiplicity            :                                               1
---------------------------------------------------------------------------
    N    Atom            :               x               y               z
---------------------------------------------------------------------------
    0       N            :       -1.037000        0.000000        0.000000
    1       N            :        1.037000        0.000000        0.000000
---------------------------------------------------------------------------
 Center of mass          :        0.000000        0.000000        0.000000
===========================================================================

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.269858176166         -1.082699e+02
--------------------------------------
norm(grad_E1) = 3.366493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.556167e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.102398e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.090289e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 1.864618e+00
--------------------------------------
Candidate Energy: -1.088907e+02
    1          1.440613e-01        -108.962388822011         -6.925306e-01
--------------------------------------
norm(grad_E1) = 8.705625e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.940525e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.387195e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.386583e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 3.421696e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.090336e+02
    2          4.312143e-02        -108.989055109792         -2.666629e-02
--------------------------------------
norm(grad_E1) = 2.085578e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.047025e-01
--------------------------------------
norm(preconditioned_grad_E) = 4.596835e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.586699e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.082851e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089864e+02
    3          1.707873e-02        -108.992299615197         -3.244505e-03
--------------------------------------
norm(grad_E1) = 1.678439e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.986398e-02
--------------------------------------
norm(preconditioned_grad_E) = 2.020410e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.018604e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 5.198068e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 4 (reason: powell)
Candidate Energy: -1.089906e+02
    4          7.687970e-03        -108.992930200435         -6.305852e-04
--------------------------------------
norm(grad_E1) = 5.095197e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.459597e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.085534e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.084000e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.448169e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089904e+02
    5          4.018083e-03        -108.993096234392         -1.660340e-04
--------------------------------------
norm(grad_E1) = 5.151056e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.202816e-02
--------------------------------------
norm(preconditioned_grad_E) = 7.129098e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.121459e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.640985e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089924e+02
    6          2.240271e-03        -108.993154249813         -5.801542e-05
--------------------------------------
norm(grad_E1) = 2.587876e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.206727e-03
--------------------------------------
norm(preconditioned_grad_E) = 5.640131e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.635313e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.133404e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089924e+02
    7          1.400137e-03        -108.993179234465         -2.498465e-05
--------------------------------------
norm(grad_E1) = 1.954818e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.832087e-03
--------------------------------------
norm(preconditioned_grad_E) = 5.009678e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.007266e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 9.285995e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089929e+02
    8          9.198816e-04        -108.993191385654         -1.215119e-05
Right now I tried a mixture of SCF and gradient descent and the convergence is super fast, even though I believe momentum is not used due to safeguards:
previous_preconditioned_grad_E = preconditioned_grad_E;
        previous_grad_E = grad_E;
        previous_h1_inner_product_preconditioned_grad_E_grad_E = h1_inner_product_preconditioned_grad_E_grad_E;

        // Backtracking line search
        OrbitalVector Phi_backup = orbital::deep_copy(Phi_n);
        auto alpha_trial = alpha;
        int count = 0;
        while (true) {
            count += 1;
            // Retraction to Stiefel is Lowdin based:
            Phi_n = orbital::add(1.0, Phi_n, alpha_trial, direction);
            // Orthonormalization updates F_mat as a side effect?!
            orbital::orthonormalize(orb_prec, Phi_n, F_mat);
            // Compute Fock matrix and energy
            F.setup(orb_prec);
            //F_mat = F(Phi_candidate, Phi_candidate);
            E_n = F.trace(Phi_n, nucs);
            std::cout << "Candidate Energy: " << E_n.getTotalEnergy() << std::endl;

            break;
        }
        F.clear();

        // Orthonormalize
        orbital::orthonormalize(orb_prec, Phi_np1, F_mat);

        // Compute orbital updates
        OrbitalVector dPhi_n = orbital::add(1.0, Phi_np1, -1.0, Phi_n);
        Phi_np1.clear();

        kain.accelerate(orb_prec, Phi_n, dPhi_n);

        // Compute errors
        errors = orbital::get_norms(dPhi_n);
        err_o = errors.maxCoeff();
        err_t = errors.norm();
        json_cycle["mo_residual"] = err_t;

        // Update orbitals
        Phi_n = orbital::add(1.0, Phi_n, 1.0, dPhi_n);
        dPhi_n.clear();

        orbital::orthonormalize(orb_prec, Phi_n, F_mat);

        // Compute Fock matrix and energy
        if (F.getReactionOperator() != nullptr) F.getReactionOperator()->updateMOResidual(err_t);
        F.setup(orb_prec);
        F_mat = F(Phi_n, Phi_n);
        E_n = F.trace(Phi_n, nucs);

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          1.000000e+00          -1.121259148073         -1.121259e+00
--------------------------------------
norm(grad_E1) = 7.719170e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.494689e-02
--------------------------------------
norm(preconditioned_grad_E) = 9.804705e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 9.804312e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.011383e-01
--------------------------------------
Candidate Energy: -1.133043e+00
    1          3.792117e-03          -1.133123908006         -1.186476e-02
--------------------------------------
norm(grad_E1) = 1.917471e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.864444e-03
--------------------------------------
norm(preconditioned_grad_E) = 1.881873e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.881804e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 3.923942e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133585e+00
    2          3.867796e-04          -1.133586516442         -4.626084e-04
--------------------------------------
norm(grad_E1) = 5.582126e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.257129e-03
--------------------------------------
norm(preconditioned_grad_E) = 5.069788e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.069613e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.064044e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133619e+00
    3          9.951053e-05          -1.133619598704         -3.308226e-05
---------------------------------------------------------------------------
                      SCF converged in 3 iterations!
===========================================================================

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Calculation             : Optimize ground state orbitals
 Method                  : Hartree-Fock
 Relativity              : None
 Environment             : None
 External fields         : None
 Checkpointing           : Off
 Max iterations          : 100
 KAIN solver             : 2
 Localization            : Off
 Diagonalization         : First two iterations
 Start precision         : 1.00000e-05
 Final precision         : 1.00000e-05
 Helmholtz precision     : Dynamic
 Energy threshold        : Off
 Orbital threshold       : 1.00000e-04
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          1.414214e+00          -3.488804061639         -3.488804e+00
--------------------------------------
norm(grad_E1) = 1.754826e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.083659e-01
--------------------------------------
norm(preconditioned_grad_E) = 2.502909e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.499467e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 5.142178e-01
--------------------------------------
Candidate Energy: -3.569972e+00
    1          9.265506e-03          -3.571745971143         -8.294191e-02
--------------------------------------
norm(grad_E1) = 6.052763e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.075909e-01
--------------------------------------
norm(preconditioned_grad_E) = 7.418470e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.402491e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.556673e-01
--------------------------------------
Polak-Ribière coefficient = 3.509740e-01
Powell/guarded restart at iteration_index 2 (reason: non-descent)
Candidate Energy: -3.579551e+00
    2          3.740434e-03          -3.579987286195         -8.241315e-03
--------------------------------------
norm(grad_E1) = 2.349168e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.357616e-02
--------------------------------------
norm(preconditioned_grad_E) = 2.794234e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.788182e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 5.978327e-02
--------------------------------------
Polak-Ribière coefficient = 5.071773e-01
Powell/guarded restart at iteration_index 3 (reason: non-descent)
Candidate Energy: -3.581171e+00
    3          1.767353e-03          -3.581256403291         -1.269117e-03
--------------------------------------
norm(grad_E1) = 1.091247e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.897994e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.204128e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.201640e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.680655e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -3.581492e+00
    4          7.516380e-03          -3.581584173003         -3.277697e-04
--------------------------------------
norm(grad_E1) = 2.447794e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.682823e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.248966e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.247974e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 6.230738e-03
--------------------------------------
Polak-Ribière coefficient = 1.188284e-01
Candidate Energy: -3.581594e+00
    5          3.773203e-03          -3.581573485709          1.068729e-05
--------------------------------------
norm(grad_E1) = 3.144394e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.504452e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.218417e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.213509e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 7.504617e-03
--------------------------------------
Polak-Ribière coefficient = 9.238694e-01
Candidate Energy: -3.581593e+00
    6          1.727671e-03          -3.581594976597         -2.149089e-05
--------------------------------------
norm(grad_E1) = 1.172736e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.029809e-03
--------------------------------------
norm(preconditioned_grad_E) = 1.732954e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.732462e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.692733e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -3.581597e+00
    7          8.498797e-05          -3.581597557830         -2.581233e-06
---------------------------------------------------------------------------
                      SCF converged in 7 iterations!
===========================================================================

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Calculation             : Optimize ground state orbitals
 Method                  : Hartree-Fock
 Relativity              : None
 Environment             : None
 External fields         : None
 Checkpointing           : Off
 Max iterations          : 100
 KAIN solver             : Off
 Localization            : First two iterations
 Diagonalization         : Off
 Start precision         : 1.00000e-05
 Final precision         : 1.00000e-05
 Helmholtz precision     : Dynamic
 Energy threshold        : Off
 Orbital threshold       : 1.00000e-04
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.270488550253         -1.082705e+02
--------------------------------------
norm(grad_E1) = 3.366493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.553354e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.096259e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.085628e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 1.864618e+00
--------------------------------------
Candidate Energy: -1.089529e+02
    1          3.367737e-02        -108.962388975031         -6.919004e-01
--------------------------------------
norm(grad_E1) = 8.702999e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.940034e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.366614e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.365918e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 3.421521e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089884e+02
    2          8.127645e-03        -108.989055314844         -2.666634e-02
--------------------------------------
norm(grad_E1) = 2.085843e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.046874e-01
--------------------------------------
norm(preconditioned_grad_E) = 4.622894e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.613665e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.082957e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089922e+02
    3          3.984630e-03        -108.992299858263         -3.244543e-03
--------------------------------------
norm(grad_E1) = 1.679433e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.987745e-02
--------------------------------------
norm(preconditioned_grad_E) = 2.018051e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.015936e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 5.198964e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 4 (reason: powell)
Candidate Energy: -1.089929e+02
    4          1.898684e-03        -108.992930338156         -6.304799e-04
--------------------------------------
norm(grad_E1) = 5.097738e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.460940e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.093198e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.091746e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.448299e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089931e+02
    5          9.077491e-04        -108.993096310587         -1.659724e-04
--------------------------------------
norm(grad_E1) = 5.154629e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.203310e-02
--------------------------------------
norm(preconditioned_grad_E) = 7.146047e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.138526e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.641093e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089931e+02
    6          5.867431e-04        -108.993154291951         -5.798136e-05
--------------------------------------
norm(grad_E1) = 2.589677e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.209788e-03
--------------------------------------
norm(preconditioned_grad_E) = 5.634977e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.630323e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.133353e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089932e+02
    7          3.572462e-04        -108.993179258041         -2.496609e-05
--------------------------------------
norm(grad_E1) = 1.956215e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.831309e-03
--------------------------------------
norm(preconditioned_grad_E) = 5.044651e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.042196e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 9.285553e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089932e+02
    8          2.327558e-04        -108.993191397949         -1.213991e-05
--------------------------------------
norm(grad_E1) = 1.282277e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.494770e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.683340e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.681946e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 8.117428e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 9 (reason: powell)
Candidate Energy: -1.089932e+02
    9          1.662764e-04        -108.993197685706         -6.287757e-06
--------------------------------------
norm(grad_E1) = 8.719163e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.488482e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.488589e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.487812e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 7.502971e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089932e+02
   10          1.093957e-04        -108.993201050154         -3.364447e-06
---------------------------------------------------------------------------
                      SCF converged in 10 iterations!
===========================================================================

I would be nice to understand this mixture: can we trust it?

Phi_np1 is computed via SCF procedure before I evaluate the gradient attached to the previous point Phi_n. Then I do steepest gradient descent, write it down to the reference Phi_n. The rest is continuation of SCF (since I did not modify the next part of the main loop): // Compute orbital updates OrbitalVector dPhi_n = orbital::add(1.0, Phi_np1, -1.0, Phi_n); so the update is Phi_np1 - Phi_n, where Phi_np1 = SCF(Phi_n) and Phi_n = RSGD(Phi_n) This mixture update is added to Phi_n, that is Phi_n = RSGD(Phi_n). So it actually looks, as if RSGD(Phi_n) just goes away when we sum the update and RSGD(Phi_n).
…hem (since the update was calculated with respect to grad_descent(Phi_n) which is closer to Phi_np1, obviously ).

It is fixed, and now the algorithm runs the gradient descent with Polyak momentum.
TODO: implement backtracking.

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.269569447381         -1.082696e+02
--------------------------------------
norm(grad_E1) = 3.366493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.554898e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.074317e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.062482e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 1.864618e+00
--------------------------------------
Candidate Energy: -1.089553e+02
    1          1.479554e-01        -108.955302310206         -6.857329e-01
--------------------------------------
norm(grad_E1) = 3.847288e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.943881e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.607459e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.577367e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 6.495689e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089825e+02
    2          6.589890e-02        -108.982522280053         -2.721997e-02
--------------------------------------
norm(grad_E1) = 2.695767e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 9.156072e-01
--------------------------------------
norm(preconditioned_grad_E) = 9.880053e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 9.319314e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 5.229221e-01
--------------------------------------
Polak-Ribière coefficient = 6.358710e-01
Candidate Energy: -1.089877e+02
    3          5.074700e-02        -108.987721846526         -5.199566e-03
--------------------------------------
norm(grad_E1) = 1.204399e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.095241e-01
--------------------------------------
norm(preconditioned_grad_E) = 6.469757e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 6.369373e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.406470e-01
--------------------------------------
Polak-Ribière coefficient = 3.545491e-01
Candidate Energy: -1.089894e+02
    4          2.169312e-02        -108.989388796046         -1.666950e-03
--------------------------------------
norm(grad_E1) = 1.192711e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.684731e-01
--------------------------------------
norm(preconditioned_grad_E) = 5.092511e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.883805e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.490397e-01
--------------------------------------
Polak-Ribière coefficient = 5.487224e-01
Candidate Energy: -1.089922e+02
    5          1.637716e-02        -108.992234964227         -2.846168e-03
--------------------------------------
norm(grad_E1) = 6.214460e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.469943e-01
--------------------------------------
norm(preconditioned_grad_E) = 2.490651e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.447566e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.223012e-01
--------------------------------------
Polak-Ribière coefficient = 6.693553e-02
Candidate Energy: -1.089930e+02
    6          1.242580e-02        -108.992957303318         -7.223391e-04
--------------------------------------
norm(grad_E1) = 3.944082e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.323873e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.485547e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.443356e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 6.987706e-02
--------------------------------------
Polak-Ribière coefficient = 4.994435e-01
Candidate Energy: -1.089931e+02
    7          7.883258e-03        -108.993105525576         -1.482223e-04
--------------------------------------
norm(grad_E1) = 2.070515e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.830372e-02
--------------------------------------
norm(preconditioned_grad_E) = 8.971594e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.915037e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 4.091528e-02
--------------------------------------
Polak-Ribière coefficient = 3.632810e-01
Candidate Energy: -1.089931e+02
    8          4.084053e-03        -108.993140876078         -3.535050e-05
--------------------------------------
norm(grad_E1) = 2.117388e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.397777e-02
--------------------------------------
norm(preconditioned_grad_E) = 7.143143e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 6.970010e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.458931e-02
--------------------------------------
Polak-Ribière coefficient = 4.606847e-01
Candidate Energy: -1.089932e+02
    9          3.020994e-03        -108.993178304520         -3.742844e-05
--------------------------------------
norm(grad_E1) = 1.257209e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.614856e-02
--------------------------------------
norm(preconditioned_grad_E) = 5.659481e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.642521e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.995531e-02
--------------------------------------
Polak-Ribière coefficient = 3.156476e-01
Candidate Energy: -1.089932e+02
   10          2.626662e-03        -108.993189089864         -1.078534e-05
--------------------------------------
norm(grad_E1) = 1.567098e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.825169e-02
--------------------------------------
norm(preconditioned_grad_E) = 4.565195e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.526100e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.139635e-02
--------------------------------------
Polak-Ribière coefficient = 7.588397e-01
Candidate Energy: -1.089932e+02
   11          1.674401e-03        -108.993189569908         -4.800442e-07
--------------------------------------
norm(grad_E1) = 1.224565e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.094875e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.794847e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.783433e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.762663e-02
--------------------------------------
Polak-Ribière coefficient = 3.332226e-01
Powell/guarded restart at iteration_index 12 (reason: powell)
Candidate Energy: -1.089932e+02
   12          2.295812e-03        -108.993195933330         -6.363421e-06
--------------------------------------
norm(grad_E1) = 8.808236e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.730822e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.548132e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.540505e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.461170e-02
--------------------------------------
Polak-Ribière coefficient = 9.301819e-01
Candidate Energy: -1.089932e+02
   13          1.402526e-03        -108.993193713704          2.219626e-06
--------------------------------------
norm(grad_E1) = 6.469799e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.526138e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.411906e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.396633e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.414325e-02
--------------------------------------
Polak-Ribière coefficient = 3.253397e-01
Candidate Energy: -1.089932e+02
   14          1.456153e-03        -108.993198408556         -4.694852e-06
--------------------------------------
norm(grad_E1) = 4.375865e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.606203e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.898210e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.892488e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.010303e-02
--------------------------------------
Polak-Ribière coefficient = 4.238893e-01
Candidate Energy: -1.089932e+02
   15          9.774299e-04        -108.993199800077         -1.391522e-06
--------------------------------------
norm(grad_E1) = 4.005792e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.898873e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.753063e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.746128e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 8.840622e-03
--------------------------------------
Polak-Ribière coefficient = 2.816766e-01
Candidate Energy: -1.089932e+02
   16          8.113870e-04        -108.993200469839         -6.697614e-07
--------------------------------------
norm(grad_E1) = 3.634696e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.313325e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.663682e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.660230e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 7.662043e-03
--------------------------------------
Polak-Ribière coefficient = 3.601268e-01
Powell/guarded restart at iteration_index 17 (reason: powell)
Candidate Energy: -1.089932e+02
   17          8.622326e-04        -108.993200158540          3.112986e-07
--------------------------------------
norm(grad_E1) = 4.947285e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.531641e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.829889e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.825657e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 8.631665e-03
--------------------------------------
Polak-Ribière coefficient = 5.996202e-01
Candidate Energy: -1.089932e+02
   18          8.061123e-04        -108.993200783598         -6.250578e-07
--------------------------------------
norm(grad_E1) = 3.271958e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.114456e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.657085e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.655698e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 7.283467e-03
--------------------------------------
Polak-Ribière coefficient = 3.221624e-01
Candidate Energy: -1.089932e+02
   19          6.267200e-04        -108.993200854030         -7.043246e-08
--------------------------------------
norm(grad_E1) = 3.100696e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.145344e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.700800e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.698877e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 7.001818e-03
--------------------------------------
Polak-Ribière coefficient = 3.345680e-01
Candidate Energy: -1.089932e+02
   20          5.436140e-04        -108.993200420083          4.339468e-07
--------------------------------------
norm(grad_E1) = 2.398148e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.996617e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.001535e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.999307e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 6.868232e-03
--------------------------------------
Polak-Ribière coefficient = 4.245575e-01
Candidate Energy: -1.089932e+02
   21          4.078736e-04        -108.993198643394          1.776690e-06
--------------------------------------
norm(grad_E1) = 1.593271e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.588745e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.333969e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.332174e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 7.280274e-03
--------------------------------------
Polak-Ribière coefficient = 8.664518e-01
Powell/guarded restart at iteration_index 22 (reason: powell)
Candidate Energy: -1.089932e+02
   22          5.130719e-04        -108.993196432611          2.210782e-06
TODO: move  F.clear(); somewhere inside of the backtracking loop and fix the problem this move is causing:
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133623e+00
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
update: 1.529064e-04 (step size = 1.000000e+00)
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
Error: apply(), line 63: Uninitialized operator
    6          1.529064e-04          -1.133622724325         -1.249997e-07

WARNING: The latter could be done, likely, by computing all the nessesary H1-inner products before entering the backtracking loop.

Otherwise, the algorithm produces reasonable results:

WARNING: There is a difference between update and MO residual, provided the molecule has more than 2 electrons.
         Why does this happend?

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          1.000000e+00          -1.121259148073         -1.121259e+00
--------------------------------------
norm(grad_E1) = 7.719170e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.494689e-02
--------------------------------------
norm(preconditioned_grad_E) = 9.804705e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 9.804312e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.011383e-01
--------------------------------------
Candidate Energy: -1.133043e+00
update: 3.577833e-02 (step size = 1.000000e+00)
    1          3.577833e-02          -1.133043149745         -1.178400e-02
--------------------------------------
norm(grad_E1) = 2.152317e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.065050e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.994583e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.994405e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 4.177150e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133570e+00
update: 9.864078e-03 (step size = 1.000000e+00)
    2          9.864078e-03          -1.133570490434         -5.273407e-04
--------------------------------------
norm(grad_E1) = 6.885801e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.296594e-03
--------------------------------------
norm(preconditioned_grad_E) = 5.838411e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.837626e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.232555e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133616e+00
update: 3.145509e-03 (step size = 1.000000e+00)
    3          3.145509e-03          -1.133616374354         -4.588392e-05
--------------------------------------
norm(grad_E1) = 2.364265e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.856565e-03
--------------------------------------
norm(preconditioned_grad_E) = 2.303092e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.302790e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 4.800344e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 4 (reason: powell)
Candidate Energy: -1.133622e+00
update: 1.079008e-03 (step size = 1.000000e+00)
    4          1.079008e-03          -1.133621826990         -5.452636e-06
--------------------------------------
norm(grad_E1) = 8.641672e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.122543e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.433174e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.433094e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.908502e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133623e+00
update: 3.947317e-04 (step size = 1.000000e+00)
    5          3.947317e-04          -1.133622599326         -7.723354e-07
--------------------------------------
norm(grad_E1) = 3.340931e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.559445e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.268195e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.268179e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.543555e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133623e+00
update: 1.529064e-04 (step size = 1.000000e+00)
    6          1.529064e-04          -1.133622724325         -1.249997e-07
--------------------------------------
norm(grad_E1) = 1.350562e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.558561e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.239968e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.239965e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.481127e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.133623e+00
Precision is achieved inside line search at iteration_index = 7
    7          6.191395e-05          -1.133622746180         -2.185525e-08
---------------------------------------------------------------------------
                      SCF converged in 7 iterations!
===========================================================================

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          1.414214e+00          -3.488804061639         -3.488804e+00
--------------------------------------
norm(grad_E1) = 1.754826e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.083659e-01
--------------------------------------
norm(preconditioned_grad_E) = 2.502909e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.499467e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 5.142178e-01
--------------------------------------
Candidate Energy: -3.569972e+00
update: 1.074611e-01 (step size = 1.000000e+00)
    1          1.246000e-01          -3.569971941787         -8.116788e-02
--------------------------------------
norm(grad_E1) = 6.441079e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.271097e-01
--------------------------------------
norm(preconditioned_grad_E) = 7.895014e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.875516e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.660001e-01
--------------------------------------
Polak-Ribière coefficient = 3.754599e-01
Powell/guarded restart at iteration_index 2 (reason: non-descent)
Candidate Energy: -3.578960e+00
update: 3.618460e-02 (step size = 1.000000e+00)
    2          4.277635e-02          -3.578960281682         -8.988340e-03
--------------------------------------
norm(grad_E1) = 2.896750e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.781201e-02
--------------------------------------
norm(preconditioned_grad_E) = 3.438895e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.428819e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 7.429348e-02
--------------------------------------
Polak-Ribière coefficient = 6.151170e-01
Powell/guarded restart at iteration_index 3 (reason: non-descent)
Candidate Energy: -3.581218e+00
update: 1.925415e-02 (step size = 1.400000e+00)
    3          2.416199e-02          -3.581218429045         -2.258147e-03
--------------------------------------
norm(grad_E1) = 9.751692e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.548415e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.186562e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.183249e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.629240e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -3.581522e+00
update: 5.053329e-03 (step size = 1.400000e+00)
    4          6.797610e-03          -3.581521882109         -3.034531e-04
--------------------------------------
norm(grad_E1) = 4.715239e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.113911e-02
--------------------------------------
norm(preconditioned_grad_E) = 5.319663e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.304058e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.195992e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -3.581594e+00
update: 3.332074e-03 (step size = 1.960000e+00)
    5          4.347294e-03          -3.581593806624         -7.192451e-05
--------------------------------------
norm(grad_E1) = 1.283946e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.466355e-03
--------------------------------------
norm(preconditioned_grad_E) = 1.827515e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.825037e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.901037e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -3.581598e+00
update: 8.710196e-04 (step size = 1.960000e+00)
    6          1.191361e-03          -3.581597847120         -4.040496e-06
--------------------------------------
norm(grad_E1) = 3.380339e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.579829e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.817511e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.817349e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.552292e-03
--------------------------------------
Polak-Ribière coefficient = 3.306023e-01
Candidate Energy: -3.581598e+00
update: 5.214281e-04 (step size = 1.960000e+00)
    7          6.773147e-04          -3.581598028042         -1.809218e-07
--------------------------------------
norm(grad_E1) = 2.281824e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.401058e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.782207e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.782118e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.467297e-03
--------------------------------------
Polak-Ribière coefficient = 3.781103e-02
Powell/guarded restart at iteration_index 8 (reason: powell)
Candidate Energy: -3.581598e+00
update: 1.667434e-04 (step size = 1.960000e+00)
    8          2.268054e-04          -3.581598161368         -1.333256e-07
--------------------------------------
norm(grad_E1) = 6.129916e-05
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.203689e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.790778e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.790772e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.475273e-03
--------------------------------------
Polak-Ribière coefficient = 1.124366e-02
Candidate Energy: -3.581598e+00
Precision is achieved inside line search at iteration_index = 9
    9          5.377371e-05          -3.581598186125         -2.475760e-08
---------------------------------------------------------------------------
                      SCF converged in 9 iterations!
===========================================================================

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.269858135840         -1.082699e+02
--------------------------------------
norm(grad_E1) = 3.366493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.556167e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.066363e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.055610e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 1.864618e+00
--------------------------------------
Candidate Energy: -1.089514e+02
update: 6.610847e-02 (step size = 1.000000e+00)
    1          1.504364e-01        -108.951433989118         -6.815759e-01
--------------------------------------
norm(grad_E1) = 4.362018e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.614407e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.712984e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.672812e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 8.270964e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089790e+02
update: 4.009396e-02 (step size = 1.000000e+00)
    2          7.628516e-02        -108.978982990193         -2.754900e-02
--------------------------------------
norm(grad_E1) = 4.108391e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.144419e+00
--------------------------------------
norm(preconditioned_grad_E) = 1.119793e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.038896e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 6.657785e-01
--------------------------------------
Polak-Ribière coefficient = 8.482698e-01
Candidate Energy: -1.089769e+02
Error: setupInternal(), line 144: Exchange not properly cleared
Candidate Energy: -1.090025e+02
update: 1.475477e-02 (step size = 5.000000e-01)
    3          2.987554e-02        -108.983423286065         -4.440296e-03
--------------------------------------
norm(grad_E1) = 3.109682e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 9.489923e-01
--------------------------------------
norm(preconditioned_grad_E) = 9.202427e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.464515e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 5.843213e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 4 (reason: powell)
Candidate Energy: -1.089912e+02
update: 1.751395e-02 (step size = 7.000000e-01)
    4          3.624992e-02        -108.991239951660         -7.816666e-03
--------------------------------------
norm(grad_E1) = 1.433189e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.544179e-01
--------------------------------------
norm(preconditioned_grad_E) = 3.677516e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.467413e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.180608e-01
--------------------------------------
Polak-Ribière coefficient = 4.083161e-01
Candidate Energy: -1.089916e+02
update: 5.283514e-03 (step size = 7.000000e-01)
    5          1.015818e-02        -108.991588232887         -3.482812e-04
--------------------------------------
norm(grad_E1) = 1.270847e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.218436e-01
--------------------------------------
norm(preconditioned_grad_E) = 3.694578e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.400963e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.387598e-01
--------------------------------------
Polak-Ribière coefficient = 1.788828e-01
Candidate Energy: -1.089928e+02
update: 7.423186e-03 (step size = 7.000000e-01)
    6          1.500638e-02        -108.992828069293         -1.239836e-03
--------------------------------------
norm(grad_E1) = 5.471612e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.382420e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.542698e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.451416e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 9.678810e-02
--------------------------------------
Polak-Ribière coefficient = 4.356812e-01
Candidate Energy: -1.089929e+02
update: 3.461197e-03 (step size = 7.000000e-01)
    7          5.542874e-03        -108.992856413831         -2.834454e-05
--------------------------------------
norm(grad_E1) = 6.084478e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.779050e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.807939e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.663359e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.160469e-01
--------------------------------------
Polak-Ribière coefficient = 5.028477e-01
Candidate Energy: -1.089931e+02
update: 5.579799e-03 (step size = 7.000000e-01)
    8          7.796768e-03        -108.993118780881         -2.623671e-04
--------------------------------------
norm(grad_E1) = 3.076078e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.863346e-02
--------------------------------------
norm(preconditioned_grad_E) = 8.869554e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.488848e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 5.013986e-02
--------------------------------------
Polak-Ribière coefficient = 4.701155e-01
Candidate Energy: -1.089931e+02
update: 1.575834e-03 (step size = 7.000000e-01)
    9          3.034280e-03        -108.993122729619         -3.948738e-06
--------------------------------------
norm(grad_E1) = 2.534145e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.243516e-02
--------------------------------------
norm(preconditioned_grad_E) = 9.906547e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 9.346897e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 5.195502e-02
--------------------------------------
Polak-Ribière coefficient = 4.489728e-01
Powell/guarded restart at iteration_index 10 (reason: powell)
Candidate Energy: -1.089932e+02
update: 2.248146e-03 (step size = 7.000000e-01)
   10          4.128492e-03        -108.993179090498         -5.636088e-05
--------------------------------------
norm(grad_E1) = 1.725758e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.340857e-02
--------------------------------------
norm(preconditioned_grad_E) = 5.320302e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.102866e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.927091e-02
--------------------------------------
Polak-Ribière coefficient = 6.136444e-01
Candidate Energy: -1.089932e+02
Error: setupInternal(), line 144: Exchange not properly cleared
Candidate Energy: -1.089928e+02
Error: setupInternal(), line 144: Exchange not properly cleared
Candidate Energy: -1.089927e+02
Error: setupInternal(), line 144: Exchange not properly cleared
It computes all the nessesary H1-inner products before entering the backtracking loop.

TODO: Reduce the amount of H1-inner products, since we have repetitions.

WARNING: There is a difference between update and MO residual, provided the molecule has more than 2 electrons.
         Why does this happend?

The algorithm works.

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.269580559548         -1.082696e+02
--------------------------------------
norm(grad_E1) = 3.366493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.554835e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.063311e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.052659e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 1.864618e+00
--------------------------------------
Descent directional H1-inner product: -1.307104e+00
Candidate Energy: -1.089514e+02
update: 6.903137e-02 (step size = 1.000000e+00)
    1          1.495674e-01        -108.951387378237         -6.818068e-01
--------------------------------------
norm(grad_E1) = 4.275736e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.340633e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.695690e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.655655e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 8.069306e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -7.992043e-02
Candidate Energy: -1.089782e+02
update: 3.950068e-02 (step size = 1.000000e+00)
    2          7.355680e-02        -108.978220786023         -2.683341e-02
--------------------------------------
norm(grad_E1) = 4.094094e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.137305e+00
--------------------------------------
norm(preconditioned_grad_E) = 1.141935e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.061179e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 6.767001e-01
--------------------------------------
Polak-Ribière coefficient = 9.029250e-01
Descent directional H1-inner product: -1.989164e-02
Candidate Energy: -1.089755e+02
Candidate Energy: -1.089825e+02
update: 1.506708e-02 (step size = 5.000000e-01)
    3          2.999008e-02        -108.982494548364         -4.273762e-03
--------------------------------------
norm(grad_E1) = 3.283696e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 9.767331e-01
--------------------------------------
norm(preconditioned_grad_E) = 9.982993e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 9.223493e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 6.134913e-01
--------------------------------------
Polak-Ribière coefficient = 7.207114e-03
Powell/guarded restart at iteration_index 4 (reason: powell)
Descent directional H1-inner product: -3.452045e-02
Candidate Energy: -1.089918e+02
update: 1.164892e-02 (step size = 5.000000e-01)
    4          2.858415e-02        -108.991819827031         -9.325279e-03
--------------------------------------
norm(grad_E1) = 3.489606e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.024515e-01
--------------------------------------
norm(preconditioned_grad_E) = 2.674080e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.663133e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 8.954980e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -1.749085e-03
Candidate Energy: -1.089925e+02
update: 3.052657e-03 (step size = 5.000000e-01)
    5          5.748032e-03        -108.992512602895         -6.927759e-04
--------------------------------------
norm(grad_E1) = 1.564060e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.198574e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.748761e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.746369e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 4.949483e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -7.015176e-04
Candidate Energy: -1.089929e+02
update: 2.630623e-03 (step size = 7.000000e-01)
    6          4.783095e-03        -108.992889847714         -3.772448e-04
--------------------------------------
norm(grad_E1) = 7.992284e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.002379e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.101714e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.100572e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.779723e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -2.591948e-04
Candidate Energy: -1.089931e+02
update: 2.260068e-03 (step size = 9.800000e-01)
    7          3.853757e-03        -108.993073491103         -1.836434e-04
--------------------------------------
norm(grad_E1) = 3.810932e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.486177e-02
--------------------------------------
norm(preconditioned_grad_E) = 7.106216e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.098264e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.558528e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -9.627896e-05
Candidate Energy: -1.089932e+02
update: 1.680785e-03 (step size = 1.372000e+00)
    8          2.901951e-03        -108.993157031473         -8.354037e-05
--------------------------------------
norm(grad_E1) = 3.992984e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.082437e-02
--------------------------------------
norm(preconditioned_grad_E) = 4.968839e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.962999e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.080207e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 9 (reason: powell)
Descent directional H1-inner product: -4.074366e-05
Candidate Energy: -1.089932e+02
update: 7.169047e-04 (step size = 1.372000e+00)
    9          1.431501e-03        -108.993183350892         -2.631942e-05
--------------------------------------
norm(grad_E1) = 3.503560e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.563484e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.261954e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.253277e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 8.594771e-03
--------------------------------------
Polak-Ribière coefficient = 6.091757e-03
Descent directional H1-inner product: -2.634542e-05
Candidate Energy: -1.089932e+02
update: 6.287665e-04 (step size = 1.372000e+00)
   10          1.101138e-03        -108.993192320190         -8.969298e-06
--------------------------------------
norm(grad_E1) = 5.428045e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 9.043855e-03
--------------------------------------
norm(preconditioned_grad_E) = 4.111609e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.089943e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.001237e-02
--------------------------------------
Polak-Ribière coefficient = 3.696432e-01
Descent directional H1-inner product: -3.031467e-05
Candidate Energy: -1.089932e+02
update: 6.145565e-04 (step size = 1.372000e+00)
   11          1.215217e-03        -108.993197937855         -5.617665e-06
--------------------------------------
norm(grad_E1) = 4.551618e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 9.641346e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.938272e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.914520e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 9.599640e-03
--------------------------------------
Polak-Ribière coefficient = 4.992982e-01
Descent directional H1-inner product: -3.058956e-05
Candidate Energy: -1.089932e+02
update: 6.378605e-04 (step size = 1.372000e+00)
   12          1.243030e-03        -108.993199485535         -1.547680e-06
--------------------------------------
norm(grad_E1) = 4.423287e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.245745e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.956215e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.944772e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 8.677535e-03
--------------------------------------
Polak-Ribière coefficient = 5.970886e-01
Descent directional H1-inner product: -3.330540e-05
Candidate Energy: -1.089932e+02
Candidate Energy: -1.089932e+02
update: 3.988129e-04 (step size = 6.860000e-01)
   13          6.423889e-04        -108.993200932267         -1.446732e-06
--------------------------------------
norm(grad_E1) = 1.433797e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.975306e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.584088e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.581835e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 5.849550e-03
--------------------------------------
Polak-Ribière coefficient = 5.052187e-02
Powell/guarded restart at iteration_index 14 (reason: powell)
Descent directional H1-inner product: -1.514005e-05
Candidate Energy: -1.089932e+02
update: 1.069337e-04 (step size = 6.860000e-01)
   14          2.039519e-04        -108.993201173388         -2.411214e-07
--------------------------------------
norm(grad_E1) = 6.330527e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.496370e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.576803e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.576028e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 5.485308e-03
--------------------------------------
Polak-Ribière coefficient = 5.923642e-02
Descent directional H1-inner product: -1.556022e-05
Candidate Energy: -1.089932e+02
Precision is achieved inside line search at iteration_index = 15
   15          1.412832e-04        -108.993201193095         -1.970696e-08
---------------------------------------------------------------------------
                      SCF converged in 15 iterations!
===========================================================================

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          1.414214e+00          -3.488804061639         -3.488804e+00
--------------------------------------
norm(grad_E1) = 1.754826e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.083659e-01
--------------------------------------
norm(preconditioned_grad_E) = 2.502909e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.499467e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 5.142178e-01
--------------------------------------
Descent directional H1-inner product: -1.253436e-01
Candidate Energy: -3.569972e+00
update: 1.074611e-01 (step size = 1.000000e+00)
    1          1.246000e-01          -3.569971941787         -8.116788e-02
--------------------------------------
norm(grad_E1) = 6.441079e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.271097e-01
--------------------------------------
norm(preconditioned_grad_E) = 7.895014e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.875516e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.660001e-01
--------------------------------------
Polak-Ribière coefficient = 3.754599e-01
Powell/guarded restart at iteration_index 2 (reason: non-descent)
Descent directional H1-inner product: -1.268430e-02
Candidate Energy: -3.578960e+00
update: 3.618460e-02 (step size = 1.000000e+00)
    2          4.277635e-02          -3.578960281682         -8.988340e-03
--------------------------------------
norm(grad_E1) = 2.896750e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.781201e-02
--------------------------------------
norm(preconditioned_grad_E) = 3.438895e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.428819e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 7.429348e-02
--------------------------------------
Polak-Ribière coefficient = 6.151170e-01
Powell/guarded restart at iteration_index 3 (reason: non-descent)
Descent directional H1-inner product: -2.481440e-03
Candidate Energy: -3.581218e+00
update: 1.925415e-02 (step size = 1.400000e+00)
    3          2.416199e-02          -3.581218429045         -2.258147e-03
--------------------------------------
norm(grad_E1) = 9.751692e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.548415e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.186562e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.183249e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.629240e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -3.059431e-04
Candidate Energy: -3.581522e+00
update: 5.053329e-03 (step size = 1.400000e+00)
    4          6.797610e-03          -3.581521882109         -3.034531e-04
--------------------------------------
norm(grad_E1) = 4.715239e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.113911e-02
--------------------------------------
norm(preconditioned_grad_E) = 5.319663e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.304058e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.195992e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -6.223704e-05
Candidate Energy: -3.581594e+00
update: 3.332074e-03 (step size = 1.960000e+00)
    5          4.347294e-03          -3.581593806624         -7.192451e-05
--------------------------------------
norm(grad_E1) = 1.283946e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.466355e-03
--------------------------------------
norm(preconditioned_grad_E) = 1.827515e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.825037e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.901037e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -6.957867e-06
Candidate Energy: -3.581598e+00
update: 8.710196e-04 (step size = 1.960000e+00)
    6          1.191361e-03          -3.581597847120         -4.040496e-06
--------------------------------------
norm(grad_E1) = 3.380339e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.579829e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.817511e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.817349e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.552292e-03
--------------------------------------
Polak-Ribière coefficient = 3.306023e-01
Descent directional H1-inner product: -7.568863e-06
Candidate Energy: -3.581598e+00
update: 5.214281e-04 (step size = 1.960000e+00)
    7          6.773147e-04          -3.581598028042         -1.809218e-07
--------------------------------------
norm(grad_E1) = 2.281824e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.401058e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.782207e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.782118e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.467297e-03
--------------------------------------
Polak-Ribière coefficient = 3.781103e-02
Powell/guarded restart at iteration_index 8 (reason: powell)
Descent directional H1-inner product: -5.992010e-06
Candidate Energy: -3.581598e+00
update: 1.667434e-04 (step size = 1.960000e+00)
    8          2.268054e-04          -3.581598161368         -1.333256e-07
--------------------------------------
norm(grad_E1) = 6.129916e-05
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.203689e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.790778e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.790772e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 3.475273e-03
--------------------------------------
Polak-Ribière coefficient = 1.124366e-02
Descent directional H1-inner product: -6.104314e-06
Candidate Energy: -3.581598e+00
Precision is achieved inside line search at iteration_index = 9
    9          5.377371e-05          -3.581598186125         -2.475760e-08
---------------------------------------------------------------------------
                      SCF converged in 9 iterations!
===========================================================================

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          1.000000e+00          -1.121259148073         -1.121259e+00
--------------------------------------
norm(grad_E1) = 7.719170e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.494689e-02
--------------------------------------
norm(preconditioned_grad_E) = 9.804705e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 9.804312e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.011383e-01
--------------------------------------
Descent directional H1-inner product: -1.970810e-02
Candidate Energy: -1.133043e+00
update: 3.577833e-02 (step size = 1.000000e+00)
    1          3.577833e-02          -1.133043149745         -1.178400e-02
--------------------------------------
norm(grad_E1) = 2.152317e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.065050e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.994583e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.994405e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 4.177150e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -8.323323e-04
Candidate Energy: -1.133570e+00
update: 9.864078e-03 (step size = 1.000000e+00)
    2          9.864078e-03          -1.133570490434         -5.273407e-04
--------------------------------------
norm(grad_E1) = 6.885801e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.296594e-03
--------------------------------------
norm(preconditioned_grad_E) = 5.838411e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.837626e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.232555e-02
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -7.188374e-05
Candidate Energy: -1.133616e+00
update: 3.145509e-03 (step size = 1.000000e+00)
    3          3.145509e-03          -1.133616374354         -4.588392e-05
--------------------------------------
norm(grad_E1) = 2.364265e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.856565e-03
--------------------------------------
norm(preconditioned_grad_E) = 2.303092e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.302790e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 4.800344e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 4 (reason: powell)
Descent directional H1-inner product: -1.104301e-05
Candidate Energy: -1.133622e+00
update: 1.079008e-03 (step size = 1.000000e+00)
    4          1.079008e-03          -1.133621826990         -5.452636e-06
--------------------------------------
norm(grad_E1) = 8.641672e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.122543e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.433174e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.433094e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.908502e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -4.165872e-06
Candidate Energy: -1.133623e+00
update: 3.947317e-04 (step size = 1.000000e+00)
    5          3.947317e-04          -1.133622599326         -7.723354e-07
--------------------------------------
norm(grad_E1) = 3.340931e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.559445e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.268195e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.268179e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.543555e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -3.225298e-06
Candidate Energy: -1.133623e+00
update: 1.529064e-04 (step size = 1.000000e+00)
    6          1.529064e-04          -1.133622724325         -1.249997e-07
--------------------------------------
norm(grad_E1) = 1.350562e-04
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.558561e-04
--------------------------------------
norm(preconditioned_grad_E) = 1.239968e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.239965e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.481127e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Descent directional H1-inner product: -3.076448e-06
Candidate Energy: -1.133623e+00
Precision is achieved inside line search at iteration_index = 7
    7          6.191395e-05          -1.133622746180         -2.185525e-08
---------------------------------------------------------------------------
                      SCF converged in 7 iterations!
===========================================================================
===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.269928842464         -1.082699e+02
--------------------------------------
norm(grad_E1) = 3.366493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.552659e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.060775e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.050150e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 1.864618e+00
--------------------------------------
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -1.306518e+00
Descent directional H1-inner product: -1.306518e+00
=============================================================
Candidate Energy: -1.089516e+02
update: 6.660031e-02 (step size = 1.000000e+00)
    1          1.488470e-01        -108.951583774233         -6.816549e-01
--------------------------------------
norm(grad_E1) = 4.205152e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.118930e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.649006e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.612702e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 7.880396e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -7.571984e-02
Descent directional H1-inner product: -7.571984e-02
=============================================================
Candidate Energy: -1.089802e+02
update: 3.401848e-02 (step size = 1.000000e+00)
    2          6.887889e-02        -108.980168585933         -2.858481e-02
--------------------------------------
norm(grad_E1) = 3.794982e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.033541e+00
--------------------------------------
norm(preconditioned_grad_E) = 1.044058e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 9.741397e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 5.986145e-01
--------------------------------------
Polak-Ribière coefficient = 7.184416e-01
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -2.304804e-02
Descent directional H1-inner product: -2.304804e-02
=============================================================
Candidate Energy: -1.089841e+02
update: 2.857572e-02 (step size = 1.000000e+00)
    3          5.800685e-02        -108.984083964658         -3.915379e-03
--------------------------------------
norm(grad_E1) = 2.340493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.531497e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.172395e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.878385e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 4.068627e-01
--------------------------------------
Polak-Ribière coefficient = 2.822775e-01
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -1.524878e-02
Descent directional H1-inner product: -1.524878e-02
=============================================================
Candidate Energy: -1.089871e+02
update: 1.385453e-02 (step size = 1.000000e+00)
    4          3.255557e-02        -108.987098334917         -3.014370e-03
--------------------------------------
norm(grad_E1) = 1.909765e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.679617e-01
--------------------------------------
norm(preconditioned_grad_E) = 7.231717e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 6.847560e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 3.782083e-01
--------------------------------------
Polak-Ribière coefficient = 1.051522e+00
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -6.632889e-03
Descent directional H1-inner product: -6.632889e-03
=============================================================
Candidate Energy: -1.089877e+02
update: 1.367638e-02 (step size = 1.000000e+00)
    5          2.712613e-02        -108.987729875113         -6.315402e-04
--------------------------------------
norm(grad_E1) = 2.543790e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.520956e-01
--------------------------------------
norm(preconditioned_grad_E) = 6.761418e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 6.283433e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 4.189827e-01
--------------------------------------
Polak-Ribière coefficient = 3.446593e-01
Powell/guarded restart at iteration_index 6 (reason: powell)
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -1.549116e-02
Descent directional H1-inner product: -1.549116e-02
=============================================================
Candidate Energy: -1.089905e+02
update: 1.583921e-02 (step size = 1.000000e+00)
    6          3.234635e-02        -108.990548434265         -2.818559e-03
--------------------------------------
norm(grad_E1) = 2.071883e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.887184e-01
--------------------------------------
norm(preconditioned_grad_E) = 5.055794e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.547069e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 3.407497e-01
--------------------------------------
Polak-Ribière coefficient = 1.253690e+00
Powell/guarded restart at iteration_index 7 (reason: non-descent)
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -9.525183e-03
Descent directional H1-inner product: -9.525183e-03
=============================================================
Candidate Energy: -1.089909e+02
update: 1.474433e-02 (step size = 1.000000e+00)
    7          2.774868e-02        -108.990926275203         -3.778409e-04
--------------------------------------
norm(grad_E1) = 1.793689e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.965874e-01
--------------------------------------
norm(preconditioned_grad_E) = 4.579879e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.105506e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 3.205437e-01
--------------------------------------
Polak-Ribière coefficient = 1.755097e+00
Powell/guarded restart at iteration_index 8 (reason: non-descent)
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -8.047012e-03
Descent directional H1-inner product: -8.047012e-03
=============================================================
Candidate Energy: -1.089916e+02
update: 1.217039e-02 (step size = 1.000000e+00)
    8          2.515707e-02        -108.991589758450         -6.634832e-04
--------------------------------------
norm(grad_E1) = 1.499346e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.092637e-01
--------------------------------------
norm(preconditioned_grad_E) = 4.068301e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.655072e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.701478e-01
--------------------------------------
Polak-Ribière coefficient = 1.598762e+00
Powell/guarded restart at iteration_index 9 (reason: non-descent)
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -6.122159e-03
Descent directional H1-inner product: -6.122159e-03
=============================================================
Candidate Energy: -1.089917e+02
update: 1.102378e-02 (step size = 1.000000e+00)
    9          2.265949e-02        -108.991702395894         -1.126374e-04
--------------------------------------
norm(grad_E1) = 1.474502e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.929835e-01
--------------------------------------
norm(preconditioned_grad_E) = 3.907259e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.535956e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.699924e-01
--------------------------------------
Polak-Ribière coefficient = 1.874752e+00
Powell/guarded restart at iteration_index 10 (reason: non-descent)
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -5.656236e-03
Descent directional H1-inner product: -5.656236e-03
=============================================================
Candidate Energy: -1.089918e+02
update: 1.029474e-02 (step size = 1.000000e+00)
   10          2.292804e-02        -108.991788400248         -8.600435e-05
--------------------------------------
norm(grad_E1) = 1.355775e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.616531e-01
--------------------------------------
norm(preconditioned_grad_E) = 4.298525e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.030641e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 2.524292e-01
--------------------------------------
Polak-Ribière coefficient = 2.063845e+00
Powell/guarded restart at iteration_index 11 (reason: non-descent)
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -6.186133e-03
Descent directional H1-inner product: -6.186133e-03
=============================================================
Candidate Energy: -1.089910e+02
Candidate Energy: -1.089931e+02
update: 8.184726e-03 (step size = 5.000000e-01)
   11          1.463521e-02        -108.993128946680         -1.340546e-03
--------------------------------------
norm(grad_E1) = 4.599120e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.074116e-02
--------------------------------------
norm(preconditioned_grad_E) = 7.632063e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 7.387220e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 5.816697e-02
--------------------------------------
Polak-Ribière coefficient = 1.593943e-01
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -7.553466e-05
Descent directional H1-inner product: -7.553466e-05
=============================================================
Candidate Energy: -1.089931e+02
update: 1.033976e-03 (step size = 5.000000e-01)
   12          1.840435e-03        -108.993137391423         -8.444743e-06
--------------------------------------
norm(grad_E1) = 3.683119e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 6.126577e-02
--------------------------------------
norm(preconditioned_grad_E) = 8.808536e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.449431e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 5.451856e-02
--------------------------------------
Polak-Ribière coefficient = 3.780509e-01
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -2.429390e-04
Descent directional H1-inner product: -2.429390e-04
=============================================================
Candidate Energy: -1.089932e+02
update: 1.801440e-03 (step size = 5.000000e-01)
   13          3.160356e-03        -108.993191635339         -5.424392e-05
--------------------------------------
norm(grad_E1) = 1.321387e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.269498e-02
--------------------------------------
norm(preconditioned_grad_E) = 4.380209e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.302014e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.908706e-02
--------------------------------------
Polak-Ribière coefficient = 8.928890e-02
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -4.050204e-05
Descent directional H1-inner product: -4.050204e-05
=============================================================
Candidate Energy: -1.089932e+02
update: 5.363866e-04 (step size = 5.000000e-01)
   14          8.732521e-04        -108.993198757840         -7.122500e-06
--------------------------------------
norm(grad_E1) = 5.764028e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.124149e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.679877e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.675264e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 9.027523e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -1.811043e-05
Descent directional H1-inner product: -1.811043e-05
=============================================================
Candidate Energy: -1.089932e+02
update: 2.002269e-04 (step size = 5.000000e-01)
   15          3.833062e-04        -108.993200147970         -1.390130e-06
--------------------------------------
norm(grad_E1) = 1.866030e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.859815e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.583197e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.582407e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 6.181039e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 16 (reason: powell)
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -1.555456e-05
Descent directional H1-inner product: -1.555456e-05
=============================================================
Candidate Energy: -1.089932e+02
update: 1.505127e-04 (step size = 5.000000e-01)
   16          2.230325e-04        -108.993200732102         -5.841316e-07
--------------------------------------
norm(grad_E1) = 1.664202e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.405484e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.541186e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.540754e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 5.829836e-03
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
=============================================================
MUST BE THE SAME:
Descent directional H1-inner product: -1.489461e-05
Descent directional H1-inner product: -1.489461e-05
=============================================================
Candidate Energy: -1.089932e+02
Precision is achieved inside line search at iteration_index = 17
   17          1.473394e-04        -108.993201057903         -3.258013e-07
---------------------------------------------------------------------------
                      SCF converged in 17 iterations!
===========================================================================
…identified.

It is left to clean a bit the code.

WARNING: There is still a difference between update and MO residual, provided the molecule has more than 2 electrons.
         Why does this happend?

WARNING: Different runs for N2 molecule are not identical.
         Could be parallelization related?

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.270487404025         -1.082705e+02
--------------------------------------
norm(grad_E1) = 3.366493e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.553361e-01
--------------------------------------
norm(preconditioned_grad_E) = 8.100363e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 8.088078e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 1.864618e+00
--------------------------------------
Descent directional H1-inner product: -1.314760e+00
Candidate Energy: -1.089581e+02
update: 6.938764e-02 (step size = 1.000000e+00)
    1          1.472060e-01        -108.958091792121         -6.876044e-01
--------------------------------------
norm(grad_E1) = 2.764326e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.317091e-01
--------------------------------------
norm(preconditioned_grad_E) = 1.502855e-01
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.477018e-01
--------------------------------------
--------------------------------------
norm(grad_E) = 5.530943e-01
--------------------------------------
Polak-Ribière coefficient = 1.450836e-02
Descent directional H1-inner product: -5.747786e-02
Candidate Energy: -1.089855e+02
update: 3.138246e-02 (step size = 1.000000e+00)
    2          5.489076e-02        -108.985514311892         -2.742252e-02
--------------------------------------
norm(grad_E1) = 1.769811e-01
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.087432e-01
--------------------------------------
norm(preconditioned_grad_E) = 7.299533e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 6.905592e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 3.553270e-01
--------------------------------------
Polak-Ribière coefficient = 3.249523e-01
Descent directional H1-inner product: -1.499712e-02
Candidate Energy: -1.089914e+02
update: 2.032043e-02 (step size = 1.000000e+00)
    3          3.839633e-02        -108.991437881785         -5.923570e-03
--------------------------------------
norm(grad_E1) = 8.273076e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.034647e-01
--------------------------------------
norm(preconditioned_grad_E) = 3.272623e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.247190e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 1.476569e-01
--------------------------------------
Polak-Ribière coefficient = 2.880157e-01
=============================================================
MUST BE THE SAME:
1.585534e-02
1.585534e-02
=============================================================
Descent directional H1-inner product: -1.995168e-03
Candidate Energy: -1.089923e+02
update: 6.355835e-03 (step size = 1.000000e+00)
    4          1.313206e-02        -108.992336132823         -8.982510e-04
--------------------------------------
norm(grad_E1) = 4.415386e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.143986e-01
--------------------------------------
norm(preconditioned_grad_E) = 2.356529e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 2.301567e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 9.450855e-02
--------------------------------------
Polak-Ribière coefficient = 1.614717e-01
=============================================================
MUST BE THE SAME:
2.880090e-03
2.880090e-03
=============================================================
Powell/guarded restart at iteration_index 5 (reason: powell)
Descent directional H1-inner product: -1.438624e-03
Candidate Energy: -1.089930e+02
update: 5.592169e-03 (step size = 1.000000e+00)
    5          1.020354e-02        -108.992985513539         -6.493807e-04
--------------------------------------
norm(grad_E1) = 3.878081e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 9.837625e-02
--------------------------------------
norm(preconditioned_grad_E) = 1.275734e-02
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 1.207934e-02
--------------------------------------
--------------------------------------
norm(grad_E) = 6.610984e-02
--------------------------------------
Polak-Ribière coefficient = 4.135496e-01
Descent directional H1-inner product: -4.412770e-04
Candidate Energy: -1.089931e+02
update: 4.709531e-03 (step size = 1.000000e+00)
    6          6.776245e-03        -108.993145815139         -1.603016e-04
--------------------------------------
norm(grad_E1) = 1.034542e-02
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.201023e-02
--------------------------------------
norm(preconditioned_grad_E) = 6.512635e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 6.484377e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 2.018125e-02
--------------------------------------
Polak-Ribière coefficient = 2.373889e-01
Descent directional H1-inner product: -6.870893e-05
Candidate Energy: -1.089932e+02
update: 1.207235e-03 (step size = 1.000000e+00)
    7          2.248658e-03        -108.993171908432         -2.609329e-05
--------------------------------------
norm(grad_E1) = 9.603170e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.312428e-02
--------------------------------------
norm(preconditioned_grad_E) = 5.417717e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 5.343427e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.863479e-02
--------------------------------------
Polak-Ribière coefficient = 2.085172e-01
Descent directional H1-inner product: -6.409837e-05
Candidate Energy: -1.089932e+02
update: 1.096350e-03 (step size = 1.000000e+00)
    8          1.910293e-03        -108.993193376949         -2.146852e-05
--------------------------------------
norm(grad_E1) = 7.053862e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.501822e-02
--------------------------------------
norm(preconditioned_grad_E) = 4.164423e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 4.111559e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 1.316179e-02
--------------------------------------
Polak-Ribière coefficient = 3.089713e-01
Descent directional H1-inner product: -3.282019e-05
Candidate Energy: -1.089932e+02
update: 6.149843e-04 (step size = 1.000000e+00)
    9          1.168307e-03        -108.993199366711         -5.989761e-06
--------------------------------------
norm(grad_E1) = 2.229068e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.387060e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.734212e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.728725e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 6.560535e-03
--------------------------------------
Polak-Ribière coefficient = 1.328943e-01
=============================================================
MUST BE THE SAME:
2.833552e-05
2.833552e-05
=============================================================
Powell/guarded restart at iteration_index 10 (reason: powell)
Descent directional H1-inner product: -1.678701e-05
Candidate Energy: -1.089932e+02
update: 2.564358e-04 (step size = 1.000000e+00)
   10          4.517438e-04        -108.993200282558         -9.158476e-07
--------------------------------------
norm(grad_E1) = 2.196016e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.076009e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.725741e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.719156e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 6.312548e-03
--------------------------------------
Polak-Ribière coefficient = 1.952046e-01
Descent directional H1-inner product: -1.873781e-05
Candidate Energy: -1.089932e+02
update: 2.079925e-04 (step size = 1.000000e+00)
   11          3.776010e-04        -108.993200524881         -2.423227e-07
--------------------------------------
norm(grad_E1) = 1.618501e-03
--------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.613433e-03
--------------------------------------
norm(preconditioned_grad_E) = 3.708661e-03
--------------------------------------
--------------------------------------
norm(preconditioned_grad_E and projected) = 3.704449e-03
--------------------------------------
--------------------------------------
norm(grad_E) = 6.103645e-03
--------------------------------------
Polak-Ribière coefficient = 2.395824e-01
Descent directional H1-inner product: -1.940657e-05
Candidate Energy: -1.089932e+02
Candidate Energy: -1.089932e+02
Precision is achieved inside line search at iteration_index = 12
   12          1.461984e-04        -108.993200862967         -3.380860e-07
---------------------------------------------------------------------------
                      SCF converged in 12 iterations!
===========================================================================
The following tests FAILED:
	 25 - H_SCF_finite_electric_field (Failed)              electric_field h_el_field hf integration mrchem scf
	 26 - H2_SCF_HartreeFock (Failed)                       H2_SCF_HartreeFock energy h2_scf_hf hartree_fock integration mrchem scf
	 32 - Li_SCF_PBE0 (Failed)                              Li_SCF_PBE0 dft energy integration li_scf_pbe0 mrchem scf
	 34 - HF_molecular_gradient_LDA (Failed)                HF_molecular_gradient_LDA gradient hf_grad_lda integration mrchem
	 37 - H2_SCF_CUBE (Failed)                              cube_guess energy h2_scf_cube integration mrchem scf
	 41 - He_ZORA_SCF_LDA (Failed)                          He_ZORA_SCF_LDA energy he he_zora_scf_lda helium integration lda mrchem scf zora
	 42 - He_AZORA_SCF_LDA (Failed)                         He_AZORA_SCF_LDA azora energy he he_azora_scf_lda helium integration lda mrchem scf zora
	 43 - Ne_ZORA_SCF_PBE (Failed)                          Ne_ZORA_SCF_PBE energy integration mrchem ne ne_zora_scf_pbe neon pbe scf zora
Errors while running CTest
Output from these tests are in: /Users/edi011/Documents/Projects/git-repositories/mrchem/build/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
make: *** [test] Error 8

This 26 - H2_SCF_HartreeFock (Failed) is strange.
I do not see much of a difference with the reference.
Of course, I do not use KAIN.

Reference:
    3          8.741007e-03          -1.133775887261         -4.103856e-04
---------------------------------------------------------------------------
                      SCF converged in 3 iterations!
===========================================================================

Gradient Descent:
    4          5.060629e-03          -1.133781391155         -1.652565e-04
---------------------------------------------------------------------------
                      SCF converged in 4 iterations!
===========================================================================
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Calculation             : Optimize ground state orbitals
 Method                  : Hartree-Fock
 Relativity              : None
 Environment             : None
 External fields         : None
 Checkpointing           : Off
 Max iterations          : 100
 KAIN solver             : Off
 Localization            : First two iterations
 Diagonalization         : Off
 Start precision         : 1.00000e-05
 Final precision         : 1.00000e-05
 Helmholtz precision     : Dynamic
 Energy threshold        : Off
 Orbital threshold       : 1.00000e-04
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.269858110393         -1.082699e+02
norm(A_proj - 4 * F_mat.real()) = 8.556165e-01
--------------------------------------
norm(grad_E) = 1.856270e+00
--------------------------------------
Candidate Energy: -1.089578e+02
update: 6.818573e-02 (step size = 1.000000e+00)
    1          1.472751e-01        -108.957822592488         -6.879645e-01
norm(A_proj - 4 * F_mat.real()) = 5.181604e-01
--------------------------------------
norm(grad_E) = 5.424490e-01
--------------------------------------
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089855e+02
update: 2.885844e-02 (step size = 1.000000e+00)
    2          5.341173e-02        -108.985507988916         -2.768540e-02
norm(A_proj - 4 * F_mat.real()) = 7.227088e-01
--------------------------------------
norm(grad_E) = 3.553530e-01
--------------------------------------
Polak-Ribière coefficient = 2.930624e-01
Candidate Energy: -1.089918e+02
update: 1.929937e-02 (step size = 1.000000e+00)
    3          3.852659e-02        -108.991772400336         -6.264411e-03
norm(A_proj - 4 * F_mat.real()) = 1.038191e-01
--------------------------------------
norm(grad_E) = 1.481974e-01
--------------------------------------
Polak-Ribière coefficient = 3.319607e-01
Candidate Energy: -1.089923e+02
update: 8.034765e-03 (step size = 1.000000e+00)
    4          1.318605e-02        -108.992342448503         -5.700482e-04
norm(A_proj - 4 * F_mat.real()) = 9.904635e-02
--------------------------------------
norm(grad_E) = 8.723344e-02
--------------------------------------
Polak-Ribière coefficient = 2.107476e-01
Powell/guarded restart at iteration_index 5 (reason: powell)
Candidate Energy: -1.089930e+02
update: 5.463023e-03 (step size = 1.000000e+00)
    5          1.053572e-02        -108.993017176844         -6.747283e-04
norm(A_proj - 4 * F_mat.real()) = 7.544441e-02
--------------------------------------
norm(grad_E) = 5.837603e-02
--------------------------------------
Polak-Ribière coefficient = 2.987561e-01
Candidate Energy: -1.089932e+02
update: 3.457509e-03 (step size = 1.000000e+00)
    6          5.972786e-03        -108.993156726616         -1.395498e-04
norm(A_proj - 4 * F_mat.real()) = 1.989172e-02
--------------------------------------
norm(grad_E) = 1.940181e-02
--------------------------------------
Polak-Ribière coefficient = 3.275686e-01
Candidate Energy: -1.089932e+02
update: 1.223429e-03 (step size = 1.000000e+00)
    7          2.326441e-03        -108.993172530183         -1.580357e-05
norm(A_proj - 4 * F_mat.real()) = 2.617930e-02
--------------------------------------
norm(grad_E) = 1.781211e-02
--------------------------------------
Polak-Ribière coefficient = 3.537565e-01
Candidate Energy: -1.089932e+02
update: 9.739402e-04 (step size = 1.000000e+00)
    8          1.815748e-03        -108.993192540193         -2.001001e-05
norm(A_proj - 4 * F_mat.real()) = 1.267430e-02
--------------------------------------
norm(grad_E) = 1.172321e-02
--------------------------------------
Polak-Ribière coefficient = 2.532918e-01
Candidate Energy: -1.089932e+02
update: 7.216277e-04 (step size = 1.000000e+00)
    9          1.338923e-03        -108.993198428200         -5.888007e-06
norm(A_proj - 4 * F_mat.real()) = 5.396968e-03
--------------------------------------
norm(grad_E) = 7.896475e-03
--------------------------------------
Polak-Ribière coefficient = 2.628296e-01
Powell/guarded restart at iteration_index 10 (reason: powell)
Candidate Energy: -1.089932e+02
update: 5.258331e-04 (step size = 1.000000e+00)
   10          7.812204e-04        -108.993199594959         -1.166759e-06
norm(A_proj - 4 * F_mat.real()) = 4.725900e-03
--------------------------------------
norm(grad_E) = 6.581432e-03
--------------------------------------
Polak-Ribière coefficient = 2.804497e-01
Candidate Energy: -1.089932e+02
update: 2.418666e-04 (step size = 1.000000e+00)
   11          4.298756e-04        -108.993200257937         -6.629771e-07
norm(A_proj - 4 * F_mat.real()) = 2.650957e-03
--------------------------------------
norm(grad_E) = 5.525865e-03
--------------------------------------
Polak-Ribière coefficient = 1.342689e-01
Candidate Energy: -1.089932e+02
update: 1.520457e-04 (step size = 1.000000e+00)
   12          2.660700e-04        -108.993200286851         -2.891431e-08
norm(A_proj - 4 * F_mat.real()) = 1.878348e-03
--------------------------------------
norm(grad_E) = 5.429640e-03
--------------------------------------
Polak-Ribière coefficient = 2.295852e-01
Candidate Energy: -1.089932e+02
Candidate Energy: -1.089932e+02
Precision is achieved inside line search at iteration_index = 13
   13          1.416109e-04        -108.993200516887         -2.300357e-07
---------------------------------------------------------------------------
                      SCF converged in 13 iterations!
===========================================================================
WARNING: Different runs for N2 molecule are not identical.
         Could be parallelization related?
===========================================================================
 Iter           MO residual             Total energy                Update
---------------------------------------------------------------------------
    0          2.645751e+00        -108.269858178882         -1.082699e+02
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.556167e-01
norm(grad_E) = 1.856270e+00
Candidate Energy: -1.089514e+02
update: 6.948613e-02 (step size = 1.000000e+00)
----------------------------------------------------------------------------
    1          1.502225e-01        -108.951400239938         -6.815421e-01
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 7.544503e-01
norm(grad_E) = 8.222362e-01
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089773e+02
update: 4.063573e-02 (step size = 1.000000e+00)
----------------------------------------------------------------------------
    2          7.597157e-02        -108.977349370825         -2.594913e-02
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.191599e+00
norm(grad_E) = 7.031510e-01
Polak-Ribière coefficient = 1.004465e+00
Candidate Energy: -1.089714e+02
Candidate Energy: -1.089813e+02
update: 1.772670e-02 (step size = 5.000000e-01)
----------------------------------------------------------------------------
    3          3.362842e-02        -108.981334103267         -3.984732e-03
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.052635e+00
norm(grad_E) = 6.411952e-01
Polak-Ribière coefficient = 1.011467e-02
Candidate Energy: -1.089918e+02
update: 1.399893e-02 (step size = 5.000000e-01)
----------------------------------------------------------------------------
    4          3.195203e-02        -108.991762240603         -1.042814e-02
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.037579e-01
norm(grad_E) = 1.027622e-01
Polak-Ribière coefficient = 1.071906e-02
Candidate Energy: -1.089926e+02
update: 4.161355e-03 (step size = 5.000000e-01)
----------------------------------------------------------------------------
    5          7.002679e-03        -108.992554660217         -7.924196e-04
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 5.163698e-02
norm(grad_E) = 5.277459e-02
Polak-Ribière coefficient = 0.000000e+00
Powell/guarded restart at iteration_index 6 (reason: powell)
Candidate Energy: -1.089929e+02
update: 2.863964e-03 (step size = 7.000000e-01)
----------------------------------------------------------------------------
    6          5.687472e-03        -108.992931405160         -3.767449e-04
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 3.803882e-02
norm(grad_E) = 2.745151e-02
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089931e+02
update: 2.240730e-03 (step size = 9.800000e-01)
----------------------------------------------------------------------------
    7          4.469521e-03        -108.993094351301         -1.629461e-04
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 2.548708e-02
norm(grad_E) = 1.621089e-02
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089932e+02
update: 1.540513e-03 (step size = 1.372000e+00)
----------------------------------------------------------------------------
    8          2.830091e-03        -108.993163792084         -6.944078e-05
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.008244e-02
norm(grad_E) = 1.073616e-02
Polak-Ribière coefficient = 0.000000e+00
Candidate Energy: -1.089932e+02
update: 9.055415e-04 (step size = 1.372000e+00)
----------------------------------------------------------------------------
    9          1.546700e-03        -108.993184453341         -2.066126e-05
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.575015e-02
norm(grad_E) = 1.212366e-02
Polak-Ribière coefficient = 2.293722e-01
Candidate Energy: -1.089932e+02
update: 6.512670e-04 (step size = 1.372000e+00)
----------------------------------------------------------------------------
   10          1.314841e-03        -108.993194554071         -1.010073e-05
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 1.733224e-02
norm(grad_E) = 1.203153e-02
Polak-Ribière coefficient = 5.478255e-01
Candidate Energy: -1.089932e+02
update: 6.541450e-04 (step size = 1.372000e+00)
----------------------------------------------------------------------------
   11          1.157032e-03        -108.993198938993         -4.384922e-06
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 8.464090e-03
norm(grad_E) = 7.778366e-03
Polak-Ribière coefficient = 3.947157e-01
Powell/guarded restart at iteration_index 12 (reason: powell)
Candidate Energy: -1.089932e+02
Candidate Energy: -1.089932e+02
update: 2.258976e-04 (step size = 6.860000e-01)
----------------------------------------------------------------------------
   12          3.853901e-04        -108.993200114094         -1.175101e-06
----------------------------------------------------------------------------
norm(A_proj - 4 * F_mat.real()) = 4.066541e-03
norm(grad_E) = 5.683517e-03
Polak-Ribière coefficient = 1.142381e-01
Candidate Energy: -1.089932e+02
Line search step is negligible; accepting.
----------------------------------------------------------------------------
   13          1.707861e-04        -108.993200446752         -3.326584e-07
---------------------------------------------------------------------------
                      SCF converged in 13 iterations!
===========================================================================
This change fixes the following problem:
Line search step is negligible; accepting.
Energy cannot be decreased more in the backtracking search.
----------------------------------------------------------------------------
Error: getUpdate(), line 131: Invalid argument
   13          1.880506e-04           0.000000000000          1.089932e+02
… type: "Stiefel" for 0 and "Grassmann" for 1.

It is parsed through the SCF variable kain.
edinvay and others added 24 commits January 28, 2026 15:20
…mentation fault, but it probably also blocks the computations further.
Grassmann case as well.
Now we have communication-dominated regime while projecting to the
horizontal space:
Every h1_inner product reduces while waiting for derivatives nabla to
finish.
TODO: compute full matrix locally then reduce once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants