The methods _integrate_sd_sd_deriv in UnrestrictedChemicalHamiltonian and RestrictedChemicalHamiltonian have lots of repetitions.
They can be shortened with impure functions that add appropriate values to the variables outside its scope as a side effect. However, this may cause the code to be a little less readable as it deviates from source material (notes on orbital optimization).