Whole powder pattern modelling: theory and applications