Using an atom-style computed array variable in an equal-style variable's formula

Hello LAMMPS users,

I am using the LAMMPS version 23Jun2022.
I have the following line in my code where I am computing a property/atom using the following command:
compute creg selreg property/atom id x y z

Then I assign a computed array value to an atom-style variable:
variable X_atom atom “c_creg[2]”

I want to add this atom-style variable value to a number and assign the sum to a new variable. I essentially want to perform the addition of ‘X_atom’ and ‘x_add’ (which is a number). I tried assigning the sum to an equal-style, an atom-style and a vector-style variable, and every time, I got the following error ‘Substitution for illegal variable (whatever variable I was assigning the sum to)’. Can someone guide me as to how I can assign the variables in order to perform the addition of a computed array value and a number, and then assign it to another variable? I intend to use this sum in a ‘create_atoms’ command.

Regards,
Rajesh

why not

variable meaning_of_life equal 42
variable meaning_of_atom atom x+v_meaning_of_life
1 Like

I really hope I dont need to wait until I am 42 to understand the meaning of life… I dont feel like I can wait this long to understand things

What is 42 (h2g2, meaning of life, The Hitchhiker's Guide to the Galaxy)? :slight_smile:

2 Likes

Oh, I see… I didnt know about this book :monkey:

PS: personally I would be very skeptical about a computer (or anyone/anything really, but especially computers) answering questions about the meaning of life: despite our hearts not always being the indicator of the truth and sometimes sending us downhill, I remain confident that the answers of certain questions are rather felt (and then, afterwards, reasoned) :sun_with_face: