Fixing COM of each molecule, 4000 molecules in total

Not sure what you are asking - I’d need to see an example(s) of

the syntax you want to support. If you mean something like this

x[blah] where blah is some more complex formula, other than 243 or v_myIndex

then I don’t think it’s a good idea for 2 reasons.

a) you can already do it as

variable myIndex blah complex-stuff

variable foo equal x[v_myIndex]

b) the logic for recursively evaulating complex stuff inside the x[] would be complicated

Steve

To be specific, I want something like:

compute cc1 all chunk/atom molecule // creates per-atom vector

compute myChunk all com/chunk cc1 // creates global array

variable cid atom c_cc1 // stores per-atom vector in v_cid
variable COMx atom c_myChunk[v_cid][1] // uses per-atom values (v_cid) to find
corresponding entry in global array c_myChunk

the last command isn’t currently supported.

Anirban

To be specific, I want something like:

compute cc1 all chunk/atom molecule // creates per-atom vector
compute myChunk all com/chunk cc1 // creates global array

variable cid atom c_cc1 // stores per-atom vector in v_cid
variable COMx atom c_myChunk[v_cid][1] // uses per-atom values (v_cid)
to find \
corresponding entry in global array c_myChunk

the last command isn't currently supported.

​i think that is going to be difficult to do in this generality. it may be
possible to do something similar to gmask(gid)​ which returns 0 or 1
depending on whether an atom is member of a group or not. the syntax you
want is something like cselect(cid,#) which would select the value at index
number # from the chunk that an atom belongs to. this avoids the nested
variable evaluation and many other complications and hides the nasty work
in the c++ source.
now, how to do this is a different story. this is something very deep in
the innards of how LAMMPS works and a script function/variable code is
necessarily complex and difficult to read and understand.

axel.

To be specific, I want something like:

compute cc1 all chunk/atom molecule // creates per-atom vector
compute myChunk all com/chunk cc1 // creates global array

variable cid atom c_cc1 // stores per-atom vector in v_cid
variable COMx atom c_myChunk[v_cid][1] // uses per-atom values (v_cid)
to find \
corresponding entry in global array c_myChunk

the last command isn't currently supported.

​i think that is going to be difficult to do in this generality. it may be
possible to do something similar to gmask(gid)​ which returns 0 or 1
depending on whether an atom is member of a group or not. the syntax you
want is something like cselect(cid,#) which would select the value at index
number # from the chunk that an atom belongs to. this avoids the nested
variable evaluation and many other complications and hides the nasty work
in the c++ source.
now, how to do this is a different story. this is something very deep in
the innards of how LAMMPS works and a script function/variable code is
necessarily complex and difficult to read and understand.

​on second thought, this might fit even better into doing it as a compute
select/chunk (or value/chunk).

I think I see what you are asking. You want to generate per-atom values
that are the chunk value for the chunk each atom belongs to. I think Axel
is right, that this is an operation better suited to a compute, than to special
variable syntax. Maybe something like:

compute expand peratom-vec global-vec1 global-vec2 …

In your case, peratom-vec would be the chunk ID. Its used
as an index into each of the global-vec args to extract the value
and the compute produces one or more per-atom vectors with
those values.

I’m thinking “expand” since it is kind of the inverse of compute reduce, which
takes a long vector and reduces it to a short value. Expand takes a short
vector (list of chunk values) and creates a long per-atom vector.

The output of compute expand could be used in a per-atom variable or
a fix like add force to add (subtract) the per-chunk COM to each atoms force
to accomplish what you asked in the first place - hold the chunk (molecules)
stationary.

Note that you still have the issue of getting the current COM force on each
chunk at the moment in the timestep you need it, namely right after
forces are computed, which is also when fix addforce will operate.
Fix ave/chunk won’t do that, so you can’t use its global vecs as args to
compute expand. I think we’d need to add another compute like
compute fcm/chunk (similar to compute vcm/chunk) to do that. Since its
just a sum, we could do it more generally, like a compute reduce/chunk
for summing/averaging any chunk value.

I can work on these new computes, but it will be a few weeks,
if someone else wants to take a whack …

Steve

Dear Steve, Axel and list,

I took a whack and wrote a new compute which works with the 10Aug15 version. I also wrote an fcm/chunk to compute the total force on chunk normalized by chunk mass (now that I think of it, I should have called it acm/chunk or something), which followed trivially from the vcm/chunk compute.

The design of the expandchunk/atom compute is exactly what Steve and Axel suggested. It reads in the global chunk arrays and generates a peratom vector. Usage and context is provided below.

I had to add the following two lines in the compute_(fcm/vcm/com)_chunk.cpp files to get them to work with my new compute:

nchunk = cchunk->setup_chunks();
size_array_rows = nchunk;

They go below the init() call on line 47, and were required as <size_array_rows> was not getting initialized to the desired value.

I’ve attached the new compute files to this mail. If anyone would like to use it, remember to add the corresponding
header files to style_compute.h.

The usage and syntax are as follows:

compute cc1 all chunk/atom molecule

compute myChunkVCOM all vcm/chunk cc1

compute myChunkFCOM all fcm/chunk cc1

compute chF all expandchunk/atom cc1 c_myChunkFCOM[1] c_myChunkFCOM[2] c_myChunkFCOM[3]
compute chV all expandchunk/atom cc1 c_myChunkVCOM[1] c_myChunkVCOM[2] c_myChunkVCOM[3]

variable forcex atom -massc_chF[1]
variable forcey atom -mass
c_chF[2]
variable forcez atom -mass*c_chF[3]

variable velx atom -c_chV[1]
variable vely atom -c_chV[2]
variable velz atom -c_chV[3]

It has worked for me so far, but if there are any issues/bugs, kindly send me a personal email as my lammps emails get directed
to a folder I don’t check often.

Regards,
Anirban

compute_expand_chunk_atom.cpp (10.1 KB)

compute_expand_chunk_atom.h (1.68 KB)

compute_fcm_chunk.cpp (6.81 KB)

compute_fcm_chunk.h (1.76 KB)

Hello,

In my last mail, I had incorrectly and ignorantly suggested that some lines be added, i.e.