forked from Huaguiyuan/ModeMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractTotalEnergies.py
executable file
·52 lines (31 loc) · 1.6 KB
/
ExtractTotalEnergies.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
# ExtractTotalEnergies.py by J. M. Skelton
import csv;
import os;
import re;
# This script assumes that the single-point calculations on the modulated structures were run in numbered directories, e.g. 001, 002, ..., NNN.
# It expects each directory matching this pattern to contain a VASP OSSICAR file with a total energy.
dirRegex = re.compile("^\d+$");
oszicarEnergyRegex = re.compile("E0= (?P<e0>[+-]?\.\d+E[+-]?\d+)");
# Extract total energies from the OSZICAR files in each numbered directory.
data = [];
for entry in os.listdir("./"):
if os.path.isdir(entry) and dirRegex.match(entry):
totalEnergy = None;
inputReader = open(os.path.join(entry, "OSZICAR"), 'r');
for line in inputReader:
match = oszicarEnergyRegex.search(line);
if match:
# The calculations on the modulated structures should be single-point energy calculations.
# If multiple total energies are found in an OSZICAR file, this is probably a sign that something is wrong, so we print a warning.
if totalEnergy != None:
print("WARNING: Multiple E0 values found in \"{0}\"".format(os.path.join(entry, "OSZICAR")));
totalEnergy = float(match.group('e0'));
inputReader.close();
data.append((int(entry), totalEnergy));
# Write a CSV-format file listing the directory (moduation) numbers and extracted total energies.
outputWriter = open(r"ExtractTotalEnergies.csv", 'w');
outputWriterCSV = csv.writer(outputWriter, delimiter = ',', quotechar = '\"', quoting = csv.QUOTE_ALL);
outputWriterCSV.writerow(["Modulation #", "E0 [eV]"]);
for row in sorted(data):
outputWriterCSV.writerow(row);
outputWriter.close();