(Quasi) Minimal Script for running sweeping inputs

The following script in Python runs the inputs that are created by this script. The symbol # means comment.

from lxml import etree as ET
import os 
import subprocess as sp
 
p=[]  # Definition of the variable to execute processes
 
for rgkm in [6.00, 6.25, 6.50, 6.75, 7.00, 7.25, 7.50, 7.75, 8.00, 8.25, 8.50, 8.75, 9.00]:
 for ngk in range(3, 21):
 
  os.chdir("ngridk_"+str(ngk)+"-rgkmax_"+str(rgkm))  # Enter directories for sweeping
 
  out=open('stdout','w')  # Opening the files to store the standard output and error messages
  err=open('stderr','w') 
 
  # Print the values of the input parameters ngridk and rgkmax to files, to read and plot them later:
  output_obj = open('ngridk',"w")
  print >>output_obj, ngk
  output_obj.close()
 
  output_obj = open('rgkmax',"w")
  print >>output_obj, rgkm
  output_obj.close()
 
  print "\n Now running Exciting in directory"+os.getcwd()
 
  # Run exciting in serial:
  p.append(sp.Popen([os.environ["EXCITINGROOT"]+'/bin/excitingser'],
            stdout=out, \
            stderr=err
            )) 
 
  # Run exciting in parallel, in 4 cores:
  #p.append(sp.Popen(['mpiexec', '-n','4 ', os.environ["EXCITINGROOT"]+'/bin/excitingmpi'],
  #      stdout=out, \
  #      stderr=err
  #      )) 
 
  err.close() # Closing the files for standard error and output
  out.close()
 
  p[-1].wait() # This makes that the executions of exciting in the loop are not run simultaneously, but
               # starting after one another. To make their execution simultaneous, just comment this line
 
  # Remove the files occupying much space (to avoid storage problems) (DO IT ONLY WITH wait ACTIVATED)
  pathname = os.path.abspath(os.path.join("./", "STATE.OUT"))
  os.remove(pathname)
  pathname = os.path.abspath(os.path.join("./", "EVECFV.OUT"))
  os.remove(pathname)
 
  os.chdir('..') # Move back to the previous directory (like $ cd ..)
 
print "\n"

As can be viewed above, either the line to run Exciting in serial or the one to run exciting in parallel must be commented.

Be sure that the loops in rgkm and in ngk are identical in the script above and in the script for generating inputs.

Once all the calculations are run, the results can be collected to a file with the following bash script:

#!/bin/bash    
#
###########################################################################
#
# This bash script reads the files containing the input parameters of the
# sweeping (in this case ngridk and rgkmax), and also the corresponding output
# (i.e., the energy of the system calculated by Exciting, which is taken from
# the file ENERGYTOT.OUT), and writes it in the file sweeping.out
#_______________________________________________________________________________
#

#!/bin/bash
FILEOUT="./sweeping.out"

# Opening file descriptors # 3 for reading and writing
# i.e. ./sweeping_Ag.out
exec 3<>$FILEOUT

# Write to file

for ngk in {3..20};
do
 for rgkm in 6.0 6.25 6.5 6.75 7.0 7.25 7.5 7.75 8.0 8.25 8.5 8.75 9.0;
 do
   cd "ngridk_"$ngk"-rgkmax_"$rgkm
   cell1=`awk '{print $1}' FS=" " ./ngridk` 
   cell2=`awk '{print $1}' FS=" " ./rgkmax`
   cell3=`awk '{print $1}' FS=" " ./TOTENERGY.OUT | tail -n1`
   echo $cell1  $cell2  $cell3 >&3
   cd ..
 done
done

# close fd # 3
exec 3>&-
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License