Why does my LAMMPS script fail with 'Illegal variable command

I have this loop:

# --- Gradual Heating (300K to 2000K) ---
label heating_loop
fix mynpt all npt temp ${T} ${T} ${damp} iso 1.0 1.0 ${pdamp}
fix equil2 all ave/time 100 10 1000 v_pe v_ke file Melt_energy_equil.dat
run 20000 
print "Equilibrated at ${T} K"
variable T equal ${T} + ${dT}
if "${T} < ${Tm}" then "jump SELF heating_loop"

But the output show this error:

Equilibrated at 300 K
ERROR: Illegal variable command: expected 3 arguments but found 5 (src/variable.cpp:449)
Last command: variable T equal ${T} + ${dT}

I did a test script just for the loop and it worked fine with the same sintaxis.

variable T equal 300
variable dT equal 50 # Incrementos de 50
variable Tm equal 2000


# --- Gradual Heating test (300K to 2000K) ---
label heating_loop
print "Actual Temperature is: ${T}"
variable T equal ${T} + ${dT}
if "${T} < ${Tm}" then "jump SELF heating_loop"

Why could this happen?

If you are interested, here is the complete script
in_melt.lmp (2.0 KB)

Your variable expression has blanks in it but is not quoted. This will confuse the LAMMPS input file parser.

The expression

variable T equal ${T} + ${dT}

Is split into 5 (five!) “words”, but LAMMPS expects 3
You can get that with either:

variable T equal "${T} + ${dT}"

or:

variable T equal ${T}+${dT}

This is documented behavior. Please see the “variable” command documentation.

1 Like