Can we define an array variable in LAMMPS?

please always copy the mailing list on your replies (i.e. use reply to
all). thanks.

Dear Axel

Many thanks for your response. Indeed having array could have been very
useful for doing some online calculations of correlation functions while
running MD.

correlation functions can be computed using fix ave/correlate.

just you saying that something might be useful, is not an argument.

I simplified the example, but my aim was to calculate the Rouse modes of
each single chain in a polymeric sample and I need to store info regarding
each chain in a different array. I do not know if there is another way to do
so.

your example made the array index explicit part of the variable name.
does this not work?
what would you gain from having an array syntax for variables?

axel.

Indeed, my aim was to use fix ave/correlate but for each chain I need a different variable to store the relevant quantities. Making the array index explicit part of the variable name in the way I wrote in my example did not work, that is why I thought about arrays. So, if I can find a way to define variables indexed with different numbers, I will be equally happy. I need 10^5 of such variables indexed by numbers to be read in a loop, so writing them explicitly in the script does not make sense.

If you have a suggestion, I will be grateful.

Thanks
Sara

Axel Kohlmeyer <[email protected]> a écrit :

Why not program a custom compute?
Trying to do this as lammps script seems to be asking too much.
You might get it done using the python wrapper, but I have no experience using that in this way.
Axel.

I’ve used the python wrapper to work on things similar to what you ask for, and the main issue was that I had ~.01s overhead total. However, taking about 1000 timestep (close to the expected correlation time) per run, it ended up being quite similar in speed.

Thanks for the responses. Now, I found a way that it does it like an array as I have written below. It works fine, but when I have "run 10000" at the end, I realized that it does not update the required values while running MD steps. How can I do this, does it mean I should write a separate compute or is there a simpler way for it?

label loop_chains
variable M loop 1 10
variable sumx equal 0

label loop_xp
variable n loop 1 \{Lchain\} variable m equal \({M}-1)*${Lchain}+$n

variable x1 equal x[${m}]

variable n2 equal \{n\}\-0\.5 variable n21 equal {n2}*\{pp\}\*PI/{Lchain}

variable phase equal cos(${n21})

variable xp equal \{x1\}\*{phase}
variable sumx equal \{sumx\}\+{xp}

next n
jump SELF loop_xp
variable XP$M equal ${sumx}

fix ${M} all ave/correlate $s $t $d &
              v_XP$M type auto file Rouse$M.dat ave running

next M
jump SELF loop_chains

Thanks for the responses. Now, I found a way that it does it like an array
as I have written below. It works fine, but when I have "run 10000" at the
end, I realized that it does not update the required values while running MD
steps. How can I do this, does it mean I should write a separate compute or
is there a simpler way for it?

you have to watch out for the different ways how variables are expanded.
if you refer to a variable in a formula with ${name} it will be
expanded into a string right away. if you refer to it via v_name it
will be expanded into its current value. you probably need to use a
smart mixture of both... or switch to use a scripting language that is
made for these kind of tasks.

axel.