Static per atom variable

Hello,

Is there any way to have a static per atom variable? For example, for an equal-type variable, writing:

variable a equal random(0,1,2)
variable b equal $a

will give me a single static random value (b), that I can use repeatedly without it changing.

However if I try to do the same with atom style variables, I get the error “Substitution for Illegal Variable” when defining variable b. Is there a way to do this on LAMMPS?

Thanks for any help that you can give me!

Hello,

Is there any way to have a static per atom variable? For example, for an
equal-type variable, writing:

variable a equal random(0,1,2)
variable b equal $a

will give me a single static random value (b), that I can use repeatedly
without it changing.

However if I try to do the same with atom style variables, I get the error
"Substitution for Illegal Variable" when defining variable b. Is there a
way to do this on LAMMPS?

please have a look at fix store/state and fix property/atom.

axel.

Thank you for the fast reply.

Yes, it seems that those fixes have exactly the behaviour I need, thanks!

One quick question though. Fix store/state doesn’t seem to be able to store the information from the custom properties added by fix property/atom, so I have to create an intermediary compute to determine the custom property and then store it in store/state. For example:

fix 1 all atom/property d_prop
set type 1 d_prop v_a
fix 2 all store/state 0 d_prop

gives me the error “Invalid fix store/state command”

To get it to work I have to do something like:

fix 1 all atom/property d_prop
set type 1 d_prop v_a
compute temp all property/atom d_prop
fix 2 all store/state 0 c_temp

While it works, I do end up with two copies of the same data (in store/state and in the compute). I can delete the compute later but it seems like unnecessary work and a waste of storage.

Is this on purpose or just an oversight in creating store/state?

Thank you for the fast reply.

Yes, it seems that those fixes have exactly the behaviour I need, thanks!

One quick question though. Fix store/state doesn't seem to be able to store
the information from the custom properties added by fix property/atom, so I
have to create an intermediary compute to determine the custom property and
then store it in store/state. For example:

fix 1 all atom/property d_prop
set type 1 d_prop v_a
fix 2 all store/state 0 d_prop

gives me the error "Invalid fix store/state command"

To get it to work I have to do something like:

fix 1 all atom/property d_prop
set type 1 d_prop v_a
compute temp all property/atom d_prop
fix 2 all store/state 0 c_temp

While it works, I do end up with two copies of the same data (in store/state
and in the compute). I can delete the compute later but it seems like
unnecessary work and a waste of storage.

Is this on purpose or just an oversight in creating store/state?

i think fix store/state predates fix property/atom and - so far -
nobody seems to have asked for this feature and thus it hasn't been
implemented. let me have a closer look. with a bit of luck, this is
easily remedied.

axel.

please try the attached version of fix_store_state.cpp, recompile your
executable (this assumes you have the current version of LAMMPS, last
change to fix_store_state.cpp was on may 7th 2014). now the first
section option should work. it works for me in a simple test when
adding these lines to the melt example:

variable a atom x
fix p1 all property/atom d_prop
set type 1 d_prop v_a
fix p2 all store/state 0 d_prop

dump dc all custom 50 dump.lammpstrj id x y z v_a f_p1

please give it a try and let us know if this works for you, too.

axel.

fix_store_state.cpp.gz (4.74 KB)

Hello,

I did a few quick tests with my input and it seems to be working perfectly. It gives the same results as using an intermediary compute. This should actually save me at least 50 lines of computes/uncomputes.

Thank you very much for your help!