-
Notifications
You must be signed in to change notification settings - Fork 0
/
orcaOptimizationJobs
executable file
·201 lines (193 loc) · 13.6 KB
/
orcaOptimizationJobs
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#! /usr/bin/env python
#code will take structures from the input directory, move them to the appropriate place, write the necessary input files for the calculation, and submit the calculation.
import subprocess
import readline
import numpy as np
from re import sub
import shutil
import time
getHost = subprocess.Popen('hostname', stdout=subprocess.PIPE)
host = getHost.communicate()[0].split()[0]
if 'login0.crc.pitt.edu' in host:
def moveStructure( struc, number, creDirectory, rDirectory, wFile ):
if '_' not in struc:
#subprocess.Popen('mkdir {0}'.format(str(struc).replace('.xyz','').replace("[","\\[").replace(",","\\,").replace("'","\\'").replace("]","\\]")), cwd=creDirectory, shell=True)
subprocess.Popen('mkdir {0}'.format(str(struc).replace('.xyz','').replace("[","\\[").replace(",","c").replace("'","\\'").replace("]","\\]")), cwd=creDirectory, shell=True)
time.sleep(0.030)
shutil.move(rDirectory, wFile)
elif '_' in struc and number !=1:
subprocess.Popen('mkdir {0}'.format(number), cwd=creDirectory, shell=True)
time.sleep(0.030)
shutil.move(rDirectory, wFile)
elif '_' in struc and number == 1:
#make the outer directory with the name of the structure first
subprocess.Popen('mkdir {0}'.format(str(struc).rsplit('_',1)[0]), cwd=creDirectory, shell=True)
time.sleep(0.030)
#make inner directory
subprocess.Popen('mkdir {0}'.format(str(number)), cwd=creDirectory+'/'+str(struc).rsplit('_',1)[0]+'/', shell=True)
time.sleep(0.030)
#move the file
shutil.move(rDirectory, wFile)
return
def writeScripts( filePath, structureFile ):
jobfile = open('{0}/job.slurm'.format(filePath), 'w')
jobfile.write('#!/bin/env bash\n\n')
jobfile.write('#SBATCH --job-name="{0}"\n'.format(structureFile.replace('.xyz','')))
jobfile.write('#SBATCH --output="{0}.out"\n'.format(structureFile.replace('.xyz','')))
jobfile.write('#SBATCH --nodes=1\n')
jobfile.write('#SBATCH --cluster=smp\n')
jobfile.write('#SBATCH --partition=smp\n')
jobfile.write('#SBATCH --ntasks-per-node=6\n')
#jobfile.write('#SBATCH --mem=5g\n')
jobfile.write('#SBATCH --time=0-12:00:00\n')
jobfile.write('#SBATCH --qos=short\n\n')
#jobfile.write('shopt -s extglob\n')
jobfile.write('module purge\n')
jobfile.write('module load openmpi/2.0.2\n')
jobfile.write('module load orca/4.0.2\n\n')
jobfile.write('date >> {0}.out\n'.format(structureFile.replace('.xyz','')))
jobfile.write('srun -n $SLURM_NNODES cp $SLURM_SUBMIT_DIR/* $LOCAL\n\n')
#jobfile.write('ulimit -s unlimited\n\n')
jobfile.write('run_on_exit(){\n')
jobfile.write(' cp -R $LOCAL/{*.prop,geometryOptimizationOrca.xyz,*engrad,*opt,*gbw,*txt,*out,*trj,*tmp} $SLURM_SUBMIT_DIR/\n')
jobfile.write(' cd $SLURM_SUBMIT_DIR\n')
jobfile.write(' find ./ -type f -exec chmod 640 {} +\n')
jobfile.write('}\n\n')
jobfile.write('trap run_on_exit EXIT\n\n')
jobfile.write('cd $LOCAL\n\n')
jobfile.write('$(which orca) geometryOptimizationOrca.inp > geometryOptimizationOrca.out\n')
jobfile.write('date >> {0}.out\n'.format(structureFile.replace('.xyz','')))
jobfile.write('exit 0\n')
jobfile.close()
optimizationFile = open('{0}/geometryOptimizationOrca.inp'.format(filePath), 'w')
optimizationFile.write('#give keywords by using !\n')
optimizationFile.write('#functional, number of basis sets, dispersion correction\n')
optimizationFile.write('! PBE Def2-TZVP TIGHTSCF OPT D3BJ pal6\n\n')
optimizationFile.write('%scf\nMaxIter 500\nend\n')
#optimizationFile.write('%geom\nMaxIter 1000\nend\n')
optimizationFile.write('#the numbers after xyzfile correspond to charge and multiplicity\n')
optimizationFile.write('* xyzfile 0 1 {0}\n'.format(structureFile))
optimizationFile.close()
return
def findNumber( directory ):
tempNum = subprocess.Popen('ls -d */', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=directory, shell=True)
number = tempNum.communicate()[0].split()
if 'ls:' in number:
maxNum = 0
else:
tempMaxVal = 0
for integer in number:
tempVal = integer.split("/")[0]
if int(tempVal) > tempMaxVal:
tempMaxVal = int(tempVal)
maxNum = tempMaxVal
return maxNum
#identify all the structures in the input directory
new = subprocess.Popen('ls', stdout=subprocess.PIPE, cwd='/ihome/kjohnson/jpr54/orca/geometryOptimizations/structureInputs/')
Lines = new.communicate()[0].split()
#determine who the user is
user = subprocess.Popen('whoami', stdout=subprocess.PIPE)
name = str(user.communicate()[0].split()).replace("['","").replace("']","")
#list to hold the job numbers and locations of the calculations.
r, c = len(Lines), 2
Jobs = [[0 for x in range(r)] for y in range(c)]
for counter, line in enumerate(Lines):
if '_' not in line:
#determine if this structure has already been run somewhere else
existing2 = subprocess.Popen('ls', stdout=subprocess.PIPE, cwd='/ihome/kjohnson/jpr54/orca/geometryOptimizations/singleMolecules/')
eLines2 = existing2.communicate()[0].split()
#add all the existing structures together
finalELines = eLines2
#compare the name of the structure to the names already present and determine if it needs to be optimized
structureCreate = 1
for itemCount, structure in enumerate(finalELines):
if (line.rsplit('.',1)[0].lower().replace(',','c') == structure.lower().replace(',','c')):
print('{0} is a repeated structure and will not be optimized'.format(line))
structureCreate = 0
break
#if the structure does not exist already, create a directory having the name of the structure and move the .xyz file to that directory.
if (structureCreate == 1):
if (name == 'jpr54'):
createDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/singleMolecules/'
readDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/structureInputs/{0}'.format(str(line))
writeFile = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/singleMolecules/{0}/{1}'.format(str(line).replace('.xyz','').replace(',','c'), str(line))
writeDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/singleMolecules/{0}'.format(str(line).replace('.xyz','').replace(',','c'))
# elif (name == 'krb115'):
# createDirectory = '/ihome/kjohnson/krb115/orca/singleMolecules/'
# readDirectory = '/ihome/kjohnson/krb115/orca/structureInputs/{0}'.format(str(line))
# writeFile = '/ihome/kjohnson/krb115/orca/singleMolecules/{0}/{1}'.format(str(line).replace('.xyz','').replace(',','c'), str(line))
# writeDirectory = '/ihome/kjohnson/krb115/orca/singleMolecules/{0}'.format(str(line).replace('.xyz','').replace(',','c'))
N = 0 #there will never be more than one optimization for a single molecule
#move the structure to the appropriate directory
moveStructure( line, N, createDirectory, readDirectory, writeFile )
#now call the function to write the job.slurm and .inp files, passing it the filepath to use and the name of the structure file.
writeScripts( writeDirectory ,line )
#submit the job.
job = subprocess.Popen('sbatch job.slurm', stdout=subprocess.PIPE, cwd=writeDirectory, shell=True)
#get the job number and structure name. Write the JobId file.
jobNumber = job.communicate()[0].split()[3]
print('{0} {1}'.format(jobNumber,line.replace('.xyz','')))
jobFile = open('{0}/JobId'.format(writeDirectory), 'w')
jobFile.write('{0}'.format(jobNumber))
jobFile.close()
elif '_' in line:
#determine if this geometry has already been run somewhere else.
existingI1 = subprocess.Popen('ls', stdout=subprocess.PIPE, cwd='/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/')
#check finished calculation directories
existingI2 = subprocess.Popen('ls', stdout=subprocess.PIPE, cwd='/zfs1/kjohnson/jpr54/orca/geometryOptimizations/interactions/')
eLinesI1 = existingI1.communicate()[0].split()
eLinesI2 = existingI2.communicate()[0].split()
#print('{0} {1}'.format(eLinesI1, eLinesI2))
#if configurations of the molecules have been run before, identify the highest numbered configuration that has been run.
maxNumber1, maxNumber2 = 0, 0
for configs in eLinesI1:
if (line.rsplit('_',1)[0].lower().replace(',','c') == configs.lower().replace(',','c')):
location = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/{0}'.format(line.rsplit('_',1)[0].replace(',','c'))
maxNumber1 = findNumber( location )
break
for configs in eLinesI2:
if (line.rsplit('_',1)[0].lower() == configs.lower()):
location = '/zfs1/kjohnson/jpr54/orca/geometryOptimizations/interactions/{0}'.format(line.rsplit('_',1)[0].replace(',','c'))
maxNumber2 = findNumber( location )
break
highestNumber = int(max(int(maxNumber1),int(maxNumber2)))
writeNumber = highestNumber + 1
#now that the highest existing number has been identified, create the directory in the appropriate location for the user. If highestNumber is 0, do a separate function call
if highestNumber == 0:
#need to create the new things.
if (name == 'jpr54'):
createDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/'
readDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/structureInputs/{0}'.format(str(line))
writeFile = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/{0}/1/{1}'.format(str(line).rsplit('_',1)[0].replace(',','c'), str(line).rsplit('_',1)[0]+'_1.xyz')
writeDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/{0}/1/'.format(str(line).rsplit('_',1)[0].replace(',','c'))
xyzName = str(line).rsplit('_',1)[0]+'_1.xyz'
elif (name == 'krb115'):
createDirectory = '/ihome/kjohnson/krb115/orca/multipleMolecules/'
readDirectory = '/ihome/kjohnson/krb115/orca/structureInputs/{0}'.format(str(line))
writeFile = '/ihome/kjohnson/krb115/orca/multipleMolecules/{0}/1/{1}'.format(str(line).rsplit('_',1)[0].replace(',','c'), str(line).rsplit('_',1)[0]+'_1.xyz')
writeDirectory = '/ihome/kjohnson/krb115/orca/multipleMolecules/{0}/1'.format(str(line).rsplit('_',1)[0].replace(',','c'))
xyzName = str(line).rsplit('_',1)[0]+'_1.xyz'
elif (highestNumber != 0):
if (name == 'jpr54'):
createDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/{0}/'.format(str(line).rsplit('_',1)[0].replace(',','c'))
readDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/structureInputs/{0}'.format(str(line))
writeFile = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/{0}/{1}/{2}'.format(str(line).rsplit('_',1)[0].replace(',','c'), writeNumber, str(line).rsplit('_',1)[0]+'_'+str(writeNumber)+'.xyz')
writeDirectory = '/ihome/kjohnson/jpr54/orca/geometryOptimizations/interactions/{0}/{1}/'.format(str(line).rsplit('_',1)[0], writeNumber)
xyzName = str(line).rsplit('_',1)[0]+'_'+str(writeNumber)+'.xyz'
elif (name == 'krb115'):
createDirectory = '/ihome/kjohnson/krb115/orca/multipleMolecules/{1}/'.format(str(line).rsplit('_',1)[0].replace(',','c'))
readDirectory = '/ihome/kjohnson/krb115/orca/structureInputs/{0}'.format(str(line))
writeFile = '/ihome/kjohnson/krb115/orca/multipleMolecules/{0}/{1}/{2}'.format(str(line).rsplit('_',1)[0].replace(',','c'), writeNumber, str(line).rsplit('_',1)[0]+'_'+str(writeNumber)+'.xyz')
writeDirectory = '/ihome/kjohnson/krb115/orca/multipleMolecules/{0}/{1}/'.format(str(line).rsplit('_',1)[0].replace(',','c'), writeNumber)
xyzName = str(line).rsplit('_',1)[0]+'_'+str(writeNumber)+'.xyz'
moveStructure( line, writeNumber, createDirectory, readDirectory, writeFile )
writeScripts( writeDirectory, xyzName )
job = subprocess.Popen('sbatch job.slurm', stdout=subprocess.PIPE, cwd=writeDirectory, shell=True)
jobNumber = job.communicate()[0].split()[3]
print('{0} {1}'.format(jobNumber,str(line).rsplit('_',1)[0]+'_'+str(writeNumber)))
#append job number to the JobId file so it can be compared in bindingEnergyTracker
jobFile = open('{0}JobId'.format(writeDirectory), 'w')
jobFile.write('{0}'.format(jobNumber))
jobFile.close()
else:
print('\nYou are logged in to the wrong location. Log in to opa.\n')