-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOUT2INP.py
More file actions
145 lines (119 loc) · 4.12 KB
/
OUT2INP.py
File metadata and controls
145 lines (119 loc) · 4.12 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
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 17 16:30:03 2022
@author: rossc
"""
import os, sys, datetime, glob, time
from ase.io import read, write
import numpy as np
CPU = """
#======================================================
#
# Job script for running a serial job on parallel core
#
#======================================================
#======================================================
# Propogate environment variables to the compute node
#SBATCH --export=ALL
#
# Run in the standard partition (queue)
#SBATCH --partition=standard
#
# Job name
#SBATCH --job-name={}
#
# Specify project account
#SBATCH --account=tuttle-rmss
#
# No. of tasks required (ntasks=1 for a single-core job)
# Here, tasks = cores (40 cores per node)
#
#SBATCH --ntasks={} --nodes=1
#
# Specify (hard) runtime (HH:MM:SS)
#SBATCH --time="{}"
#
#======================================================
module purge
#example module load command
module laod orca/5.0.1
module load orca/5.0.2
#======================================================
# Prologue script to record job details
# Do not change the line below
#======================================================
/opt/software/scripts/job_prologue.sh
#------------------------------------------------------
"""
def readin(fname):
f = open(fname)
content = f.read()
f.close()
return content
def out2inps(fname):
CPUS = 4
strT = '240:00:00'
name = fname.split("/")[-1].replace(".out", "")
folder = os.path.dirname(fname)
#species = frames[0].get_chemical_symbols()
#print("".join(species))
content = readin(fname)
for i,frame in enumerate(content.split("CARTESIAN COORDINATES (ANGSTROEM)")[1:]):
jobname = fname.replace(".out", f"_opt_step_{i}.inp")
newOutName = jobname.replace(".inp", ".out")
shname = jobname.replace(".inp", ".sh")
QueueName = os.path.basename(jobname).replace(".inp", "")
print(jobname, shname)
if os.path.exists(jobname):
continue
sbatch = open(shname, 'w')
sbatch.write(CPU.format(QueueName, str(CPUS), strT))
cartesianSection = frame.split("CARTESIAN COORDINATES (A.U.)")[0]
#Filter for just the lines that contain atoms (length = 4)
cartesian = []
for line in cartesianSection.split("\n"):
if len(line.strip().split()) == 4:
cartesian.append(line)
#Turn this list of lines into one string of text with a newline between each item in the list
cartesian = "\n".join(cartesian)
file = open(jobname, 'w')
file.write(f"""# ORCAForces - {jobname}
# Basic Mode
#
! OPT wB97X D4 Def2-tzvpp SlowConv TightSCF DEFGRID2 Def2/J RIJCOSX
%maxcore 3375
%PAL NPROCS {CPUS} END
* xyz 0 1
""".format(name))
#print(cartesian)
file.write(cartesian)
file.write("\n")
file.write("*")
file.close()
sbatch.write("/opt/software/orca/5.0.2/orca {} > {}\n".format(os.path.basename(jobname), os.path.basename(newOutName)))
sbatch.write("\n/opt/software/scripts/job_epilogue.sh\n")
sbatch.close()
cdir = os.path.abspath(".")
os.chdir(folder)
cmd = "sbatch {}".format(os.path.basename(jobname).replace(".inp", ".sh"))
print("RUNNING:", cmd)
print(cmd)
#os.system(cmd)
os.chdir(cdir)
if __name__ == "__main__":
tasks = glob.glob("../engrad/Alex/RandomLigands/*/*.out")
completed_jobs = []
for task in tasks:
with open(task, "r") as f:
#Validate that this is an optimization that contains all the frames
content = f.read()
if "* Geometry Optimization Run *" not in content:
print(task, "This is not a geometry optimization")
continue
if "ReducePrint".upper() not in content.upper():
print(task, "This is job did not have ReducePrint set to false")
continue
completed_jobs.append(task)
for task in completed_jobs:
print(task)
#out2inps(task)