Dear All,

Recently, I am trying to modify fix_addforce.cpp to get rid of the limit imposed by group, basically, I want to be able to add different forces to each individual molecules based on their position and direction. So in the new addforce(name it fix_push), I will use coordinate information of some atoms belong to each molecule to decide the direct of my addforce.

the main part of code I modify is in post_force:

"

double unwrap[3];

double unwrap2[3];

double dx,dy,dz, dist;

int j;

for(int i = 0; i < nlocal; i++){ // i is the local index, not the id

if(mask[i] & groupbit){ // if the particle is in the right group

if(region && !region->match(x[i][0],x[i][1],x[i][2])) continue;

if( i-mol_length*int(i/mol_length) == 0){ // this is the first particle of a molecule

domain->unmap(x[i],image[i],unwrap);

j = i+1;

domain->unmap(x[j],image[j],unwrap2);

// compute the versor

dx = unwrap[0]-unwrap2[0];

dy = unwrap[1]-unwrap2[1];

dz = unwrap[2]-unwrap2[2];

dist = sqrt(dx*dx + dy*dy + dz*dz);
dx /= dist;
dy /= dist;
dz /= dist;
// now we need to find the position of particles i and j, and bla bla
foriginal[0] -= xvalue*unwrap[0] + yvalue

*unwrap[1] + zvalue*unwrap[2]; // energy change

foriginal[1] += fvalue

*dx;*

foriginal[2] += fvaluedy;

foriginal[2] += fvalue

foriginal[3] += fvalue

*dz;*

f[i][0] += fvaluedx;

f[i][0] += fvalue

f[i][1] += fvalue

*dy;*

f[i][2] += fvaluedz;

f[i][2] += fvalue

}

}

}

"

It went on good for most of the case, but sometimes the molecule is not moving as I hoped. Sometimes, it is moving forward and move backward and is oscillating all the time. So I’m thinking is it because I didn’t consider what the difference of i of nlocal and id of atoms. I’m not very clear about how lammps communication and organized in multi-processors(parallel).

Will the id of atoms change during the process of running ? and is it ok that I manipulate as i show in the code? and anyone can tell me the use of foriginal here and how to understand “domain-> unmap(x[j],image[j],unwarp)”, I know the function of it, but I don’t know for example, what is image[i].

anyone who can tell me any of my questions are welcome to reply. I may ask too many questions at one time.