Simultaneous refinement of structure and microstructure of layered materials