Calculation of the dynamic structure factor from thermal neutron time-of-flight spectra