Compute chunk com with wrapped coordinates?

Hello lammps users:

I am trying to compute center-of-mass coordinates of spatial bins divided in z-direction with compute com/chunk, the Nchunk and ids are updated every step.

I know that the com/chunk uses unwrapped atom coordinates, but I would like to use wrapped coordinates to do the job, I set the atoms to image 0 in the script but it only guarantees the atoms are in image 0 in the first step, after that the atoms may cross pbc and enter another image.

Is there any way to accomplish this besides post-processing the dump file??

Thanks, let me know.

Best,

Jianlan

the simplest approach would be to change the source code.
the LAMMPS developers are aware of this issue: https://github.com/lammps/lammps/issues/1710
but nobody has yet had the time to implement a general solution.

for your specific case you would need something like this (untested):

diff --git a/src/compute_com_chunk.cpp b/src/compute_com_chunk.cpp
index c39911214…8669d2e33 100644
— a/src/compute_com_chunk.cpp
+++ b/src/compute_com_chunk.cpp
@@ -32,13 +32,14 @@ ComputeCOMChunk::ComputeCOMChunk(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg),
idchunk(NULL), masstotal(NULL), massproc(NULL), com(NULL), comall(NULL)
{

  • if (narg != 4) error->all(FLERR,“Illegal compute com/chunk command”);
  • if (narg < 4) error->all(FLERR,“Illegal compute com/chunk command”);

array_flag = 1;
size_array_cols = 3;
size_array_rows = 0;
size_array_rows_variable = 1;
extarray = 0;

  • unwrap_flag = 1;

// ID of compute chunk/atom

@@ -46,6 +47,16 @@ ComputeCOMChunk::ComputeCOMChunk(LAMMPS *lmp, int narg, char **arg) :
idchunk = new char[n];
strcpy(idchunk,arg[3]);

  • if (narg == 6) {
  • if (strcmp(arg[4],“unwrap”) == 0) {
  • if (strcmp(arg[5],“yes”) == 0) {
  • unwrap_flag = 1;
  • } else if (strcmp(arg[6],“no”) == 0) {
  • unwrap_flag = 0;
  • } else error->all(FLERR,“Illegal compute com/chunk command”);
  • } else error->all(FLERR,“Illegal compute com/chunk command”);
  • } else error->all(FLERR,“Illegal compute com/chunk command”);