  Understanding the gas abundance distribution is essential when tracing star
formation using molecular line observations. Changing density and temperature
conditions cause gas to freeze-out onto dust grains, and this needs to be taken
into account when modeling a collapsing molecular cloud. This study aims to
provide a realistic estimate of the CO abundance distribution throughout the
collapse of a molecular cloud. We provide abundance profiles and synthetic
spectral lines which can be compared to observations. We use a 2D
hydrodynamical simulation of a collapsing cloud and subsequent formation of a
protoplanetary disk as input for the chemical calculations. From the resulting
abundances, synthetic spectra are calculated using a molecular excitation and
radiation transfer code. We compare three different methods to calculate the
abundance of CO. Our models also consider cosmic ray desorption and the effects
of an increased CO binding energy. The resulting abundance profiles are
compared to observations from the literature and are found to agree well. The
resulting abundance profiles agree well with analytic approximations, and the
corresponding line fluxes match observational data. Our developed method to
calculate abundances in hydrodynamical simulations should greatly aid in
comparing these to observations, and can easily be generalized to include
gas-phase reaction networks.
