[bad406] | 1 | #!@SHELL@
|
---|
| 2 | #
|
---|
| 3 | # Performs an molecular dynamics simulation with the BOSSANOVA method
|
---|
| 4 |
|
---|
| 5 | #MPIRUN="/opt/packages/mpichgm-1.2.7..15/bin/mpirun.ch_gm"
|
---|
| 6 | MPIRUN="/usr/bin/mpirun.mpich"
|
---|
| 7 | exec_prefix="@prefix@"
|
---|
| 8 | database="@bindir@"
|
---|
| 9 | MOLECUILDER="@bindir@/molecuilder"
|
---|
| 10 | JOINER="@bindir@/joiner"
|
---|
| 11 | CRUNCHER="/mount/bespin/heber/build/mpqc-2.3.0/bin/mpqc"
|
---|
[b562aa] | 12 | CONVERTER="/mount/bespin/heber/tmp/mpqc/espack2mpqc.py"
|
---|
[bad406] | 13 | PREPARER="/mount/bespin/heber/tmp/mpqc/convertresults.sh"
|
---|
| 14 |
|
---|
[7d6f65] | 15 | function check()
|
---|
| 16 | {
|
---|
| 17 | #1 MESSAGE
|
---|
| 18 | if [ $? -eq 0 ]; then
|
---|
| 19 | if [ -z $1 ]; then
|
---|
| 20 | echo "ok."
|
---|
| 21 | else
|
---|
| 22 | echo "ok: $1."
|
---|
| 23 | fi
|
---|
| 24 | else
|
---|
| 25 | if [ -z $1 ]; then
|
---|
| 26 | echo "failed."
|
---|
| 27 | else
|
---|
| 28 | echo "failed: $1."
|
---|
| 29 | fi
|
---|
| 30 | exit 1
|
---|
| 31 | fi
|
---|
| 32 | }
|
---|
[bad406] | 33 |
|
---|
[b562aa] | 34 | #function MultiRunSim {
|
---|
| 35 | # # 1 is config file dir (with all files)
|
---|
| 36 | # # 2 is the machine file
|
---|
| 37 | #
|
---|
| 38 | # ${JOBRUNNER} --mpqc ${CRUNCHER} -nprocpernode 2 -nprocperjob 1 -nthreadperproc 2 --threadgrp=posix --messagegrp=proc --memorygrp=proc --nodefile $2 --readdir $1 --inputprefix=${1}/ --outputprefix=${1}/ --autoout --verbose --rerun 2>/dev/stdout | tee -a dynamic.log
|
---|
| 39 | #}
|
---|
[bad406] | 40 |
|
---|
| 41 | function MultiRunSim {
|
---|
[b562aa] | 42 | # 1 is the number of groups
|
---|
| 43 | # 2 is the directory
|
---|
| 44 | # 3, ... are config files
|
---|
[bad406] | 45 |
|
---|
| 46 | # find the next free proc group
|
---|
[b562aa] | 47 | divisor=$1
|
---|
| 48 | shift
|
---|
| 49 | DIR=$1
|
---|
| 50 | shift
|
---|
[bad406] | 51 | started=0
|
---|
[b562aa] | 52 | pwd=`pwd`
|
---|
[bad406] | 53 | while [ $started -eq 0 ]; do
|
---|
| 54 | groupnr=1
|
---|
[b562aa] | 55 | while [ $groupnr -le $divisor ]; do
|
---|
[bad406] | 56 | if [ ! -e "${DIR}/ProcRuns${groupnr}" ]; then
|
---|
[b562aa] | 57 | #MaxNodes=`cat ${DIR}/ProcGroup${groupnr} | awk 'END{print NR}'`
|
---|
| 58 | #gamma=`grep ProcPEGamma $1 | awk -F"\t" {'print $2'}`
|
---|
| 59 | #psi=`grep ProcPEPsi $1 | awk -F"\t" {'print $2'}`
|
---|
| 60 | #let nodes=$gamma*$psi
|
---|
| 61 | #if [ $nodes -gt $MaxNodes ]; then
|
---|
| 62 | # echo "Process $1 needs too many nodes! Breaking." | tee -a dynamic.log
|
---|
| 63 | # exit 1
|
---|
| 64 | #fi
|
---|
| 65 | nodes=1
|
---|
[bad406] | 66 | echo "touch ${DIR}/ProcRuns${groupnr}" >"${DIR}/ProcBatch${groupnr}"
|
---|
[b562aa] | 67 | if [ ! -z $1 ]; then
|
---|
| 68 | echo -n "rsh `cat <${DIR}/ProcGroup${groupnr}` 'cd ${pwd}/${DIR}" >>"${DIR}/ProcBatch${groupnr}"
|
---|
| 69 | fi
|
---|
| 70 | while [ ! -z $1 ]; do # add all config files as single lines
|
---|
| 71 | #echo -n "${MPIRUN} -machinefile ${DIR}/ProcGroup${groupnr} -np $nodes " >>"${DIR}/ProcBatch${groupnr}"
|
---|
| 72 | echo -n "; ${CRUNCHER} -o ${1/conf/out} ${1/conf/in}" >>"${DIR}/ProcBatch${groupnr}"
|
---|
| 73 | shift
|
---|
| 74 | done
|
---|
| 75 | echo "'" >>"${DIR}/ProcBatch${groupnr}"
|
---|
[bad406] | 76 | echo "rm -f ${DIR}/ProcRuns${groupnr}" >>"${DIR}/ProcBatch${groupnr}"
|
---|
| 77 | /bin/sh "${DIR}/ProcBatch${groupnr}" &
|
---|
| 78 | started=1
|
---|
[b562aa] | 79 | let groupnr=${divisor}+1
|
---|
[bad406] | 80 | else
|
---|
| 81 | let groupnr=$groupnr+1
|
---|
| 82 | fi
|
---|
| 83 | done
|
---|
| 84 | # wait a few seconds
|
---|
[b562aa] | 85 | #if [ $2 -gt 1 ]; then
|
---|
| 86 | # sleep 2
|
---|
| 87 | #fi
|
---|
[bad406] | 88 | done
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | # get command line options
|
---|
[b562aa] | 92 | if [ -z $3 ]; then
|
---|
[bad406] | 93 | echo "Usage: $0 <config file> <Order> <max. bond distance> <MaxNodes> [MaxMDsteps]"
|
---|
| 94 | echo -e "\t<config file> the pcp config file of the total molecule"
|
---|
| 95 | echo -e "\t<Order> the highest bond order (i.e. the cutoff number in ANOVA series expansion)"
|
---|
| 96 | echo -e "\t<max. bond distance> maximum distance to look for bonds (bonds are associated by element covalent radii criterion)"
|
---|
| 97 | echo -e "\t[MaxMDSteps] overrides given MaxOuterStep in config file"
|
---|
| 98 | exit 1;
|
---|
| 99 | else
|
---|
| 100 | arg=$1
|
---|
| 101 | mainname=`grep mainname $arg | awk -F"\t" {'print $2'}`
|
---|
| 102 | order=$2
|
---|
| 103 | distance=$3
|
---|
[b562aa] | 104 | if [ -z $4 ]; then
|
---|
[bad406] | 105 | MaxSteps=`grep MaxOuterStep $arg | awk -F"\t" {'print $2'}`
|
---|
| 106 | else
|
---|
[b562aa] | 107 | MaxSteps=$4
|
---|
[bad406] | 108 | fi
|
---|
[b562aa] | 109 | echo "Going to run for a total of $MaxSteps steps, bond order $order and maximum distance $distance of config file $arg." | tee -a dynamic.log
|
---|
[bad406] | 110 | fi
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | # get the directory
|
---|
| 114 | DIR=`dirname $arg`
|
---|
| 115 | if [ -z "`grep $DIR $arg`" ]; then
|
---|
| 116 | echo "Cannot find the directory $DIR in the config file." | tee -a dynamic.log
|
---|
| 117 | exit 1;
|
---|
| 118 | else
|
---|
| 119 | echo "Using $DIR as directory." | tee -a dynamic.log
|
---|
| 120 | fi
|
---|
| 121 |
|
---|
| 122 | PBS_NODEFILE="${DIR}/machines"
|
---|
| 123 | if [ ! -e $PBS_NODEFILE ]; then
|
---|
[26f52a] | 124 | i=1
|
---|
| 125 | cpus=`cat /proc/cpuinfo | grep processor | wc -l`
|
---|
[bad406] | 126 | echo "localhost" >$PBS_NODEFILE
|
---|
[b7fafb] | 127 | while [ $i -lt $cpus ]; do # add one localhost per cpu to machines file
|
---|
[26f52a] | 128 | echo "localhost" >>$PBS_NODEFILE
|
---|
| 129 | let i=$i+1
|
---|
| 130 | done
|
---|
[bad406] | 131 | fi
|
---|
| 132 |
|
---|
| 133 | # delete old processor group files
|
---|
| 134 | rm ${DIR}/ProcGroup* -f
|
---|
| 135 | rm ${DIR}/ProcRuns* -f
|
---|
| 136 | rm ${DIR}/ProcBatch* -f
|
---|
| 137 |
|
---|
| 138 | # put nodes into groups
|
---|
[b562aa] | 139 | MaxNodes=0
|
---|
| 140 | for node in `cat <$PBS_NODEFILE`; do
|
---|
| 141 | let MaxNodes=$MaxNodes+1
|
---|
| 142 | done
|
---|
[bad406] | 143 | gamma=`grep ProcPEGamma $arg | awk -F"\t" {'print $2'}`
|
---|
| 144 | psi=`grep ProcPEPsi $arg | awk -F"\t" {'print $2'}`
|
---|
| 145 | let nodes=$gamma*$psi
|
---|
| 146 | let divisor=$MaxNodes/$nodes
|
---|
| 147 | echo "Using $divisor processor groups." | tee -a dynamic.log
|
---|
| 148 | nodenr=0
|
---|
| 149 | groupnr=1
|
---|
| 150 | for node in `cat <$PBS_NODEFILE`; do
|
---|
| 151 | let nodenr=$nodenr+1
|
---|
| 152 | #echo "Current node $nodenr is $node." | tee -a dynamic.log
|
---|
| 153 | let currentgrouplimit=$groupnr*$nodes
|
---|
| 154 | if [ $currentgrouplimit -lt $nodenr ]; then
|
---|
| 155 | let groupnr=$groupnr+1
|
---|
| 156 | fi
|
---|
| 157 | #echo "Putting into group $groupnr." | tee -a dynamic.log
|
---|
| 158 | echo "$node" >>"${DIR}/ProcGroup${groupnr}"
|
---|
| 159 | done
|
---|
| 160 | i=0
|
---|
| 161 | while [ $i -lt $groupnr ]; do
|
---|
| 162 | let i=$i+1
|
---|
| 163 | echo "Group nr. $i" | tee -a dynamic.log
|
---|
| 164 | echo "===========" | tee -a dynamic.log
|
---|
| 165 | cat <"${DIR}/ProcGroup${i}"
|
---|
| 166 | cat <"${DIR}/ProcGroup${i}" >>dynamic.log
|
---|
| 167 | echo -e "\n" | tee -a dynamic.log
|
---|
| 168 | done
|
---|
| 169 |
|
---|
| 170 | # copy first conf
|
---|
| 171 | cp $arg ${arg}.MD
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | i=1;
|
---|
| 175 | while [ $i -le $MaxSteps ]; do
|
---|
| 176 | # break down the molecule with molecuilder
|
---|
| 177 | echo -n "Fragmenting ... " | tee -a dynamic.log
|
---|
| 178 | ${MOLECUILDER} ${arg}.MD -e ${database} -f $distance $order 2>/dev/null >/dev/null
|
---|
| 179 | check | tee -a dynamic.log
|
---|
| 180 | echo "done." | tee -a dynamic.log
|
---|
| 181 |
|
---|
| 182 | # get the number of digits of the fragment count
|
---|
| 183 | digits=1
|
---|
| 184 | while [ ! -e ${DIR}/BondFragment`printf "%0${digits}d" 0`.conf ]; do
|
---|
| 185 | let digits=$digits+1
|
---|
| 186 | done
|
---|
| 187 | echo "Found $digits digits for the fragment number." | tee -a dynamic.log
|
---|
| 188 |
|
---|
| 189 | # get the fragment count
|
---|
| 190 | frag=0
|
---|
| 191 | while [ -e ${DIR}/BondFragment`printf "%0${digits}d" $frag`.conf ]; do
|
---|
| 192 | # unset MaxOuterStep in config file
|
---|
| 193 | sed -i -e "s#MaxOuterStep.*\##MaxOuterStep\t0\t\##" ${DIR}/BondFragment`printf "%0${digits}d" $frag`.conf
|
---|
| 194 | rm -rf ${DIR}/BondFragment`printf "%0${digits}d" $frag`
|
---|
| 195 | let frag=$frag+1
|
---|
| 196 | done
|
---|
| 197 | echo "There are $frag fragments." | tee -a dynamic.log
|
---|
| 198 |
|
---|
[b562aa] | 199 |
|
---|
[bad406] | 200 | # evaluate each fragment
|
---|
[b562aa] | 201 | # j=0
|
---|
| 202 | # while [ $j -lt $frag ]; do
|
---|
| 203 | # number=`printf "%0${digits}d" $j`
|
---|
| 204 | # # convert all configs
|
---|
| 205 | # echo -n "Converting ${DIR}/BondFragment${number}.conf ..." | tee -a dynamic.log
|
---|
| 206 | # sh $CONVERTER ${DIR}/BondFragment${number}.conf
|
---|
| 207 | # check | tee -a dynamic.log
|
---|
| 208 | # let j=$j+1
|
---|
| 209 | # done
|
---|
| 210 | #
|
---|
| 211 | # MultiRunSim ${DIR} $PBS_NODEFILE
|
---|
| 212 | #
|
---|
| 213 | # j=0
|
---|
| 214 | # while [ $j -lt $frag ]; do
|
---|
| 215 | # number=`printf "%0${digits}d" $j`
|
---|
| 216 | # # rename output files
|
---|
| 217 | # echo -n "Renaming `ls ${DIR}/BondFragment${number}.out.001.02.02` ..." | tee -a dynamic.log
|
---|
| 218 | # mv ${DIR}/BondFragment${number}.out.001.02.02 ${DIR}/BondFragment${number}.out
|
---|
| 219 | # check | tee -a dynamic.log
|
---|
| 220 | # let j=$j+1
|
---|
| 221 | # done
|
---|
| 222 |
|
---|
| 223 | # reset command arrays
|
---|
| 224 | grp=0;
|
---|
| 225 | while [ $grp -lt $divisor ]; do
|
---|
| 226 | command[$grp]=""
|
---|
| 227 | let grp=$grp+1
|
---|
| 228 | done
|
---|
| 229 |
|
---|
| 230 | # distribute the jobs among the groups
|
---|
[bad406] | 231 | j=0;
|
---|
| 232 | while [ $j -lt $frag ]; do
|
---|
| 233 | number=`printf "%0${digits}d" $j`
|
---|
| 234 | # convert all configs
|
---|
[b562aa] | 235 | #echo -n "Converting ${DIR}/BondFragment${number}.conf ..." | tee -a dynamic.log
|
---|
| 236 | #sh $CONVERTER ${DIR}/BondFragment${number}.conf
|
---|
| 237 | #check | tee -a dynamic.log
|
---|
| 238 | # and distribute
|
---|
| 239 | let grp=${j}%${divisor}
|
---|
| 240 | #echo "BondFragment${number}.conf is evaluated by group $grp."
|
---|
| 241 | command[$grp]="${command[$grp]}BondFragment${number}.conf "
|
---|
[bad406] | 242 | let j=$j+1
|
---|
| 243 | done
|
---|
| 244 |
|
---|
[b7fafb] | 245 | # go through all groups and run the job
|
---|
| 246 | olddivisor=$divisor
|
---|
| 247 | if [ $divisor -gt $frag ]; then
|
---|
| 248 | divisor=$frag
|
---|
[46cd68] | 249 | fi
|
---|
[b562aa] | 250 | grp=0;
|
---|
| 251 | while [ $grp -lt $divisor ]; do
|
---|
| 252 | number=`printf "%0${digits}d" $j`
|
---|
| 253 | echo -n "Starting calculation of group $grp with fragments \"${command[$grp]}\" at step $i ... " | tee -a dynamic.log
|
---|
| 254 | MultiRunSim $divisor ${DIR} ${command[$grp]}
|
---|
| 255 | echo "done." | tee -a dynamic.log
|
---|
| 256 | let grp=$grp+1
|
---|
| 257 | done
|
---|
[b7fafb] | 258 | divisor=$olddivisor
|
---|
[b562aa] | 259 |
|
---|
[bad406] | 260 | # wait till all ProcRuns files are gone
|
---|
[b562aa] | 261 | # if [ $divisor -gt 1 ]; then
|
---|
[bad406] | 262 | echo "Waiting for all running jobs at step $i to end ... " | tee -a dynamic.log
|
---|
[b562aa] | 263 | while [ ! -z "`find ${DIR} -name 'ProcRuns*'`" ]; do
|
---|
| 264 | #if [ ! -z "`find ${DIR} -name 'ProcRuns*'`" ]; then
|
---|
| 265 | # echo "still `ls ${DIR}/ProcRuns*` present"
|
---|
| 266 | #fi
|
---|
| 267 | sleep 1
|
---|
[bad406] | 268 | done
|
---|
| 269 | echo "done." | tee -a dynamic.log
|
---|
[b562aa] | 270 | # fi
|
---|
| 271 |
|
---|
[bad406] | 272 |
|
---|
| 273 | # convert results
|
---|
| 274 | sleep 1 # necessary for result files to close
|
---|
[b562aa] | 275 | echo -n "Converting all results ... " | tee -a dynamic.log
|
---|
[bad406] | 276 | sh $PREPARER $DIR
|
---|
| 277 | check | tee -a dynamic.log
|
---|
| 278 |
|
---|
| 279 | # join the resulting forces into a single file
|
---|
| 280 | echo -n "Joining fragment energies ... " | tee -a dynamic.log
|
---|
| 281 | ${JOINER} ${DIR}/ $mainname >/dev/null 2>/dev/null
|
---|
| 282 | check | tee -a dynamic.log
|
---|
| 283 | echo "done." | tee -a dynamic.log
|
---|
| 284 |
|
---|
| 285 | # move the ions by calling pcp with this force file
|
---|
| 286 | sed -i -e "s#MaxOuterStep.*\##MaxOuterStep\t$i\t\##" ${arg}.MD
|
---|
| 287 | echo -n "Moving ions with obtained forces at step $i ... " | tee -a dynamic.log
|
---|
| 288 | $MOLECUILDER ${arg}.MD -e ${database} -P "${DIR}/pcp.Order${order}.forces.all" 2>/dev/null >/dev/null
|
---|
| 289 | echo "done" | tee -a dynamic.log
|
---|
| 290 |
|
---|
| 291 | # last of all, put "joined" energy and forces under this step
|
---|
| 292 | cp ${DIR}/pcp.Order${order}.energy.all ${DIR}/pcp.step${i}.energy.all
|
---|
| 293 | cp ${DIR}/pcp.Order${order}.forces.all ${DIR}/pcp.step${i}.forces.all
|
---|
| 294 |
|
---|
| 295 | # next step
|
---|
| 296 | let i=$i+1
|
---|
| 297 | done
|
---|
| 298 |
|
---|
| 299 | exit 0
|
---|