Optimizing the rheology of pharmaceutical formulations