Reading the lines of a text file one by one in LAMMPS

Hello LAMMPS users,

I am using the LAMMPS version 23Jun2022. I dumped the selected atoms of type 1 from a specified region into a text file.

region R block 0 80 INF INF INF INF
group selreg region R
group selatom type 1
group select intersect selreg selatom
variable nn equal “count(select)”
print “Number of atoms selected = ${nn}”
write_dump select custom Selected_Atoms.txt id

Then I used variable type ‘file’ to open the created text file full of atom IDs.

variable atomlist file Selected_Atoms.txt

But I am not sure how to go through the list of atom IDs in that text file line by line. I used the ‘next atomlist’ command followed by ‘jump Selected_Atoms.txt’ to try to go through the lines in the text file, but it gave me an error. What is/are the right way or the right command/s to implement this?


What is the error message? And have you tried changing your script based on what it says?

LAMMPS developers spend time and effort putting those error messages into the code instead of having LAMMPS just crash out silently. So please use that information (or help us improve it if the error message doesn’t help).

Why do you have to go through the list of atom IDs line by line? What is the task you are trying to accomplish? LAMMPS is not a general-purpose programming language; it is specialised for very customisable MD simulations, which means that (1) almost anything you want to do in a good simulation is possible in LAMMPS (2) it may not often be exposed in programming paradigms such as list comprehension.