Effects of intermolecular interactions and intramolecular dynamics on nuclear resonance in nitrogen trifluoride, phosphorus trifluoride, phosphoryl fluoride, and phosphorus pentafluoride