  We study the structural and vibrational properties of the high-temperature
superconducting sulfur trihydride and trideuteride in the high-pressure
$Im\bar{3}m$ and $R3m$ phases by first-principles density-functional-theory
calculations. On lowering pressure, the rhombohedral transition $Im\bar{3}m
\rightarrow R3m$ is expected, with hydrogen bond desymmetrization and
occurrence of trigonal lattice distortion. In hydrostatic conditions we find
that, contrary to what suggested in some recent experiments, if the
rhombohedral distortion exists it affects mainly the hydrogen-bonds, whereas
the resulting cell distortion is minimal. We estimate that the occurrence of a
stress anisotropy of approximately $10\%$ could explain this discrepancy.
Assuming hydrostatic conditions, we calculate the critical pressure at which
the rhombohedral transition occurs. Quantum and anharmonic effects, which are
relevant in this system, are included at nonperturbative level with the
stochastic self-consistent harmonic approximation (SSCHA). Within this
approach, we determine the transition pressure by calculating the free energy
Hessian. We find that quantum anharmonic effects are responsible for a strong
reduction of the critical pressure with respect to the one obtained with the
classical harmonic approach. Moreover, we observe a prominent isotope effect,
as we estimate higher pressure transition for D${}_3$S than for H${}_3$S.
Finally, within SSCHA we calculate the anharmonic phonon spectral functions in
the $Im\bar{3}m$ phase. The strong anharmonicity of the system is confirmed by
the occurrence of very large anharmonic broadenings leading to complex
non-Lorentzian line shapes. However, for the vibrational spectra at zone
center, accessible e.g. by infrared spectroscopy, the broadenings are very
small (linewidth at most around 2~meV) and anharmonic phonon quasiparticles are
well defined.
