Calculate gradient normal direction wrt PBCs.

Calculate gradient normal direction wrt PBCs to fix another problem related to #2965 (fixes the baseclass that was already supposed to fully support PBCs) by using the new minPeriodicVector. The meat is in 3637b54. The other patches contain whitespace crap and missing std:: ns prefixes.