"Ab-initio" modelling of x-ray absorption spectra