Self-consistent calculation of protein folding pathways