Lammps input script error in loop

Hello, everyone, I want to access the list number of each atom by atom vector. I used the compute command to run it, and reported an error “non digit character between brackets in variable”. What should I do? I would appreciate it if it could be solved.
The script is the following:

units metal

dimension 3
atom_modify map yes
change_box all boundary p f p
variable xlow equal 25.7751
variable xhigh equal 221.081
variable ylow equal 1.95017
variable yhigh equal 86.1442
variable zlow equal 15.9019
variable zhigh equal 71.5211

variable cutoff_1 equal 1.7             #cutoff distance of sp2
pair_style airebo 4.0
pair_coeff * * CH.airebo C NULL
pair_style tersoff
pair_coeff  * * BNC.tersoff C N
region region_box block ${xlow} ${xhigh} ${ylow} ${yhigh} ${zlow} ${zhigh} units box
group group_fiber region region_box
variable n_atom_box equal count(group_fiber,region_box)

#identify sp2
compute num_neibor all coord/atom cutoff 1.7
variable temp_v1 atom c_num_neibor
thermo 1000
dump 1 all custom 800 id v_temp_v1
run 0
#variable temp_v2 atomfile
variable temp_v2 vector temp_v1
variable i loop ${n_atom_box}
label loop_sp2  
    print $(v_temp_v2[i])
    if '(v_temp_v2)==3' then &
        'group group_sp2 id i'
next i
jump fiber_1.lmp loop_sp2  
set group group_sp2 type 2

This all seems horribly complex and needlessly so. It is almost an abuse of the LAMMPS script language. Why not try defining the group based on an atom style variable?

variable sp2atom atom c_num_neibor==3
group group_sp2 sp2atom

Thanks for your comments. Although I have tried to learn lammps through the help document, I’m sorry for my superficial understanding of lammps. Thanks for your help again.

Dear akohlmey,
Could I ask you some questions? I’m confused about the vector and atom styles in variable, such as’ variable temp_v1 atom c num neighbor’. Does it store the number of neighboring atoms calculated by ‘c_num_neighbor’ in the variable temp_v1? In this case, since each atom has a number of neighboring atoms, temp_v1 should be a vector or matrix. The help document mentions’ ‘For atom-style variables, the formula computers one quantity for each atom when it is evaluated.’, which seems to be only a brief introduction.
Another example is ‘variable temp_v1 vector’. Does it define a vector? Whether array can be used in lammps, which can bring a lot of convenience when processing data.
In addition, can the atomic vector be directly accessed? For example, use ‘Compute num_neibor All coord/Atom cutoff 1.7’ to calculate the number of neighboring atoms, whether the result of num_neibor can be assigned to a vector, so that it can be regarded as an atomic vector like x, y, z, vx, vy, vz, which be accessed by x[i], y[i] et al. I look forward to your reply, which will help us to better understand lammps scripting language. Thank you sincerely.

  • you are trying to use the LAMMPS input language for what it was not designed for. it is not a generic scripting language where you can program complex operations. you need to specifically keep in mind the parallel data model of LAMMPS which complicates things massively. if you want more flexibility in scripting (and are not running in parallel!!), you can achieve much more using the LAMMPS python module and do your scripting in python instead. if you do want to run in parallel, you need to do parallel programming at the python script level as well.

  • you have not read up enough about the types of “variables” (the term variable is a bit of a misnomer, since many of them are more like functions) and the LAMMPS data model. Atoms are in general distributed across multiple processors and an “atom style” variable is processed for each atom individually and stores one result per atom. “vector style” variables in contrast are “global” (i.e. are a list of values stored on every processor in the same order). whenever you do operations like you did in your input, you first need to copy data from each MPI process to global space (for all MPI processes) and then process them on each process simultaneously and identically. that is not very efficient and often cumbersome, too.

  • you are making the mistake to infer properties from names or how you would think they should be. that will not work. you need to study the documentation carefully. if you encounter a too terse description, then likely you are missing some other explanation about something more general that is elsewhere in the same page or given with related commands.

  • some tasks are much easier done in post-processing. so it would be sufficient to make certain you output the relevant data and then write your custom program to analyze the results.

Thank you for your reply, which is very helpful to me.