Randomly select a certain number of atoms (more than 1)

Hi @hdy2022,
Some comments here:

  1. Please help people read your post by enclosing your script extract between three backticks characters ``` (do not use apostrophes '). See more about formatting your post here. You can read the other useful general advices there.
  2. Your script is long and complicated. Try to restrict it to a simple case if you want meaningful help from other users.
  3. The error gives you the line at which the code fails: variable a equal $(v_check[v_select]) But this line does not appear elsewhere in your script extract and full script. Is this normal?
  4. I am not sure the command random(1, atoms, 4224) is legal. I think you should give it the variable natoms instead of atoms. Not sure this is related to your problem though.