Foldy–Wouthuysen transformation for relativistic particles in external fields