-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXYZ2ORCA.py
More file actions
182 lines (148 loc) · 4.79 KB
/
XYZ2ORCA.py
File metadata and controls
182 lines (148 loc) · 4.79 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
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
# -*- coding: utf-8 -*-
"""
Created on Wed May 4 13:57:18 2022
@author: bwb16179
"""
import os, sys, datetime, glob, time
from ase.io import read, write
import numpy as np
ElectronNos = {
"H" : 1,
"B" : 5,
"C" : 6,
"N" : 7,
"O" : 8,
"F" : 9,
"P" : 15,
"S" : 16,
"Cl" : 17,
"Ir" : 77
}
def buffer(string, L, end=True):
while len(string) < L:
string = string+"0"
return string
CPU = """#!/bin/bash
#SBATCH --export=ALL
#SBATCH --job-name={}
#SBATCH --account=tuttle-rmss
#SBATCH --partition=standard
#SBATCH --time="{}"
#SBATCH --ntasks={} --nodes=1
module purge
module load orca/5.0.3
/opt/software/scripts/job_prologue.sh
"""
def xyz2orca(fname):
frames = read(fname, index=":")
if len(frames) == 0:
return False
name = fname.split("/")[-1].replace(".xyz", "")
species = frames[0].get_chemical_symbols()
print("".join(species))
folder = os.path.dirname(fname)
CPUS = 1
strT = '240:00:00'
print(strT)
for i,frame in enumerate(frames):
jobname = fname.replace(".xyz", ".inp")
inp = jobname.split("/")[-1]
out = jobname.split("/")[-1].replace(".inp", ".out")
if os.path.exists(folder+"/"+inp):
print(f"Found: {out}, skipping.")
return 0
sbatch = open(jobname.replace(".inp", ".sh"), 'w')
sbatch.write(CPU.format(jobname.replace(".inp", ""), strT, str(CPUS)))
# Check Multiplicity of Molecule
electrons = 0
for coord, atom in zip(frame.get_positions(), species):
if atom == "H":
electrons += ElectronNos["H"]
if atom == "B":
electrons += ElectronNos["B"]
if atom == "C":
electrons += ElectronNos["C"]
if atom == "N":
electrons += ElectronNos["N"]
if atom == "O":
electrons += ElectronNos["O"]
if atom == "F":
electrons += ElectronNos["F"]
if atom == "P":
electrons += ElectronNos["P"]
if atom == "S":
electrons += ElectronNos["S"]
if atom == "Cl":
electrons += ElectronNos["Cl"]
if atom == "Ir":
electrons += ElectronNos["Ir"]
if electrons % 2 == 1:
multiplicity = 2
else:
multiplicity = 1
f = open(jobname, 'w')
print(jobname)
f.write(f"""# ORCAForces - {jobname}
# Basic Mode
#
! OPT wB97X D4 Def2-TZVPP SlowConv TightSCF DEFGRID2 Def2/J RIJCOSX Smallprint
%maxcore 3375
%geom
Maxiter 2000
END
* xyz 0 {multiplicity}
""".format(name))
for coord, atom in zip(frame.get_positions(), species):
line = [" "]*51
line[0] = atom
line[11:19] = buffer(str(coord[0]), 8)
line[27:35] = buffer(str(coord[1]), 8)
line[43:51] = buffer(str(coord[2]), 8)
f.write("".join(line))
f.write("\n")
f.write("*")
f.close()
sbatch.write("/opt/software/orca/5.0.3/orca {} > {}\n".format(inp, out))
break
sbatch.write("\n/opt/software/scripts/job_epilogue.sh\n")
sbatch.close()
print(f"Electrons = {electrons}")
print(f"Multiplicity = {multiplicity}")
cdir = os.path.abspath(".")
os.chdir(folder)
cmd = "sbatch {}".format(os.path.basename(jobname).replace(".inp", ".sh"))
print(cmd)
os.system(cmd)
os.chdir(cdir)
return True
def FilterChemistry(atomlist):
species_order = ["H", "C", "N", "O", "F", "P", "S", "Cl", "Ir"] # MUST BE ORDERED BY ATOMIC NUMBER
for atom in atomlist:
if atom not in species_order:
return False
return True
if __name__ == "__main__":
tasks = glob.glob("PTM/*.xyz") + glob.glob("CSD/*.xyz") + glob.glob("AJD/*.xyz")
ordered_tasks = []
ordered_tasks_natoms = []
tasks_symbols = {}
skipped = 0
for task in tasks:
try:
mol = read(task)
except:
continue
ordered_tasks.append(task)
ordered_tasks_natoms.append(len(mol.get_chemical_symbols()))
tasks_symbols[task] = mol.get_chemical_symbols()
ordered_tasks = np.array(ordered_tasks)
ordered_tasks_natoms = np.array(ordered_tasks_natoms)
order_small_to_large = np.argsort(ordered_tasks_natoms)
for task in ordered_tasks[order_small_to_large]:
if FilterChemistry(tasks_symbols[task]):
print(task, len(tasks_symbols[task]))
xyz2orca(task)
else:
skipped += 1
print(task, len(tasks_symbols[task]), "skipping because it contains a bad atom")
print(f"{skipped} jobs were skipped due to bad atoms")