-
Notifications
You must be signed in to change notification settings - Fork 0
/
DM_FHIaims_Analysis.py
247 lines (163 loc) · 5.91 KB
/
DM_FHIaims_Analysis.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env python
"""
A script to analyse FHI-aims simulations
@author Tomas Lazauskas, 2016
@web www.lazauskas.net
@email tomas.lazauskas[a]gmail.com
"""
import copy
import os
import sys
import numpy as np
from optparse import OptionParser
import source.Atoms as Atoms
import source.Fhiaims as FHIaims
import source.IO as IO
_fhiaimsGeometryFile = "geometry.in"
_fhiaimsOutFile = "fhiAims.out"
_outputDir = "output"
_topDir = "tops"
_uniqueDir = "unique"
def cmd_line_args():
"""
Handles command line arguments and options.
"""
usage = "usage: %prog "
parser = OptionParser(usage=usage)
parser.add_option("-s", "--single", dest="single", action="store_true", default=False,
help="Whether geometry relaxation was used.")
parser.disable_interspersed_args()
(options, args) = parser.parse_args()
return options, args
def getFileList(dirPath=None):
"""
Checks the directory for fhiaims output files with ending "FHIaims.out" and returns a directory list
"""
dirList = []
for root, _, files in os.walk("./"):
for fileName in files:
if fileName == _fhiaimsOutFile:
dirList.append(os.path.join(root[2:]))
return dirList
def generateStatistics(systemlist, unique=False):
"""
Generates statistics about the FHI-aims simulations
"""
noOfSystems = len(systemlist)
sumOfCores = 0
runTimes = np.zeros(noOfSystems, np.float64)
if not unique:
f = open("Stats.csv", "w")
else:
f = open("%s/Stats.csv" % (_uniqueDir), "w")
f.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % ("System",
"Ini_Energy", "Energy", "Hashkey", "Cores",
"Time", "Tot.Time", "H-L",
"VBM", "VBMOcc", "VBMSpinChannel",
"CBM", "CBMOcc", "CBMSpinChannel",
"SpinN", "SpinS", "SpinJ","Size"))
systemCnt = 0
for system in systemlist:
f.write("%s,%f,%f,%s,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n" % (system.name,
system.totalEnergy_initial, system.totalEnergy, system.hashkey,
system.noOfcores, system.runTime, system.noOfcores*system.runTime,
system.homo_lumo_gap, system.vbm, system.vbm_occ_num, system.vbm_spin_chan,
system.cbm, system.cbm_occ_num, system.cbm_spin_chan,
system.spin_N, system.spin_S, system.spin_J, float(system.NAtoms)))
runTimes[systemCnt] = system.runTime
sumOfCores += system.noOfcores
systemCnt += 1
f.close()
avgCores = sumOfCores / noOfSystems
print ("Avg. number of cores: ", avgCores)
print ("Avg. run time: ", np.average(runTimes))
print ("Min run time: ", np.min(runTimes))
print ("Max run time: ", np.max(runTimes))
print ("Stdev run time: ", np.std(runTimes))
def readFHIaimsSystems(fhiaimsDirs, single=False):
"""
Reads in the FHI-aims systems.
"""
systemsList = []
cnt = 0
totalCnt = len(fhiaimsDirs)
for dirName in fhiaimsDirs:
if (cnt % 10 == 0): print ("Reading %d/%d" % (cnt+1, totalCnt))
cwd = os.getcwd()
os.chdir(dirName)
#systemName = dirName[len(_outputDir)+1:-2].strip()
nameArray = (dirName.strip()).split("/")
nameArrayLen = len(nameArray)
systemName = nameArray[nameArrayLen-1]
success, error, system = FHIaims._readAimsStructure(_fhiaimsGeometryFile, _fhiaimsOutFile, relaxed=(not single))
if success:
system.name = systemName
systemsList.append(system)
else:
print ("Error reading in [%s]: %s" % (systemName, error))
os.chdir(cwd)
cnt += 1
return systemsList
def saveFiles(systemsList):
"""
Saves systems as xyz files
"""
cwd = os.getcwd()
os.system("rm -rf %s" % (_topDir))
os.system("rm -rf %s" % (_uniqueDir))
IO.checkDirectory(_uniqueDir, True)
IO.checkDirectory(_topDir, True)
os.chdir(_topDir)
systemListLen = len(systemsList)
uniquehashkeys = []
uniqueSystems = []
uniqueCnt = 0
for i in range(systemListLen):
nStr = "n%02d" % (systemsList[i].NAtoms)
#fileName = "%s_%03d_%s.xyz" % (nStr, i+1, systemsList[i].name)
fileName = "%s.xyz" % (systemsList[i].name)
success_, error_ = IO.writeXYZ(systemsList[i], fileName)
hashkeyRadius = Atoms.getRadius(systemsList[i]) + 1.0
hashkeyRadius = 2.8
#hashkeyRadius = 3.06
#hashkeyRadius = 2.6
cmdLine = "python ~/git/hkg/hkg.py %s %f" % (fileName, hashkeyRadius)
hashkey = os.popen(cmdLine).read().strip()
systemsList[i].hashkey = copy.deepcopy(hashkey)
# saving only uniques:
if not (hashkey in uniquehashkeys):
uniqueCnt += 1
uniquehashkeys.append(hashkey)
uniqueSystems.append(systemsList[i])
fileName2 = "%s_%03d_%s.xyz" % (nStr, uniqueCnt, systemsList[i].name)
os.system("cp %s ../%s/%s" % (fileName, _uniqueDir, fileName2))
os.chdir(cwd)
return uniqueSystems
def sortSystems(systemsList):
"""
Sorts systems according to their energy
"""
systemListLen = len(systemsList)
for i in range(systemListLen):
for j in range(systemListLen):
if systemsList[i].totalEnergy < systemsList[j].totalEnergy:
tempSystem = copy.deepcopy(systemsList[i])
systemsList[i] = copy.deepcopy(systemsList[j])
systemsList[j] = copy.deepcopy(tempSystem)
if __name__ == "__main__":
# reading the command line arguments and options
options, _ = cmd_line_args()
# looks for FHI-aims simulations in the output directory
fhiaimsDirs = getFileList()
# reads in the FHI-aims systems
systems = readFHIaimsSystems(fhiaimsDirs, options.single)
# sort the systems according to energy
sortSystems(systems)
# save files
uniqueSystems = saveFiles(systems)
sortSystems(uniqueSystems)
# generate statistics
generateStatistics(systems)
# generating unique statistics
generateStatistics(uniqueSystems, True)
print ("Finished.")