Thermo every variable returned a bad timestep

I prepared the following restart scritp.

read_restart restart.run.750000.tio2.t1273.p1.01325 LAMMPS restart file

Some constants

variable tequi equal 1273 # equilibrium temperature, K
variable pequi equal 1.01325 # equilibrium pressure, bat

variable nrun equal 1000000 # number of running steps
variable nrestart equal 25000 # number of steps before a new restart file is output

variable ndump equal 25000 # number of steps between dumps

variable ndt equal 0.001 # timestep, picoseconds
variable damp equal 100 # T damp in timesteps units (recommended by the manual), same value is applied for T and P

variable nthermomd equal 10000 # number of fix output results for molecular dynamics calculation

log log.tio2.t${tequi}.p${pequi}.max${nrun}

type1 = O e type2 = Ti

group type1 type 1
compute charge1 type1 property/atom q
compute q1 type1 reduce ave c_charge1
group type2 type 2
compute charge2 type2 property/atom q
compute q2 type2 reduce ave c_charge2

variable qcat equal 4.
variable qani equal -${qcat}*count(type2)/count(type1)
set group type1 charge ${qani}
set group type2 charge ${qcat}
variable qsum equal count(type1)*c_q1+count(type2)*c_q2

pair_style hybrid/overlay eam/alloy coul/ctip 0.3 12.
pair_coeff * * coul/ctip TiO.ctip O Ti
pair_coeff * * eam/alloy HfNbZrTiTaO.eam.alloy O Ti

fix qeq all qeq/ctip 1 15.0 1.0e-8 200 coul/ctip cdamp 0.30 maxrepeat 10

timestep ${ndt}

Compute the energy per atom

compute eperat all pe/atom

Compute the average energy per atom for all atoms

compute meperat all reduce ave c_eperat

Compute the temperature

compute T1 all temp

Thermodynamic output

thermo_style custom step temp c_meperat pe lx ly lz pxx pyy pzz c_q1 c_q2 v_qsum press
thermo_modify warn default norm yes
thermo v_nthermomd

dump of atom positions

dump 1 all custom {ndump} dump.tio2.t{tequi}.p${pequi}.max${nrun} id type x y z c_eperat

#Dynamics
fix npt1 all npt temp {tequi} {tequi} (v_damp*dt) iso {pequi} {pequi} (v_damp*dt)

restart v_nrestart restart.run.*.tio2.t${tequi}.p${pequi}

run ${nrun}

I got the following output with error.

LAMMPS (10 Dec 2025)
using 4 OpenMP thread(s) per MPI task
Reading restart file …
restart file = 10 Dec 2025, LAMMPS = 10 Dec 2025
restoring atom style charge from restart
orthogonal box = (-0.39624574 -0.39624574 -0.42692949) to (26.887746 26.887746 28.969829)
1 by 1 by 1 MPI processor grid
pair style hybrid/overlay stores no restart info
1764 atoms
read_restart CPU = 0.005 seconds
1176 atoms in group type1
588 atoms in group type2
Setting atom values …
1176 settings made for charge
Setting atom values …
588 settings made for charge
Reading coul/ctip potential file TiO.ctip with DATE: 2022-04-28,
Resetting global fix info from restart file:
fix style: npt, fix ID: npt1
All restart file global fix info was re-assigned
Neighbor list info …
update: every = 1 steps, delay = 0 steps, check = yes
max neighbors/atom: 2000, page size: 100000
master list distance cutoff = 14
ghost atom cutoff = 14
binsize = 7, bins = 4 4 5
3 neighbor lists, perpetual/occasional/extra = 3 0 0
(1) pair eam/alloy, perpetual, half/full from (3)
attributes: half, newton on
pair build: halffull/newton
stencil: none
bin: none
(2) pair coul/ctip, perpetual, half/full from (3)
attributes: half, newton on, cut 14
pair build: halffull/newton
stencil: none
bin: none
(3) fix qeq/ctip, perpetual
attributes: full, newton on
pair build: full/bin/atomonly
stencil: full/bin/3d
bin: standard
Setting up Verlet run …
Unit style : metal
Current step : 750000
Time step : 0.001
Per MPI rank memory allocation (min/avg/max) = 48.17 | 48.17 | 48.17 Mbytes
Step Temp c_meperat PotEng Lx Ly Lz Pxx Pyy Pzz c_q1 c_q2 v_qsum Press
750000 1263.3956 -1.9700289 -1.9700289 27.283991 27.283991 29.396759 19217.216 20729.941 -48892.856 0.11993657 -0.23987313 -1.9895197e-13 -2981.8999
ERROR: Thermo every variable returned a bad timestep (src/output.cpp:223)
Last input line: run ${nrun}

I cannot see the reason for the error. I hope someone may help me. Furthermore, I had restarted the computation without problems using the same script but with different restart files.

Thanks,

Roberto

Hi @rra , please have a look on the forum guideline topic for how to format your post so that it is more readable for people. (You can start by enclosing the text file you copy with three backticks ` so that it is not reformatted by the Markdown parser).

As for your question it is documented behavior. See the documentation of the thermo command :

Instead of a numeric value, N can be specified as an equal-style variable, which should be specified as v_name, where name is the variable name. In this case, the variable is evaluated at the beginning of a run to determine the next timestep at which thermodynamic info will be written out. On that timestep, the variable will be evaluated again to determine the next timestep, etc. Thus the variable should return timestep values. See the stagger() and logfreq() and stride() math functions for equal-style variables, as examples of useful functions to use in this context. Other similar math functions could easily be added as options for equal-style variables.

Since you set your variable using a constant and an equal_style variable, the thermo output is only expected at this single timestep and not multiple of your constant. The error occurs because your restart file already past that value.

1 Like

Thank you. I did read every text in the Thermo command and related, but I understood that the variable would return timesteps starting from the last saved timestep.

You cannot argue with software. It does what it is programmed to do. If LAMMPS tells you the timestep that the variable computes is invalid, then this is the case and you have to figure out what you have to change so it becomes valid.

After looking at your input (after struggling with making sense of it because you didn’t edit your post in the way that @Germain suggested and how the guidelines explain as well), I believe there is a general problem of understanding here.

First of all, you have to understand that there is a difference between using ${name} variables and v_name variables. In the first case the content of the variable is substituted when the input file is read and the LAMMPS commands do not get to see that there was a variable, while in the second case, the LAMMPS command must support getting the value from the variable and then will evaluate it at run time and thus this is usually required when you need some parameter that changes over time.

Second, the thermo command works differently if you use a number as the argument or a variable reference (i.e. v_name). In the first case, the number represents the output frequency and thermo output is printed on every timesteps that is a multiple of that number. In the second case the variable is supposed to return the next timestep when there should be thermo output. So this number must be larger than the current timestep number. This is useful when you want to have thermo output on specific timesteps only or not on equally spaced timesteps or when specific conditions are met and so on.

Both of these cases are documented in the manual. Assuming that I read your input correctly, you probably need to use ${name} expansion instead of a v_name reference.

As a final observation, your input is in my personal opinion a case of overusing variables.
It makes it rather difficult to debug and understand what are your intentions. I also think that using equal style variables for just storing constants is not always a practical choice. In most cases, it would be more convenient to use index style variables, since you can easily override those from the command line with the -v flag.

Please also note that excessively using the count() function in variable expressions can severely impact parallel performance because each individual evaluation requires a collective MPI call. Since the number of atoms in the group doesn’t change, you could make this a one time evaluation by using an immediate expansion during pre-processing with $(count(<group-ID>)) so you have the communications only when the variable is defined and not every time it is evaluated.

1 Like

Thank you for your time and detailed explanations.

I will do my best to edit my post as asked by @Germain and yourself.