Running lammps in consecutive folders

Dear lammpsers,

I have simulations with a number of potential values that I am studying, and I am interested whether I can execute lammps first in folder 0, than folders 1, 2, etc... Without the need to do it manually?

With best wishes,
Anna

Dear lammpsers,

I have simulations with a number of potential values that I am studying,
and I am interested whether I can execute lammps first in folder 0, than
folders 1, 2, etc... Without the need to do it manually?

http://lammps.sandia.gov/doc/shell.html

Dear Axel,

Thank you very much, I do see the cd command there but do not see how that can be used with a variable?
So say for example I want lammps to run in folders 1-5, I want something like this perhaps?
variable x uloop 5 pad
shell cd $x

Dear Anna,

Are you running lammps sequentially? (e.g. Folder 1 then Folder 2 then
Folder 3...etc) Or, are you running all of them at the same time? For
the latter case, it would be better to do it in bash or some shell
script.

#!/bin/bash

dir=(Folder1 Folder2 Folder3)
for d_t in ${dir[*]}
do
echo $d_t
cd `echo $d_t`
mpirun -np $PROCS $LMP_PATH/lmp_binary < in.script &
cd ../
done
wait

Dear Jan-Michael,

thank you for your response! I am running them sequentially- one after another.

Dear Anna,

> Dear Axel,
>
> Thank you very much, I do see the cd command there but do not see how
that
> can be used with a variable?

​have you actually *tried* it?​

> So say for example I want lammps to run in folders 1-5, I want something
> like this perhaps?
> variable x uloop 5 pad
> shell cd $x

​please also read:
http://lammps.sandia.gov/doc/variable.html​

Dear Axel,

I guess the way I articulated my problem was wrong, and I did read the documentation, but not everything in it was clear to me. In his example, Jan-Michael is operating with several folders one by one, by this is not exactly how I need it: Firstly, I need 1000 values, hence 1000 folders, and it would not be easy to type that up in this manner, if we are talking about a bash script: dir=(Folder1 Folder2 Folder3).

Another important issue is that I am using a colvar file, which has to be copied from the previous folder to the new one and the harmonic constraint has to be changed according to the number of the folder. Also, before we move from folder 0 to folder 1, we need to copy the restart file as an initial configuration of the structure in folder 1.

if you need to do many things like that, maybe you should consider using lammps as a library?

You could also consider having the bash script make the files/folders you need as it runs. Doing so would make the folders based on some template name instead of doing each manually. This would also allow you to make new colvar file for each folder and let you write some predefined or looped variable as the harmonic in each new file.

Additionally, if all start from the same restart file, you could have the restart file (and any other files you need that aren’t changing) in the overall directory and copy it as each folder is made.

if i may add to this - i’ve been using python as a very effective tool to prepare all sorts of data for lammps, as well as run batches of simulations under various conditions.

with the subprocess module you have a reasonably powerful tool to execute shell commands and already the basic I/O capabilities of python allow you to read, parse and generate input files for lammps. there’s also modules measuring the cpu load if you want to run a bunch simulations simultaneously (at least on a workstation). the pizza.py package is probably providing you with bunch of extremely helpful tools as well.

i don’t want to push you into anything, though - running python scripts that call other python scripts that call mpirun that calls lammps that uses infiles that include parameter files that were generated by some python script called somewhere throughout the process may not be the best practice. on the upside, if you end with a mess with this approach, it’s at least a reproducible one.

best,

nikita

Dear Axel,

I guess the way I articulated my problem was wrong, and I did read the
documentation, but not everything in it was clear to me. In his example,
Jan-Michael is operating with several folders one by one, by this is not
exactly how I need it: Firstly, I need 1000 values, hence 1000 folders, and
it would not be easy to type that up in this manner, if we are talking
about a bash script: dir=(Folder1 Folder2 Folder3).

Another important issue is that I am using a colvar file, which has to be
copied from the previous folder to the new one and the harmonic constraint
has to be changed according to the number of the folder. Also, before we
move from folder 0 to folder 1, we need to copy the restart file as an
initial configuration of the structure in folder 1.

​i don't see how any of that is an insurmountable problem​ and either could
be realized through either writing a script wrapper around your various
lammps runs and passing settings from the script either through processing
template files or passing variables with the -var command line flags, or
via using the shell command in LAMMPS. it is simply a matter of breaking
the procedure down to small steps and implementing them step by step. but
that is something *you* will have to sort out for yourself.

perhaps you should practice some advanced shell scripting and text
processing first, so that you see what kind of tools you can combine how.

axel.

Assuming you name your 1000 folders (dirs) something
like fooN, where N = 1 to 1000, then it is easy to have

one simple LAMMPS script loop over them and run

1000 simulations, either one after the other, or in parallel
on as many procs as you wish. Section 6.4 of the manual

discusses several ways to do it and has snippets of
input scripts.

Steve