Calculating property per timestep using current temperature

Dear all,
I need to calculate a property per timestep and print it which requires the use of temperature of the current timestep. I used variable command to define the new variable and used temp keyword for the current temperature. I then used " fix print " . But an error occurs :

ERROR: Thermo keyword in variable requires thermo to use/init temp (…/thermo.cpp:1171)

Can you suggest me a way to get around the error .


a) please always report which version of LAMMPS you are using
b) please provide a minimal input example demonstrating the issue.


Here, is a portion from my input script that i think is relevant :

variable q equal 1.912788e-15
variable eps0 equal 8.85e-12
variable a equal 2.2854e-3
variable k_B equal 1.38e-23
variable gamma equal ({q}*{q})/(43.14{eps0}*{a}*{k_B}*(temp))

fix printgamma all print 100 ${gamma} screen yes

I am using LAMMPS version : 3 Mar 2020

this cannot work as expected, because you are using “$(temp)”, which will result in an instant evaluation and replace it with the current value of the temperature at the time of defining the variable. if there is no system initialized at that time, you get the error message you saw. you need to use “temp” keyword directly, so that the temperature is retrieved at the time the variable is evaluated (not defined).

please see the documentation of the variable command for additional details and explanations.