[lammps-users] Modify displace_atoms command

Hello, all

I tried to add "INPUT" option to the command "displace_atoms " but did not
succeed. I want to do it like this: read information from a data file by
processor 0
then broadcast to other processors. If the type of atoms is matched, the
coordinates of atoms (x,y,z) will be assigned values as read from the file.

Codes are attached here:

else if (style == INPUT) {

    int me;
  int m;
  int itg,ityp;
  double xtmp,ytmp,ztmp;
  char *buffer,*buffer2;
  char *next;

  buffer = new char[CHUNK*MAXLINE];
  buffer2 = new char[CHUNK*MAXLINE];
      MPI_Comm_rank(MPI_COMM_WORLD,&me);

    FILE *fp;
    int ninput;

    double **x = atom->x;
    int *mask = atom->mask;
    int nlocal = atom->nlocal;

  if (me == 0)
    {fp = fopen(arg[2],"r");
      if (fp == NULL) {
          char str[128];
              sprintf(str,"Cannot open file %s",arg[2]);
      error->one(str);
        }
    fgets(buffer,MAXLINE,fp);
    fgets(buffer,MAXLINE,fp);
    fgets(buffer,MAXLINE,fp);
    fgets(buffer,MAXLINE,fp);
    sscanf(buffer,"%d",&ninput);
    fgets(buffer,MAXLINE,fp);
    fgets(buffer,MAXLINE,fp);
    fgets(buffer,MAXLINE,fp);
    fgets(buffer,MAXLINE,fp);
    fgets(buffer,MAXLINE,fp);
    }
         MPI_Bcast(&ninput,1,MPI_INT,0,MPI_COMM_WORLD);

    for (int i = 0; i < ninput; i++) {

  if (me == 0) {
        char *eof = fgets(buffer,MAXLINE,fp);
        if (eof == NULL) error->one("Unexpected end of data file");
        m = strlen(buffer) + 1;
  }

    MPI_Bcast(&m,1,MPI_INT,0,MPI_COMM_WORLD);
    MPI_Bcast(buffer,m,MPI_CHAR,0,MPI_COMM_WORLD);
    sscanf(buffer,"%d %d %lg %lg %lg",&itg,&ityp,&xtmp,&ytmp,&ztmp);
    // printf("%d\n",itg);

       if ((mask[itg] & groupbit)&&(ityp==4)) {
          x[itg][0] = xtmp;
    x[itg][1] = ytmp;
    x[itg][2] = ztmp;
    // printf("%d %d %d %lg %lg %lg\n",i,itg,ityp,xtmp,ytmp,ztmp);
      }
    }
  if (me == 0) fclose(fp);

    // move atoms in ramped fashion

  }

I will be greatly appreciated if you can take a look and give me some
suggestions.

Best regards,
Wen

----- End forwarded message -----