Precursor structures in ferroelectrics from first-principles calculations