Improved molecular replacement by density- and energy-guided protein structure optimization