source: util/src/dynamicANOVA.sh.in@ b7fafb

Last change on this file since b7fafb was b7fafb, checked in by Frederik Heber <heber@…>, 17 years ago

nothing really changed, just identation

  • Property mode set to 100755
File size: 8.8 KB
Line 
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"
6MPIRUN="/usr/bin/mpirun.mpich"
7exec_prefix="@prefix@"
8database="@bindir@"
9MOLECUILDER="@bindir@/molecuilder"
10JOINER="@bindir@/joiner"
11CRUNCHER="/mount/bespin/heber/build/mpqc-2.3.0/bin/mpqc"
12CONVERTER="/mount/bespin/heber/tmp/mpqc/espack2mpqc.py"
13PREPARER="/mount/bespin/heber/tmp/mpqc/convertresults.sh"
14
15function 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}
33
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#}
40
41function MultiRunSim {
42 # 1 is the number of groups
43 # 2 is the directory
44 # 3, ... are config files
45
46 # find the next free proc group
47 divisor=$1
48 shift
49 DIR=$1
50 shift
51 started=0
52 pwd=`pwd`
53 while [ $started -eq 0 ]; do
54 groupnr=1
55 while [ $groupnr -le $divisor ]; do
56 if [ ! -e "${DIR}/ProcRuns${groupnr}" ]; then
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
66 echo "touch ${DIR}/ProcRuns${groupnr}" >"${DIR}/ProcBatch${groupnr}"
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}"
76 echo "rm -f ${DIR}/ProcRuns${groupnr}" >>"${DIR}/ProcBatch${groupnr}"
77 /bin/sh "${DIR}/ProcBatch${groupnr}" &
78 started=1
79 let groupnr=${divisor}+1
80 else
81 let groupnr=$groupnr+1
82 fi
83 done
84 # wait a few seconds
85 #if [ $2 -gt 1 ]; then
86 # sleep 2
87 #fi
88 done
89}
90
91# get command line options
92if [ -z $3 ]; then
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;
99else
100 arg=$1
101 mainname=`grep mainname $arg | awk -F"\t" {'print $2'}`
102 order=$2
103 distance=$3
104 if [ -z $4 ]; then
105 MaxSteps=`grep MaxOuterStep $arg | awk -F"\t" {'print $2'}`
106 else
107 MaxSteps=$4
108 fi
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
110fi
111
112
113# get the directory
114DIR=`dirname $arg`
115if [ -z "`grep $DIR $arg`" ]; then
116 echo "Cannot find the directory $DIR in the config file." | tee -a dynamic.log
117 exit 1;
118else
119 echo "Using $DIR as directory." | tee -a dynamic.log
120fi
121
122PBS_NODEFILE="${DIR}/machines"
123if [ ! -e $PBS_NODEFILE ]; then
124 i=1
125 cpus=`cat /proc/cpuinfo | grep processor | wc -l`
126 echo "localhost" >$PBS_NODEFILE
127 while [ $i -lt $cpus ]; do # add one localhost per cpu to machines file
128 echo "localhost" >>$PBS_NODEFILE
129 let i=$i+1
130 done
131fi
132
133# delete old processor group files
134rm ${DIR}/ProcGroup* -f
135rm ${DIR}/ProcRuns* -f
136rm ${DIR}/ProcBatch* -f
137
138# put nodes into groups
139MaxNodes=0
140for node in `cat <$PBS_NODEFILE`; do
141 let MaxNodes=$MaxNodes+1
142done
143gamma=`grep ProcPEGamma $arg | awk -F"\t" {'print $2'}`
144psi=`grep ProcPEPsi $arg | awk -F"\t" {'print $2'}`
145let nodes=$gamma*$psi
146let divisor=$MaxNodes/$nodes
147echo "Using $divisor processor groups." | tee -a dynamic.log
148nodenr=0
149groupnr=1
150for 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}"
159done
160i=0
161while [ $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
168done
169
170# copy first conf
171cp $arg ${arg}.MD
172
173
174i=1;
175while [ $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
199
200# evaluate each fragment
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
231 j=0;
232 while [ $j -lt $frag ]; do
233 number=`printf "%0${digits}d" $j`
234 # convert all configs
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 "
242 let j=$j+1
243 done
244
245 # go through all groups and run the job
246 olddivisor=$divisor
247 if [ $divisor -gt $frag ]; then
248 divisor=$frag
249 fi
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
258 divisor=$olddivisor
259
260# wait till all ProcRuns files are gone
261# if [ $divisor -gt 1 ]; then
262 echo "Waiting for all running jobs at step $i to end ... " | tee -a dynamic.log
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
268 done
269 echo "done." | tee -a dynamic.log
270# fi
271
272
273# convert results
274 sleep 1 # necessary for result files to close
275 echo -n "Converting all results ... " | tee -a dynamic.log
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
297done
298
299exit 0
Note: See TracBrowser for help on using the repository browser.