About the gmx angle command in gromacs

GROMACS version:2023
GROMACS modification: No
When simulating the equilibrium of surfactant molecules in an aqueous solution, I need to obtain the angle distribution between the head group of the surfactant molecule and its Z-axis direction, similar to the figure below. How should I write the relevant instructions? Do I need to set up a group in advance?

You need to create an index file, but you do not need to create it in advance of running the simulations. You only need it for analysis. In the index file you list the triplets of angles you want to analyze, e.g:

[ surfactant ]
5 9 21 46 50 62 87 94 103 128 135 144 169 176 185 ...

N.b., that this is just an example. 5 9 21 might correspond to OC1 C2 and C6. Pick the atoms you want to use for the angle calculation. I’m not aware of any tool that generates these triplets for you, but I’m sure you can generate such an index file yourself, e.g., using a simple python script.

Thank you very much for your answer, I will try it right away.