bashgnu-parallelmultiple-arguments

How to run on BASH a python script that takes multiple arguments using GNU parallel?


I have a python script which I normally execute from BASH shell like this:

pychimera $(which dockprep.py) -rec receptor1.pdb -lig ligand1.mol -cmethod gas -neut

As you see some of the arguments need an input (e.g. -rec) while others don't (e.g. -neut). I must execute this script 154 times with different inputs. How is it possible to run 8 threads in parallel using GNU parallel script?

pychimera $(which dockprep.py) -rec receptor1.pdb -lig ligand1.mol -cmethod gas -neut
pychimera $(which dockprep.py) -rec receptor2.pdb -lig ligand2.mol -cmethod gas -neut
pychimera $(which dockprep.py) -rec receptor3.pdb -lig ligand3.mol -cmethod gas -neut
...

Solution

  • Example commands.txt generator script:

    #!/usr/bin/env bash
    
    if [ "$#" -ne 1 ]; then
        echo "missing parameter: n"
        exit 1
    fi
    
    rm commands.txt 2> /dev/null 
    dockp=$(which dockprep.py)
    
    for((i=1;i<=$1;i++)); do
      echo "pychimera $dockp -rec receptor$i.pdb -lig ligand$i.mol -cmethod gas -neut" >> commands.txt
    done
    

    If you save above bash script as cmdgen.sh you can run it as:

    bash cmdgen.sh 100
    

    if you need n to be 100.

    To run commands in parallel:

    $ module load parallel
    $ parallel < commands.txt