-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspecRun.py
More file actions
100 lines (78 loc) · 3.31 KB
/
specRun.py
File metadata and controls
100 lines (78 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
##############################################################################
# importing packages
##############################################################################
import numpy as np
import os as os
import sys as sys
import shutil as shutil
import glob as glob
import subprocess
##############################################################################
# check to see if proper files and folders exist
##############################################################################
##############################################################################
'''
The necessary files and folders to submit simulation jobs are:
fSl : The dummy .slurm file to be copied to each simulation
directory, edited, and run. Usually named
'launch_each_XXX.slurm', where 'XXX' is the name of the server
partition to which the simulation jobs are being submitted.
wlDlist : List of the directories in which jobs will be run for each
frequency requested. Usually named WN, where N is a number
indexing the wavelength to be run in that directory. Each
directory in the list is described with an absolute path.
These files should be located in the same directory as specRun.py
'''
##############################################################################
fSl = "sampleCHEM.slurm"
pwd = os.getcwd()
wlDlist = glob.glob(pwd + '/W*/')
if os.path.isfile(pwd + "/" + fSl):
print("SLURM submission example file found : " + fSl)
else:
print("SLURM submission example file not found. Exiting program.")
sys.exit()
if len(wlDlist) != 0:
print("Simulation directories found : " + str(len(wlDlist)))
else:
print("Simulation directories not found. Exiting program.")
sys.exit()
##############################################################################
# copy files
##############################################################################
'''The jobName variable contains the job name header for the jobs to be
submitted. Each job will also include an index.'''
jobName = 'dftJob'
print('Job name header is : ' + jobName)
pArg = input('Continue? (y/n) ')
if pArg is 'y':
pass
else:
print('Exiting program.')
sys.exit()
for i in range(len(wlDlist)):
shutil.copyfile(pwd + '/' + fSl, pwd + '/W' + str(i+1) + '/' + fSl)
with open(pwd + '/W' + str(i+1) + '/' + fSl,'r') as oldFile:
with open(pwd + '/W' + str(i+1) + '/' + fSl + '_temp','w+') as newFile:
for line in oldFile.readlines():
if line[0:18] == '#SBATCH --job-name':
newFile.write('#SBATCH --job-name=' + jobName + str(i+1) +
'\n' )
elif line[0:17] == '#SBATCH --workdir':
newFile.write('#SBATCH --workdir=' + pwd + '/W' + str(i+1)+
'\n')
else:
newFile.write(line)
newFile.close()
oldFile.close()
os.remove(pwd + "/W" + str(i+1) + "/" + fSl)
os.rename(pwd + "/W" + str(i+1) + "/" + fSl + "_temp",
pwd + "/W" + str(i+1) + "/" + "W" + str(i+1) + '_' + fSl)
print('SLURM script copied.')
##############################################################################
# submit jobs
##############################################################################
print('Submitting jobs...')
for i in range(len(wlDlist)):
subprocess.call(['sbatch',pwd + "/W" + str(i+1) + "/" + "W" +
str(i+1) + '_' + fSl])