1#!/usr/bin/env bash
2#
3# Simple script to run octopus for all atoms in the
4# periodic table for which pseudopotentials are available.
5#
6
7
8# the defaults file
9defaults=/usr/share/octopus/PP/defaults
10
11# the octopus executable
12octopus=/usr/bin/octopus
13
14ECHO=""
15fromScratch="yes"
16
17# usage
18function usage() {
19    cat <<EOF
20
21 Copyright (C) 2005 by Heiko Appel
22
23Usage: oct-run_periodic_table [options]
24    
25     -h              this message
26     -n              dry run mode (show what would be executed)
27     -s species      run octopus for given species
28     -a              run octopus for all atoms            
29     -r              do a restart, i.e. do not use fromScratch=yes
30     -t temperature  run with electronic temperature
31     -e no_states    use extra states
32     -x              octopus executable
33     -d              defaults file for pseudopotentials
34
35Report bugs to <appel@physik.fu-berlin.de>.
36EOF
37 exit 0;
38}
39
40
41# show usage info if no args at all
42[ "$#" -eq 0 ] && usage;
43
44# process command line options
45while getopts "hns:art:e:x:d:" opt ; do
46    case "$opt" in
47        h) usage ;;
48        n) ECHO="echo" ;;
49        s) species="$OPTARG" ;;
50        a) ECHO="" ;;
51        r) fromScratch="no" ;;
52        t) electronic_temp="$OPTARG" ;;
53        e) no_states="$OPTARG" ;;
54        x) octopus="$OPTARG" ;;
55        d) defaults="$OPTARG" ;;
56        ?) echo "Error parsing arguments"; exit 1 ;;
57    esac
58done
59shift $(( OPTIND - 1 ))
60
61# do we have all required files?
62if [ ! -x $octopus  ]; then
63  echo "Error: could not find octopus executable: $octopus"
64  exit 1
65fi
66if [ ! -f $defaults ]; then
67  echo "Error: could not find defaults file: $defaults"
68  exit 1
69fi
70
71if [ "$species" = "" ]; then
72  # for which atoms are pseudopotentials available?
73  pseudos=$(awk '{ print $1 }' $defaults | grep -v "#")
74else
75  pseudos="$species"
76fi
77
78# loop over all pseudopotentials
79for x in $pseudos; do
80
81  # TM2(100) or HGH(101)?
82  flavour=$(grep -E "${x}[[:space:]]" $defaults | grep -v "#" | awk '{ print $3 }');
83  # Extract atomic number
84  atomic_no=$(grep -E "${x}[[:space:]]" $defaults | grep -v "#" | awk '{ print $4 }');
85
86  # generate working directory
87  workdir=$(printf "%02d_%s\n" ${atomic_no} ${x})
88  $ECHO mkdir $workdir
89
90  # setup input file
91  if [ -d $workdir ]; then
92    {
93cat <<-EOF
94
95CalculationMode = gs
96fromScratch = $fromScratch
97
98%Coordinates
99  "$x" | 0 | 0 | 0
100%
101
102EOF
103    } > $workdir/inp 2>/dev/null
104
105    if [ "$electronic_temp" = "" ]; then
106	# append atomic configuration
107	/usr/bin/oct-atomic_occupations -s $x >> $workdir/inp
108    else
109
110    {
111cat <<-EOF
112
113ElectronicTemperature = $electronic_temp
114ExtraStates = $no_states
115
116EOF
117    } >> $workdir/inp 2>/dev/null
118
119    fi
120
121  fi
122
123  # change to working directory
124  $ECHO pushd $workdir
125
126  # run octopus
127  echo "running $workdir ..."
128  $ECHO nice -n 19 $octopus
129
130  # change to previous directory
131  $ECHO popd
132
133done
134