loop / if for number of sputtered atoms

Dear All,

I try to calculate the number of sputtered atoms in each step
and print it out.
However, I have difficulty in writing a simple cycle for
this purpose even after checking the manual:

dear peter,

2011/8/11 Süle Péter <[email protected]>:

Dear All,

I try to calculate the number of sputtered atoms in each step
and print it out.
However, I have difficulty in writing a simple cycle for
this purpose even after checking the manual:

------------------------------------------------------------------
# calculate sputtered atoms

variable i loop natoms
if "${z[i]} > 30" then &
"variable ns equal v_ns + 1"

fix sp cr print 100 "number of sputtered atoms = ${ns}"
------------------------------------------------------------------

I tried different options, but I get all the time
ERROR: Illegal if command
or in other cases "illegal substitution' or so.

Basically I do not understand how to cycle over 'i', the ID of atoms
in order to check a z-coordinate of each atoms.
This looks very simple but does not work for me.
Could you help me please ?

i don't think that this _can_ work. you always have
to keep in mind that in lammps everything is done
in parallel and that different MPI tasks have only
a subset of information available to them. that is
particularly true for atom style variables.

what you can try is a compute reduce operation:
in your specific case, i would define a region for the
area that you want to count atoms in, then define an
atom style variable that is initialized to 1 and then
use compute reduce/region to sum this variable for
the given region. that should give you a c_ style
property that you can output with a print.

this is off the top of my head, so there may be
better ways to do this, but it follows the logic of
how things are done in lammps more closely.

cheers,
     axel.