Hello,
I am trying to write a custom fix that calculates unit tangent vector for every interior bead in a linear polymer. The tangent on ith bead is defined as r[i+1] - r[i-1]. The force thus calculated should be added to the main force array in POST_FORCE.
The fix takes three arguments, fp = magnitude of the tagential force, t_start = timestep when application of tangential force is started, t_stop = the force is stopped. Something likefix ID group-ID tanactiveforce fp t_start t_stop. Here is a snippet from the fix -
void FixTanactiveforce::post_force(int vflag)
{
bigint step = update->ntimestep;
if (step < t_start || step > t_stop) return;//runs fix b/w t_start and t_stop
double **x = atom->x;
double **f = atom->f;
int *mask = atom->mask;
int **bond_atom = atom->bond_atom;
int *num_bond = atom->num_bond;
int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++) {
// Apply only to group atoms and atoms with 2 bonds (skips beads at ends)
if ((mask[i] & groupbit) && num_bond[i]==2) {
int la = atom->map(bond_atom[i][0]);
int lb = atom->map(bond_atom[i][1]);
if (la == -1 || lb == -1) continue; // neighbor not on this proc
// Tangent vector = pos(a) - pos(b)
double t[3];
t[0] = x[la][0] - x[lb][0];
t[1] = x[la][1] - x[lb][1];
t[2] = x[la][2] - x[lb][2];
double mag = sqrt(t[0]*t[0] + t[1]*t[1] + t[2]*t[2]);
if (mag > 0.0) {
t[0] /= mag;
t[1] /= mag;
t[2] /= mag;
}
//printf("Step %lld: Atom %d, Tangent = (%g, %g, %g), Mag = %g\n", update->ntimestep, i, t[0], t[1], t[2], mag);
// Add tangential force to this bead
f[i][0] += fp * t[0];
f[i][1] += fp * t[1];
f[i][2] += fp * t[2];
}
}
}
The problem is that I am not seeing the effects of active force in the animation. I have confirmed that the fix is being compiled. I am using atom_style angle
Below is a portion of my script.
fix 1 all langevin 1.0 1.5 1.0 904297
fix 2 all tanactiveforce 10.0 1 5000
fix 3 all nve
timestep 0.005
thermo 500
thermo_style custom step
dump 1 all custom 50 dump.polymer3d.lammpstrj.cusfix.100b.5fp id type xu yu zu
run 5000
I am following the LAMMPS developer guide and this project for reference.