Physicochemical principles of semiconductor doping