Conventional torsion angle potentials used in molecular dynamics (MD) have a singularity problem when three bonded particles are collinearly aligned. This problem is often encountered in coarse-grained (CG) simulations. Here, we propose a new form of the torsion angle potential, which introduces an angle-dependent modulating function. By carefully tuning the parameters for this modulating function, our method can eliminate the problematic angle-dependent singularity while being combined with existing models. As an example, we optimized the modulating function of the torsion angle potential for popular CG models of biomolecules based on the statistics over experimental structures deposited in the Protein Data Bank. By applying our method to designed and natural biomolecules, we show that the new torsion angle potential is able to eliminate the singularity problem while maintaining the structural features in the original models. Furthermore, by comparing our design with previous methods, we found that our new potential has advantages in computational efficiency and numerical stability. We strongly recommend the usage of our new potential in the CG simulations of flexible molecules.