#!/bin/bash -l
#$ -P Gold
#$ -A KCL_Kantorovitch
#$ -l h_rt=12:00:00
#$ -N cp2k_test
#$ -pe mpi 20
#$ -cwd

module purge
module load gerun
module load gcc-libs
module load compilers/gnu/4.9.2
module load mpi/openmpi/3.1.4/gnu-4.9.2
module load openblas/0.3.7-openmp/gnu-4.9.2
module load cp2k/7.1/ompi/gnu-4.9.2

export OMP_NUM_THREADS=1


for d1 in 0 1 2 3 4
do
  for d2 in 0 1 2 3 4
  do
    for d3 in 0 1 2 3 4
    do

	cd $d1.$d2.$d3

#..... run CP2K
    
	gerun cp2k.popt -inp input.inp > output.out  

#..... collect all file names of the KS Hamiltonian

	ls Gold-KS_MAT-1_0_*Log > names.dat

#...... determine the KS Hamiltonian file from the last iteration

	~/bin/lastname > 0
	echo 'last name found is ' `cat 0`

#...... move it to a fixed name; remove the rest of the files

	mv `cat 0` Gold-KS_MAT_last.Log
	rm Gold-KS_MAT-1*.Log
	rm *bak*
	rm cp2k*
	
	cd ..

    done
  done
done




