ABSTRACT 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 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 d 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 and Zr) and the strong absorption feature is reproduced well by Sr ii absorption. At this epoch, we set an upper limit on the lanthanide mass fraction of $X_{{\small LN}} \lesssim 5 \times 10^{-3}$. In contrast, all subsequent spectra from +2.4 to 6.4 d require the presence of a modest amount of lanthanide material ($X_{{\small LN}} \simeq 0.05^{+0.05}_{-0.02}$), produced by a trajectory with Ye = 0.29. This produces lanthanide-induced line blanketing below 6000 Å, and sufficient light r-process elements to explain the persistent strong feature at ∼0.7–1.0 $\mu$m (Sr 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’ KN model, and constrains the element composition from nucleosynthetic trajectories. The major uncertainties lie in availability of atomic data and the ionization state of the expanding material.