[lammps-users] illegal variable error with fix print

Hello,

I have below error message:

ERROR on proc 0: Substitution for illegal variable

The variable doc page explains you need something like:

ix rg polymer print 100 "rg = ${rg_polymer}" file rg.rg

with the {} enclosing a variable of more than a single letter.

Steve

Thank you!!

By the way,
If I’d like to add current step in the result, what can I do?
e.g., result will be " time step = “current step”, rg = “xxx”

Do I need to define another variable for step?
In the variable doc page, I don’t see any for step.
I think it’s probably preset.
Do anyone know?

Variables can include thermo keywords - step is a thermo keyword.

Steve

I got results like below:
Step = 501368872, RG = 16.5189053

Step = 501368872, RG = 16.03852748
Step = 501368872, RG = 15.48693143
Step = 501368872, RG = 14.87531537

I don’t know why each step has the same value (501368872).
Related part of my script is:
variable step equal step
compute rg polymer gyration/molecule

fix rg polymer print 100 “Step = {step}, RG = {rg_polymer}” file polymer.rg

Even if I replaced “step” with “elapsed”, I got same results.
Do anyone know what the problem is?

Thank you.

I got results like below:
Step = 501368872, RG = 16.5189053
Step = 501368872, RG = 16.03852748
Step = 501368872, RG = 15.48693143
Step = 501368872, RG = 14.87531537
I don't know why each step has the same value (501368872).
Related part of my script is:
variable step equal step
compute rg polymer gyration/molecule
fix rg polymer print 100 "Step = \{step\}, RG = {rg_polymer}" file
polymer.rg
Even if I replaced "step" with "elapsed", I got same results.
Do anyone know what the problem is?

which version of the code are you using?

this could be a side effect of the switch to
64-bit time step counters.

axel.

I used 15 Jan 2011 version of LAMMPS.

Thanks.

I used 15 Jan 2011 version of LAMMPS.

ok. that is recent but not the latest version.

i've tested the latest version and the issue still exists
and is indeed a bug. fortunately, it is easy to find and fix.

if you load the file thermo.cpp in your editor go to
line 944 and add the line:
  dvalue = bivalue;
right after "compute_step();"

similarly a few lines down, change
"dvalue = ivalue;" into "dvalue = bivalue;"
right after compute_elapsed();
and compute_elapsed_long();

and then near line 978 add
  dvalue = bivalue;
right after "compute_atoms();"

or if you are familiar reading patches:
diff --git a/src/thermo.cpp b/src/thermo.cpp
index 1931017..919ca35 100644
--- a/src/thermo.cpp
+++ b/src/thermo.cpp
@@ -941,18 +941,19 @@ int Thermo::evaluate_keyword(char *word, double *answer)

   if (strcmp(word,"step") == 0) {
     compute_step();
+ dvalue = bivalue;

   } else if (strcmp(word,"elapsed") == 0) {
     if (update->whichflag == 0)
       error->all("This variable thermo keyword cannot be used between runs");
     compute_elapsed();
- dvalue = ivalue;
+ dvalue = bivalue;

   } else if (strcmp(word,"elaplong") == 0) {
     if (update->whichflag == 0)
       error->all("This variable thermo keyword cannot be used between runs");
     compute_elapsed_long();
- dvalue = ivalue;
+ dvalue = bivalue;

   } else if (strcmp(word,"dt") == 0) {
     compute_dt();
@@ -974,6 +975,7 @@ int Thermo::evaluate_keyword(char *word, double *answer)

   } else if (strcmp(word,"atoms") == 0) {
     compute_atoms();
+ dvalue = bivalue;

   } else if (strcmp(word,"temp") == 0) {
     if (!temperature)

that should fix your problems and one that you
didn't run into (yet).

cheers,
     axel.

Posted a patch for this - thanks Axel

Steve