How to use NVE on Simulations?

GROMACS version: 2018.1
GROMACS modification: No

I’m trying to do some simulations of water with tip4p/2005 model. First I did and NPT on the system until the equilibrium and now I want to run a NVE

I would like to modify the script below to do an NVE simulations. The script is for NPT simulations using Pcoupl and Tcoupl. It’s very easy to switch to NVT with Tcoupl=no, but the problem that I want to change it to NVE. I though that I should use Tcoupl=no, Pcoupl=no and some other options that I found in the manual, and this will be enough, but it looks like is not cause the energy not remains constant… Someone knows how to change properly the code or can give me some hints?

Thank you
José


; RUN CONTROL PARAMETERS
integrator = md
; Start time and timestep in ps
tinit = 0
dt = 0.001
nsteps = 400000
; For exact run continuation or redoing part of a run
init_step = 0
; Part index is updated automatically on checkpointing (keeps files separate)
simulation-part = 1
; mode for center of mass motion removal
comm-mode = linear
; number of steps for center of mass motion removal
nstcomm = 5
; group(s) for center of mass motion removal
comm-grps =

;freezegrps =
;freezedim =

; LANGEVIN DYNAMICS OPTIONS
; Friction coefficient (amu/ps) and random seed
bd-fric = 0
ld_seed = 232354

; ENERGY MINIMIZATION OPTIONS
; Force tolerance and initial step-size
emtol = 10
emstep = 0.01
; Max number of iterations in relax-shells
niter = 20
; Step size (ps^2) for minimization of flexible constraints
fcstep = 0
; Frequency of steepest descents steps when doing CG
nstcgsteep = 1000
nbfgscorr = 10

; TEST PARTICLE INSERTION OPTIONS
rtpi = 0.05

; OUTPUT CONTROL OPTIONS
; Output frequency for coords (x), velocities (v) and forces (f)
nstxout = 0
nstvout = 0
nstfout = 0
; Output frequency for energies to log file and energy file
nstlog = 10000
nstcalcenergy = 10000
nstenergy = 2000
; Output frequency and precision for .xtc file
nstxout-compressed = 200000
compressed-x-precision = 1000
; This selects the subset of atoms for the compressed
; trajectory file. You can select multiple groups. By
; default, all atoms will be written.
compressed-x-grps =
; Selection of energy groups
energygrps =

; NEIGHBORSEARCHING PARAMETERS
; cut-off scheme (Verlet: particle based cut-offs, group: using charge groups)
cutoff-scheme = Verlet
; nblist update frequency
nstlist = 1
; ns algorithm (simple or grid)
ns_type = grid
; Periodic boundary conditions: xyz, no, xy
pbc = xyz
periodic_molecules = yes
; Allowed energy error due to the Verlet buffer in kJ/mol/ps per atom,
; a value of -1 means: use rlist
verlet-buffer-tolerance = 0.005
; nblist cut-off
rlist = 0.95
; long-range cut-off for switched potentials

; OPTIONS FOR ELECTROSTATICS AND VDW
; Method for doing electrostatics
coulombtype = pme
coulomb-modifier = Potential-shift-Verlet
rcoulomb-switch = 0
rcoulomb = 0.95
; Relative dielectric constant for the medium and the reaction field
epsilon-r = 1
epsilon-rf = 0
; Method for doing Van der Waals
vdw-type = cut-off
vdw-modifier = Potential-shift-Verlet
; cut-off lengths
rvdw-switch = 0.85
rvdw = 0.95
; Apply long range dispersion corrections for Energy and Pressure
DispCorr = EnerPres
; Extension of the potential lookup tables beyond the cut-off
table-extension = 1
; Separate tables between energy group pairs
energygrp-table =
; Spacing for the PME/PPPM FFT grid
fourierspacing = 0.1
; FFT grid size, when a value is 0 fourierspacing will be used
fourier-nx = 0
fourier-ny = 0
fourier-nz = 0
; EWALD/PME/PPPM parameters
pme_order = 4
ewald-rtol = 1e-05
ewald-rtol-lj = 0.001
lj-pme-comb-rule = Geometric
ewald-geometry = 3d
epsilon-surface = 0

; IMPLICIT SOLVENT ALGORITHM
implicit-solvent = No

; GENERALIZED BORN ELECTROSTATICS
; Algorithm for calculating Born radii
gb-algorithm = Still
; Frequency of calculating the Born radii inside rlist
nstgbradii = 1
; Cutoff for Born radii calculation; the contribution from atoms
; between rlist and rgbradii is updated every nstlist steps
rgbradii = 1
; Dielectric coefficient of the implicit solvent
gb-epsilon-solvent = 80
; Salt concentration in M for Generalized Born models
gb-saltconc = 0
; Scaling factors used in the OBC GB model. Default values are OBC(II)
gb-obc-alpha = 1
gb-obc-beta = 0.8
gb-obc-gamma = 4.85
gb-dielectric-offset = 0.009
sa-algorithm = Ace-approximation
; Surface tension (kJ/mol/nm^2) for the SA (nonpolar surface) part of GBSA
; The value -1 will set default value for Still/HCT/OBC GB-models.
sa-surface-tension = -1

; OPTIONS FOR WEAK COUPLING ALGORITHMS
; Temperature coupling
Tcoupl = v-rescale
nsttcouple = 1
nh-chain-length = 10
print-nose-hoover-chain-variables = no
; Groups to couple separately
tc-grps = system
; Time constant (ps) and reference temperature (K)
tau_t = 0.3
ref_t = 300
; pressure coupling
;Pcoupl = no
Pcoupl = parrinello-rahman
pcoupltype = isotropic
nstpcouple = 1
; Time constant (ps), compressibility (1/bar) and reference P (bar)
tau_p = 0.3
compressibility = 4.5e-5
ref_p = 1
; Scaling of reference coordinates, No, All or COM
refcoord-scaling = com

; OPTIONS FOR QMMM calculations

; SIMULATED ANNEALING
; Type of annealing for each temperature group (no/single/periodic)
annealing = no
; Number of time points to use for specifying annealing in each group
annealing-npoints =
; List of times at the annealing points for each group
annealing-time =
; Temp. at each annealing point, for each group.
annealing-temp =

; GENERATE VELOCITIES FOR STARTUP RUN
gen_vel = yes
gen_temp = 300
gen_seed = -1

; OPTIONS FOR BONDS
constraints = none
; Type of constraint algorithm
constraint-algorithm = lincs
; Do not constrain the start configuration
continuation = no
; Use successive overrelaxation to reduce the number of shake iterations
Shake-SOR = no
; Relative tolerance of shake
shake-tol = 1e-6
; Highest order in the expansion of the constraint coupling matrix
lincs-order = 4
; Number of iterations in the final step of LINCS. 1 is fine for
; normal simulations, but use 2 to conserve energy in NVE runs.
; For energy minimization with constraints it should be 4 to 8.
lincs-iter = 1
; Lincs will write a warning to the stderr if in one step a bond
; rotates over more degrees than
lincs-warnangle = 30

Hi Jose,

as far as I understand, the total energy will not stay constant anyway because of numerical errors; the question is: does it drift/oscillate a lot?
It would be helpful to have a look at the output of gmx energy.

p.s. in the script you are effectively thermalizing the system with v-rescale

Hi Michele,

There is someway to avoid or minimize this numerical errors?

In the simulations I’m doing first an NPT with the script that I already show you, then I find this output

[See panels at the end]

This looks like it is at the equilibrium (isn’t it?), so I start a NVE from the confout.g96 of the NPT. The script that I use is the script below. Note that I only change few lines in the NPT script that I already post to use NVE (maybe there is the error), and I would like to compute the viscosity via Green-Kubo so I need to save the energy very frequently. Then the output is


; RUN CONTROL PARAMETERS
integrator = md
; Start time and timestep in ps
tinit = 0
dt = 0.001
nsteps = 1000000
;30000000
; For exact run continuation or redoing part of a run
init_step = 0
; Part index is updated automatically on checkpointing (keeps files separate)
simulation-part = 1
; mode for center of mass motion removal
comm-mode = linear
; number of steps for center of mass motion removal
nstcomm = 5
; group(s) for center of mass motion removal
comm-grps =

;freezegrps =
;freezedim =

; LANGEVIN DYNAMICS OPTIONS
; Friction coefficient (amu/ps) and random seed
bd-fric = 0
ld_seed = 232354

; ENERGY MINIMIZATION OPTIONS
; Force tolerance and initial step-size
;emtol = 10
;emstep = 0.01
; Max number of iterations in relax-shells
;niter = 20
; Step size (ps^2) for minimization of flexible constraints
;fcstep = 0
; Frequency of steepest descents steps when doing CG
;nstcgsteep = 1000
;nbfgscorr = 10

; TEST PARTICLE INSERTION OPTIONS
rtpi = 0.05

; OUTPUT CONTROL OPTIONS
; Output frequency for coords (x), velocities (v) and forces (f)
nstxout = 0
nstvout = 0
nstfout = 0
; Output frequency for energies to log file and energy file
nstlog = 10000
nstcalcenergy = 10000
nstenergy = 2
; Output frequency and precision for .xtc file
nstxout-compressed = 200000
compressed-x-precision = 1000
; This selects the subset of atoms for the compressed
; trajectory file. You can select multiple groups. By
; default, all atoms will be written.
compressed-x-grps =
; Selection of energy groups
energygrps =

; NEIGHBORSEARCHING PARAMETERS
; cut-off scheme (Verlet: particle based cut-offs, group: using charge groups)
cutoff-scheme = Verlet
; nblist update frequency
nstlist = 1
; ns algorithm (simple or grid)
ns_type = grid
; Periodic boundary conditions: xyz, no, xy
pbc = xyz
periodic_molecules = yes
; Allowed energy error due to the Verlet buffer in kJ/mol/ps per atom,
; a value of -1 means: use rlist
verlet-buffer-tolerance = -1
; nblist cut-off
rlist = 0.95
; long-range cut-off for switched potentials

; OPTIONS FOR ELECTROSTATICS AND VDW
; Method for doing electrostatics
coulombtype = pme
coulomb-modifier = Potential-shift-Verlet
rcoulomb-switch = 0
rcoulomb = 0.95
; Relative dielectric constant for the medium and the reaction field
epsilon-r = 1
epsilon-rf = 0
; Method for doing Van der Waals
vdw-type = cut-off
vdw-modifier = Potential-shift-Verlet
; cut-off lengths
rvdw-switch = 0.85
rvdw = 0.95
; Apply long range dispersion corrections for Energy and Pressure
DispCorr = EnerPres
; Extension of the potential lookup tables beyond the cut-off
table-extension = 1
; Separate tables between energy group pairs
energygrp-table =
; Spacing for the PME/PPPM FFT grid
fourierspacing = 0.1
; FFT grid size, when a value is 0 fourierspacing will be used
fourier-nx = 0
fourier-ny = 0
fourier-nz = 0
; EWALD/PME/PPPM parameters
pme_order = 4
ewald-rtol = 1e-05
ewald-rtol-lj = 0.001
lj-pme-comb-rule = Geometric
ewald-geometry = 3d
epsilon-surface = 0

; IMPLICIT SOLVENT ALGORITHM
implicit-solvent = No

; GENERALIZED BORN ELECTROSTATICS
; Algorithm for calculating Born radii
gb-algorithm = Still
; Frequency of calculating the Born radii inside rlist
nstgbradii = 1
; Cutoff for Born radii calculation; the contribution from atoms
; between rlist and rgbradii is updated every nstlist steps
rgbradii = 1
; Dielectric coefficient of the implicit solvent
gb-epsilon-solvent = 80
; Salt concentration in M for Generalized Born models
gb-saltconc = 0
; Scaling factors used in the OBC GB model. Default values are OBC(II)
gb-obc-alpha = 1
gb-obc-beta = 0.8
gb-obc-gamma = 4.85
gb-dielectric-offset = 0.009
sa-algorithm = Ace-approximation
; Surface tension (kJ/mol/nm^2) for the SA (nonpolar surface) part of GBSA
; The value -1 will set default value for Still/HCT/OBC GB-models.
sa-surface-tension = -1

; OPTIONS FOR WEAK COUPLING ALGORITHMS
; Temperature coupling
;Tcoupl = v-rescale
Tcoupl = no
nsttcouple = 1
nh-chain-length = 10
print-nose-hoover-chain-variables = no
; Groups to couple separately
tc-grps = system
; Time constant (ps) and reference temperature (K)
tau_t = 0.3
ref_t = 300
; pressure coupling
Pcoupl = no
;Pcoupl = parrinello-rahman
pcoupltype = isotropic
nstpcouple = 1
; Time constant (ps), compressibility (1/bar) and reference P (bar)
tau_p = 0.3
compressibility = 4.5e-5
ref_p = 1
; Scaling of reference coordinates, No, All or COM
refcoord-scaling = com

; OPTIONS FOR QMMM calculations

; SIMULATED ANNEALING
; Type of annealing for each temperature group (no/single/periodic)
annealing = no
; Number of time points to use for specifying annealing in each group
annealing-npoints =
; List of times at the annealing points for each group
annealing-time =
; Temp. at each annealing point, for each group.
annealing-temp =

; GENERATE VELOCITIES FOR STARTUP RUN
gen_vel = yes
gen_temp = 300
gen_seed = -1

; OPTIONS FOR BONDS
constraints = none
; Type of constraint algorithm
constraint-algorithm = lincs
; Do not constrain the start configuration
continuation = no
; Use successive overrelaxation to reduce the number of shake iterations
Shake-SOR = no
; Relative tolerance of shake
shake-tol = 1e-6
; Highest order in the expansion of the constraint coupling matrix
lincs-order = 4
; Number of iterations in the final step of LINCS. 1 is fine for
; normal simulations, but use 2 to conserve energy in NVE runs.
; For energy minimization with constraints it should be 4 to 8.
lincs-iter = 2
; Lincs will write a warning to the stderr if in one step a bond
; rotates over more degrees than
lincs-warnangle = 30

To the best of my understanding, Green-Kubo is ment to work in a canonical ensemble (either NPT or NVT); viscosity is a function of temperature and either density or pressure: I am not sure you can get a meaningful number for water viscosity from a NVE simulation.

Thus said, the energy drift is too large to be due to numerical errors, I believe.

How large is your simulation box (number of atoms)? The NPT output is a bit strange, but I guess it’s difficult to judge without any information on the specific system.
Are gmx grompp or mdrun complaining? All I can think a propri is that something could be wrong in the neighbour search or in electostatic… Why are you using refcoord-scaling = com? I believe you can safely put that to no, unless restrainted positions are employed.

I’m trying to compute the bulk viscosity (and also the shear viscosity) in NVE ensemble following this paper

J. Chem. Phys. 148 , 174504 (2018); https://doi.org/10.1063/1.5022752

I start with a small system, just 256 water molecules, using tip4p/2005 force field. I start from this just to understand how to do a NVE and find known results


gmx mdrun -s topol.tpr -c confout.g96

Not show any error or strange note in any case

For NPT simulation:

gmx grompp -c conf.g96 -maxwarn 5

NOTE 1 [file grompp.mdp]:
With Verlet lists the optimal nstlist is >= 10, with GPUs >= 20. Note
that with the Verlet scheme, nstlist has no effect on the accuracy of
your simulation.

NOTE 2 [file grompp.mdp]:
Setting nstcalcenergy (10000) equal to nstenergy (2000)

NOTE 3 [file grompp.mdp]:
nstcomm < nstcalcenergy defeats the purpose of nstcalcenergy, setting
nstcomm to nstcalcenergy

WARNING 1 [file grompp.mdp]:
You are generating velocities so I am assuming you are equilibrating a
system. You are using Parrinello-Rahman pressure coupling, but this can
be unstable for equilibration. If your system crashes, try equilibrating
first with Berendsen pressure coupling. If you are not equilibrating the
system, you can probably ignore this warning.

For NVE simulation:


NOTE 1 [file grompp.mdp]:
With Verlet lists the optimal nstlist is >= 10, with GPUs >= 20. Note
that with the Verlet scheme, nstlist has no effect on the accuracy of
your simulation.

NOTE 2 [file grompp.mdp]:
Setting nstcalcenergy (10000) equal to nstenergy (2)

NOTE 3 [file grompp.mdp]:
The optimal PME mesh load for parallel simulations is below 0.5
and for highly parallel simulations between 0.25 and 0.33,
for higher performance, increase the cut-off and the PME grid spacing.

I think there is nothing to worry about in the notes

And about the command refcoord-scaling = com, I just take it from another gromacs code that works properly when I was doing some test in the code…

Have you tried to switch to Berendsen (instead of P-R) in the NPT equilibration? In GROMACS 2021 you can use c-rescale, which is basically the equivalent of v-rescale for thermostats.
Also, since you aim for NVE for production runs, would it make sense to have an intermediate NVT simulation?
I know this not answers your original question, but it may be worth trying.

As far as I know for NPT doesn’t really matter which barostat I use, it should give me the same thermodynamics results, but I will try

Due to the system is in the equilibrium at the end of NPT, I don’t know if make sense an intermediate NVT before NVE, because all magnitudes should be at the equilibrium at the end of NPT. But I will try to check if Pressure and Energy are in equilibrium after NPT

Thank you very much for your time

As far as I know for NPT doesn’t really matter which barostat I use, it should give me the same thermodynamics results, but I will try

It actually does matter, and that is why grompp complains: P-R introduces a second-order coupling which can produce significant oscillations if the simulations starts far from equilibrium, so generally a linear coupling barostat, like Berendsen, is more apt for equilibration runs.

Some information that may be helpful:

  • Berendsen barostat will not correctly sample the isothermal-isobaric (NPT) ensemble, but it does lead to fast relaxation of the box vectors to equilibrium.
  • Parrinello-Rahman (P-R) does correctly sample the NPT ensemble. However, it does lead to large oscillations if far away from equilibrium as Michele stated.

Because of these facts, generally the Berendsen barostat is favored over P-R for equilibration purposes (which is why GROMACS warns you if P-R is used for equilibration). However, in my own experience, sometimes P-R can be used for NPT equilibration as long as the initial box size is reasonable relative to the equilibration density and gen-vel = yes is used to make sure that the acceleration of the atoms is not ridiculously large. In these circumstances (and after an energy minimization run), my simulations tend to be stable enough not to crash during equilibration even when using P-R.

However, if you want to simulate in NVE, then I would suggest an Energy Minimization (steepest descent and then possibly conjugate gradient afterwards) → NPT (tcoupl=v-rescale, pcoupl=parrinello-rahman) → NVT (tcoupl=v-rescale, pcoupl=no) → NVE (tcoupl=no, pcoupl=no) workflow. If you experience crashing when using P-R for NPT equilibration, then add another NPT equilibration run with Berendsen barostat before that. It is not recommended to go straight from NPT to NVE because too many changes are taking place simultaneously.