fix_bond_create.cpp Question

Dear Lammps users/developers,

I looked at fox_bond_create.cpp and in the method
FixBondCreate::post_integrate(), I found something odd.

When choosing a candidate partner for bonds to be created, the routine
looks for the squared distance between i and j candidates and stores
the partner and square distances in the pointers "partner" and
"distsq" if rsq<cutsq as shown in the code snippet below.

     if (!possible) continue;

      delx = xtmp - x[j][0];
      dely = ytmp - x[j][1];
      delz = ztmp - x[j][2];
      rsq = delx*delx + dely*dely + delz*delz;
      if (rsq >= cutsq) continue;

      if (rsq < distsq[i]) {
        partner[i] = tag[j];
        distsq[i] = rsq;
      if (rsq < distsq[j]) {
        partner[j] = tag[i];
        distsq[j] = rsq;

I placed printfs so that I can see the indexes i and j of the
candidate bond atoms. And I noticed that i and j are sometimes bigger
than nlocal. So when the code continues and try to create the bond. It
loops through nlocal and it will miss those candidate atoms whose
indexes are greater than nlocal.

  int ncreate = 0;
  for (i = 0; i < nlocal; i++) {
    if (partner[i] == 0) continue;
    j = atom->map(partner[i]);
    if (partner[j] != tag[i]) continue;

    // apply probability constraint
    // MIN,MAX insures values are added in same order on different procs

    if (fraction < 1.0) {
      min = MIN(probability[i],probability[j]);
      max = MAX(probability[i],probability[j]);
      if (0.5*(min+max) >= fraction) continue;

Is this by design? This is where I had problems when I tried to write
my fix where I break one bond and create two bonds to insert a
monomer. In my code , I am always successful in finding the bond to
break but sometimes fails to create the two bonds.


Hi Jan-Michael,
i runs from 0 to nlocal so that i should never be larger than nlocal.
However j, being neighbors of i, can have indices larger than nlocal since
it includes ghost atoms. Partner[] array is forward/reverse communicated
so that ghost j (j > nlocal) also has values.


Hi Ray,

Thanks. So in my code I should be looking at
comm->reverse_comm_fix(this); and comm->forward_comm_fix(this); with
their associated pack_reverse_comm and pack_comm methods. Can you tell
me more about these methods and how they work.