OSDN Git Service

MOPAC 6.06 is included in the binary
[molby/Molby.git] / mopac606_nbo / src / mopac.csh
1 #
2 ##########################SYSTEM SPECIFIC VARIBLES######################
3 ##########please change to suit your local setup. ######################
4 #set echo verbose
5 #set echo verify
6 #
7 #  First, lets define all system specific variables
8 #
9 #  The location of this file and the executable.
10 set mopacdir = /usr/users/stewart/mopac6
11 #
12 #  The name of the "normal" mopac executable.  (commonly the small version)
13 set smallmopac = MOPAC
14 #
15 #  The name of the "alternate" mopac executable.  (the larger version)
16 set bigmopac = MOPACBIG
17 #
18 #
19 #########################END OF SYSTEM SPECIFIC DEFINITIONS#############
20 #
21 #   This is actually a compilation of several individual .csh files into
22 #     a single larger .csh file.  Before, each of the files would be called
23 #     in turn.  Now, the name of the individual .csh files is simply the 
24 #     first argument in the call to this master file.  The job name has
25 #     been slipped to the second argument.  This has been done to ease 
26 #     installation and periodic updates by reducing the number of separate
27 #     files to change to a single one.  This also reduces the number of 
28 #     files that must be updated to just one since all the variables defined
29 #     once at the top and then used throughout the rest of the script.
30 #     NOTE:  If you wish to split this file into the smaller .csh files, it
31 #     will require substanital altering of the code.  It is not an easy 
32 #     process.  FJSRL will support the present form only.
33 #
34 #  To activate this .csh file, add the line 
35 #    " source csh mopac.csh "
36 #        to your .cshrc file.
37 #
38 # set echo verify
39
40 #-------------------------------------------------------------------------
41 #
42 #  This script was written at the US Air Force Academy, Frank J. Seiler
43 #    Research Laboratory for use on a DECStation 3100.  It is a generic 
44 #    ULTRIX/UNIX csh script that should be easily adapted to other UNIX
45 #    systems.  For assistance please contact:
46 #
47 #        Dr. Michael B. Coolidge
48 #        FJSRL/NC
49 #        USAFA CO 80840
50 #        (719)472-2655
51 #
52 #  ARPA net address:  Coolidge@usafa.af.mil
53 #
54 #-------------------------------------------------------------------------
55 #
56 #  Now, lets get the two possible arguments that can be specified assigned.
57 set type = $1
58 set job = $2
59 #
60 #  Now, to go to the correct section of code as determined by the first\
61 #    argument given.  Note:  if no argument is given, assume it should
62 #    be startup.
63 #
64 if ( a$type == asubmit )      goto submit
65 if ( a$type == aqueue )       goto queue
66 if ( a$type == acleanup )     goto cleanup
67 if ( a$type == aimopac )      goto imopac
68 if ( a$type == armopac )      goto rmopac
69 if ( a$type == achkmopac )    goto chkmopac
70 if ( a$type == ashut )        goto shut
71 if ( a$type == a )            goto setupmopac
72 if ( a$type == asetupmopac )  goto setupmopac
73 #
74 echo  Warning, your first argument is not a valid choice
75 #
76 exit
77 #
78 #---------------------start of setupmopac.csh---------------------------
79 setupmopac:
80 #  This portion will take care of all aliases needed in order to run MOPAC.
81 #
82 #-------------------------------------------------------------------------
83 #
84 #  Use the next command to run a job in background 'mopac filename'
85 alias mopac '$mopacdir/mopac.csh imopac \!*'
86 #
87 #  The next command allows you to stop a currently running mopac job.
88 #    Once in the same directory as the running job, type:  'shut filename'
89 #
90 alias shut  '$mopacdir/mopac.csh shut'
91 #
92 #  This commands gives a directory of all output files
93 alias dout   'ls -tl *.out |  more '
94 #
95 #  The next series of commands are for a pseudo batch queue.  This queue
96 #    system uses the four portions of this file, 'submit', 'queue', 'cleanup',
97 #    and 'chkmopac' and creates or uses three more '.qlock', '.qdone', 
98 #    and '.qjobs'.  The queue is managed by queue.csh.  Jobs are placed 
99 #    onto the queue by submit by adding the current path, username,
100 #    and filename to the end of .qjobs.  After a single job is completed,
101 #    cleanup compares the list of files to do, .qjobs, with the list
102 #    of files that have completed, .qdone, and deletes all finished jobs
103 #    from both lists.  The function of chkmopac is to check the system
104 #    for a currently running queue.  If that queue does not exist, then
105 #    chkmopac will start it.  If it does, then do not start a second one.
106 #    The file .qlock contains the name of the currently executing file.
107 #    If the name listed is 'waiting', then there is not a job current running.
108 #    The queue is waiting for a new job to be submitted.  Once a job is
109 #    submitted, then the queue will be restarted.
110 #
111 #  To submit a job to the queue, type: 'submit filename'
112 alias submit 'csh $mopacdir/mopac.csh submit \!*'
113 #
114 #  To restart the queue after a crash, type: 'startmopac'
115 alias startmopac 'csh $mopacdir/mopac.csh chkmopac'
116 #
117 #  To check what is currently running, type: 'doing'
118 alias doing 'more $mopacdir/.qlock'
119 #
120 #  To check what is currently on the queue, type: 'todo'
121 alias todo 'more $mopacdir/.qjobs'
122 #
123 #  Note: The order jobs are executed on the queue can be changed at
124 #    anytime by simply editing the file $mopacdir/.qjobs.  The only
125 #    job that cannot be affected is the currently executing one.
126 exit
127 #----------------------------end of setupmopac.csh----------------------
128 #
129 #----------------------------start of submit.csh------------------------
130 submit:
131 #  This will setup a pseudo batch queue.  By typing submit 'jobname',
132 #    that job will be entered into a holding file along with the current
133 #    path name.  Before the job is entered though, it will be checked to
134 #    see that it is valid.
135 #  This will also check to see if the batch queue has been started.  If not,
136 #    the queue will be started. 
137 #
138 #  set echo verbose
139 #
140 #  Check to see if the queue is presently running.  If not, start it.
141 csh $mopacdir/mopac.csh chkmopac &
142 #  
143 #  Now, parse the job name and store it in the correct format in .qjobs
144 set pname = $cwd
145 set rname = $job:r
146 set ename = $job:e
147 set owner = `whoami`
148 #
149 if !(-e $rname.dat) goto warn
150 echo $pname/$owner/$rname >> $mopacdir/.qjobs
151 exit
152 #
153 warn:
154 #  The input file did not exist.  Warn the user.
155 echo The file $rname.dat did not exist.  Your job is not submitted
156 exit
157 #------------------------------end of submit.csh------------------------
158 #
159 #----------------------------start of queue.csh-------------------------
160 queue:
161 #----------------------------------------------------------
162 # set echo verbose
163 # code to establish a pseudo batch queue ...
164 #
165 #----------------------------------------------------------
166 # don't go on if there's already a job executing
167 #----------------------------------------------------------
168 if -e $mopacdir/.qlock goto doing
169 #
170 #  entry point to start a new run
171 nextone:
172 echo queue is running >> $mopacdir/.qlock
173 #
174 #  do a cleanup
175 csh $mopacdir/mopac.csh cleanup
176 #
177 #  Now, setup the rest of the needed variables
178 #
179 set job = locked
180 #----------------------------------------------------------
181 # loop over the jobs in qjobs and start the first one that
182 # has not completed yet.  upon completion, jobs copy the job
183 # name into file qdone
184 #----------------------------------------------------------
185 set njobs = `wc -l < $mopacdir/.qjobs`
186 set nleft = $njobs
187 #
188 if "$nleft" == 0 then
189 echo waiting >> $mopacdir/.qlock
190 #
191 #  if this queue should now wait, then put it to sleep.  Otherwise
192 #    exit.  (uncomment the desired option)
193 exit
194 #sleep 300
195 if -e $mopacdir/.qlock rm $mopacdir/.qlock
196 goto nextone
197 endif
198 #
199 while "$nleft" != 0
200 set njob = `expr $njobs - $nleft + 1`
201 #
202 #  every tenth job, do a cleanup
203 if "$njob" == 10 csh $mopacdir/mopac.csh cleanup
204 #
205 set job = `sed -n "$njob"p $mopacdir/.qjobs`
206 if "$job" == quit then
207 if -e $mopacdir/.qlock rm $mopacdir/.qlock
208 exit
209 endif
210 if "$job" == done then
211 #
212 #  if this queue should now wait, then put it to sleep.  Otherwise
213 #    exit.  (uncomment the desired option)
214 exit
215 #sleep  300
216 goto nextone
217 endif
218 #  now, to separate the job name from the path name
219 #
220 set full = $job
221 set pname = $full:h
222 set owner = $pname:t
223 set pname = $pname:h
224 set job = $full:t
225 if ( $job == $pname ) set pname = "."
226 #
227 #
228 set idone = `grep $job.is $mopacdir/.qdone | wc -l`
229 if "$idone" != 0 goto nogoodq
230
231 #set echo verbose
232 #
233 echo $job >> $mopacdir/.qlock
234 #
235 #  Now, execute the mopac job
236 #
237 #
238 chdir $pname
239 #
240 #  Next, see if job.dat exists.  If not, goto helpmessage
241 if -z $job.dat goto helpmessageq 
242 #
243 #  Check $job.dat to see if this is a nextrun job.  
244 set restart = `head -3 $job.dat | grep -i " restart" | wc -l`
245 if ($restart != 0) then
246   foreach file (res den)
247         if !(-e $job.$file) goto norestartq
248     end
249 else
250   foreach file (res den)
251         if -e $job.$file mv $job.$file $job.$file.$$
252   end
253 endif
254 #
255 #  Check that prior copies of files do not exist
256 foreach file (out log arc end)
257     if -e $job.$file mv $job.$file $job.$file.$$
258   end
259 #
260 #  Now, make all the necessary assignments
261 setenv FOR005 $job.dat
262 setenv FOR006 $job.out
263 setenv FOR009 $job.res
264 setenv FOR010 $job.den
265 setenv FOR011 $job.log
266 setenv FOR012 $job.arc
267 setenv FOR013 $job.gpt
268 setenv FOR016 $job.syb
269 setenv FOR020 $job.ump
270 setenv SETUP  SETUP.DAT
271 setenv SHUTDOWN $job.end
272 if -e core rm core
273 if -e fort.2 rm fort.2
274 if -e fort.16 rm fort.16
275 nice -8 $mopacdir/$smallmopac >> $job.log 
276 set iok1 = `tail -1 "$job.out" | grep "IN SYSTEM" | wc -l`
277 set iok2 = `tail -1 "$job.out" | grep "ATOMS ALLOWED" | wc -l`
278 set iok3 = `tail -1 "$job.out" | grep "MAXIMUM ALLOWED" | wc -l`
279 set iok = `expr "$iok1" + "$iok2" + "$iok3" `
280 if $iok == 1 then
281     set idone2 = `grep "== MOPAC DONE ==" "$job.out" | wc -l`
282     if $idone2 == 0 then
283 check:
284       set nobig = `ps ax | grep "$mopacdir" | grep "/$bigmopac" | wc -l`
285         if $nobig != 0 sleep 300 
286         if $nobig != 0 goto check
287             rm $job.out
288             rm $job.log
289             time $mopacdir/$bigmopac >> $job.log
290     endif
291 endif
292 chown $owner $job.*
293 echo $job is done >> $mopacdir/.qdone
294 if -e core rm core
295 if -e fort.2 rm fort.2
296 if -e fort.16 rm fort.16
297 #  this job has completed normally
298 #
299 if -e SHUTDOWN rm SHUTDOWN
300 if -e $job.end rm $job.end
301 goto nextrun 
302 #
303 helpmessageq:
304 #  the file specified on the command line either did not exist or has
305 #     zero length
306 echo 'Your file either does not exist or has zero length'
307 echo $job is not done >> $mopacdir/.qdone
308 #
309 goto nextrun 
310 #
311 norestartq:
312 #  A nextrun has been specified but the .res or .den files do not exist
313 echo 'I cannot find either "$job".den or "$job".res.  Please help'
314 echo $job is not done >> $mopacdir/.qdone
315 #
316 goto nextrun 
317 #
318 #
319 nextrun:
320 if -e $mopacdir/.qlock rm $mopacdir/.qlock
321 #
322 set nleft = `expr $nleft - $nleft + 1`
323
324 nogoodq:
325 set nleft = `expr $nleft - 1`
326 end
327 #  now to cleanup the todo and done lists
328 csh $mopacdir/mopac.csh cleanup
329
330 if -e $mopacdir/.qlock rm $mopacdir/.qlock
331 echo waiting >> $mopacdir/.qlock
332 if -e $mopacdir/.qlock rm $mopacdir/.qlock
333 goto nextone
334 #
335 #  now, to do the next one
336 #
337 goto nextone
338 #
339 doing:
340 echo there is presently a job running
341 exit
342 #--------------------------------------------------------------
343 # the end.
344 #--------------------------------------------------------------
345 #------------------------------end of queue.csh-------------------------
346 #
347 #----------------------------start of cleanup.csh-----------------------
348 cleanup:
349 #----------------------------------------------------------
350 #
351 # set echo verbose
352 #
353 # code to look after jobs in the batch queues ...
354 #  this file automatically cleans up the input list and
355 #  zero's out the output list.  
356 #----------------------------------------------------------
357 #
358 set njobs = `wc -l < $mopacdir/.qjobs`
359 set nleft = $njobs
360 if -e $mopacdir/.qjobs2 rm $mopacdir/.qjobs2
361 #
362 if "$nleft" == 0 exit
363 #
364 while "$nleft" != 0
365 set njob = `expr $njobs - $nleft + 1`
366 set job = `sed -n "$njob"p $mopacdir/.qjobs`
367 #  now, to separate the job name from the path name
368 #
369 set full = $job
370 set pname = $full:h
371 set job = $full:t
372 if ( $job == $pname ) set pname = "."
373 #
374 #
375 set idone = `grep $job.is $mopacdir/.qdone | wc -l`
376 if "$idone" != 0 goto nogoodm
377
378 #
379 echo $pname/$job >> $mopacdir/.qjobs2
380 #
381
382 nogoodm:
383 set nleft = `expr $nleft - 1`
384 end
385 #
386 #  now, to do the next one
387 #
388 #
389 if -e $mopacdir/.qjobs rm $mopacdir/.qjobs
390 if !(-e $mopacdir/.qjobs2) echo   > $mopacdir/.qjobs
391 if -e $mopacdir/.qjobs2 mv $mopacdir/.qjobs2 $mopacdir/.qjobs
392 if -e $mopacdir/.qdone rm $mopacdir/.qdone
393 echo this file has been cleaned > $mopacdir/.qdone
394 chmod +w $mopacdir/.qjobs
395 chmod +w $mopacdir/.qdone
396 exit
397 #------------------------------end of cleanup.csh-----------------------
398 #
399 #----------------------------start of mopac.csh-------------------------
400 imopac:
401 #
402 # A csh file that will assign all the necessary variables to run MOPAC
403 #
404 # set echo verbose
405 #
406 #       If filename is missing, or are the names 'help' or 'h', then
407 #               the help facility will be invoked.
408 #
409 #-------------------------------------------------------------------------
410 #
411 #  First, set the job to be executed to the variable 'job'
412 set full = $job
413 set job = $full:r
414 set ext = $full:e
415 if (null$ext == null) set ext = dat 
416 if (null$ext == null$full) set ext = dat 
417 #
418 #  Next, see if job is blank, h, or help
419 if (null$job == null) goto help
420 if (null$job == nullh) goto help
421 if (null$job == nullhelp) goto help
422 #  Next, see if job.dat exists.  If not, goto helpmessage
423 if ( $ext != dat ) goto datmessage
424 #
425 if !(-e $job.dat) goto helpmessagem 
426 if -z $job.dat goto helpmessagem 
427 #
428 #  Check $job.dat to see if this is a restart job.  
429 set restart = `head -3 $job.dat | grep -i " restart"  | wc -l`
430 if ($restart != 0) then
431   foreach file (res den)
432         if !(-e $job.$file) goto norestartm
433     end
434 else
435   foreach file (res den)
436         if -e $job.$file mv $job.$file $job.$file.$$
437   end
438 endif
439 #
440 #  Now, to execute MOPAC 
441 csh $mopacdir/mopac.csh rmopac $job &
442 exit
443 #
444 help:
445 #  run the help program since either no filename was given, or the file name
446 #    given was h or help
447 set hold = $cwd
448 chdir $mopacdir
449 $mopacdir/HELP
450 chdir $hold
451 #
452 exit
453 datmessage:
454 #  the extension given was not .dat
455 echo 'Your filename did not have a .dat extension'
456 echo   ' but a ' $ext ' extension'
457 #
458 exit
459 #
460 helpmessagem:
461 #  the file specified on the command line either did not exist or has
462 #     zero length
463 echo 'Your file either does not exist or has zero length'
464 #
465 exit
466 #
467 norestartm:
468 #  A restart has been specified but the .res or .den files do not exist
469 echo 'I cannot find either "$job".den or "$job".res.  Please help'
470 #
471 exit
472 #
473 #------------------------------end of imopac.csh-------------------------
474 #
475 #----------------------------start of rmopac.csh------------------------
476 rmopac:
477 #
478 # set job = $1
479 #
480 # set echo verbose
481 #
482 #  Check that prior copies of files do not exist
483 foreach file (out log arc end)
484     if -e $job.$file mv $job.$file $job.$file.$$
485   end
486 #
487 #  Now, make all the necessary assignments
488 #
489 setenv FOR005 $job.dat
490 setenv FOR006 $job.out
491 setenv FOR009 $job.res
492 setenv FOR010 $job.den
493 setenv FOR011 $job.log
494 setenv FOR012 $job.arc
495 setenv FOR013 $job.gpt
496 setenv FOR016 $job.syb
497 setenv FOR020 $job.ump
498 setenv SETUP  SETUP.DAT
499 setenv SHUTDOWN $job.end
500 if -e core rm core
501 if -e fort.2 rm fort.2
502 if -e fort.16 rm fort.16
503 time $mopacdir/$smallmopac >> $job.log  
504 set iok1 = `tail -1 "$job.out" | grep "IN SYSTEM" | wc -l`
505 set iok2 = `tail -1 "$job.out" | grep "ATOMS ALLOWED" | wc -l`
506 set iok3 = `tail -1 "$job.out" | grep "MAXIMUM ALLOWED" | wc -l`
507 set iok = `expr "$iok1" + "$iok2" + "$iok3" `
508 if $iok == 1 then
509     set idone2 = `grep "== MOPAC DONE ==" "$job.out" | wc -l`
510     if $idone2 == 0 then
511       set nobig = `ps ax | grep "$mopacdir" | grep "/$bigmopac" | wc -l`
512         if $nobig == 0 then
513             rm $job.out
514             rm $job.log
515             time $mopacdir/$bigmopac >> $job.log
516           else
517             rm $job.out
518             rm $job.log
519             echo $job must be submitted to batch queue since there is
520             echo      currently a big job running.
521         endif
522     endif
523 endif
524 echo job $job is finished
525 head -3 $job.dat
526 if -e core rm core
527 if -e fort.2 rm fort.2
528 if -e fort.16 rm fort.16
529 #  this job has completed normally
530 #
531 if -e SHUTDOWN rm SHUTDOWN
532 if -e $job.end rm $job.end
533 if -e nul      rm nul
534 exit
535 #
536 #------------------------------end of rmopac.csh------------------------
537 #
538 #----------------------------start of chkmopac.csh----------------------
539 chkmopac:
540 #  This will check if a job is running.  If not, startup the mopac queue.
541 #    Note: It is necessary to do the two grep's in order to not get a flase
542 #    hit with itself or another job of itself running in memory at the same
543 #    time.
544 #  The two grep's should together contain the path and file name of the queue
545 #    handler.  Neither should contain the complete name.
546 #    
547 # set echo verbose
548 #
549 #  Now, parse the job name and store it in the correct format in .qjobs
550 set hname = $mopacdir:h
551 set tname = $mopacdir:t
552 #
553 set jobs = `ps ax | grep "csh $hname/" | grep "$tname/mopac.csh queue" | wc -l`
554 if "$jobs" == 0 then
555     if -e  $mopacdir/.qlock rm  $mopacdir/.qlock
556     csh  $mopacdir/mopac.csh queue &
557   endif
558 exit
559 #------------------------------end of chkmopac.csh----------------------
560 #
561 #----------------------------start of shut.csh--------------------------
562 shut:
563 #
564 #
565 #  Now, to parse the job name and possibly remove any extension
566 # set job = $1
567 set rname = $job:r
568 #
569 if -e $rname.dat goto shut_ok      
570 echo The file $rname.dat does not exist in this directory
571 exit
572 shut_ok:
573 echo shutting down this job >> $rname.end
574 exit
575 #------------------------------end of shut.csh--------------------------
576 #
577 #-----------------------------------------------------------------------