[lammps-users] Image flags!

Dear Lammps users,

I am using “chain.f” file to generate initial polymer configuration. However, I had to
modify it to suit my interest. I understood the program except for the part where
image flags are generated. The program has a comment “includes image flags in data file so chains can be unraveled later”.
And the chunk of code where the image flags are generated is a bit confusing for me

if (abs(x(n)-x(n-1)) < 2.0*bondlength(iset)) then
imagex(n) = imagex(n-1)
else if (x(n) - x(n-1) < 0.0) then
imagex(n) = imagex(n-1) + 1
else if (x(n) - x(n-1) > 0.0) then
imagex(n) = imagex(n-1) - 1
endif

and similar chunks for y and z coordinates also. I don’t understand this part. Can anyone help me with this. Thanks in advance.

Regards
Srikanth

Srikanth,

As you know, this “chain.f” tool is creating a polymer chain that consists of bonded beads. Any given chain might pass out the side of the box through the periodic boundary condition (pbc) and back in the opposite side. As you’ve noted, the “chain.f” tool keeps track of the image flags so that the application of the pbc can be undone later (like during post-processing). This code snippet that you’ve pasted assigns the image flag to the most recently added bead of the growing chain. Note that the new bead has already had pbc applied to it, and so may sit on the opposite side of the box from the previous bead. The new bead gets the same image flag as the previous bead if they are close together. If the new bead is far to the left of the previous bead, then the new bead gets an image flag one larger than the previous bead. If the new bead is far to the right of the previous bead, then the new bead gets an image flag one less than the previous bead. I hope this helps.

Paul