-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchargechecker.py
More file actions
45 lines (34 loc) · 1.18 KB
/
chargechecker.py
File metadata and controls
45 lines (34 loc) · 1.18 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
import os, glob, time, shutil
charged = " Charge = 1 Multiplicity = 1"
uncharged = " Charge = 0 Multiplicity = 1"
def readin(fname):
f = open(fname)
lines = f.read()
f.close()
return lines
def chargechecker(folder, fname):
# Get list of atoms
name = fname.split("\\")[-1].replace(".log", "")
print(name)
log = f"{name}.log"
one_folder = os.path.join(folder, "Charged")
zero_folder = os.path.join(folder, "Uncharged")
lines = readin(fname)
if charged in lines:
subsubfolder = one_folder
elif uncharged in lines: # Best not to use elif if you can use else
subsubfolder = zero_folder
else:
print(f"Error with {name}")
subsubfolder = folder
exit
if os.path.exists(f"{folder}\\{log}"):
shutil.move(f"{folder}\\{log}", f"{subsubfolder}\\{log}")
if __name__ == "__main__":
tasks = glob.glob("AJD_files\\*.log")
topfolder = os.path.join(os.path.abspath("."), "AJD_files")
for subfolder in ["Charged", "Uncharged"]:
if not os.path.exists(f"AJD_files\\{subfolder}"):
os.mkdir(f"AJD_files\\{subfolder}")
for job in tasks:
chargechecker(topfolder, job)