How to run many simulations with the same input file but different data files?

Dear LAMMPS users and developers,

I have N data files named: datafile_1, datafile_2, …, datafile_N.

I would like to run the same simulation for each one of them, as follows:

for i=1 to N
read_data datafile_i ;
execute the algorithm;
dump myDump all atom 100;

Does the for loop exist on LAMMPS ? if not, Is there any alternative ?

Best regards,

Yes, this exists, but not quite with this kind of syntax. On top of it, you could also use the partition keyword and run multiple calculations concurrently in parallel as separate MPI groups.

There are several kinks and caveats:

  • since the read_data command defines a simulation box and you can define that box only once, you have to start each loop with a “clear” command to reset the state of the LAMMPS simulation entirely (except for variables)
  • you can either use a loop, an index, or a file style variable to loop over, for a multi-partition run, there also are uloop or universe style variables
  • you need to use the “label”, “jump” and “next” commands in your script besides the variable definitions
1 Like

I’ve found that my scripts look the cleanest when I use getenv variables and then control the overall set-of-simulations with an external script. For example:

(in LAMMPS script)

variable n getenv N
read_data datafile_$n
print 'Some Generic Output' file output_$n

(in wrapper script / on command line)

for nloop in {1..5}; do export N=$nloop; lmp -i input_script; done

(note N=$nloop cannot have spaces).

As for more advanced needs such as running this script on a computing cluster, running these jobs in parallel, etc, those will then be shell scripting questions that are separate from running LAMMPS itself.

1 Like

Thanks a lot. It perfectly worked.

1 Like