-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathShared.py
More file actions
77 lines (52 loc) · 2.44 KB
/
Shared.py
File metadata and controls
77 lines (52 loc) · 2.44 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
# Shared.py by J. M. Skelton
import os;
import re;
_OUTCAR_TSCFRegex = re.compile("LOOP\:\s+cpu time\s+\d+\.\d+\:\s+real time\s+(?P<t_scf>\d+\.\d+)");
_OUTCAR_TElapsedRegex = re.compile("Elapsed time \(sec\)\:\s+(?P<t_elapsed>\d+\.\d+)");
_OSZICAR_TotalEnergyRegex = re.compile("E0= (?P<total_energy>[+-]?\d*\.\d+E[+-]?\d+)");
def ParseOUTCAR(filePath, skipSCFCycles = 0):
numSCFSteps, tSCFAve, tElapsed = None, None, None;
scfTimes = [];
with open(filePath, 'r') as inputReader:
for line in inputReader:
match = _OUTCAR_TSCFRegex.search(line);
if match:
scfTimes.append(
float(match.group('t_scf'))
);
else:
match = _OUTCAR_TElapsedRegex.search(line);
if match:
tElapsed = float(match.group('t_elapsed'));
if skipSCFCycles > 0:
if len(scfTimes) > skipSCFCycles:
scfTimes = scfTimes[skipSCFCycles:];
else:
print("WARNING: _ParseOUTCAR(): Number of SCF steps {0} <= skipSCFCycles {1}".format(len(scfTimes), skipSCFCycles));
scfTimes = [];
if len(scfTimes) > 0:
numSCFSteps = len(scfTimes);
tSCFAve = sum(scfTimes) / numSCFSteps;
return (numSCFSteps, tSCFAve, tElapsed);
def ParseOSZICAR(filePath):
finalTotalEnergy = None;
with open(filePath, 'r') as inputReader:
for line in inputReader:
match = _OSZICAR_TotalEnergyRegex.search(line);
if match:
finalTotalEnergy = float(match.group('total_energy'));
return finalTotalEnergy;
def CollectResults(vaspDirectory, outcarSkipSCFCycles = 0):
numSCFSteps, tSCFAve, tElapsed = None, None, None;
outcarPath = os.path.join(vaspDirectory, "OUTCAR");
if os.path.isfile(outcarPath):
numSCFSteps, tSCFAve, tElapsed = ParseOUTCAR(outcarPath, skipSCFCycles = outcarSkipSCFCycles);
else:
print("WARNING: _CollectResults(): \"{0}\" not found".format(outcarPath));
finalTotalEnergy = None;
oszicarPath = os.path.join(vaspDirectory, "OSZICAR");
if os.path.isfile(oszicarPath):
finalTotalEnergy = ParseOSZICAR(oszicarPath);
else:
print("WARNING: _CollectResults(): \"{0}\" not found".format(oszicarPath));
return (numSCFSteps, tSCFAve, tElapsed, finalTotalEnergy);