Berry phase calculations of the rotational and pseudorotational g-factor in molecules and solids