Details of viscosity estimation (gmx energy -vis)

GROMACS version: 2023.2
GROMACS modification: No

Hello everyone,

I have started using gmx energy -vis to estimate shear viscosity (file visco.xvg) from equilibrium MD simulations. The command is very convenient and easy to use, but I would like to know the details of these calculations. For instance, it is not clear to me whether it is using the Green-Kubo relation or the Einstein relation (I assume that the Green-Kubo is used, but it is not stated in the output file). Which stress tensors are taken in to account for the estimation? I would also like more specifics about the estimation of the autocorrelation function and the integration. For instance, is there a time lag considered for the correlation function?

Can I find somewhere this information? Any help you can provide is appreciated. Thank you!

Best regards,
Evangelos (Vangelis)

Yes, documentation is lacking. There are two outputs. visco.xvg is from Green-Kubo and the plots are as a function of integration time over the AC function. evisco output is using the Einstein formula. For the shear viscosity all three off-diagonal terms are used.

Note that both methods require extremely frequent pressure calculation, nstcalcenergy should be at most 5. For Green-Kubo, you need nstenergy=nstcalcenergy. Einstein has the advantage that that is not needed. So I would advise to use Einstein. I just updated the manual for 2024 with this information:
https://manual.gromacs.org/2024-beta/reference-manual/special/viscosity-calculation.html

The Einstein viscosity calculation is much improved the the 2024 version, I would advise to use the 2024 version of gmx energy:
https://manual.gromacs.org/2024-beta/onlinehelp/gmx-energy.html

Thank you so much for all the help!

Best regards,
Vangelis

Hi VangelisT,

I have completed my simulation up to 100 ns, and now I would like to calculate the viscosity of my system.

You mentioned before that you used gmx energy -vis to generate the visco.xvg file. Could you please share the full command that you used?

So far, I have tried the following command:

gmx energy -f md_vis.edr -evisco evisco.xvg -eviscoi eviscoi.xvg

However, this only generated the energy.xvg file

Instead of using the Einstein method, I would like to calculate viscosity using the Green-Kubo method. Could you please let me know the correct command for calculating viscosity with the Green-Kubo approach in GROMACS?

In addition, I would also like to apply shear deformation to my simulation box (in the X, Y, or Z direction), but I am not sure how to set this up in the simulation input or command. If possible, could you also explain how to apply shear to the box and which settings I should modify?

Thank you very much for your help.

Hello Kemala23,

Hope you are doing well and thank you for asking. So, the command you are using should output only viscosity using einstein method. Here is an example of the full command I used for a sample:

gmx energy -f ../prd.edr -o energy_1.xvg -corr corr_1.xvg -evisco ev_1.xvg -eviscoi evi_1.xvg -vis visco_1.xvg -b 0 -e 2000

This performs both Einstein and Green-Kubo as far as I understand. I think in general, or at least in the version that I used, gmx energy -vis performs both methods and I am not sure if it is possible to perform only Green-Kubo. It should also be possible if you take stress tensor values and then perform autocorrelation and integration. The results by Green-Kubo should be in visco_1.xvg in this example. You can find the other flags in the manual I believe, but if in doubt feel free to ask here.

Be mindful that for Green-Kubo you need to sample the stress tensors frequently. Also, it is quite noisy, so to smooth the final result, it might be good to sample from different trajectories.

For the application of the shear, I will need to look it up a bit. I strongly recommend checking the manual and there should be something there. Keep in mind, that the two methods can require different size/box settings and so for NEMD, it might be better to have an elongated box instead of a cubic one.

I hope this was helpful and I will try to get back to you with the shear, hopefully tomorrow.

Best regards,

Evangelos (Vangelis)

Note that Green-Kubo is inconvenient, as you need extremely frequent energy output. Einstein is mathematically equivalent and does not have the inconvenience, as mdrun computes sums and stores sum over nstcalcenergy steps. This means that nstenergy can be large while nstcalcenergy should be chosen small.