  The kilonova (KN) associated with the binary neutron star (BNS) merger
GW170817 is the only known electromagnetic counterpart to a gravitational wave
source. Here we produce a sequence of radiative transfer models (using
$\textsc{tardis}$) with updated atomic data, and compare them to accurately
calibrated spectra. We use element compositions from nuclear network
calculations based on a realistic hydrodynamical simulation of a BNS merger. We
show that the blue spectrum at +1.4 days after merger requires a
nucleosynthetic trajectory with a high electron fraction. Our best-fitting
model is composed entirely of first $r$-process peak elements (Sr & Zr) and the
strong absorption feature is reproduced well by Sr$\,\textsc{ii}$ absorption.
At this epoch, we set an upper limit on the lanthanide mass fraction of
$X_{\textsc{ln}} \lesssim 5 \times 10^{-3}$. In contrast, all subsequent
spectra from $+2.4 - 6.4$ days require the presence of a modest amount of
lanthanide material ($X_{\textsc{ln}} \simeq 0.05^{+0.05}_{-0.02}$), produced
by a trajectory with $Y_{\rm e} = 0.29$. This produces lanthanide-induced line
blanketing below 6000$\,$\AA, and sufficient light $r$-process elements to
explain the persistent strong feature at $\sim 0.7 - 1.0 \, \micron$
(Sr$\,\textsc{ii}$). The composition gives good matches to the observed data,
indicating that the strong blue flux deficit results in the near-infrared (NIR)
excess. The disjoint in composition between the first epoch and all others
indicates either ejecta stratification, or the presence of two distinct
components of material. This further supports the `two-component' kilonova
model, and constrains the element composition from nucleosynthetic
trajectories. The major uncertainties lie in availability of atomic data and
the ionisation state of the expanding material.
