-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyzer.py
148 lines (118 loc) · 5.61 KB
/
analyzer.py
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
"""
Searches DOSCARs in the directory tree, calculates DOS and returns plots.
For a specified n, T, and target (DOSCAR for PBE or DOSCAR0 for PBE0), searches DOSCAR
and creates plot, which is saves in its respective stack_hollow/ folder in the home dir.
Diego Ontiveros
"""
import os
from argparse import ArgumentParser
# os.environ['OPENBLAS_NUM_THREADS'] = '1'
from searcher import SEARCH, getStructure, parseTermination, mx_folders,mxt_folders
from DOS import DOSCAR
from LOCPOT import WF
def analyzeDOS(paths):
"""Analyzes the DOSCAR of the path tree for the given n and T.\n
Makes a plot in the correspondent /home folder, and returns bandgap information: Eg, VBM and CBM."""
for path in paths:
dos = DOSCAR(path)
stack,hollows,pristine,queue_name = getStructure(path)
# if stack=="ABA":continue
# Select out folder
if pristine: out_folder = stack+"/"
else: out_folder = stack+"_"+hollows+"/"
print(f"{stack} {hollows} ",end='',flush=True)
dos.plot(
["M","red"],["X","blue"],["Term","green"],["Term2","fuchsia"],
spc = False,
out_path = out_folder
)
continue
print(f"{stack} {hollows} ",end='',flush=True)
# Plots spin contributions (if spin polarized)
if dos.spin=="sp":
dos.plot(
["Ma","orange"], ["Mb","cyan"],["Xa","pink"],["Xb","violet"],
["Terma","yellow"],["Termb","grey"],["Term2a","fuchsia"],["Term2b","coral"],
spc = True,
out_path = out_folder
)
def analyzeWF(paths,limit=None,extra=''):
"""Analyzed the LOCPOT file for all the given paths.
Makes a plot in the respective home folder and returns LOCPOT information: vaccuum potential for each surface."""
for i,path in enumerate(paths):
stack,hollows,pristine,queue_name = getStructure(path)
# if stack=="ABA":continue
# Select out folder
if pristine: out_folder = stack+"/"
else: out_folder = stack+"_"+hollows+"/"
# print(*extra[i],end=' ',flush=True)
print(f"{stack} {hollows} ",end='',flush=True)
wf = WF(path)
wf.calculate(tol_janus=10)
wf.plot(name=out_folder+f"{wf.file}_{wf.mx.name}.png")
############################# MAIN PROGRAM ####################################
home = os.path.abspath("..")
searcher = SEARCH()
# Parsing user arguments
parser = ArgumentParser(description="Calls the visualization scripts (DOS and LOCPOT) to make plots and return bandgap or Vvsurf for the specified n and T. \
Or for a given file of paths.",
usage= "\n\
General: analyzer.py [-h] [-n N_INDEX] [-T TERMINATION] [-f FILE] [-DOS] [-WF]\n\
DOS analysis: analyzer.py -DOS[0] [-n N_INDEX] [-T TERMINATION] [-f FILE] \n\
WF analysis: analyzer.py -WF [-n N_INDEX] [-T TERMINATION] [-f FILE]")
parser.add_argument("-n","--n_index",type=int,help="MXene n index (int) from the formula Mn+1XnT2.")
parser.add_argument("-T","--termination",type=str,default="",help="MXene termination (str) from the formula Mn+1XnT2. Specifyit with the index, i.e 'O2'. \
For pristine MXenes, don't use this or use None. Defaults to None.")
parser.add_argument("-f","--file",type=str,help="Read the paths to do analysis from a specified file.")
parser.add_argument("-DOS","--DOS",action="store_true",help="To analyze DOSCAR (PBE) files (from paths in file or for the given -n and -T).")
parser.add_argument("-DOS0","--DOS0",action="store_true",help="To analyze DOSCAR (PBE0) files (from paths in file or for the given -n and -T).")
parser.add_argument("-WF","--WF",action="store_true",help="To analyze LOCPOT files (from paths in file or for the given -n and -T).")
args = parser.parse_args()
n,T = args.n_index, args.termination # limit?
file,calc_dos,calc_dos0,calc_wf = args.file,args.DOS,args.DOS0,args.WF
if T == "None": T = ""
T, pristine = parseTermination(T)
if file is None and n is None: parser.error(f"Some arguments are needed. Choose -file or -n. For help, run python3 calculate.py -h.")
elif not calc_dos and not calc_dos0 and not calc_wf: parser.error(f"Analysis flag needed. Choose -DOS or -WF. For help, run python3 calculate.py -h.")
# Creating folders
if not n is None: path_folders = f"{home}/searcher_dos{n}/"
else: path_folders = f"{home}/searcher_dos/"
if not file is None: file_path = os.path.abspath(file)
try: os.mkdir(path_folders)
except FileExistsError: pass
os.chdir(path_folders)
# All possible combinations
if file is None:
if pristine: folders = mx_folders
else: folders = mxt_folders
for folder in folders:
try: os.mkdir(folder)
except FileExistsError: pass
if calc_dos:
target = "DOSCAR"
paths,data = searcher.search(target,n,T)
analyzeDOS(paths)
elif calc_dos0:
target = "DOSCAR0"
paths,data = searcher.search(target,n,T)
analyzeDOS(paths)
elif calc_wf:
target = "LOCPOT"
paths,data = searcher.search(target,n,T)
analyzeWF(paths)
else:
# if pristine: folders = mx_folders
# else: folders = mxt_folders
folders = mxt_folders
for folder in folders:
try: os.mkdir(folder)
except FileExistsError: pass
with open(file_path,"r") as inFile:
paths = inFile.readlines()
# procesing of file here
# extra = []
# for i,line in enumerate(paths):
# extra.append(line.strip().split()[1:])
# paths[i] = line.strip().split()[0] + "WF/LOCPOT"
if calc_dos or calc_dos0: analyzeDOS(paths)
elif calc_wf: analyzeWF(paths)