it seems a clever way to get rid of this problem with set command.
but before using set command, we should put the target atoms based on bonded neighbours into a group. What commands did you use for judging bonded neighbours of an atom？maybe it’s hard and inconvenient.
can you put a simple example？
by the way, i don’t really understand
“i+2 i j
i+3 i j
i j j+2” . what does plus mean?