To understand the properties of polyaniline (PANI), aim gas, and the interaction between them in PANI-based gas sensors and help us to design sensors with better properties, direct calculations with molecular dynamics (MD) simulations were done in this work. Polyamide 6/polyaniline (PA6/PANI) nanofiber ammonia gas sensors were studied as an example here, and the structural, morphological, and ammonia sensing properties (to 50-250 ppm ammonia) of PA6/PANI nanofibers were tested and evaluated by scanning electron microscopy, Fourier transform infrared spectroscopy, and a homemade test system. The PA6/PANI nanofibers were prepared by in situ polymerization of aniline with electrospun PA6 nanofibers as templates and hydrochloric acid (HCl) as a doping agent for PANI, and the sensors show rapid response, ideal selectivity, and acceptable repeatability. Then, complementary molecular dynamics simulations were performed to understand how ammonia molecules interact with HCl-doped PANI chains, thus providing insights into the molecular-level details of the ammonia sensing performances of this system. Results of the radial distribution functions and mean square displacement analysis of the MD simulations were consistent with the dedoping mechanism of the PANI chains.