  The physical conditions in a collapsing cloud can be traced by observations
of molecular lines. To correctly interpret these observations the abundance
distributions of the observed species need to be derived. The chemistry in a
collapsing molecular cloud is not in a steady state as the density and
temperature evolve. We therefore need to follow chemical reactions, both in the
gas phase and on dust grains, as well as gas-grain interactions, to predict the
abundance distributions. Our aim is to model the abundances of molecules, in
the gas phase and on grain mantles in the form of ice, from prestellar core
collapse to disk formation. We use a 2-dimensional hydrodynamical simulation as
a physical model from which we take the density, temperature, and the flow of
the gas. Trace particles, moving along with the gas, are used to follow the
chemistry during prestellar core collapse and disk formation. The evolution of
the abundances and the composition of ices on grain mantles were compared to
observations. We also investigated the initial abundances to be adopted in more
detailed modeling of protoplanetary disks by following the chemical evolution
of trace particles accreting onto the disk. Fractional abundances of HCO+,
N2H+, H2CO, HC3N, and CH3OH from our model with grain surface reactions provide
a good match to observations, while abundances of CO, CS, SO, HCN, and HNC show
better agreement without grain surface reactions. The observed mantle
composition of dust grains is best reproduced when we include surface
reactions. The initial chemical abundances to be used for detailed modeling of
a protoplanetary disk are found to be different from those in dark interstellar
clouds. Ices with a binding energy lower than about 1200 K sublimate before
accreting onto the disk, while those with a higher binding energy do not.
