Hi Lammps users!
Here's the short form of my question: is it possible to generate a random integer (say i) and set a variable (say v) equal to the current z coordinate of the atom with index i? So I would like to have something like
variable i equal "round(random(1,10,1))"
variable v equal "z[v]"
I'm getting the following error:
ERROR: Non digit character between brackets in variable (variable.cpp:2463)
The long version of why I want to do this. I'm simulating some ions moving around a fixed colloid in a channel, two of the dimensions are periodic. The colloid distorts the spatial distribution of my ions when they come back around the periodic domain; i.e. it's as if I'm simulating the ions moving around an array of colloids. My idea was to essentially have two channels atop each other with no interaction between the atoms in distinct channels. The bottom channel has the colloid in it. When an ion is about to exit the domain in the bottom channel I would like to sample one of the ions in the top channel for it's z coordinate and reset the bottom ions z coordinate to this value when it comes back around.
Thanks!
K. Sikorski
Hi Lammps users!
Here’s the short form of my question: is it possible to generate a
random integer (say i) and set a variable (say v) equal to the current z
coordinate of the atom with index i? So I would like to have something like
variable i equal “round(random(1,10,1))”
variable v equal “z[v]”
I’m getting the following error:
ERROR: Non digit character between brackets in variable (variable.cpp:2463)
As you should, since this is incorrect syntax. Please re-read the documentation of the variable command.
Axel
You’re not following correct syntax for defining a variable.
z[100] or z[123] is required, not z[v] where you expect
v to be evaluated as a variable each time it is invoked.
See the variable doc page for details.
You could do z[$v], which will evaluated v once and insert
the current value. But that’s probably not useful if you
expect it to happen repeatedly.
Steve
Thanks for your input.
Neither z[123] or z[$v] would do what I want. I understand it’s not correct syntax, I was just trying to communicate what I’d like to do; which is evaluate a different atom every time. I guess there isn’t a way to do it?
Thanks!
K. S.
Thanks for your input.
Neither z[123] or z[$v] would do what I want. I understand it's not correct
syntax, I was just trying to communicate what I'd like to do; which is
evaluate a different atom every time. I guess there isn't a way to do it?
well, first of all, you have to get the syntax right. what is the
point of discussing something, if you don't even try properly?
Just extended the variable syntax with the 3May
patch to allow something like this:
variable i equal round(random(1,10,1))
variable v equal z[v_i]
Ditto for indexing a per-atom compute, fix, or other atom-style
variable.
Note that you have to prefix the variable inside
the brackets with “v_”, same as for other
variables used within a variable formula.
Try it out and see if it works for what you want to do.
Steve