Spin state transformations of a 3d ion in the pyramidal environment and under lattice distortions