[lammps-users] reset atom coordinates to specific timestep

Hello everybody,

i am using lammps version of 24th december and trying to save atom coordinates when a condition is met and then reset the coordiantes after another condition is met at a specific timestep (only minimization is done here). I am able to store my coordinates by using a fix which adds the coordinates of the atoms to an array:

void own::addState(int currstate)
{
    fix_s->add_vector(7);
    double *x0;
    x0 = fix_s->request_vector(currstate);
    double **x = atom->x;
    int *tag = atom->tag;
    int *type = atom->type;
    int *image = atom->image;
    int *mask = atom->mask;
    int nlocal = atom->nlocal;
    int n = 0;
    for (int i = 0; i < nlocal; i++){
        x0[n] = x[i][0];
        x0[n+1] = x[i][1];
        x0[n+2] = x[i][2];
        x0[n+3] = tag[i];
        x0[n+4] = type[i];
        x0[n+5] = image[i];
        x0[n+6] = mask[i];
        n += 7;
    }
}

The problem is in MPI when i want to reset my coordinates to a specific timestep i am losing atoms:

void own::back()
{
    double *x0;
    x0 = fix_s->request_vector(0); // get coordinates for timestep (here 0)
    double **x = atom->x;
    int nlocal = atom->nlocal;
    int *tag = atom->tag;
    int *type = atom->type;
    int *image = atom->image;
    int *mask = atom->mask;
    int n = 0;
    int triclinic = domain->triclinic;
    for (int i = 0; i < nlocal; i++){
        x[i][0] = x0[n];
        x[i][1] = x0[n+1];
        x[i][2] = x0[n+2];
        tag[i] = x0[n+3];
        type[i] = x0[n+4];
        image[i] = x0[n+5];
        mask[i] = x0[n+6];
        n += 7;
    }
    output->write_dump(update->ntimestep);
    atom->setup();
    modify->setup_pre_exchange();
    if (domain->triclinic) domain->x2lamda(atom->nlocal);
    domain->pbc();
    domain->reset_box();
    comm->setup();
    if (neighbor->style) neighbor->setup_bins();
    comm->exchange();
    if (atom->sortfreq > 0) atom->sort();
    comm->borders();
    if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost);
    domain->image_check();
    domain->box_too_small_check();
    modify->setup_pre_neighbor();
    neighbor->build(1);
    modify->setup_post_neighbor();
    neighbor->ncalls = 0;

}

Now i do understand the issue but how can i solve my problem ? Do i need to add a fix where the atom exchange between the processors happens ? I could not find a fix which does a similar thing.

Best regards